Skip to content

Commit

Permalink
Merge pull request #31 from hyperdivision/test-runner
Browse files Browse the repository at this point in the history
Initial test runner idea
  • Loading branch information
bcomnes authored Sep 2, 2019
2 parents 893f57e + ac550ad commit 9e68695
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 5 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
96 changes: 96 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env node

const resolvePath = require('path').resolve
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 = subarg(args, {
'--': true,
default: {
ignore: ['node_modules/**', '.git/**']
},
alias: {
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()

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: opts.ignore
})

if (!Array.isArray(files)) {
throw new TypeError('unknown error: glob.sync did not return an array or throw. Please report this.')
}

files.forEach(function (file) {
fileSet.add(resolvePath(cwd, file))
})
})

if (Array.from(fileSet).length < 1) {
console.error('No tests found')
process.exit(1)
}

const browserifyArgs = opts['--']
const tapeRunOpts = opts['tape-run']

let bundler
if (browserifyArgs && Array.isArray(browserifyArgs)) {
// CLI args for browserify
bundler = fromArgs(browserifyArgs, {
entries: Array.from(fileSet)
})
} else {
// just assume JS only options
bundler = browserify(Array.from(fileSet))
}

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)
process.exit(1)
}
})
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
"bugs": {
"url": "https://github.com/hyperdivision/vhs-tape/issues"
},
"bin": "bin.js",
"dependencies": {
"browserify": "^16.5.0",
"events.once": "^2.0.2",
"fast-on-load": "^1.1.0",
"tape": "^4.6.2"
"glob": "^7.1.4",
"pump": "^3.0.0",
"subarg": "^1.0.0",
"tape": "^4.6.2",
"tape-run": "^6.0.1"
},
"devDependencies": {
"browserify": "^16.0.0",
"budo": "^11.6.2",
"dependency-check": "^3.0.0",
"hui": "^1.2.5",
"npm-run-all": "^4.0.0",
"standard": "^12.0.1",
"tape-run": "^6.0.0"
"standard": "^12.0.1"
},
"homepage": "https://github.com/hyperdivision/vhs-tape#readme",
"keywords": [
Expand All @@ -37,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 9e68695

Please sign in to comment.