Skip to content

Commit 3346fc1

Browse files
committed
Don't require argv file list if specified in taprc
Previously, checking for specified test files was done by looking at argv.length. So, if a `files` config was specified in taprc, it would work if a `--` was passed in on the command line, but otherwise would dump the usage message one sees when running `tap` with no arguments (or would wait for stdin if not run on a TTY). Fix #438
1 parent fe8158e commit 3346fc1

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

bin/run.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ const coverageServices = [
5252
const main = _ => {
5353
const args = process.argv.slice(2)
5454

55-
if (!args.length && isTTY) {
56-
console.error(usage())
57-
process.exit(1)
58-
}
59-
6055
// set default args
6156
const defaults = constructDefaultArgs()
6257

@@ -86,6 +81,11 @@ const main = _ => {
8681

8782
options.files = globFiles(options.files)
8883

84+
if (!args.length && !options.files.length && isTTY) {
85+
console.error(usage())
86+
process.exit(1)
87+
}
88+
8989
// this is only testable by escaping from the covered environment
9090
/* istanbul ignore next */
9191
if ((options.coverageReport || options.checkCoverage) &&

tap-snapshots/test-run.js-TAP.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ ok 1 - test/cli-tests/ok.js # {time}
1818
1919
`
2020

21+
exports[`test/run.js TAP rc file specifies test files > expected stdout 1`] = `
22+
TAP version 13
23+
# Subtest: test/cli-tests/via-rcfile.js
24+
# Subtest: child
25+
ok 1 - this is fine
26+
1..1
27+
ok 1 - child # {time}
28+
29+
1..1
30+
# {time}
31+
ok 1 - test/cli-tests/via-rcfile.js # {time}
32+
33+
1..1
34+
# {time}
35+
36+
`
37+
2138
exports[`test/run.js TAP stdin with file > undefined 1`] = `
2239
TAP version 13
2340
ok 1 - test/cli-tests/foo.test.js # {time} {

test/run.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,28 @@ jobs: 3
251251
t.end()
252252
})
253253

254+
t.test('rc file specifies test files', t => {
255+
const testfile = tmpfile(t, 'via-rcfile.js', `
256+
'use strict'
257+
require(${tap}).test('child', t => {
258+
t.pass('this is fine')
259+
t.end()
260+
})
261+
`)
262+
263+
const rc = tmpfile(t, 'taprc', `
264+
files: [ ${testfile} ]
265+
reporter: tap
266+
`)
267+
268+
const c = run([], { env: { TAP_RCFILE: rc }}, (er, o, e) => {
269+
t.equal(er, null)
270+
t.matchSnapshot(clean(o), 'expected stdout')
271+
t.equal(e, '')
272+
t.end()
273+
})
274+
})
275+
254276
t.test('stdin', t => {
255277
const tapcode = 'TAP version 13\n1..1\nok\n'
256278

0 commit comments

Comments
 (0)