Skip to content

Commit 9e68695

Browse files
authored
Merge pull request #31 from hyperdivision/test-runner
Initial test runner idea
2 parents 893f57e + ac550ad commit 9e68695

File tree

3 files changed

+128
-5
lines changed

3 files changed

+128
-5
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: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env node
2+
3+
const resolvePath = require('path').resolve
4+
const subarg = require('subarg')
5+
const glob = require('glob')
6+
const browserify = require('browserify')
7+
const fromArgs = require('browserify/bin/args')
8+
const run = require('tape-run')
9+
const pump = require('pump')
10+
const pkg = require('./package.json')
11+
12+
let args = process.argv.slice(2)
13+
14+
const opts = subarg(args, {
15+
'--': true,
16+
default: {
17+
ignore: ['node_modules/**', '.git/**']
18+
},
19+
alias: {
20+
version: ['v'],
21+
help: ['h']
22+
}
23+
})
24+
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+
47+
const cwd = process.cwd()
48+
49+
const fileSet = new Set()
50+
51+
opts._.forEach(function (arg) {
52+
// If glob does not match, `files` will be an empty array.
53+
// Note: `glob.sync` may throw an error and crash the node process.
54+
var files = glob.sync(arg, {
55+
ignore: opts.ignore
56+
})
57+
58+
if (!Array.isArray(files)) {
59+
throw new TypeError('unknown error: glob.sync did not return an array or throw. Please report this.')
60+
}
61+
62+
files.forEach(function (file) {
63+
fileSet.add(resolvePath(cwd, file))
64+
})
65+
})
66+
67+
if (Array.from(fileSet).length < 1) {
68+
console.error('No tests found')
69+
process.exit(1)
70+
}
71+
72+
const browserifyArgs = opts['--']
73+
const tapeRunOpts = opts['tape-run']
74+
75+
let bundler
76+
if (browserifyArgs && Array.isArray(browserifyArgs)) {
77+
// CLI args for browserify
78+
bundler = fromArgs(browserifyArgs, {
79+
entries: Array.from(fileSet)
80+
})
81+
} else {
82+
// just assume JS only options
83+
bundler = browserify(Array.from(fileSet))
84+
}
85+
86+
const tapeRun = run(tapeRunOpts)
87+
tapeRun.on('results', (results) => {
88+
process.exit(Number(!results.ok))
89+
})
90+
91+
pump(bundler.bundle(), tapeRun, process.stdout, (err) => {
92+
if (err) {
93+
console.error(err)
94+
process.exit(1)
95+
}
96+
})

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
"bugs": {
77
"url": "https://github.com/hyperdivision/vhs-tape/issues"
88
},
9+
"bin": "bin.js",
910
"dependencies": {
11+
"browserify": "^16.5.0",
1012
"events.once": "^2.0.2",
1113
"fast-on-load": "^1.1.0",
12-
"tape": "^4.6.2"
14+
"glob": "^7.1.4",
15+
"pump": "^3.0.0",
16+
"subarg": "^1.0.0",
17+
"tape": "^4.6.2",
18+
"tape-run": "^6.0.1"
1319
},
1420
"devDependencies": {
15-
"browserify": "^16.0.0",
1621
"budo": "^11.6.2",
1722
"dependency-check": "^3.0.0",
1823
"hui": "^1.2.5",
1924
"npm-run-all": "^4.0.0",
20-
"standard": "^12.0.1",
21-
"tape-run": "^6.0.0"
25+
"standard": "^12.0.1"
2226
},
2327
"homepage": "https://github.com/hyperdivision/vhs-tape#readme",
2428
"keywords": [
@@ -37,7 +41,7 @@
3741
"scripts": {
3842
"test": "run-s test:*",
3943
"test:deps": "dependency-check package.json --missing --unused --no-dev -i tape-run",
40-
"test:example": "browserify example.js --debug | tape-run",
44+
"test:example": "./bin.js example.js",
4145
"test:lint": "standard",
4246
"start": "budo --live --open example.js"
4347
}

0 commit comments

Comments
 (0)