-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (38 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env node
'use strict'
const execa = require('execa')
const split2 = require('split2')
const Tape = require('./reporters/tape')
const Tree = require('./reporters/tree')
const bin = require('pkg-bin')
const pkg = require('./package.json')
const yargs = require('yargs')
.usage(`USAGE: ${bin(pkg)} <script>`)
.default('reporter', 'tree')
.alias('r', 'reporter')
.choices('r', ['tape', 'tree', 'pass'])
.help('h')
.alias('h', 'help')
.version()
.alias('v', 'version')
.showHelpOnFail(false, 'Specify --help for available options')
const args = yargs.argv
if (!args._.length) {
process.stderr.write('Missing argument: <script>\n')
process.exit()
}
const cp = execa('node', ['--trace-inlining'].concat(args._))
pipe(cp.stdout, args.reporter).pipe(process.stdout)
cp.stderr.pipe(process.stderr)
function pipe(from, reporter_name) {
switch (reporter_name) {
case 'tape':
return from.pipe(split2()).pipe(new Tape())
case 'tree':
return from.pipe(split2()).pipe(new Tree())
case 'pass':
return from
default:
break
}
}