@@ -23,6 +23,15 @@
const rimraf = require('rimraf').sync
const {Repl} = require('../lib/repl.js')
+/* istanbul ignore next */
+const debug = process.env.TAP_DEBUG === '1'
+ || /\btap\b/.test(process.env.NODE_DEBUG) ? (...args) => {
+ const {format} = require('util')
+ const prefix = `TAP ${process.pid} RUN: `
+ const msg = format(...args).trim()
+ console.error(prefix + msg.split('\n').join(`\n${prefix}`))
+ } : () => {}
+
const filesFromTest = exports.filesFromTest = (index, testFile) => {
const set = index.externalIds[testFile]
return !set ? null
@@ -64,18 +73,23 @@
}
const defaultFiles = options => new Promise((res, rej) => {
+ debug('try to get default files')
const findit = require('findit')
const good = strToRegExp(options['test-regex'])
const bad = strToRegExp(options['test-ignore'])
const fileFilter = f => {
- const parts = f.split(/\\|\//)
- return good.test(f) &&
+ f = f.replace(/\\/g, '/')
+ debug('fileFilter', f)
+ const parts = f.split('/')
+ const include = good.test(f) &&
!bad.test(f) &&
!parts.includes('node_modules') &&
!parts.includes('tap-snapshots') &&
!parts.includes('fixtures') &&
!parts.includes('.git') &&
!parts.includes('.hg')
+ debug('include?', f, include)
+ return include
}
const addFile = files => f => fileFilter(f) && files.push(f)
@@ -83,10 +97,12 @@
// search in any folder that isn't node_modules, .git, or tap-snapshots
// these can get pretty huge, so just walking them at all is costly
fs.readdir(process.cwd(), (er, entries) => {
+ debug('readdir cwd', er, entries)
Promise.all(entries.filter(entry =>
!/^(node_modules|tap-snapshots|.git|.hg|fixtures)$/.test(entry)
).map(entry => new Promise((res, rej) => {
fs.lstat(entry, (er, stat) => {
+ debug('lstat', entry, er, stat)
// It's pretty unusual to have a file in cwd you can't even stat
/* istanbul ignore next */
if (er)
@@ -106,16 +122,20 @@
})
const main = async options => {
+ debug('main', options)
+
if (require.main !== module)
- return
+ return debug('not main module, do not run tests')
const rc = parseRcFile(options.rcfile)
+ debug('rc options', rc)
for (let i in rc) {
if (!options._.explicit.has(i))
options[i] = rc[i]
}
const pj = parsePackageJson()
+ debug('package.json options', pj)
for (let i in pj) {
if (!options._.explicit.has(i))
options[i] = pj[i]
@@ -185,8 +205,10 @@
return runCoverageReportOnly(options)
try {
+ debug('try to get default files?', options._.length === 0, isTTY)
if (options._.length === 0 && isTTY)
options._.push.apply(options._, await defaultFiles(options))
+ debug('added default files', options._)
} /* istanbul ignore next */ catch (er) /* istanbul ignore next */ {
// This gets tested on Mac, but not Linux/travis, and is
// somewhat challenging to do in a cross-platform way.
@@ -195,6 +217,7 @@
}
options.files = globFiles(options._)
+ debug('after globbing', options.files)
if (options.files.length === 0 && !isTTY)
options.files.push('-')
@@ -203,6 +226,7 @@
mkdirp(options['output-dir'])
if (options.files.length === 1 && options.files[0] === '-') {
+ debug('do stdin only')
setupTapEnv(options)
stdinOnly(options)
return
@@ -222,8 +246,10 @@
/* istanbul ignore next */
const nycReporter = options =>
- options['coverage-report'] === 'html' ? 'lcov'
- : (options['coverage-report'] || 'text')
+ options['coverage-report'] === 'html' ? '--reporter=lcov'
+ : options['coverage-report'] === false ? '--silent'
+ : options['coverage-report'] === null ? '--reporter=text'
+ : `--reporter=${options['coverage-report']}`
/* istanbul ignore next */
const runNyc = (cmd, programArgs, options, spawnOpts) => {
@@ -238,7 +264,7 @@
'--functions=' + options.functions,
'--lines=' + options.lines,
'--statements=' + options.statements,
- '--reporter=' + reporter,
+ reporter,
'--extension=.js',
'--extension=.jsx',
'--extension=.mjs',
@@ -261,7 +287,7 @@
]
require(nycBin)
- if (reporter === 'lcov' && options.browser)
+ if (reporter === '--reporter=lcov' && options.browser)
process.on('exit', () => openHtmlCoverageReport(options))
}
@@ -290,6 +316,7 @@
/* istanbul ignore next */
const respawnWithCoverage = options => {
+ debug('respawn with coverage')
// If we have a coverage map, then include nothing by default here.
runNyc(options['coverage-map'] ? [
'--include=',
@@ -506,6 +533,7 @@
}
const runAllFiles = (options, tap) => {
+ debug('run all files')
let doStdin = false
let parallelOk = Object.create(null)
@@ -545,6 +573,7 @@
if (seen.has(file))
continue
+ debug('run file', file)
seen.add(file)
// Pick up stdin after all the other files are handled.
@@ -562,6 +591,7 @@
}
if (st.isDirectory()) {
+ debug('is a directory', file)
const dir = filterFiles(fs.readdirSync(file).map(f =>
file.replace(/[\/\\]+$/, '') + '/' + f), options, parallelOk)
options.files.splice(i, 1, ...dir)
@@ -578,6 +608,7 @@
opt.buffered = isParallelOk(parallelOk, file) !== false
if (file.match(/\.m?js$/)) {
+ debug('js file', file)
const args = [
...(options.esm ? ['-r', esm] : []),
...options['node-arg'],
@@ -586,6 +617,7 @@
]
tap.spawn(node, args, opt, file)
} else if (file.match(/\.tsx?$/)) {
+ debug('ts file', file)
const compilerOpts = JSON.stringify({
...JSON.parse(process.env.TS_NODE_COMPILER_OPTIONS || '{}'),
jsx: 'react'
@@ -602,6 +634,7 @@
]
tap.spawn(node, args, opt, file)
} else if (file.match(/\.jsx$/)) {
+ debug('jsx file', file)
const args = [
...(options['node-arg']),
jsx,
@@ -610,17 +643,23 @@
]
tap.spawn(node, args, opt, file)
} else if (file.match(/\.tap$/)) {
+ debug('tap file', file)
tap.spawn('cat', [file], opt, file)
- } else if (isexe.sync(options.files[i]))
+ } else if (isexe.sync(options.files[i])) {
+ debug('executable', file)
tap.spawn(options.files[i], options['test-arg'], opt, file)
}
}
+ }
if (doStdin)
tap.stdin()
+
+ debug('scheduled all files for execution')
}
const runTests = options => {
+ debug('run tests')
// At this point, we know we need to use the tap root,
// because there are 1 or more files to spawn.
const tap = require('../lib/tap.js')
@@ -666,6 +705,7 @@
}
tap.end()
+ debug('called tap.end()')
}
const parsePackageJson = () => {