Skip to content

Commit

Permalink
Initial test runner idea
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Aug 30, 2019
1 parent 893f57e commit 0cf3a8a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
69 changes: 69 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env node

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

let args = process.argv.slice(2)

const opts = parseOpts(args, {
'--': true,
alias: {
wait: 'w',
port: 'p',
static: 's',
browser: 'b',
render: 'r',
'keep-open': ['k', 'keepOpen'],
node: ['n', 'node-integration', 'nodeIntegration']
}
})

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: ['node_modules/**', '.git/**']
})

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))
})
})

const browserifyArgs = opts['--']

delete opts['--']
delete opts._

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(opts)
tapeRun.on('results', (results) => {
process.exit(Number(!results.ok))
})

pump(bundler.bundle(), tapeRun, process.stdout, (err) => {
if (err) console.error(err)
})
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
"bugs": {
"url": "https://github.com/hyperdivision/vhs-tape/issues"
},
"bin": "bin.js",
"dependencies": {
"events.once": "^2.0.2",
"fast-on-load": "^1.1.0",
"tape": "^4.6.2"
"glob": "^7.1.4",
"minimist": "^1.2.0",
"pump": "^3.0.0",
"resolve": "^1.12.0",
"tape": "^4.6.2",
"tape-run": "^6.0.1",
"browserify": "^16.5.0"
},
"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 Down

0 comments on commit 0cf3a8a

Please sign in to comment.