Skip to content

Commit 11b5d09

Browse files
committed
cli-options
1 parent fc3fd51 commit 11b5d09

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ or in `package.json`
2323
}
2424
```
2525

26+
### CLI Options
27+
28+
```
29+
--no-ansi Disable ANSI formatting
30+
--no-progress Disable progress output during tests
31+
```
32+
2633
## Example
2734

2835
![summary](example/clip.gif)
29-

example/run-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ var exec = require('child_process').exec
33
var tapeCmd = require.resolve('../node_modules/task-tape/bin/task-tape')
44
var tapCmd = require.resolve('../bin/cmd')
55
var tests = require.resolve('./test')
6+
var extra = '--no-ansi --no-progress'
67

7-
exec([tapeCmd, tests, '|', tapCmd].join(' ')).stdout.pipe(process.stdout)
8-
8+
exec([tapeCmd, tests, '|', tapCmd, extra].join(' ')).stdout.pipe(process.stdout)

index.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1-
var showAnsi = false
2-
var showProgress = false
3-
41
var through = require('through2')
52
var duplexer = require('duplexer2')
63
var parser = require('tap-out')
7-
var format = showAnsi ? require('ansi-escape') : require('./no-ansi')
84
var symbols = require('figures')
95
var prettyMs = require('pretty-ms')
6+
var parseOpts = require('minimist')
7+
8+
var opts = parseOpts(process.argv.slice(2), {
9+
boolean: true,
10+
alias: {
11+
ansi: 'a',
12+
progress: 'p',
13+
},
14+
default: {
15+
ansi: true,
16+
progress: true,
17+
},
18+
})
19+
20+
var showAnsi = opts.ansi
21+
var showProgress = opts.progress
22+
23+
var format = showAnsi ? require('ansi-escape') : require('./lib/no-ansi')
24+
1025
var LF = '\n'
1126

1227
module.exports = function () {
@@ -70,6 +85,9 @@ module.exports = function () {
7085
test.end = new Date()
7186
test.duration = test.end - test.start
7287
duration += test.duration
88+
if (showAnsi && !showProgress) {
89+
output.push(LF)
90+
}
7391
if (test.fail) {
7492
output.push(format.cha.red.eraseLine.escape(symbols.cross + ' ' + test.title))
7593
} else {

no-ansi.js renamed to lib/no-ansi.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
/** Generates a API matching ansi-escape
2+
* but without the escape codes */
3+
14
var LF = '\n'
25

36
var escapes = require('ansi-escape/lib/escapes')
47
var colors = require('ansi-escape/lib/colors')
58

69
var escape = function (x) { return x }
10+
escape.escape = escape;
711

812
Object.keys(colors).forEach(function (key) {
913
escape[key] = escape
@@ -13,6 +17,8 @@ Object.keys(escapes).forEach(function (key) {
1317
escape[key] = escape
1418
})
1519

16-
escape.eraseLine.escape = function (x) { return x + LF}
20+
escape.eraseLine = {
21+
escape: function (x) { return LF + x }
22+
}
1723

1824
module.exports = escape

0 commit comments

Comments
 (0)