Spawn and merge tap-producing tests. Accepts JavaScript entries (spawns node by default), package.json
files or directories containing a package.json
(spawns npm run test
by default). Can run multiple test scripts per package, with glob pattern support.
Let's say we have a monorepo with a bunch of packages with self-contained tests, as well as functional tests at the root of the monorepo:
test.js
require('tape')('monorepo', function (t) {
t.ok(true, 'beep')
t.end()
})
packages/has-window/index.js
module.exports = function hasWindow () {
return typeof window !== 'undefined'
}
packages/has-window/test.js
const test = require('tape')
, hasWindow = require('.')
test('return value', function (t) {
const expected = !!process.browser
t.is(hasWindow(), expected, 'value is ' + expected)
t.end()
})
packages/has-window/package.json
{
"name": "has-window",
"scripts": {
"test:node": "node test.js",
"test:browser": "browserify test.js | smokestack",
"test": "multi-tap -r test:*"
}
}
With multi-tap
, we can run all three test suites:
> multi-tap test-*.js packages/*
TAP version 13
# monorepo
ok 1 beep
# has-window › browser › return value
ok 2 value is true
# has-window › node › return value
ok 3 value is false
1..3
# tests 3
# pass 3
# ok
Options
--run -r npm script(s) to run ("test")
--ignore-missing -i don't fail on missing npm scripts (false)
--basedir -b resolve patterns from this path (cwd)
--cwd -c working directory for js entries (cwd)
--binary --bin command for js entries ("node")
--stderr -e inherit standard error (false)
--fail-fast -f if a test fails, cancel subsequent tests (false)
--version -v print multi-tap version and exit
Spawn npm test
for packages/one
and packages/two
, pipe the merged output to the tap-spec reporter:
multi-tap packages/{one,two} | tap-spec
Spawn beep <file>
in working directory /tmp
for each file in test
:
multi-tap --bin beep --cwd /tmp test/*.js
Spawn two npm scripts in the current directory:
multi-tap -r test-node -r test-chrome
Short options can be joined together. This runs the test suites of modules/middleware-*
, fast failing, showing stderr, and ignoring packages without a test
script:
multi-tap middleware-* -efib modules | faucet
const multi = require('multi-tap')
multi(['modules/*'])
.pipe(process.stdout)
These options are available for both the CLI and API:
- basedir: resolve patterns from this path, defaults to
process.cwd()
- stderr: inherit standard error (false)
- failFast: if a test fails, cancel subsequent tests (false)
Additional options that only apply to packages:
- run: npm script(s) to run ("test")
- ignoreMissing: don't fail on missing npm scripts. Adds a passing assertion with a
skip
directive. Default behavior is to add a failing assertion with aTODO
directive.
Additional options that only apply to js entries:
- cwd: working directory, defaults to
process.cwd()
- binary: command to run, defaults to
node
Unix note: if your shell performs glob expansion but you want to resolve glob patterns from basedir
, quote or escape the pattern(s) so that multi-tap
performs the glob expansion instead:
# a.js, b.js
multi-tap --basedir lib *.js
# lib/a.js, lib/b.js
multi-tap --basedir lib \*.js
With npm do:
npm install multi-tap
- Run tests in series
- Rename
--runner/-r
to--binary/--bin
- Add
--run/-r
to specify npm script(s) with glob support - Check if npm script(s) are defined before spawning
- Add
--fail-fast/-f
option - Prefix TAP comments with package name and npm script
MIT © ironSource.