Skip to content

Commit

Permalink
Don't require argv file list if specified in taprc
Browse files Browse the repository at this point in the history
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
  • Loading branch information
isaacs committed Apr 13, 2018
1 parent fe8158e commit 3346fc1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bin/run.js
Expand Up @@ -52,11 +52,6 @@ const coverageServices = [
const main = _ => {
const args = process.argv.slice(2)

if (!args.length && isTTY) {
console.error(usage())
process.exit(1)
}

// set default args
const defaults = constructDefaultArgs()

Expand Down Expand Up @@ -86,6 +81,11 @@ const main = _ => {

options.files = globFiles(options.files)

if (!args.length && !options.files.length && isTTY) {
console.error(usage())
process.exit(1)
}

// this is only testable by escaping from the covered environment
/* istanbul ignore next */
if ((options.coverageReport || options.checkCoverage) &&
Expand Down
17 changes: 17 additions & 0 deletions tap-snapshots/test-run.js-TAP.test.js
Expand Up @@ -18,6 +18,23 @@ ok 1 - test/cli-tests/ok.js # {time}
`

exports[`test/run.js TAP rc file specifies test files > expected stdout 1`] = `
TAP version 13
# Subtest: test/cli-tests/via-rcfile.js
# Subtest: child
ok 1 - this is fine
1..1
ok 1 - child # {time}
1..1
# {time}
ok 1 - test/cli-tests/via-rcfile.js # {time}
1..1
# {time}
`

exports[`test/run.js TAP stdin with file > undefined 1`] = `
TAP version 13
ok 1 - test/cli-tests/foo.test.js # {time} {
Expand Down
22 changes: 22 additions & 0 deletions test/run.js
Expand Up @@ -251,6 +251,28 @@ jobs: 3
t.end()
})

t.test('rc file specifies test files', t => {
const testfile = tmpfile(t, 'via-rcfile.js', `
'use strict'
require(${tap}).test('child', t => {
t.pass('this is fine')
t.end()
})
`)

const rc = tmpfile(t, 'taprc', `
files: [ ${testfile} ]
reporter: tap
`)

const c = run([], { env: { TAP_RCFILE: rc }}, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(clean(o), 'expected stdout')
t.equal(e, '')
t.end()
})
})

t.test('stdin', t => {
const tapcode = 'TAP version 13\n1..1\nok\n'

Expand Down

0 comments on commit 3346fc1

Please sign in to comment.