Skip to content

Commit

Permalink
Finish up test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Sep 2, 2019
1 parent 0cf3a8a commit ac550ad
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 20 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,29 @@ Sumulate typing to an `elementOrQuerySelector` by repeatedly setting the value a

Shortcut to use [`'events.once'`](https://github.com/davidmarkclements/events.once#readme), which is useful for catching events as promises.


## CLI

VSH-Tape ships with a headless test runner that utilizes [browserify](https://github.com/browserify/browserify) and [tape-run](https://github.com/juliangruber/tape-run).

Pass a [glob](https://github.com/isaacs/node-glob) string, or series of glob strings as arguments to locate test files. [Browserify flags](https://github.com/browserify/browserify#usage) are passed at the end after the `--` and tape-run opts are passed as a [`subarg`]() under the `--tape-run` flag. **Note**: tape-run opts are not aliased. Refer to the [tape-run README](https://github.com/juliangruber/tape-run#runopts) to see the available options.

If no file glob is passed, the default `'**/*.vhs.js'` is used. Ensure that you quote your file globs so that your CLI doesn't try to perform a depth limited globbing search instead of the built in globber.

```
Usage:
vhs-tape '**/*.vhs.js' [opts] --tape-run [tape-run opts] -- [browserify opts]
Options:
--help, -h show help message
--version show version
--tape-run tape-run subargs
--ignore file globs to ignore default: node_modules/** .git/**
-- [browserify options] raw flags to pass to browserify
```

WIP: Interactive test runner

## FAQ

### How do I run vhs-tests?
Expand Down
57 changes: 42 additions & 15 deletions bin.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
#!/usr/bin/env node

const resolvePath = require('path').resolve
const parseOpts = require('minimist')
const subarg = require('subarg')
const glob = require('glob')
const browserify = require('browserify')
const fromArgs = require('browserify/bin/args')
const run = require('tape-run')
const pump = require('pump')
const pkg = require('./package.json')

let args = process.argv.slice(2)

const opts = parseOpts(args, {
const opts = subarg(args, {
'--': true,
default: {
ignore: ['node_modules/**', '.git/**']
},
alias: {
wait: 'w',
port: 'p',
static: 's',
browser: 'b',
render: 'r',
'keep-open': ['k', 'keepOpen'],
node: ['n', 'node-integration', 'nodeIntegration']
version: ['v'],
help: ['h']
}
})

if (opts.help) {
console.log(`Usage:
vhs-tape '**/*.vhs.js' [opts] --tape-run [tape-run opts] -- [browserify opts]
Options:
--help, -h show help message
--version show version
--tape-run tape-run subargs
--ignore file globs to ignore default: 'node_modules/** .git/**'
-- [browserify options] raw flags to pass to browserify`)
process.exit(0)
}

if (opts.version) {
console.log(`vhs-tape v${pkg.version}`)
process.exit(0)
}

if (opts._.length < 1) {
opts._.push('**/*.vhs.js')
}

const cwd = process.cwd()

const fileSet = new Set()
Expand All @@ -31,7 +52,7 @@ opts._.forEach(function (arg) {
// If glob does not match, `files` will be an empty array.
// Note: `glob.sync` may throw an error and crash the node process.
var files = glob.sync(arg, {
ignore: ['node_modules/**', '.git/**']
ignore: opts.ignore
})

if (!Array.isArray(files)) {
Expand All @@ -43,10 +64,13 @@ opts._.forEach(function (arg) {
})
})

const browserifyArgs = opts['--']
if (Array.from(fileSet).length < 1) {
console.error('No tests found')
process.exit(1)
}

delete opts['--']
delete opts._
const browserifyArgs = opts['--']
const tapeRunOpts = opts['tape-run']

let bundler
if (browserifyArgs && Array.isArray(browserifyArgs)) {
Expand All @@ -59,11 +83,14 @@ if (browserifyArgs && Array.isArray(browserifyArgs)) {
bundler = browserify(Array.from(fileSet))
}

const tapeRun = run(opts)
const tapeRun = run(tapeRunOpts)
tapeRun.on('results', (results) => {
process.exit(Number(!results.ok))
})

pump(bundler.bundle(), tapeRun, process.stdout, (err) => {
if (err) console.error(err)
if (err) {
console.error(err)
process.exit(1)
}
})
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
},
"bin": "bin.js",
"dependencies": {
"browserify": "^16.5.0",
"events.once": "^2.0.2",
"fast-on-load": "^1.1.0",
"glob": "^7.1.4",
"minimist": "^1.2.0",
"pump": "^3.0.0",
"resolve": "^1.12.0",
"subarg": "^1.0.0",
"tape": "^4.6.2",
"tape-run": "^6.0.1",
"browserify": "^16.5.0"
"tape-run": "^6.0.1"
},
"devDependencies": {
"budo": "^11.6.2",
Expand All @@ -42,7 +41,7 @@
"scripts": {
"test": "run-s test:*",
"test:deps": "dependency-check package.json --missing --unused --no-dev -i tape-run",
"test:example": "browserify example.js --debug | tape-run",
"test:example": "./bin.js example.js",
"test:lint": "standard",
"start": "budo --live --open example.js"
}
Expand Down

0 comments on commit ac550ad

Please sign in to comment.