Skip to content

Commit ac550ad

Browse files
committed
Finish up test runner
1 parent 0cf3a8a commit ac550ad

File tree

3 files changed

+69
-20
lines changed

3 files changed

+69
-20
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,29 @@ Sumulate typing to an `elementOrQuerySelector` by repeatedly setting the value a
202202

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

205+
206+
## CLI
207+
208+
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).
209+
210+
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.
211+
212+
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.
213+
214+
```
215+
Usage:
216+
vhs-tape '**/*.vhs.js' [opts] --tape-run [tape-run opts] -- [browserify opts]
217+
218+
Options:
219+
--help, -h show help message
220+
--version show version
221+
--tape-run tape-run subargs
222+
--ignore file globs to ignore default: node_modules/** .git/**
223+
-- [browserify options] raw flags to pass to browserify
224+
```
225+
226+
WIP: Interactive test runner
227+
205228
## FAQ
206229

207230
### How do I run vhs-tests?

bin.js

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
11
#!/usr/bin/env node
22

33
const resolvePath = require('path').resolve
4-
const parseOpts = require('minimist')
4+
const subarg = require('subarg')
55
const glob = require('glob')
66
const browserify = require('browserify')
77
const fromArgs = require('browserify/bin/args')
88
const run = require('tape-run')
99
const pump = require('pump')
10+
const pkg = require('./package.json')
1011

1112
let args = process.argv.slice(2)
1213

13-
const opts = parseOpts(args, {
14+
const opts = subarg(args, {
1415
'--': true,
16+
default: {
17+
ignore: ['node_modules/**', '.git/**']
18+
},
1519
alias: {
16-
wait: 'w',
17-
port: 'p',
18-
static: 's',
19-
browser: 'b',
20-
render: 'r',
21-
'keep-open': ['k', 'keepOpen'],
22-
node: ['n', 'node-integration', 'nodeIntegration']
20+
version: ['v'],
21+
help: ['h']
2322
}
2423
})
2524

25+
if (opts.help) {
26+
console.log(`Usage:
27+
vhs-tape '**/*.vhs.js' [opts] --tape-run [tape-run opts] -- [browserify opts]
28+
29+
Options:
30+
--help, -h show help message
31+
--version show version
32+
--tape-run tape-run subargs
33+
--ignore file globs to ignore default: 'node_modules/** .git/**'
34+
-- [browserify options] raw flags to pass to browserify`)
35+
process.exit(0)
36+
}
37+
38+
if (opts.version) {
39+
console.log(`vhs-tape v${pkg.version}`)
40+
process.exit(0)
41+
}
42+
43+
if (opts._.length < 1) {
44+
opts._.push('**/*.vhs.js')
45+
}
46+
2647
const cwd = process.cwd()
2748

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

3758
if (!Array.isArray(files)) {
@@ -43,10 +64,13 @@ opts._.forEach(function (arg) {
4364
})
4465
})
4566

46-
const browserifyArgs = opts['--']
67+
if (Array.from(fileSet).length < 1) {
68+
console.error('No tests found')
69+
process.exit(1)
70+
}
4771

48-
delete opts['--']
49-
delete opts._
72+
const browserifyArgs = opts['--']
73+
const tapeRunOpts = opts['tape-run']
5074

5175
let bundler
5276
if (browserifyArgs && Array.isArray(browserifyArgs)) {
@@ -59,11 +83,14 @@ if (browserifyArgs && Array.isArray(browserifyArgs)) {
5983
bundler = browserify(Array.from(fileSet))
6084
}
6185

62-
const tapeRun = run(opts)
86+
const tapeRun = run(tapeRunOpts)
6387
tapeRun.on('results', (results) => {
6488
process.exit(Number(!results.ok))
6589
})
6690

6791
pump(bundler.bundle(), tapeRun, process.stdout, (err) => {
68-
if (err) console.error(err)
92+
if (err) {
93+
console.error(err)
94+
process.exit(1)
95+
}
6996
})

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
},
99
"bin": "bin.js",
1010
"dependencies": {
11+
"browserify": "^16.5.0",
1112
"events.once": "^2.0.2",
1213
"fast-on-load": "^1.1.0",
1314
"glob": "^7.1.4",
14-
"minimist": "^1.2.0",
1515
"pump": "^3.0.0",
16-
"resolve": "^1.12.0",
16+
"subarg": "^1.0.0",
1717
"tape": "^4.6.2",
18-
"tape-run": "^6.0.1",
19-
"browserify": "^16.5.0"
18+
"tape-run": "^6.0.1"
2019
},
2120
"devDependencies": {
2221
"budo": "^11.6.2",
@@ -42,7 +41,7 @@
4241
"scripts": {
4342
"test": "run-s test:*",
4443
"test:deps": "dependency-check package.json --missing --unused --no-dev -i tape-run",
45-
"test:example": "browserify example.js --debug | tape-run",
44+
"test:example": "./bin.js example.js",
4645
"test:lint": "standard",
4746
"start": "budo --live --open example.js"
4847
}

0 commit comments

Comments
 (0)