[Pkg-javascript-commits] [node-tap] 03/186: use strict, replace var with const/let
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 1 16:40:38 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 3fa36956daa131cb82cc9adcf8e1ec7c453682e8
Author: isaacs <i at izs.me>
Date: Mon Jun 26 16:52:08 2017 -0700
use strict, replace var with const/let
---
bin/run.js | 243 ++++++++++++++++++++----------------------
lib/asserts.js | 65 ++++++-----
lib/base.js | 32 +++---
lib/clean-yaml-object.js | 91 ++++++++--------
lib/diags.js | 10 +-
lib/extra-from-error.js | 22 ++--
lib/mocha.js | 44 ++++----
lib/obj-to-yaml.js | 13 +--
lib/parse-test-args.js | 17 +--
lib/point.js | 11 +-
lib/spawn.js | 25 ++---
lib/stack.js | 11 +-
lib/stdin.js | 9 +-
lib/synonyms.js | 8 +-
lib/tap.js | 43 ++++----
lib/test.js | 180 +++++++++++++++----------------
scripts/generate-test-test.js | 55 +++++-----
17 files changed, 425 insertions(+), 454 deletions(-)
diff --git a/bin/run.js b/bin/run.js
index 78cbda4..eeba2fa 100755
--- a/bin/run.js
+++ b/bin/run.js
@@ -1,21 +1,22 @@
#!/usr/bin/env node
-
-var node = process.execPath
-var fs = require('fs')
-var spawn = require('child_process').spawn
-var fg = require('foreground-child')
-var opener = require('opener')
-var colorSupport = require('color-support')
-var nycBin = require.resolve('nyc/bin/nyc.js')
-var glob = require('glob')
-var isexe = require('isexe')
-var osHomedir = require('os-homedir')
-var yaml = require('js-yaml')
-var path = require('path')
-var exists = require('fs-exists-cached').sync
-var os = require('os');
-
-var coverageServiceTest = process.env.COVERAGE_SERVICE_TEST === 'true'
+'use strict'
+
+const node = process.execPath
+const fs = require('fs')
+const spawn = require('child_process').spawn
+const fg = require('foreground-child')
+const opener = require('opener')
+const colorSupport = require('color-support')
+const nycBin = require.resolve('nyc/bin/nyc.js')
+const glob = require('glob')
+const isexe = require('isexe')
+const osHomedir = require('os-homedir')
+const yaml = require('js-yaml')
+const path = require('path')
+const exists = require('fs-exists-cached').sync
+const os = require('os');
+
+const coverageServiceTest = process.env.COVERAGE_SERVICE_TEST === 'true'
// NYC will not wrap a module in node_modules.
// So, we need to tell the child proc when it's been added.
@@ -34,7 +35,7 @@ if (coverageServiceTest)
// Currently only Coveralls is supported, but the infrastructure
// is left in place in case some noble soul fixes the codecov
// module in the future. See https://github.com/tapjs/node-tap/issues/270
-var coverageServices = [
+const coverageServices = [
{
env: 'COVERALLS_REPO_TOKEN',
bin: require.resolve('coveralls/bin/coveralls.js'),
@@ -45,7 +46,7 @@ var coverageServices = [
main()
function main () {
- var args = process.argv.slice(2)
+ const args = process.argv.slice(2)
if (!args.length && process.stdin.isTTY) {
console.error(usage())
@@ -53,11 +54,11 @@ function main () {
}
// set default args
- var defaults = constructDefaultArgs()
+ const defaults = constructDefaultArgs()
// parse dotfile
- var rcFile = process.env.TAP_RCFILE || (osHomedir() + '/.taprc')
- var rcOptions = parseRcFile(rcFile)
+ const rcFile = process.env.TAP_RCFILE || (osHomedir() + '/.taprc')
+ const rcOptions = parseRcFile(rcFile)
// supplement defaults with parsed rc options
if (rcOptions)
@@ -68,7 +69,7 @@ function main () {
defaults.rcFile = rcFile
// parse args
- var options = parseArgs(args, defaults)
+ const options = parseArgs(args, defaults)
if (!options)
return
@@ -111,11 +112,9 @@ function main () {
}
function constructDefaultArgs () {
- var defaultTimeout = 30
- if (global.__coverage__)
- defaultTimeout = 240
+ const defaultTimeout = (global.__coverage__) ? 240 : 30
- var defaultArgs = {
+ const defaultArgs = {
nodeArgs: [],
nycArgs: [],
testArgs: [],
@@ -147,9 +146,9 @@ function constructDefaultArgs () {
}
function parseArgs (args, defaults) {
- var options = defaults || {}
+ const options = defaults || {}
- var singleFlags = {
+ const singleFlags = {
b: 'bail',
B: 'no-bail',
i: 'invert',
@@ -164,7 +163,7 @@ function parseArgs (args, defaults) {
v: 'version'
}
- var singleOpts = {
+ const singleOpts = {
j: 'jobs',
g: 'grep',
R: 'reporter',
@@ -175,16 +174,16 @@ function parseArgs (args, defaults) {
// 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 (var i = 0; i < coverageServices.length && !options.pipeToService; i++) {
+ for (let i = 0; i < coverageServices.length && !options.pipeToService; i++) {
if (process.env[coverageServices[i].env])
options.pipeToService = true
}
- var defaultCoverage = options.pipeToService
- var dumpConfig = false
+ let defaultCoverage = options.pipeToService
+ let dumpConfig = false
- for (i = 0; i < args.length; i++) {
- var arg = args[i]
+ for (let i = 0; i < args.length; i++) {
+ const arg = args[i]
if (arg.charAt(0) !== '-' || arg === '-') {
options.files.push(arg)
continue
@@ -192,18 +191,16 @@ function parseArgs (args, defaults) {
// short-flags
if (arg.charAt(1) !== '-' && arg !== '-gc') {
- var expand = []
- for (var f = 1; f < arg.length; f++) {
- var fc = arg.charAt(f)
- var sf = singleFlags[fc]
- var so = singleOpts[fc]
+ const expand = []
+ for (let f = 1; f < arg.length; f++) {
+ const fc = arg.charAt(f)
+ const sf = singleFlags[fc]
+ const so = singleOpts[fc]
if (sf)
expand.push('--' + sf)
else if (so) {
- var soval = arg.slice(f + 1)
- if (soval.charAt(0) !== '=') {
- soval = '=' + soval
- }
+ const soslice = arg.slice(f + 1)
+ const soval = soslice.charAt(0) === '=' ? soslice : '=' + soslice
expand.push('--' + so + soval)
f = arg.length
} else if (arg !== '-' + fc)
@@ -216,13 +213,9 @@ function parseArgs (args, defaults) {
}
}
- var key = arg
- var val = null
- if (key.match(/^--/) && arg.indexOf('=') !== -1) {
- var kv = arg.split('=')
- key = kv.shift()
- val = kv.join('=')
- }
+ const argsplit = arg.split('=')
+ const key = argsplit.shift()
+ const val = argsplit.length ? argsplit.join('=') : null
switch (key) {
case '--help':
@@ -246,13 +239,11 @@ function parseArgs (args, defaults) {
return null
case '--jobs':
- val = val || args[++i]
- options.jobs = +val
+ options.jobs = +(val || args[++i])
continue
case '--jobs-auto':
- val = os.cpus().length;
- options.jobs = +val
+ options.jobs = +os.cpus().length
continue
case '--coverage-report':
@@ -279,13 +270,11 @@ function parseArgs (args, defaults) {
continue
case '--save':
- val = val || args[++i]
- options.saveFile = val
+ options.saveFile = val || args[++i]
continue
case '--reporter':
- val = val || args[++i]
- options.reporter = val
+ options.reporter = val || args[++i]
continue
case '--gc': case '-gc': case '--expose-gc':
@@ -308,28 +297,31 @@ function parseArgs (args, defaults) {
options.nodeArgs.push('--harmony')
continue
- case '--node-arg':
- val = val || args[++i]
- if (val !== undefined)
- options.nodeArgs.push(val)
+ case '--node-arg': {
+ const v = val || args[++i]
+ if (v !== undefined)
+ options.nodeArgs.push(v)
continue
+ }
case '--check-coverage':
defaultCoverage = true
options.checkCoverage = true
continue
- case '--test-arg':
- val = val || args[++i]
- if (val !== undefined)
- options.testArgs.push(val)
+ case '--test-arg': {
+ const v = val || args[++i]
+ if (v !== undefined)
+ options.testArgs.push(v)
continue
+ }
- case '--nyc-arg':
- val = val || args[++i]
- if (val !== undefined)
- options.nycArgs.push(val)
+ case '--nyc-arg': {
+ const v = val || args[++i]
+ if (v !== undefined)
+ options.nycArgs.push(v)
continue
+ }
case '--100':
defaultCoverage = true
@@ -345,9 +337,8 @@ function parseArgs (args, defaults) {
case '--lines':
case '--statements':
defaultCoverage = true
- val = val || args[++i]
options.checkCoverage = true
- options[key.slice(2)] = val
+ options[key.slice(2)] = val || args[++i]
continue
case '--color':
@@ -358,19 +349,19 @@ function parseArgs (args, defaults) {
options.color = false
continue
- case '--output-file':
- val = val || args[++i]
- if (val !== undefined)
- options.outputFile = val
+ case '--output-file': {
+ const v = val || args[++i]
+ if (v !== undefined)
+ options.outputFile = v
continue
+ }
case '--no-timeout':
options.timeout = 0
continue
case '--timeout':
- val = val || args[++i]
- options.timeout = +val
+ options.timeout = +(val || args[++i])
continue
case '--invert':
@@ -381,11 +372,12 @@ function parseArgs (args, defaults) {
options.grepInvert = false
continue
- case '--grep':
- val = val || args[++i]
- if (val !== undefined)
- options.grep.push(strToRegExp(val))
+ case '--grep': {
+ const v = val || args[++i]
+ if (v !== undefined)
+ options.grep.push(strToRegExp(v))
continue
+ }
case '--bail':
options.bail = true
@@ -429,7 +421,7 @@ function parseArgs (args, defaults) {
function respawnWithCoverage (options) {
// console.error('respawn with coverage')
// Re-spawn with coverage
- var args = [nycBin].concat(
+ const args = [nycBin].concat(
'--silent',
'--cache=true',
options.nycArgs,
@@ -438,7 +430,7 @@ function respawnWithCoverage (options) {
process.argv.slice(1)
)
process.env._TAP_COVERAGE_ = '1'
- var child = fg(node, args)
+ const child = fg(node, args)
child.removeAllListeners('close')
child.on('close', function (code, signal) {
runCoverageReport(options, code, signal)
@@ -447,8 +439,8 @@ function respawnWithCoverage (options) {
function pipeToCoverageServices (options, child) {
// console.error('pipe to services')
- var piped = false
- for (var i = 0; i < coverageServices.length; i++) {
+ let piped = false
+ for (let i = 0; i < coverageServices.length; i++) {
// console.error('pipe to service?', coverageServices[i].env)
if (process.env[coverageServices[i].env]) {
pipeToCoverageService(coverageServices[i], options, child)
@@ -463,7 +455,7 @@ function pipeToCoverageServices (options, child) {
function pipeToCoverageService (service, options, child) {
// console.error('pipe to service yes', service.env)
- var bin = service.bin
+ let bin = service.bin
if (coverageServiceTest) {
// console.error('use fakey test bin')
@@ -473,7 +465,7 @@ function pipeToCoverageService (service, options, child) {
console.log('%s:%s', service.name, process.env[service.env])
}
- var ca = spawn(node, [bin], {
+ const ca = spawn(node, [bin], {
stdio: [ 'pipe', 1, 2 ]
})
@@ -507,10 +499,10 @@ function runCoverageReportOnly (options, code, signal) {
options.coverageReport = 'text'
}
- var args = [nycBin, 'report', '--reporter', options.coverageReport]
+ const args = [nycBin, 'report', '--reporter', options.coverageReport]
// console.error('run coverage report', args)
- var child
+ let child
// automatically hook into coveralls
if (options.coverageReport === 'text-lcov' && options.pipeToService) {
// console.error('pipeToService')
@@ -541,7 +533,7 @@ function runCoverageReportOnly (options, code, signal) {
}
function coverageCheckArgs (options) {
- var args = []
+ const args = []
if (options.branches)
args.push('--branches', options.branches)
if (options.functions)
@@ -555,9 +547,9 @@ function coverageCheckArgs (options) {
}
function runCoverageCheck (options, code, signal) {
- var args = [nycBin, 'check-coverage'].concat(coverageCheckArgs(options))
+ const args = [nycBin, 'check-coverage'].concat(coverageCheckArgs(options))
- var child = fg(node, args)
+ const child = fg(node, args)
child.removeAllListeners('close')
child.on('close', function (c, s) {
runCoverageReportOnly(options, code || c, signal || s)
@@ -579,15 +571,14 @@ function nycVersion () {
}
function getReporters () {
- var types = require('tap-mocha-reporter').types
- types = types.reduce(function (str, t) {
- var ll = str.split('\n').pop().length + t.length
+ const types = require('tap-mocha-reporter').types.reduce(function (str, t) {
+ const ll = str.split('\n').pop().length + t.length
if (ll < 40)
return str + ' ' + t
else
return str + '\n' + t
}, '').trim()
- var ind = ' '
+ const ind = ' '
return ind + types.split('\n').join('\n' + ind)
}
@@ -629,7 +620,7 @@ function globFiles (files) {
}
function makeReporter (options) {
- var TMR = require('tap-mocha-reporter')
+ const TMR = require('tap-mocha-reporter')
return new TMR(options.reporter)
}
@@ -638,7 +629,7 @@ function stdinOnly (options) {
// to the reporter, so we don't get '/dev/stdin' in the suite list.
// We have to pause() before piping to switch streams2 into old-mode
process.stdin.pause()
- var reporter = makeReporter(options)
+ const reporter = makeReporter(options)
process.stdin.pipe(reporter)
process.stdin.resume()
}
@@ -656,8 +647,8 @@ function saveFails (options, tap) {
if (!options.saveFile)
return
- var fails = []
- var successes = []
+ let fails = []
+ const successes = []
tap.on('result', function (res) {
// we will continue to re-run todo tests, even though they're
// not technically "failures".
@@ -707,30 +698,26 @@ function filterFiles (files, saved, parallelOk) {
}
function isParallelOk (parallelOk, file) {
- var dir = path.resolve(path.dirname(file))
-
- if (dir in parallelOk)
- return parallelOk[dir]
-
- if (exists(dir + '/tap-parallel-ok'))
- return parallelOk[dir] = true
-
- if (exists(dir + '/tap-parallel-not-ok'))
- return parallelOk[dir] = false
-
- if (dir.length >= process.cwd().length)
- return isParallelOk(parallelOk, dir)
+ const dir = path.resolve(path.dirname(file))
+ return (dir in parallelOk) ? parallelOk[dir]
+ : exists(dir + '/tap-parallel-ok')
+ ? parallelOk[dir] = true
+ : exists(dir + '/tap-parallel-not-ok')
+ ? parallelOk[dir] = false
+ : dir.length >= process.cwd().length
+ ? isParallelOk(parallelOk, dir)
+ : true
}
function runAllFiles (options, saved, tap) {
- var doStdin = false
- var parallelOk = Object.create(null)
+ let doStdin = false
+ let parallelOk = Object.create(null)
options.files = filterFiles(options.files, saved, parallelOk)
- for (var i = 0; i < options.files.length; i++) {
- var opt = {}
- var file = options.files[i]
+ for (let i = 0; i < options.files.length; i++) {
+ const opt = {}
+ const file = options.files[i]
// Pick up stdin after all the other files are handled.
if (file === '-') {
@@ -738,7 +725,7 @@ function runAllFiles (options, saved, tap) {
continue
}
- var st = fs.statSync(options.files[i])
+ const st = fs.statSync(options.files[i])
if (options.timeout)
opt.timeout = options.timeout * 1000
@@ -747,10 +734,10 @@ function runAllFiles (options, saved, tap) {
opt.buffered = isParallelOk(parallelOk, file) !== false
if (file.match(/\.js$/)) {
- var args = options.nodeArgs.concat(file).concat(options.testArgs)
+ const args = options.nodeArgs.concat(file).concat(options.testArgs)
tap.spawn(node, args, opt, file)
} else if (st.isDirectory()) {
- var dir = filterFiles(fs.readdirSync(file).map(function (f) {
+ const dir = filterFiles(fs.readdirSync(file).map(function (f) {
return file + '/' + f
}), saved, parallelOk)
options.files.push.apply(options.files, dir)
@@ -763,11 +750,11 @@ function runAllFiles (options, saved, tap) {
}
function runTests (options) {
- var saved = readSaveFile(options)
+ const saved = readSaveFile(options)
// At this point, we know we need to use the tap root,
// because there are 1 or more files to spawn.
- var tap = require('../lib/tap.js')
+ const tap = require('../lib/tap.js')
tap.runOnly = false
// greps are passed to children, but not the runner itself
@@ -793,7 +780,7 @@ function runTests (options) {
function parseRcFile (path) {
try {
- var contents = fs.readFileSync(path, 'utf8')
+ const contents = fs.readFileSync(path, 'utf8')
return yaml.safeLoad(contents) || {}
} catch (er) {
// if no dotfile exists, or invalid yaml, fail gracefully
@@ -802,8 +789,8 @@ function parseRcFile (path) {
}
function strToRegExp (g) {
- var p = g.match(/^\/(.*)\/([a-z]*)$/)
+ const p = g.match(/^\/(.*)\/([a-z]*)$/)
g = p ? p[1] : g
- var flags = p ? p[2] : ''
+ const flags = p ? p[2] : ''
return new RegExp(g, flags)
}
diff --git a/lib/asserts.js b/lib/asserts.js
index 4871348..5d0621e 100644
--- a/lib/asserts.js
+++ b/lib/asserts.js
@@ -1,11 +1,12 @@
-var synonyms = require('./synonyms.js')
-var tsame = require('tsame') // same thing, strict or not
-var tmatch = require('tmatch') // ok with partial estimates
-var extraFromError = require('./extra-from-error.js')
-var stack = require('./stack.js')
+'use strict'
+const synonyms = require('./synonyms.js')
+const tsame = require('tsame') // same thing, strict or not
+const tmatch = require('tmatch') // ok with partial estimates
+const extraFromError = require('./extra-from-error.js')
+const stack = require('./stack.js')
// Load Buffer the old way for browserify's sake
-var Buffer = require('buffer').Buffer // eslint-disable-line
+const Buffer = require('buffer').Buffer // eslint-disable-line
// this is actually the "working half" of the Test class.
// each method figures out if it's a pass or fail, and decorates
@@ -125,10 +126,10 @@ function decorate (t) {
})
t.addAssert('type', 2, function (obj, klass, m, e) {
- var name = klass
- if (typeof name === 'function') {
- name = name.name || '(anonymous constructor)'
- }
+ const name = typeof klass === 'function' ?
+ klass.name || '(anonymous constructor)'
+ : klass
+
m = m || 'type is ' + name
// simplest case, it literally is the same thing
@@ -136,18 +137,14 @@ function decorate (t) {
return this.pass(m, e)
}
- var type = typeof obj
- if (!obj && type === 'object') {
- type = 'null'
- }
-
- if (type === 'function' &&
- typeof klass === 'function' &&
- klass !== Object) {
+ const tof = typeof obj
+ const type = (!obj && tof === 'object') ? 'null'
// treat as object, but not Object
// t.type(() => {}, Function)
- type = 'object'
- }
+ : (tof === 'function' &&
+ typeof klass === 'function' &&
+ klass !== Object) ? 'object'
+ : tof
if (type === 'object' && klass !== 'object') {
if (typeof klass === 'function') {
@@ -160,23 +157,21 @@ function decorate (t) {
// at this point, we already know klass is not a function
// if the klass specified is an obj in the proto chain, pass
// if the name specified is the name of a ctor in the chain, pass
- var p = obj
- do {
- var ctor = p.constructor && p.constructor.name
+ for (let p = obj; p; p = Object.getPrototypeOf(p)) {
+ const ctor = p.constructor && p.constructor.name
if (p === klass || ctor === name) {
return this.pass(m, e)
}
- p = Object.getPrototypeOf(p)
- } while (p)
+ }
}
return this.equal(type, name, m, e)
})
t.addAssert('throws', 4, function (fn_, wanted_, m_, e_, m, e__) {
- var fn, wanted, e
- for (var i = 0; i < arguments.length - 1; i++) {
- var arg = arguments[i]
+ let fn, wanted, e
+ for (let i = 0; i < arguments.length - 1; i++) {
+ const arg = arguments[i]
if (typeof arg === 'function') {
if (arg === Error || arg.prototype instanceof Error) {
wanted = arg
@@ -205,7 +200,7 @@ function decorate (t) {
if (wanted) {
if (wanted instanceof Error) {
- var w = {
+ const w = {
message: wanted.message
}
if (wanted.name) {
@@ -255,7 +250,7 @@ function decorate (t) {
t.addAssert('doesNotThrow', 1, function (fn, m, e) {
if (typeof fn === 'string') {
- var x = fn
+ const x = fn
fn = m
m = x
}
@@ -273,7 +268,7 @@ function decorate (t) {
fn()
return this.pass(m, e)
} catch (er) {
- var extra = extraFromError(er, e)
+ const extra = extraFromError(er, e)
extra.message = er.message
return this.fail(m, extra)
}
@@ -282,9 +277,9 @@ function decorate (t) {
// like throws, but rejects a returned promise instead
// also, can pass in a promise instead of a function
t.addAssert('rejects', 4, function (fn_, wanted_, m_, e_, m, e__) {
- var fn, wanted, e = {}, promise
- for (var i = 0; i < arguments.length - 1; i++) {
- var arg = arguments[i]
+ let fn, wanted, e = {}, promise
+ for (let i = 0; i < arguments.length - 1; i++) {
+ const arg = arguments[i]
if (typeof arg === 'function') {
if (arg === Error || arg.prototype instanceof Error) {
wanted = arg
@@ -315,7 +310,7 @@ function decorate (t) {
if (wanted) {
if (wanted instanceof Error) {
- var w = {
+ const w = {
message: wanted.message
}
if (wanted.name) {
diff --git a/lib/base.js b/lib/base.js
index 600285d..4d0d40e 100644
--- a/lib/base.js
+++ b/lib/base.js
@@ -1,23 +1,23 @@
-module.exports = Base
+'use strict'
-var Readable = require('stream').Readable
+const Readable = require('stream').Readable
/* istanbul ignore if */
if (!Readable || process.version.match(/^v0\.10/)) {
Readable = require('readable-stream').Readable
}
-var extraFromError = require('./extra-from-error.js')
-var assert = require('assert')
-var cleanYamlObject = require('./clean-yaml-object.js')
+const extraFromError = require('./extra-from-error.js')
+const assert = require('assert')
+const cleanYamlObject = require('./clean-yaml-object.js')
-var domain = require('domain')
-var util = require('util')
+const domain = require('domain')
+const util = require('util')
util.inherits(Base, Readable)
-var Parser = require('tap-parser')
+const Parser = require('tap-parser')
-var ownOr = require('own-or')
-var ownOrEnv = require('own-or-env')
+const ownOr = require('own-or')
+const ownOrEnv = require('own-or-env')
function Base (options) {
this.start = 0
@@ -85,7 +85,7 @@ Base.prototype.threw = function (er, extra, proxy) {
if (this.name && !proxy)
er.test = this.name
- var message = er.message
+ const message = er.message
if (!extra)
extra = extraFromError(er, extra, this.options)
@@ -112,7 +112,7 @@ Base.prototype.threw = function (er, extra, proxy) {
Base.prototype.timeout = function (options) {
this.setTimeout(false)
- var er = new Error('timeout!')
+ const er = new Error('timeout!')
options = options || {}
options.expired = options.expired || this.name
this.threw(new Error('timeout!'), options)
@@ -168,7 +168,7 @@ Base.prototype.oncomplete = function (results) {
this.results = results
this.emit('complete', results)
- var failures = results.failures.filter(function (f) {
+ const failures = results.failures.filter(function (f) {
delete f.diag
delete f.ok
return f.tapError
@@ -247,8 +247,10 @@ function nodebug () {}
/* istanbul ignore next */
function debug () {
- var prefix = 'TAP ' + process.pid + ' ' + this.name + ': '
- var msg = util.format.apply(util, arguments).trim()
+ const prefix = 'TAP ' + process.pid + ' ' + this.name + ': '
+ const msg = util.format.apply(util, arguments).trim()
msg = prefix + msg.split('\n').join('\n' + prefix)
console.error(msg)
}
+
+module.exports = Base
diff --git a/lib/clean-yaml-object.js b/lib/clean-yaml-object.js
index 1739bc6..8d25364 100644
--- a/lib/clean-yaml-object.js
+++ b/lib/clean-yaml-object.js
@@ -1,10 +1,11 @@
-var cleanYamlObject = require('clean-yaml-object')
-var path = require('path')
-var Module = require('module')
-var fs = require('fs')
-var binpath = path.resolve(__dirname, '../bin')
-var stack = require('./stack.js')
-var Domain = require('domain').Domain
+'use strict'
+const cleanYamlObject = require('clean-yaml-object')
+const path = require('path')
+const Module = require('module')
+const fs = require('fs')
+const binpath = path.resolve(__dirname, '../bin')
+const stack = require('./stack.js')
+const Domain = require('domain').Domain
function hasOwn (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key)
@@ -16,20 +17,20 @@ function cleanTapYamlObject (object) {
if (hasOwn(object, 'stack') && !hasOwn(object, 'at'))
object.at = stack.parseLine(object.stack.split('\n')[0])
- var file = object.at && object.at.file && path.resolve(object.at.file)
+ const file = object.at && object.at.file && path.resolve(object.at.file)
if (file && (file.indexOf(__dirname) === 0 || file.indexOf(binpath) === 0))
delete object.at
- if (object.at && object.at.file && object.at.line && !object.source) {
- var content
- file = path.resolve(object.at.file)
- try {
- content = Module.wrap(fs.readFileSync(file))
- } catch (er) {}
+ if (file && object.at && object.at.file && object.at.line && !object.source) {
+ const content = (() => {
+ try {
+ return Module.wrap(fs.readFileSync(file))
+ } catch (er) {}
+ })()
if (content) {
- content = (content.split('\n')[object.at.line - 1] || '').trim()
- if (content)
- object.source = content + '\n'
+ const csplit = (content.split('\n')[object.at.line - 1] || '').trim()
+ if (csplit)
+ object.source = csplit + '\n'
}
}
@@ -37,36 +38,28 @@ function cleanTapYamlObject (object) {
}
function yamlFilter (propertyName, isRoot, source, target) {
- if (source instanceof Domain)
- return false
-
- if (!isRoot)
- return true
-
- if (propertyName === 'stack') {
- if (source.stack)
- target.stack = source.stack
- return false
- }
-
- return !(propertyName === 'todo' ||
- propertyName === 'time' ||
- /^_?tapChild/.test(propertyName) ||
- /^tapStream/.test(propertyName) ||
- /^tapMochaTest/.test(propertyName) ||
- propertyName === 'cb' ||
- propertyName === 'name' ||
- propertyName === 'indent' ||
- propertyName === 'skip' ||
- propertyName === 'bail' ||
- propertyName === 'grep' ||
- propertyName === 'grepInvert' ||
- propertyName === 'only' ||
- propertyName === 'diagnostic' ||
- propertyName === 'buffered' ||
- propertyName === 'parent' ||
- propertyName === 'domainEmitter' ||
- propertyName === 'domainThrew' ||
- propertyName === 'domain' ||
- (propertyName === 'at' && !source.at))
+ return source instanceof Domain ? false
+ : !isRoot ? true
+ : propertyName === 'stack' ? (
+ (source.stack ? target.stack = source.stack : false), false)
+ : !(propertyName === 'todo' ||
+ propertyName === 'time' ||
+ /^_?tapChild/.test(propertyName) ||
+ /^tapStream/.test(propertyName) ||
+ /^tapMochaTest/.test(propertyName) ||
+ propertyName === 'cb' ||
+ propertyName === 'name' ||
+ propertyName === 'indent' ||
+ propertyName === 'skip' ||
+ propertyName === 'bail' ||
+ propertyName === 'grep' ||
+ propertyName === 'grepInvert' ||
+ propertyName === 'only' ||
+ propertyName === 'diagnostic' ||
+ propertyName === 'buffered' ||
+ propertyName === 'parent' ||
+ propertyName === 'domainEmitter' ||
+ propertyName === 'domainThrew' ||
+ propertyName === 'domain' ||
+ (propertyName === 'at' && !source.at))
}
diff --git a/lib/diags.js b/lib/diags.js
index 75e29c2..6ed0079 100644
--- a/lib/diags.js
+++ b/lib/diags.js
@@ -1,11 +1,9 @@
+'use strict'
module.exports = diags
-var objToYaml = require('./obj-to-yaml.js')
+const objToYaml = require('./obj-to-yaml.js')
function diags (extra) {
- var y = objToYaml(extra)
- if (y)
- y = '\n' + y
-
- return y
+ const y = objToYaml(extra)
+ return y ? '\n' + y : y
}
diff --git a/lib/extra-from-error.js b/lib/extra-from-error.js
index 4bb9743..849fd22 100644
--- a/lib/extra-from-error.js
+++ b/lib/extra-from-error.js
@@ -1,4 +1,5 @@
-var stack = require('./stack.js')
+'use strict'
+const stack = require('./stack.js')
module.exports = function (er, extra, options) {
extra = Object.keys(options || {}).reduce(function (set, k) {
@@ -12,21 +13,18 @@ module.exports = function (er, extra, options) {
return extra
}
- var message = er.message
- var addName = true
-
- if (!message && er.stack) {
- message = er.stack.split('\n')[0]
- addName = false
- }
+ const message = er.message ? er.message
+ : er.stack ? er.stack.split('\n')[0]
+ : ''
+ const addName = er.message || !er.stack
er.message = ''
- var st = er.stack
+ const st = er.stack
if (st) {
- st = st.split('\n')
+ const splitst = st.split('\n')
// parse out the 'at' bit from the first line.
- extra.at = stack.parseLine(st[1])
- extra.stack = stack.clean(st)
+ extra.at = stack.parseLine(splitst[1])
+ extra.stack = stack.clean(splitst)
}
er.message = message
diff --git a/lib/mocha.js b/lib/mocha.js
index 776bca7..c93c2a6 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -1,3 +1,4 @@
+'use strict'
exports.it = exports.specify = it
exports.context = exports.describe = describe
exports.before = before
@@ -11,11 +12,11 @@ exports.global = function () {
})
}
-var t = require('./tap.js')
+const t = require('./tap.js')
t.jobs = 1
-var tapStack = [ t ]
-var level = 0
-var suiteStack = []
+const tapStack = [ t ]
+let level = 0
+const suiteStack = []
function describe (name, fn) {
new Suite(name, fn)
@@ -37,12 +38,12 @@ function Suite (name, fn) {
}
Suite.prototype.run = function () {
- var t = tapStack[ tapStack.length - 1 ]
+ const t = tapStack[ tapStack.length - 1 ]
t.test(this.name, { todo: this.todo }, function (tt) {
this.test = tt
tapStack.push(tt)
suiteStack.push(this)
- var ret = this.fn()
+ const ret = this.fn()
this.runAfter()
suiteStack.pop()
return ret
@@ -51,12 +52,13 @@ Suite.prototype.run = function () {
Suite.prototype.runAfter = function () {
this.after.forEach(function (namefn) {
- var name = namefn[0]
- var fn = namefn[1]
+ const name = namefn[0]
+ const fn = namefn[1]
before(name, fn)
})
+ let t
do {
- var t = tapStack.pop()
+ t = tapStack.pop()
} while (t && t !== this.test)
if (this.test && !this.test.results)
t.end()
@@ -67,13 +69,13 @@ function before (name, fn) {
fn = name, name = null
if (fn && fn.name && !name)
name = fn.name
- var todo = !fn
- var suite = suiteStack[ suiteStack.length - 1 ]
- var t = tapStack[ tapStack.length - 1 ]
+ const todo = !fn
+ const suite = suiteStack[ suiteStack.length - 1 ]
+ const t = tapStack[ tapStack.length - 1 ]
if (!name)
name = ''
t.test(name, { todo: todo, silent: true }, function (tt) {
- var ret = fn.call(suite, done(tt))
+ const ret = fn.call(suite, done(tt))
if (!ret && fn.length === 0)
tt.end()
else
@@ -93,13 +95,13 @@ function it (name, fn) {
fn = name, name = null
if (fn && fn.name && !name)
name = fn.name
- var todo = !fn
- var suite = suiteStack[ suiteStack.length - 1 ]
- var t = tapStack[ tapStack.length - 1 ]
+ const todo = !fn
+ const suite = suiteStack[ suiteStack.length - 1 ]
+ const t = tapStack[ tapStack.length - 1 ]
if (!name)
name = ''
t.test(name, { todo: todo, tapMochaTest: true }, function (tt) {
- var ret = fn.call(tt, done(tt))
+ const ret = fn.call(tt, done(tt))
if (ret && ret.then)
return ret
else if (fn.length === 0)
@@ -115,7 +117,7 @@ function it (name, fn) {
}
function after (name, fn) {
- var suite = suiteStack[ suiteStack.length - 1 ]
+ const suite = suiteStack[ suiteStack.length - 1 ]
if (!suite)
throw new Error('cannot call "after" outside of describe()')
if (fn)
@@ -125,12 +127,12 @@ function after (name, fn) {
}
function moment (when, fn) {
- var t = tapStack[ tapStack.length - 1 ]
+ const t = tapStack[ tapStack.length - 1 ]
t[when](function (cb) {
if (!this.options.tapMochaTest)
return cb()
- var suite = suiteStack[ suiteStack.length - 1 ]
- var ret = fn.call(this, cb)
+ const suite = suiteStack[ suiteStack.length - 1 ]
+ const ret = fn.call(this, cb)
if (ret && ret.then)
return ret
else if (fn.length === 0)
diff --git a/lib/obj-to-yaml.js b/lib/obj-to-yaml.js
index 56cddcc..4f51ec4 100644
--- a/lib/obj-to-yaml.js
+++ b/lib/obj-to-yaml.js
@@ -1,17 +1,18 @@
+'use strict'
module.exports = objToYaml
-var cleanYamlObject = require('./clean-yaml-object.js')
-var yaml = require('js-yaml')
+const cleanYamlObject = require('./clean-yaml-object.js')
+const yaml = require('js-yaml')
function objToYaml (obj) {
obj = cleanYamlObject(obj)
- var y = ''
+ let ret = ''
if (obj && typeof obj === 'object' && Object.keys(obj).length) {
- y = yaml.safeDump(obj).split('\n').map(function (l) {
+ const y = yaml.safeDump(obj).split('\n').map(function (l) {
return l.trim() ? ' ' + l : l.trim()
}).join('\n')
- y = ' ---\n' + y + ' ...\n'
+ ret = ' ---\n' + y + ' ...\n'
}
- return y
+ return ret
}
diff --git a/lib/parse-test-args.js b/lib/parse-test-args.js
index f7b02cb..76b3aeb 100644
--- a/lib/parse-test-args.js
+++ b/lib/parse-test-args.js
@@ -1,5 +1,6 @@
+'use strict'
function typeOf (arg) {
- var t = typeof arg
+ const t = typeof arg
switch (t) {
case 'object':
return arg ? 'object' : 'null'
@@ -9,17 +10,17 @@ function typeOf (arg) {
}
module.exports = function (name_, extra_, cb_, defaultName) {
- var name
- var extra
- var cb
+ let name
+ let extra
+ let cb
// this only works if it's literally the 4th argument. it's mostly
// used internally.
defaultName = defaultName || '(unnamed test)'
- for (var i = 0; i < 3 && i < arguments.length; i++) {
- var arg = arguments[i]
- var type = typeOf(arg)
+ for (let i = 0; i < 3 && i < arguments.length; i++) {
+ const arg = arguments[i]
+ const type = typeOf(arg)
if (name === undefined && (type === 'string' || type === 'number'))
name = '' + arg
else if (type === 'object') {
@@ -34,7 +35,7 @@ module.exports = function (name_, extra_, cb_, defaultName) {
cb = arg
} else if (arg === false) {
// it's handy while developing to put a ! in front of a
- // function to temporarily make a test TODO
+ // function to temporarily make a test todo
continue
} else if (type !== 'undefined')
throw new TypeError('unknown argument passed to parseTestArgs: ' + type)
diff --git a/lib/point.js b/lib/point.js
index aa0bbd7..5551054 100644
--- a/lib/point.js
+++ b/lib/point.js
@@ -1,9 +1,10 @@
+'use strict'
module.exports = TestPoint
-var path = require('path')
-var binpath = path.resolve(__dirname, '../bin')
-var util = require('util')
-var diags = require('./diags.js')
+const path = require('path')
+const binpath = path.resolve(__dirname, '../bin')
+const util = require('util')
+const diags = require('./diags.js')
function TestPoint (ok, message, extra) {
if (typeof ok !== 'boolean')
@@ -34,7 +35,7 @@ function tpMessage (message, extra) {
} else if (extra.time)
message += ' # time=' + extra.time + 'ms'
- var diagYaml = extra.diagnostic ? diags(extra) : ''
+ const diagYaml = extra.diagnostic ? diags(extra) : ''
message += diagYaml
if (extra.tapChildBuffer || extra.tapChildBuffer === '') {
diff --git a/lib/spawn.js b/lib/spawn.js
index acc5ae6..e0c27c7 100644
--- a/lib/spawn.js
+++ b/lib/spawn.js
@@ -1,16 +1,17 @@
-var Base = require('./base.js')
+'use strict'
+const Base = require('./base.js')
-var assert = require('assert')
-var util = require('util')
+const assert = require('assert')
+const util = require('util')
util.inherits(Spawn, Base)
-var ownOr = require('own-or')
-var path = require('path')
-var cleanYamlObject = require('./clean-yaml-object.js')
+const ownOr = require('own-or')
+const path = require('path')
+const cleanYamlObject = require('./clean-yaml-object.js')
module.exports = Spawn
-var cp = require('child_process')
-var spawn = cp.spawn
+const cp = require('child_process')
+const spawn = cp.spawn
function Spawn (options) {
options = options || {}
@@ -35,7 +36,7 @@ function Spawn (options) {
this.stdio = [ 0, 'pipe', 2 ]
this.stdio[1] = 'pipe'
- var env = options.env || process.env
+ const env = options.env || process.env
this.env = Object.keys(env).reduce(function (e, k) {
e[k] = env[k]
return e
@@ -76,7 +77,7 @@ Spawn.prototype.endAll = function () {
Spawn.prototype.main = function (cb) {
this.cb = cb
this.setTimeout(this.options.timeout)
- var options = Object.keys(this.options).reduce(function (o, k) {
+ const options = Object.keys(this.options).reduce(function (o, k) {
o[k] = this.options[k]
return o
}.bind(this), {
@@ -85,7 +86,7 @@ Spawn.prototype.main = function (cb) {
stdio: this.stdio
})
try {
- var proc = this.proc = spawn(this.command, this.args, options)
+ const proc = this.proc = spawn(this.command, this.args, options)
proc.stdout.pipe(this.parser)
proc.on('close', this.onprocclose.bind(this))
proc.on('error', this.threw.bind(this))
@@ -129,7 +130,7 @@ Spawn.prototype.onprocclose = function (code, signal) {
Spawn.prototype.timeout = function (extra) {
if (this.proc)
this.proc.kill('SIGTERM')
- var t = setTimeout(function () {
+ const t = setTimeout(function () {
if (!this.options.signal && this.options.exitCode === undefined) {
Base.prototype.timeout.call(this, extra)
this.proc.kill('SIGKILL')
diff --git a/lib/stack.js b/lib/stack.js
index 11f2c85..5eb463e 100644
--- a/lib/stack.js
+++ b/lib/stack.js
@@ -1,10 +1,11 @@
-var sourceMapSupport = require('source-map-support')
-var StackUtils = require('stack-utils')
-var path = require('path')
-var tapDir = path.resolve(__dirname, '..')
+'use strict'
+const sourceMapSupport = require('source-map-support')
+const StackUtils = require('stack-utils')
+const path = require('path')
+const tapDir = path.resolve(__dirname, '..')
// don't skip when developing on tap itself
-var skip = process.cwd() !== tapDir ||
+const skip = process.cwd() !== tapDir ||
+process.env.TAP_DEV_SHORTSTACK === 1 &&
+process.env.TAP_DEV_LONGSTACK !== 1
? [
diff --git a/lib/stdin.js b/lib/stdin.js
index e85c773..07fc6f4 100644
--- a/lib/stdin.js
+++ b/lib/stdin.js
@@ -1,7 +1,8 @@
-var Base = require('./base.js')
-var util = require('util')
-var ownOr = require('own-or')
-var domain = require('domain')
+'use strict'
+const Base = require('./base.js')
+const util = require('util')
+const ownOr = require('own-or')
+const domain = require('domain')
util.inherits(Stdin, Base)
diff --git a/lib/synonyms.js b/lib/synonyms.js
index cb0a31d..c5b272b 100644
--- a/lib/synonyms.js
+++ b/lib/synonyms.js
@@ -1,3 +1,4 @@
+'use strict'
// A list of all the synonyms of assert methods.
// In addition to these, multi-word camelCase are also synonymized to
// all lowercase and snake_case
@@ -65,9 +66,8 @@ module.exports = multiword({
function multiword (obj) {
Object.keys(obj).forEach(function (i) {
- var list = obj[i]
- var res = [ multiword_(i) ].concat(list.map(multiword_))
- res = res.reduce(function (set, i) {
+ const list = obj[i]
+ const res = [ multiword_(i) ].concat(list.map(multiword_)).reduce(function (set, i) {
set.push.apply(set, i)
return set
}, [])
@@ -77,7 +77,7 @@ function multiword (obj) {
}
function multiword_ (str) {
- var res = [ str ]
+ const res = [ str ]
if (str.match(/[A-Z]/)) {
res.push(str.toLowerCase())
res.push(str.replace(/[A-Z]/g, function ($0) {
diff --git a/lib/tap.js b/lib/tap.js
index 3a67da1..d405b72 100644
--- a/lib/tap.js
+++ b/lib/tap.js
@@ -1,9 +1,10 @@
-var Test = require('./test.js')
-var Stdin = require('./stdin.js')
-var Spawn = require('./spawn.js')
-var util = require('util')
-var objToYaml = require('./obj-to-yaml.js')
-var yaml = require('js-yaml')
+'use strict'
+const Test = require('./test.js')
+const Stdin = require('./stdin.js')
+const Spawn = require('./spawn.js')
+const util = require('util')
+const objToYaml = require('./obj-to-yaml.js')
+const yaml = require('js-yaml')
util.inherits(TAP, Test)
function TAP (options) {
@@ -12,13 +13,13 @@ function TAP (options) {
this.start = Date.now()
}
-var didPipe = false
+let didPipe = false
TAP.prototype.pipe = function () {
didPipe = true
this.setTimeout(this.options.timeout)
this.pipe = Test.prototype.pipe
this.push = Test.prototype.push
- var ret = this.pipe.apply(this, arguments)
+ const ret = this.pipe.apply(this, arguments)
this.process()
return ret
}
@@ -53,7 +54,7 @@ function monkeypatchExit () {
process.on('exit', onExitEvent)
}
-var didOnExitEvent = false
+let didOnExitEvent = false
function onExitEvent (code) {
if (didOnExitEvent)
return process.exitCode || code
@@ -114,16 +115,16 @@ TAP.prototype.teardown = TAP.prototype.tearDown = function (fn) {
return Test.prototype.teardown.apply(this, arguments)
}
-var opt = { name: 'TAP' }
+const opt = { name: 'TAP' }
if (process.env.TAP_DEBUG === '1' ||
/\btap\b/.test(process.env.NODE_DEBUG || ''))
opt.debug = true
if (process.env.TAP_GREP) {
opt.grep = process.env.TAP_GREP.split('\n').map(function (g) {
- var p = g.match(/^\/(.*)\/([a-z]*)$/)
+ const p = g.match(/^\/(.*)\/([a-z]*)$/)
g = p ? p[1] : g
- var flags = p ? p[2] : ''
+ const flags = p ? p[2] : ''
return new RegExp(g, flags)
})
}
@@ -136,7 +137,7 @@ if (process.env.TAP_ONLY === '1') {
opt.only = true
}
-var tap = new TAP(opt)
+const tap = new TAP(opt)
module.exports = tap
tap.mocha = require('./mocha.js')
tap.mochaGlobals = tap.mocha.global
@@ -147,29 +148,29 @@ tap.Stdin = Stdin
tap.synonyms = require('./synonyms.js')
// SIGTERM means being forcibly killed, almost always by timeout
-var onExit = require('signal-exit')
-var didTimeoutKill = false
+const onExit = require('signal-exit')
+let didTimeoutKill = false
onExit(function (code, signal) {
if (signal !== 'SIGTERM' || !didPipe || didTimeoutKill)
return
- var handles = process._getActiveHandles().filter(function (h) {
+ const handles = process._getActiveHandles().filter(function (h) {
return h !== process.stdout &&
h !== process.stdin &&
h !== process.stderr
})
- var requests = process._getActiveRequests()
+ const requests = process._getActiveRequests()
// Ignore this because it's really hard to test cover in a way
// that isn't inconsistent and unpredictable.
/* istanbul ignore next */
- var extra = {
+ const extra = {
at: null,
signal: signal
}
if (requests.length) {
extra.requests = requests.map(function (r) {
- var ret = { type: r.constructor.name }
+ const ret = { type: r.constructor.name }
if (r.context) {
ret.context = r.context
}
@@ -178,7 +179,7 @@ onExit(function (code, signal) {
}
if (handles.length) {
extra.handles = handles.map(function (h) {
- var ret = { type: h.constructor.name }
+ const ret = { type: h.constructor.name }
if (h.msecs) {
ret.msecs = h.msecs
}
@@ -207,7 +208,7 @@ onExit(function (code, signal) {
if (!extra.at) {
delete extra.at
}
- var yaml = require('js-yaml')
+ const yaml = require('js-yaml')
console.error(objToYaml(extra))
}
didTimeoutKill = true
diff --git a/lib/test.js b/lib/test.js
index c3b8947..27e93a9 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -1,3 +1,4 @@
+'use strict'
// We need TWO queues (work and subtest) and one jobs pool
//
// The pool stores buffered subtests being run in parallel.
@@ -16,32 +17,32 @@
// encounter an unfinished test. When we encounter ANY kind of test, we
// block until its output is completed, dumping it all into the parser.
-var Base = require('./base.js')
-var Spawn = require('./spawn.js')
-var Stdin = require('./stdin.js')
-var Deferred = require('trivial-deferred')
-var Pool = require('yapool')
-var TestPoint = require('./point.js')
-var parseTestArgs = require('./parse-test-args.js')
-var loop = require('function-loop')
-
-var extraFromError = require('./extra-from-error.js')
-var stack = require('./stack.js')
-var assert = require('assert')
-var util = require('util')
+const Base = require('./base.js')
+const Spawn = require('./spawn.js')
+const Stdin = require('./stdin.js')
+const Deferred = require('trivial-deferred')
+const Pool = require('yapool')
+const TestPoint = require('./point.js')
+const parseTestArgs = require('./parse-test-args.js')
+const loop = require('function-loop')
+
+const extraFromError = require('./extra-from-error.js')
+const stack = require('./stack.js')
+const assert = require('assert')
+const util = require('util')
util.inherits(Test, Base)
-var ownOr = require('own-or')
-var ownOrEnv = require('own-or-env')
-var tapAsserts = require('./asserts.js')
-var Promise = require('bluebird')
-var bindObj = require('bind-obj-methods')
+const ownOr = require('own-or')
+const ownOrEnv = require('own-or-env')
+const tapAsserts = require('./asserts.js')
+const Promise = require('bluebird')
+const bindObj = require('bind-obj-methods')
// A sigil object for implicit end() calls that should not
// trigger an error if the user then calls t.end()
-var IMPLICIT = {}
+const IMPLICIT = {}
// Sigil to put in the queue to signal the end of all things
-var EOF = { EOF: true }
+const EOF = { EOF: true }
function hasOwn (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key)
@@ -78,8 +79,8 @@ function Test (options) {
this.ranAfterEach = false
// bind all methods to this object, so we can pass t.end as a callback
- // and do `var test = require('tap').test` like people do.
- var bound = Object.create(null)
+ // and do `const test = require('tap').test` like people do.
+ const bound = Object.create(null)
bindObj(this, this, bound)
bindObj(this, Object.getPrototypeOf(this), bound)
bindObj(this, Test.prototype, bound)
@@ -112,12 +113,10 @@ Test.prototype.spawn = function spawn (cmd, args, options, name) {
Test.prototype.sub = function (Class, extra, caller) {
extra = extra || {}
if (!extra.skip && this.grep.length) {
- var match = this.grep[0].test(extra.name)
- if (this.grepInvert) {
- match = !match
- }
+ const m = this.grep[0].test(extra.name)
+ const match = this.grepInvert ? !m : m
if (!match) {
- var p = 'filter' + (this.grepInvert ? ' out' : '') + ': '
+ const p = 'filter' + (this.grepInvert ? ' out' : '') + ': '
extra.skip = p + this.grep[0]
}
}
@@ -149,12 +148,12 @@ Test.prototype.sub = function (Class, extra, caller) {
extra.bail = ownOr(extra, 'bail', this.bail)
extra.parent = this
extra.stack = stack.captureString(80, caller)
- var t = new Class(extra)
+ const t = new Class(extra)
this.queue.push(t)
this.subtests.push(t)
- var d = new Deferred()
+ const d = new Deferred()
t.deferred = d
this.process()
return d.promise
@@ -190,8 +189,8 @@ Test.prototype.bailout = function (message) {
}
Test.prototype.comment = function () {
- var message = util.format.apply(util, arguments)
- message = '# ' + message.split(/\r?\n/).join('\n# ') + '\n'
+ const body = util.format.apply(util, arguments)
+ const message = '# ' + body.split(/\r?\n/).join('\n# ') + '\n'
if (this.results)
this.push(message)
@@ -214,12 +213,14 @@ Test.prototype.main = function (cb) {
this.setTimeout(this.options.timeout)
this.debug('MAIN pre', this)
- var self = this
- try {
- var ret = this.cb(this)
- } catch (er) {
- this.threw(er)
- }
+ const self = this
+ const ret = (() => {
+ try {
+ return this.cb(this)
+ } catch (er) {
+ this.threw(er)
+ }
+ })()
if (ret && ret.then) {
this.promise = ret
@@ -254,10 +255,10 @@ Test.prototype.process = function () {
this.debug('\nPROCESSING(%s)', this.name, this.queue.length)
this.processing = true
- var p
-
- while (!this.occupied && (p = this.queue.shift())) {
- this.debug('PROCESS(%s)', this.name, p)
+ while (!this.occupied) {
+ const p = this.queue.shift()
+ if (!p)
+ break
if (p instanceof Base) {
this.processSubtest(p)
} else if (p === EOF) {
@@ -272,20 +273,23 @@ Test.prototype.process = function () {
this.parser.write(p)
} else if (Array.isArray(p)) {
this.debug(' > METHOD')
- var m = p.shift()
+ const m = p.shift()
this[m].apply(this, p)
} else {
throw new Error('weird thing got in the queue')
}
}
- while (!this.noparallel &&
- this.pool.length < this.jobs &&
- (p = this.subtests.shift())) {
+ while (!this.noparallel && this.pool.length < this.jobs) {
+ const p = this.subtests.shift()
+ if (!p)
+ break
+
if (!p.buffered) {
this.noparallel = true
break
}
+
this.debug('start subtest', p)
this.pool.add(p)
if (this.bailedOut)
@@ -346,10 +350,9 @@ Test.prototype.emitSubTeardown = function (p) {
}
Test.prototype.writeSubComment = function (p, cb) {
- var comment = '# Subtest'
- if (p.name)
- comment += ': ' + p.name
- comment += '\n'
+ const comment = '# Subtest' +
+ (p.name ? ': ' + p.name : '') +
+ '\n'
this.parser.write(comment)
cb()
}
@@ -358,9 +361,8 @@ Test.prototype.onbufferedend = function (p, er) {
delete p.ondone
p.results = p.results || {}
p.readyToProcess = true
- var to = p.options.timeout
- if (to && p.passing())
- var dur = Date.now() - p.start
+ const to = p.options.timeout
+ const dur = (to && p.passing()) ? Date.now() - p.start : null
if (dur && dur > to)
p.timeout()
else
@@ -383,16 +385,15 @@ Test.prototype.onindentedend = function (p, er) {
delete p.ondone
this.debug('onindentedend', p)
this.noparallel = false
- var sti = this.subtests.indexOf(p)
+ const sti = this.subtests.indexOf(p)
if (sti !== -1)
this.subtests.splice(sti, 1)
p.readyToProcess = true
p.results = p.results || {}
if (p.time)
p.options.time = p.time
- var to = p.options.timeout
- if (to && p.passing())
- var dur = Date.now() - p.start
+ const to = p.options.timeout
+ const dur = (to && p.passing()) ? Date.now() - p.start : null
if (dur && dur > to)
p.timeout()
else
@@ -430,8 +431,8 @@ Test.prototype.addAssert = function (name, length, fn) {
if (!this.currentAssert) {
this.currentAssert = ASSERT
}
- var args = new Array(length + 2)
- for (var i = 0; i < length; i++) {
+ const args = new Array(length + 2)
+ for (let i = 0; i < length; i++) {
args[i] = arguments[i]
}
if (typeof arguments[length] === 'object') {
@@ -465,11 +466,8 @@ Test.prototype.fail = function fail (message, extra) {
this.printResult(false, message, extra)
- var ret = true
- if (!extra.todo && !extra.skip)
- ret = false
-
- return ret
+ // if it's todo or skip, it's still technically passing
+ return !!(extra.todo || extra.skip)
}
Test.prototype.pass = function pass (message, extra) {
@@ -481,16 +479,16 @@ Test.prototype.pass = function pass (message, extra) {
}
Test.prototype.printResult = function pR (ok, message, extra, front) {
- var n = this.count + 1
+ const n = this.count + 1
if (this.planEnd !== -1 && n > this.planEnd) {
if (!this.passing())
return
- var failMessage = this.explicitEnded
+ const failMessage = this.explicitEnded
? 'test after end() was called'
: 'test count exceeds plan'
- var er = new Error(failMessage)
+ const er = new Error(failMessage)
Error.captureStackTrace(er, this.currentAssert || pR)
er.test = this.name
er.plan = this.planEnd
@@ -513,7 +511,7 @@ Test.prototype.printResult = function pR (ok, message, extra, front) {
if (hasOwn(extra, 'stack') && !hasOwn(extra, 'at'))
extra.at = stack.parseLine(extra.stack.split('\n')[0])
- var fn = this.currentAssert || pR
+ const fn = this.currentAssert || pR
this.currentAssert = null
if (!ok && !extra.skip && !hasOwn(extra, 'at')) {
assert.equal(typeof fn, 'function')
@@ -522,25 +520,19 @@ Test.prototype.printResult = function pR (ok, message, extra, front) {
extra.stack = stack.captureString(80, fn)
}
- var diagnostic
- if (!ok)
- diagnostic = true
-
- if (extra.skip)
- diagnostic = false
-
- if (process.env.TAP_DIAG === '0')
- diagnostic = false
-
- if (typeof extra.diagnostic === 'boolean')
- diagnostic = extra.diagnostic
+ const diagnostic =
+ typeof extra.diagnostic === 'boolean' ? extra.diagnostic
+ : process.env.TAP_DIAG === '0' ? false
+ : process.env.TAP_DIAG === '1' ? true
+ : extra.skip ? false
+ : !ok
if (diagnostic)
extra.diagnostic = true
this.count = n
- var res = { ok: ok, message: message, extra: extra }
- var output = new TestPoint(ok, message, extra)
+ const res = { ok: ok, message: message, extra: extra }
+ const output = new TestPoint(ok, message, extra)
// when we jump the queue, skip an extra line
if (front)
output.message = output.message.trimRight() + '\n\n'
@@ -558,10 +550,9 @@ Test.prototype.printResult = function pR (ok, message, extra, front) {
}
Test.prototype.pragma = function (set) {
- var p = ''
- Object.keys(set).forEach(function (i) {
- p += 'pragma ' + (set[i] ? '+' : '-') + i + '\n'
- })
+ const p = Object.keys(set).reduce(function (acc, i) {
+ return acc + 'pragma ' + (set[i] ? '+' : '-') + i + '\n'
+ }, '')
this.queue.push(p)
this.process()
}
@@ -579,10 +570,7 @@ Test.prototype.plan = function (n, comment) {
}
// Cannot get any tests after a trailing plan, or a plan of 0
- var ending = false
- if (this.count !== 0 || n === 0) {
- ending = true
- }
+ const ending = this.count !== 0 || n === 0
if (n === 0)
this.skip = comment || true
@@ -624,7 +612,7 @@ function end (implicit) {
if (implicit !== IMPLICIT && !this.multiEndThrew) {
if (this.explicitEnded) {
this.multiEndThrew = true
- var er = new Error('test end() method called more than once')
+ const er = new Error('test end() method called more than once')
Error.captureStackTrace(er, this.currentAssert || end)
er.test = this.name
this.threw(er)
@@ -669,7 +657,7 @@ Test.prototype.threw = function (er, extra, proxy) {
}
Test.prototype.runBeforeEach = function (who, cb) {
- var self = this
+ const self = this
if (this.parent)
this.parent.runBeforeEach(who, function () {
loop(who, self.onBeforeEach, cb, who.threw)
@@ -679,7 +667,7 @@ Test.prototype.runBeforeEach = function (who, cb) {
}
Test.prototype.runAfterEach = function (who, cb) {
- var self = this
+ const self = this
loop(who, self.onAfterEach, function () {
if (self.parent)
self.parent.runAfterEach(who, cb)
@@ -701,7 +689,7 @@ Test.prototype.teardown = Test.prototype.tearDown = function (fn) {
}
Test.prototype.shouldAutoend = function () {
- var should = (
+ const should = (
this.options.autoend &&
!this.ended &&
!this.occupied &&
@@ -723,7 +711,7 @@ Test.prototype.maybeAutoend = function () {
clearTimeout(this.autoendTimer)
if (this.shouldAutoend()) {
- var self = this
+ const self = this
self.autoendTimer = setTimeout(function () {
if (self.shouldAutoend()) {
self.autoendTimer = setTimeout(function () {
@@ -754,7 +742,7 @@ function queueEmpty (t) {
Test.prototype.endAll = function (sub) {
this.processing = true
if (this.occupied) {
- var p = this.occupied
+ const p = this.occupied
if (p.endAll)
p.endAll(true)
else {
@@ -763,7 +751,7 @@ Test.prototype.endAll = function (sub) {
} else if (sub) {
this.process()
if (queueEmpty(this)) {
- var options = Object.keys(this.options).reduce(function (o, k) {
+ const options = Object.keys(this.options).reduce(function (o, k) {
o[k] = this.options[k]
return o
}.bind(this), {})
diff --git a/scripts/generate-test-test.js b/scripts/generate-test-test.js
index 3086c36..0a55d3c 100644
--- a/scripts/generate-test-test.js
+++ b/scripts/generate-test-test.js
@@ -1,15 +1,17 @@
#!/usr/bin/env node
-var spawn = require('child_process').spawn
-var path = require('path')
-var node = process.execPath
-var fs = require('fs')
-var yaml = require('js-yaml')
+'use strict'
-var queue = []
-var running = false
+const spawn = require('child_process').spawn
+const path = require('path')
+const node = process.execPath
+const fs = require('fs')
+const yaml = require('js-yaml')
-for (var i = 2; i < process.argv.length; i++) {
+const queue = []
+let running = false
+
+for (let i = 2; i < process.argv.length; i++) {
generate(process.argv[i], false, false)
generate(process.argv[i], true, false)
generate(process.argv[i], false, true)
@@ -24,20 +26,20 @@ function generate (file, bail, buffer) {
running = true
file = path.resolve(file)
- var cwd = process.cwd()
- var f = file
+ const cwd = process.cwd()
+ let f = file
if (f.indexOf(cwd) === 0) {
f = './' + file.substr(cwd.length + 1)
}
- var outfile = file.replace(/\.js$/,
+ const outfile = file.replace(/\.js$/,
(bail ? '--bail' : '') +
(buffer ? '--buffer' : '') +
'.tap')
console.error(outfile)
- var output = ''
- var c = spawn(node, [file], {
+ let output = ''
+ const c = spawn(node, [file], {
env: {
TAP_BAIL: bail ? 1 : 0,
TAP_BUFFER: buffer ? 1 : 0
@@ -54,8 +56,8 @@ function generate (file, bail, buffer) {
try { fs.unlinkSync(outfile) } catch (er) {}
} else {
- var timep = '# time=[0-9.]+(ms)?'
- var timere = new RegExp(timep, 'g')
+ const timep = '# time=[0-9.]+(ms)?'
+ const timere = new RegExp(timep, 'g')
output = output.replace(timere, '___/' + timep + '/~~~')
// raw stack traces vary in depth between node versions, and always
@@ -67,7 +69,7 @@ function generate (file, bail, buffer) {
output = output.split(file).join('___/.*/~~~' + path.basename(file))
output = output.split(f).join('___/.*/~~~' + path.basename(f))
- var dir = path.dirname(file)
+ const dir = path.dirname(file)
output = output.split(dir + '/').join('___/.*/~~~')
output = output.split(dir).join('___/.*/~~~' + path.basename(dir))
@@ -90,7 +92,7 @@ function generate (file, bail, buffer) {
running = false
if (queue.length) {
- var q = queue.shift()
+ const q = queue.shift()
generate(q[0], q[1], q[2])
}
})
@@ -121,18 +123,17 @@ function deStackify (data) {
}
function yamlishToJson (output) {
- var lines = output.split(/\n/)
- var ret = ''
- var inyaml = false
- var y = ''
- var startlen = 0
- for (var i = 0; i < lines.length; i++) {
- var line = lines[i]
+ const lines = output.split(/\n/)
+ let ret = ''
+ let inyaml = false
+ let y = ''
+ let startlen = 0
+ for (let i = 0; i < lines.length; i++) {
+ const line = lines[i]
if (inyaml) {
if (line.match(/^\s+\.\.\.$/) && line.length === startlen) {
- var data = yaml.safeLoad(y)
- data = deStackify(data)
- data = JSON.stringify(data)
+ const yload = yaml.safeLoad(y)
+ const data = JSON.stringify(deStackify(yload))
ret += new Array(startlen - 2).join(' ') +
data + '\n' + line + '\n'
inyaml = false
--
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