[Pkg-javascript-commits] [node-tap] 95/186: Tests bringing bin/run.js up to 100%
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 1 16:40:48 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-tap.
commit 2b53362bb9d423cc8c0eb7476408013acef4d27f
Author: isaacs <i at izs.me>
Date: Sat Nov 18 20:07:48 2017 -0800
Tests bringing bin/run.js up to 100%
---
bin/run.js | 44 ++++----
lib/test.js | 2 +-
tap-snapshots/test-run.js-TAP.test.js | 186 ++++++++++++++++++++++------------
test/clean-stacks.js | 3 +-
test/run.js | 117 +++++++++++++++++++--
5 files changed, 254 insertions(+), 98 deletions(-)
diff --git a/bin/run.js b/bin/run.js
index a1bacb1..d3a47e8 100755
--- a/bin/run.js
+++ b/bin/run.js
@@ -179,6 +179,7 @@ const parseArgs = (args, options) => {
// If we're running under Travis-CI with a Coveralls.io token,
// then it's a safe bet that we ought to output coverage.
for (let i = 0; i < coverageServices.length && !options.pipeToService; i++) {
+ /* istanbul ignore next */
if (process.env[coverageServices[i].env])
options.pipeToService = true
}
@@ -614,7 +615,9 @@ const stdinOnly = options => {
const readSaveFile = options => {
if (options.saveFile)
try {
- return fs.readFileSync(options.saveFile, 'utf8').trim().split('\n')
+ const s = fs.readFileSync(options.saveFile, 'utf8').trim()
+ if (s)
+ return s.split('\n')
} catch (er) {}
return null
@@ -637,6 +640,7 @@ const saveFails = (options, tap) => {
const save = () => {
fails = fails.reduce((set, f) => {
+ f = f.replace(/\\/g, '/')
if (set.indexOf(f) === -1)
set.push(f)
return set
@@ -663,25 +667,20 @@ const saveFails = (options, tap) => {
}
const filterFiles = (files, saved, parallelOk) =>
- files.filter(file => {
- if (path.basename(file) === 'tap-parallel-ok')
- parallelOk[path.resolve(path.dirname(file))] = true
- else if (path.basename(file) === 'tap-parallel-not-ok')
+ files.filter(file =>
+ path.basename(file) === 'tap-parallel-ok' ?
+ ((parallelOk[path.resolve(path.dirname(file))] = true), false)
+ : path.basename(file) === 'tap-parallel-not-ok' ?
parallelOk[path.resolve(path.dirname(file))] = false
- else
- return saved === null || onSavedList(saved, file)
- })
+ : onSavedList(saved, file)
+ )
// check if the file is on the list, or if it's a parent dir of
// any items that are on the list.
const onSavedList = (saved, file) =>
!saved || !saved.length ? true
- : file === path.dirname(file) ? false
: saved.indexOf(file) !== -1 ? true
- : onSavedList(saved.filter(
- f => f !== path.dirname(f)).map(
- f => path.dirname(f)
- ), file)
+ : saved.some(f => f.indexOf(file + '/') === 0)
const isParallelOk = (parallelOk, file) => {
const dir = path.resolve(path.dirname(file))
@@ -716,18 +715,19 @@ const runAllFiles = (options, saved, tap) => {
opt.timeout = options.timeout * 1000
opt.file = file
- if (options.jobs > 1)
- opt.buffered = isParallelOk(parallelOk, file) !== false
-
- if (file.match(/\.js$/)) {
- const args = options.nodeArgs.concat(file).concat(options.testArgs)
- tap.spawn(node, args, opt, file)
- } else if (st.isDirectory()) {
+ if (st.isDirectory()) {
const dir = filterFiles(fs.readdirSync(file).map(f =>
file + '/' + f), saved, parallelOk)
options.files.push.apply(options.files, dir)
- } else if (isexe.sync(options.files[i]))
- tap.spawn(options.files[i], options.testArgs, opt, file)
+ } else {
+ if (options.jobs > 1)
+ opt.buffered = isParallelOk(parallelOk, file) !== false
+ if (file.match(/\.js$/)) {
+ const args = options.nodeArgs.concat(file).concat(options.testArgs)
+ tap.spawn(node, args, opt, file)
+ } else if (isexe.sync(options.files[i]))
+ tap.spawn(options.files[i], options.testArgs, opt, file)
+ }
}
if (doStdin)
diff --git a/lib/test.js b/lib/test.js
index f86508e..a4bee75 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -38,6 +38,7 @@ const ownOr = require('own-or')
const ownOrEnv = require('own-or-env')
const Promise = require('bluebird')
const bindObj = require('bind-obj-methods')
+const cwd = process.cwd()
// A sigil object for implicit end() calls that should not
// trigger an error if the user then calls t.end()
@@ -960,7 +961,6 @@ class Test extends Base {
}
get fullname () {
- const cwd = process.cwd()
const main = process.argv[1] || ''
return (this.parent ? this.parent.fullname
: main.indexOf(cwd) === 0 ? main.substr(cwd.length + 1)
diff --git a/tap-snapshots/test-run.js-TAP.test.js b/tap-snapshots/test-run.js-TAP.test.js
index 78e09a4..de1d2e4 100644
--- a/tap-snapshots/test-run.js-TAP.test.js
+++ b/tap-snapshots/test-run.js-TAP.test.js
@@ -34,7 +34,7 @@ ok 2 - /dev/stdin # {time} {
`
-exports[`run.js TAP coverage --100 pass > 100 pass 1`] = `
+exports[`test/run.js TAP coverage --100 pass > 100 pass 1`] = `
TAP version 13
# Subtest: 1.test.js
ok 1 - should be equal
@@ -65,7 +65,7 @@ All files | 100 | 100 | 100 | 100 | |
`
-exports[`run.js TAP coverage --100 fail > 100 fail 1`] = `
+exports[`test/run.js TAP coverage --100 fail > 100 fail 1`] = `
TAP version 13
# Subtest: 1.test.js
ok 1 - should be equal
@@ -90,7 +90,7 @@ All files | 75 | 75 | 100 | 75 | |
`
-exports[`run.js TAP coverage report only > lcov output 1`] = `
+exports[`test/run.js TAP coverage report only > lcov output 1`] = `
TN:
SF:{CWD}/ok.js
FN:2,(anonymous_0)
@@ -113,7 +113,7 @@ end_of_record
`
-exports[`run.js TAP coverage report with checks > lcov output and 100 check 1`] = `
+exports[`test/run.js TAP coverage report with checks > lcov output and 100 check 1`] = `
TN:
SF:{CWD}/ok.js
FN:2,(anonymous_0)
@@ -136,7 +136,7 @@ end_of_record
`
-exports[`run.js TAP coverage pipe to service > piped to coverage service cat 1`] = `
+exports[`test/run.js TAP coverage pipe to service > piped to coverage service cat 1`] = `
COVERAGE_SERVICE_TEST
TN:
SF:{CWD}/ok.js
@@ -160,103 +160,100 @@ end_of_record
`
-exports[`run.js TAP save file with bailout, should save all untested > stdout 1`] = `
+exports[`test/run.js TAP save file with bailout, should save all untested > stdout 1`] = `
TAP version 13
-# Subtest: a/b/2.js
- ok 1 - 2
- 1..1
- # {time}
-ok 1 - a/b/2.js # {time}
-
-# Subtest: a/b/f1.js
- not ok 1 - a/b
+# Subtest: z.js
+ not ok 1 - c/d
---
at:
line: #
column: #
- file: a/b/f1.js
+ file: z.js
source: |
- require("{TAPDIR}/").fail('a/b')
+ require("{CWD}/").fail('c/d')
...
- Bail out! # a/b
-Bail out! # a/b
+ Bail out! # c/d
+Bail out! # c/d
`
-exports[`run.js TAP save file with bailout, should save all untested > savefile 1`] = `
+exports[`test/run.js TAP save file with bailout, should save all untested > savefile 1`] = `
a
x
+z.js
a/b
x/y
+a/b/2.js
a/b/f1.js
-a/b/f2.js
x/y/1.js
`
-exports[`run.js TAP save file without bailout, run untested, save failures > stdout 1`] = `
+exports[`test/run.js TAP save file without bailout, run untested, save failures > stdout 1`] = `
TAP version 13
-# Subtest: a/b/2.js
- ok 1 - 2
- 1..1
- # {time}
-ok 1 - a/b/2.js # {time}
-
-# Subtest: a/b/f1.js
- not ok 1 - a/b
+# Subtest: z.js
+ not ok 1 - c/d
---
at:
line: #
column: #
- file: a/b/f1.js
+ file: z.js
source: |
- require("{TAPDIR}/").fail('a/b')
+ require("{CWD}/").fail('c/d')
...
1..1
# failed 1 test
# {time}
-not ok 2 - a/b/f1.js # {time}
+not ok 1 - z.js # {time}
---
args:
- - a/b/f1.js
- command: /usr/local/bin/node
- cwd: {CWD}
+ - z.js
+ command: {NODE}
+ cwd: {CWD}/test/cli-tests
exitCode: 1
- file: a/b/f1.js
+ file: z.js
stdio:
- 0
- pipe
- - 2 timeout: {default}
+ - 2
+ timeout: {default}
...
-# Subtest: a/b/f2.js
- not ok 1 - c/d
+# Subtest: a/b/2.js
+ ok 1 - 2
+ 1..1
+ # {time}
+ok 2 - a/b/2.js # {time}
+
+# Subtest: a/b/f1.js
+ not ok 1 - a/b
---
at:
line: #
column: #
- file: a/b/f2.js
+ file: a/b/f1.js
source: |
- require("{TAPDIR}/").fail('c/d')
+ require("{CWD}/").fail('a/b')
...
1..1
# failed 1 test
# {time}
-not ok 3 - a/b/f2.js # {time}
+not ok 3 - a/b/f1.js # {time}
---
args:
- - a/b/f2.js
- command: /usr/local/bin/node
- cwd: {CWD}
+ - a/b/f1.js
+ command: {NODE}
+ cwd: {CWD}/test/cli-tests
exitCode: 1
- file: a/b/f2.js
+ file: a/b/f1.js
stdio:
- 0
- pipe
- - 2 timeout: {default}
+ - 2
+ timeout: {default}
...
# Subtest: x/y/1.js
@@ -271,19 +268,19 @@ ok 4 - x/y/1.js # {time}
`
-exports[`run.js TAP save file without bailout, run untested, save failures > savefile 1`] = `
+exports[`test/run.js TAP save file without bailout, run untested, save failures > savefile 1`] = `
+z.js
a/b/f1.js
-a/b/f2.js
`
-exports[`run.js TAP save file pass, empty save file > stdout 1`] = `
+exports[`test/run.js TAP save file pass, empty save file > stdout 1`] = `
TAP version 13
-# Subtest: a/b/2.js
- ok 1 - 2
+# Subtest: z.js
+ ok 1 - fine now too
1..1
# {time}
-ok 1 - a/b/2.js # {time}
+ok 1 - z.js # {time}
# Subtest: a/b/f1.js
ok 1 - fine now
@@ -291,11 +288,30 @@ ok 1 - a/b/2.js # {time}
# {time}
ok 2 - a/b/f1.js # {time}
-# Subtest: a/b/f2.js
+1..2
+# {time}
+
+`
+
+exports[`test/run.js TAP save file empty save file, run all tests > stdout 1`] = `
+TAP version 13
+# Subtest: z.js
ok 1 - fine now too
1..1
# {time}
-ok 3 - a/b/f2.js # {time}
+ok 1 - z.js # {time}
+
+# Subtest: a/b/2.js
+ ok 1 - 2
+ 1..1
+ # {time}
+ok 2 - a/b/2.js # {time}
+
+# Subtest: a/b/f1.js
+ ok 1 - fine now
+ 1..1
+ # {time}
+ok 3 - a/b/f1.js # {time}
# Subtest: x/y/1.js
ok 1 - one
@@ -308,33 +324,69 @@ ok 4 - x/y/1.js # {time}
`
-exports[`run.js TAP save file empty save file, run all tests > stdout 1`] = `
+exports[`test/run.js TAP parallel > output 1`] = `
TAP version 13
-# Subtest: a/b/2.js
+ok 1 - p/y/1.js # {time} {
+ ok 1 - one
+ 1..1
+ # {time}
+}
+
+ok 2 - p/y/2.js # {time} {
ok 1 - 2
1..1
# {time}
-ok 1 - a/b/2.js # {time}
+}
-# Subtest: a/b/f1.js
- ok 1 - fine now
+# Subtest: r/y/1.js
+ ok 1 - one
1..1
# {time}
-ok 2 - a/b/f1.js # {time}
+ok 3 - r/y/1.js # {time}
-# Subtest: a/b/f2.js
- ok 1 - fine now too
+# Subtest: r/y/2.js
+ ok 1 - 2
1..1
# {time}
-ok 3 - a/b/f2.js # {time}
+ok 4 - r/y/2.js # {time}
-# Subtest: x/y/1.js
+# Subtest: q/b/f1.js
+ ok 1 - a/b
+ 1..1
+ # {time}
+ok 5 - q/b/f1.js # {time}
+
+# Subtest: q/b/f2.js
+ ok 1 - c/d
+ 1..1
+ # {time}
+ok 6 - q/b/f2.js # {time}
+
+ok 7 - z/y/1.js # {time} {
ok 1 - one
1..1
# {time}
-ok 4 - x/y/1.js # {time}
+}
-1..4
+ok 8 - z/y/2.js # {time} {
+ ok 1 - 2
+ 1..1
+ # {time}
+}
+
+1..8
+# {time}
+
+`
+
+exports[`test/run.js TAP executables > undefined 1`] = `
+TAP version 13
+# Subtest: exe/ok.sh
+ 1..1
+ ok 1 File with executable bit should be executed
+ok 1 - exe/ok.sh # {time}
+
+1..1
# {time}
`
diff --git a/test/clean-stacks.js b/test/clean-stacks.js
index 64d7b71..89622d5 100644
--- a/test/clean-stacks.js
+++ b/test/clean-stacks.js
@@ -46,11 +46,12 @@ module.exports = out => out
.replace(/\n( +)type: .*\n/g, '\n')
// timeout values are different when coverage is present
- .replace(/\n( *)timeout: (30000|240000)(\n|$)/g, '$1timeout: {default}$3')
+ .replace(/\n( *)timeout: (30000|240000)(\n|$)/g, '\n$1timeout: {default}$3')
// fix references to cwd
.split(process.cwd()).join('{CWD}')
.split(require('path').resolve(__dirname, '..')).join('{TAPDIR}')
+ .split(process.execPath).join('{NODE}')
// nothing to see here
if (module === require.main)
diff --git a/test/run.js b/test/run.js
index 1e30848..054e11b 100644
--- a/test/run.js
+++ b/test/run.js
@@ -2,6 +2,7 @@
const fs = require('fs')
const mkdirp = require('mkdirp')
const rimraf = require('rimraf')
+// const rimraf = { sync: () => {} }
const path = require('path')
const cp = require('child_process')
const execFile = cp.execFile
@@ -38,7 +39,12 @@ const tmpfile = (t, filename, content) => {
// make any necessary dirs
if (parts.length > 1)
mkdirp.sync(path.join(dir, parts.slice(0, -1).join('/')))
- t.teardown(() => rimraf.sync(path.join(dir, parts[0])))
+ if (t.tmpfiles)
+ t.tmpfiles.push(path.join(dir, parts[0]))
+ else {
+ t.tmpfiles = [path.join(dir, parts[0])]
+ t.teardown(() => t.tmpfiles.forEach(f => rimraf.sync(f)))
+ }
filename = path.join(dir, filename)
fs.writeFileSync(filename, content)
return path.relative('', filename)
@@ -317,6 +323,7 @@ t.test('unknown arg throws', t => {
t.test('coverage', t => {
const cwd = process.cwd()
process.chdir(dir)
+ t.teardown(() => process.chdir(cwd))
const ok = tmpfile(t, 'ok.js', `'use strict'
module.exports = (x, y) => {
if (x)
@@ -419,14 +426,14 @@ t.test('save file', t => {
require(${tap}).fail('a/b')
`)
- const abf2 = tmpfile(t, 'a/b/f2.js', `'use strict'
+ const abf2 = tmpfile(t, 'z.js', `'use strict'
require(${tap}).fail('c/d')
`)
const savefile = path.resolve(tmpfile(t, 'fails.txt', ''))
t.test('with bailout, should save all untested', t => {
- run(['a', 'x', '-s', savefile, '-b'], { cwd: dir }, (er, o, e) => {
+ run(['a', 'x', 'z.js', '-s', savefile, '-b'], { cwd: dir }, (er, o, e) => {
t.match(er, { code: 1 })
t.matchSnapshot(clean(o), 'stdout')
t.equal(e, '')
@@ -436,7 +443,7 @@ t.test('save file', t => {
})
t.test('without bailout, run untested, save failures', t => {
- run(['a', 'x', '-s', savefile], { cwd: dir }, (er, o, e) => {
+ run(['a', 'x', 'z.js', '-s', savefile], { cwd: dir }, (er, o, e) => {
t.match(er, { code: 1 })
t.matchSnapshot(clean(o), 'stdout')
t.equal(e, '')
@@ -456,7 +463,7 @@ t.test('save file', t => {
})
t.test('pass, empty save file', t => {
- run(['a', 'x', '-s', savefile], { cwd: dir }, (er, o, e) => {
+ run(['a', 'x', 'z.js', '-s', savefile], { cwd: dir }, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(clean(o), 'stdout')
t.equal(e, '')
@@ -466,7 +473,7 @@ t.test('save file', t => {
})
t.test('empty save file, run all tests', t => {
- run(['a', 'x', '-s', savefile], { cwd: dir }, (er, o, e) => {
+ run(['a', 'x', 'z.js', '-s', savefile], { cwd: dir }, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(clean(o), 'stdout')
t.equal(e, '')
@@ -478,4 +485,100 @@ t.test('save file', t => {
t.end()
})
-t.test('parallel')
+t.test('parallel', t => {
+ // should see start, start, end, end, in the output
+ tmpfile(t, 'p/y/1.js', `'use strict'
+ console.error('start')
+ setTimeout(() => console.error('end'), 100)
+ const t = require(${tap})
+ t.pass('one')
+ `)
+
+ tmpfile(t, 'p/y/2.js', `'use strict'
+ console.error('start')
+ setTimeout(() => console.error('end'), 100)
+ const t = require(${tap})
+ t.pass('2')
+ `)
+
+ tmpfile(t, 'p/tap-parallel-not-ok', '')
+ tmpfile(t, 'p/y/tap-parallel-ok', '')
+
+ tmpfile(t, 'q/b/f1.js', `'use strict'
+ require(${tap}).pass('a/b')
+ setTimeout(() => console.error('f1'), 100)
+ `)
+
+ tmpfile(t, 'q/b/f2.js', `'use strict'
+ require(${tap}).pass('c/d')
+ console.error('f2')
+ `)
+
+ tmpfile(t, 'q/tap-parallel-ok', '')
+ tmpfile(t, 'q/b/tap-parallel-not-ok', '')
+
+ tmpfile(t, 'r/y/1.js', `'use strict'
+ console.error('ry1')
+ setTimeout(() => console.error('ry1'), 100)
+ const t = require(${tap})
+ t.pass('one')
+ `)
+
+ tmpfile(t, 'r/y/2.js', `'use strict'
+ console.error('ry2')
+ setTimeout(() => console.error('ry2'), 100)
+ const t = require(${tap})
+ t.pass('2')
+ `)
+
+ tmpfile(t, 'r/tap-parallel-not-ok', '')
+
+ tmpfile(t, 'z/y/1.js', `'use strict'
+ console.error('start')
+ setTimeout(() => console.error('end'), 100)
+ const t = require(${tap})
+ t.pass('one')
+ `)
+
+ tmpfile(t, 'z/y/2.js', `'use strict'
+ console.error('start')
+ setTimeout(() => console.error('end'), 100)
+ const t = require(${tap})
+ t.pass('2')
+ `)
+
+ run(['p/y/*.js', 'q', 'r/y', 'z', '-j2'], { cwd: dir }, (er, o, e) => {
+ t.equal(er, null)
+ t.matchSnapshot(clean(o), 'output')
+ t.equal(e,
+ 'start\nstart\nend\nend\n' +
+ 'ry1\nry1\nry2\nry2\n' +
+ 'f1\nf2\n' +
+ 'start\nstart\nend\nend\n'
+ )
+ t.end()
+ })
+})
+
+t.test('executables', {
+ todo: process.platform === 'win32' ?
+ 'port the shell scripts to equivalent CMD files' : false
+}, t => {
+ const ok = tmpfile(t, 'exe/ok.sh', `#!/bin/sh
+ echo 1..1
+ echo ok 1 File with executable bit should be executed
+ `)
+ fs.chmodSync(ok, 0o755)
+ const notok = tmpfile(t, 'exe/notok.sh', `!#/bin/sh
+ echo 1..1
+ echo not ok 1 File without executable bit should not be run
+ exit 1
+ `)
+ fs.chmodSync(notok, 0o644)
+ run(['exe', '-C'], { cwd: dir }, (er, o, e) => {
+ t.equal(er, null)
+ t.matchSnapshot(clean(o))
+ t.equal(e, '')
+ t.end()
+ })
+})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap.git
More information about the Pkg-javascript-commits
mailing list