function Spawn(options) { options = options || {} if (!(this instanceof Spawn)) return new Spawn(options) Base.call(this, options) this.command = options.command if (!this.command) throw new TypeError('no command provided') this.args = options.args // stdout must be a pipe if (options.stdio) { if (typeof options.stdio === 'string') this.stdio = [ options.stdio, 'pipe', options.stdio ] else this.stdio = options.stdio.slice(0) } else this.stdio = [ 0, 'pipe', 2 ] this.stdio[1] = 'pipe' var env = options.env || process.env this.env = Object.keys(env).reduce(function (e, k) { e[k] = env[k] return e }, {}) this.env.TAP = '1' if (this.bail) this.env.TAP_BAIL = '1' this.cwd = ownOr(options, 'cwd', process.cwd()) options.cwd = this.cwd if (!this.name) { if (this.command === process.execPath) { this.name = path.basename(process.execPath) + ' ' + this.args.map(function (a) { if (a.indexOf(this.cwd) === 0) { return './' + a.substr(this.cwd.length + 1).replace(/\\/g, '/') } else { return a } }, this).join(' ') } else { this.name = this.command + ' ' + this.args.join(' ') } } this.proc = null }
n/a
function Base(options) { this.start = 0 this.hrtime = null this.time = null this.readyToProcess = false this.options = options this.parent = ownOr(options, 'parent', null) this.bail = ownOrEnv(options, 'bail', 'TAP_BAIL', true) this.name = ownOr(options, 'name', '') if (!this.name) this.name = '' else this.name = this.name.replace(/[\n\r\s\t]/g, ' ') this.indent = ownOr(options, 'indent', '') this.silent = !!options.silent this.buffered = !!options.buffered || !!options.silent this.finished = false this.strict = ownOrEnv(options, 'strict', 'TAP_STRICT', true) this.omitVersion = !!options.omitVersion this.preserveWhitespace = ownOr(options, 'preserveWhitespace', true) this.jobs = +ownOrEnv(options, 'jobs', 'TAP_JOBS') || 0 this.skip = ownOr(options, 'skip', false) this.todo = ownOr(options, 'todo', false) this.setupParser(options) this.finished = false this.output = '' this.results = null this.bailedOut = false if (this.skip || this.todo) this.main = Base.prototype.main Readable.apply(this, options) domain.create().add(this) this.domain.on('error', this.threw.bind(this)) if (typeof options.debug === 'boolean') this.debug = options.debug ? debug : nodebug }
n/a
function Stdin(options) { options = options || {} if (!(this instanceof Stdin)) return new Stdin(options) options.name = ownOr(options, 'name', '/dev/stdin') Base.call(this, options) // This has to be here for node 0.10's wonky streams this.stream = ownOr(options, 'tapStream', process.stdin) this.stream.pause() }
n/a
function Test(options) { options = options || {} if (!(this instanceof Test)) return new Test(options) Base.call(this, options) this.pushedEnd = false this.jobs = ownOr(options, 'jobs', 1) this.subtests = [] this.pool = new Pool() this.queue = ['TAP version 13\n'] this.noparallel = false this.cb = this.domain.bind(options.cb) this.occupied = false this.currentAssert = null this.count = 0 this.n = 0 this.ended = false this.explicitEnded = false this.multiEndThrew = false this.currentAssert = null this.assertAt = null this.assertStack = null this.planEnd = -1 this.onBeforeEach = [] this.onAfterEach = [] 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) bindObj(this, this, bound) bindObj(this, Object.getPrototypeOf(this), bound) bindObj(this, Test.prototype, bound) }
n/a
addAssert = function () { [native code] }
...
// typically, a plugin would do this on a specific instance, eg on
// the root test harness instance. but we do this here to add some
// useful prototype methods.
exports.decorate = decorate
function decorate (t) {
t.addAssert('ok', 1, function (obj, message, extra) {
message = message || 'expect truthy value'
if (obj) {
return this.pass(message, extra)
}
return this.fail(message, extra)
})
...
afterEach = function () { [native code] }
n/a
autoend = function () { [native code] }
n/a
bailout = function () { [native code] }
n/a
beforeEach = function () { [native code] }
n/a
cb = function () { [native code] }
n/a
comment = function () { [native code] }
n/a
current = function () { [native code] }
n/a
done = function () { [native code] }
n/a
emitSubTeardown = function () { [native code] }
n/a
end = function () { [native code] }
...
if (options.outputFile !== null)
tap.pipe(fs.createWriteStream(options.outputFile)).write('TAP version 13\n')
saveFails(options, tap)
runAllFiles(options, saved, tap)
tap.end()
}
function parseRcFile (path) {
try {
var contents = fs.readFileSync(path, 'utf8')
return yaml.safeLoad(contents) || {}
} catch (er) {
...
endAll = function () { [native code] }
n/a
fail = function () { [native code] }
...
function decorate (t) {
t.addAssert('ok', 1, function (obj, message, extra) {
message = message || 'expect truthy value'
if (obj) {
return this.pass(message, extra)
}
return this.fail(message, extra)
})
t.addAssert('notOk', 1, function (obj, message, extra) {
message = message || 'expect falsey value'
return this.ok(!obj, message, extra)
})
...
main = function () { [native code] }
n/a
maybeAutoend = function () { [native code] }
n/a
mochaGlobals = function () { Object.keys(exports).forEach(function (g) { global[g] = exports[g] }) }
...
#!/usr/bin/env node
var tap = require('../lib/tap.js')
var args = process.argv.slice(2)
if (args.length === 1) {
var path = require('path')
var file = path.resolve(args[0])
tap.mochaGlobals()
require(file)
} else {
for (var i = 0; i < args.length; i++) {
tap.spawn(process.execPath, [__filename, args[i]])
}
}
...
onbail = function () { [native code] }
n/a
onbeforeend = function () { [native code] }
n/a
onbufferedend = function () { [native code] }
n/a
ondone = function () { [native code] }
n/a
onindentedend = function () { [native code] }
n/a
pass = function () { [native code] }
...
exports.decorate = decorate
function decorate (t) {
t.addAssert('ok', 1, function (obj, message, extra) {
message = message || 'expect truthy value'
if (obj) {
return this.pass(message, extra)
}
return this.fail(message, extra)
})
t.addAssert('notOk', 1, function (obj, message, extra) {
message = message || 'expect falsey value'
...
patchProcess = function () { [native code] }
...
var 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')
tap.jobs = options.jobs
tap.patchProcess()
// if not -Rtap, then output what the user wants.
// otherwise just dump to stdout
tap.pipe(options.reporter === 'tap' ? process.stdout: makeReporter(options))
// need to replay the first version line, because the previous
// line will have flushed it out to stdout or the reporter already.
...
pipe = function () { [native code] }
...
console.log('%s:%s', service.name, process.env[service.env])
}
var ca = spawn(node, [bin], {
stdio: [ 'pipe', 1, 2 ]
})
child.stdout.pipe(ca.stdin)
ca.on('close', function (code, signal) {
if (signal)
process.kill(process.pid, signal)
else if (code)
console.log('Error piping coverage to ' + service.name)
else
...
plan = function () { [native code] }
n/a
pragma = function () { [native code] }
n/a
printResult = function () { [native code] }
n/a
process = function () { [native code] }
n/a
processSubtest = function () { [native code] }
n/a
push = function () { [native code] }
...
if ((options.coverageReport || options.checkCoverage) &&
options.files.length === 0)
return runCoverageReport(options)
if (options.files.length === 0) {
console.error('Reading TAP data from stdin (use "-" argument to suppress)')
options.files.push('-')
}
if (options.files.length === 1 && options.files[0] === '-') {
if (options.coverage)
console.error('Coverage disabled because stdin cannot be instrumented')
stdinOnly(options)
return
...
runAfterEach = function () { [native code] }
n/a
runBeforeEach = function () { [native code] }
n/a
shouldAutoend = function () { [native code] }
n/a
spawn = function () { [native code] }
...
if (args.length === 1) {
var path = require('path')
var file = path.resolve(args[0])
tap.mochaGlobals()
require(file)
} else {
for (var i = 0; i < args.length; i++) {
tap.spawn(process.execPath, [__filename, args[i]])
}
}
...
stdin = function () { [native code] }
...
}), 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)
}
if (doStdin)
tap.stdin()
}
function runTests (options) {
var saved = readSaveFile(options)
// At this point, we know we need to use the tap root,
// because there are 1 or more files to spawn.
...
sub = function () { [native code] }
n/a
tearDown = function () { [native code] }
n/a
teardown = function () { [native code] }
n/a
test = function () { [native code] }
...
return files.reduce(function (acc, f) {
if (f === '-') {
acc.push(f)
return acc
}
// glob claims patterns MUST not include any '\'s
if (!/\\/.test(f))
f = glob.sync(f) || f
return acc.concat(f)
}, [])
}
function makeReporter (options) {
...
threw = function () { [native code] }
n/a
timeout = function () { [native code] }
n/a
writeSubComment = function () { [native code] }
n/a
function Spawn(options) { options = options || {} if (!(this instanceof Spawn)) return new Spawn(options) Base.call(this, options) this.command = options.command if (!this.command) throw new TypeError('no command provided') this.args = options.args // stdout must be a pipe if (options.stdio) { if (typeof options.stdio === 'string') this.stdio = [ options.stdio, 'pipe', options.stdio ] else this.stdio = options.stdio.slice(0) } else this.stdio = [ 0, 'pipe', 2 ] this.stdio[1] = 'pipe' var env = options.env || process.env this.env = Object.keys(env).reduce(function (e, k) { e[k] = env[k] return e }, {}) this.env.TAP = '1' if (this.bail) this.env.TAP_BAIL = '1' this.cwd = ownOr(options, 'cwd', process.cwd()) options.cwd = this.cwd if (!this.name) { if (this.command === process.execPath) { this.name = path.basename(process.execPath) + ' ' + this.args.map(function (a) { if (a.indexOf(this.cwd) === 0) { return './' + a.substr(this.cwd.length + 1).replace(/\\/g, '/') } else { return a } }, this).join(' ') } else { this.name = this.command + ' ' + this.args.join(' ') } } this.proc = null }
n/a
function Base(options) { this.start = 0 this.hrtime = null this.time = null this.readyToProcess = false this.options = options this.parent = ownOr(options, 'parent', null) this.bail = ownOrEnv(options, 'bail', 'TAP_BAIL', true) this.name = ownOr(options, 'name', '') if (!this.name) this.name = '' else this.name = this.name.replace(/[\n\r\s\t]/g, ' ') this.indent = ownOr(options, 'indent', '') this.silent = !!options.silent this.buffered = !!options.buffered || !!options.silent this.finished = false this.strict = ownOrEnv(options, 'strict', 'TAP_STRICT', true) this.omitVersion = !!options.omitVersion this.preserveWhitespace = ownOr(options, 'preserveWhitespace', true) this.jobs = +ownOrEnv(options, 'jobs', 'TAP_JOBS') || 0 this.skip = ownOr(options, 'skip', false) this.todo = ownOr(options, 'todo', false) this.setupParser(options) this.finished = false this.output = '' this.results = null this.bailedOut = false if (this.skip || this.todo) this.main = Base.prototype.main Readable.apply(this, options) domain.create().add(this) this.domain.on('error', this.threw.bind(this)) if (typeof options.debug === 'boolean') this.debug = options.debug ? debug : nodebug }
n/a
endAll = function () { if (this.proc) this.proc.kill('SIGKILL') this.parser.abort('test unfinished') this.cb() }
n/a
main = function (cb) { this.cb = cb this.setTimeout(this.options.timeout) var options = Object.keys(this.options).reduce(function (o, k) { o[k] = this.options[k] return o }.bind(this), { cwd: this.cwd, env: this.env, stdio: this.stdio }) try { var 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)) } catch (er) { this.threw(er) } }
n/a
onprocclose = function (code, signal) { this.debug('SPAWN close %j %s', code, signal) this.options.exitCode = code if (signal) this.options.signal = signal this.results = this.results || {} // spawn closing with no tests is treated as a skip. if (this.results.plan && this.results.plan.skipAll && !code && !signal) this.options.skip = this.results.plan.skipReason || true if (code || signal) { this.results.ok = false this.parser.ok = false } return this.cb() }
n/a
threw = function (er, extra, proxy) { extra = Base.prototype.threw.call(this, er, extra, proxy) extra = cleanYamlObject(extra) // unhook entirely this.parser.abort(er.message, extra) if (this.proc) { this.proc.stdout.removeAllListeners('data') this.proc.stdout.removeAllListeners('end') this.proc.removeAllListeners('close') this.proc.kill('SIGKILL') } this.cb() }
n/a
timeout = function (extra) { if (this.proc) this.proc.kill('SIGTERM') var t = setTimeout(function () { if (!this.options.signal && this.options.exitCode === undefined) { Base.prototype.timeout.call(this, extra) this.proc.kill('SIGKILL') } }.bind(this), 1000) if (t.unref) t.unref() }
n/a
function Readable(options) { if (!(this instanceof Readable)) return new Readable(options); this._readableState = new ReadableState(options, this); // legacy this.readable = true; if (options && typeof options.read === 'function') this._read = options.read; Stream.call(this); }
n/a
_read = function (n) { // this.emit('readable') // this.debug('_read %j', this.name, arguments) }
n/a
function nodebug() {}
n/a
inspect = function () { return this.constructor.name + ' ' + util.inspect({ name: this.name, jobs: this.jobs, buffered: this.buffered, occupied: this.occupied, pool: this.pool, queue: this.queue, subtests: this.subtests, output: this.output, skip: this.skip, todo: this.todo, results: this.results, options: [ 'autoend', 'command', 'args', 'stdio', 'env', 'cwd', 'exitCode', 'signal', 'expired', 'timeout', 'at', 'skip', 'todo' ].reduce(function (set, k) { if (this.options[k] !== undefined) set[k] = this.options[k] return set }.bind(this), {}) }) }
n/a
main = function (cb) { cb() }
n/a
onbail = function (reason) { this.bailedOut = reason || true this.emit('bailout', reason) }
n/a
onbeforeend = function () {}
n/a
oncomplete = function (results) { if (this.hrtime) { this.hrtime = process.hrtime(this.hrtime) this.time = Math.round(this.hrtime[0] * 1e6 + this.hrtime[1] / 1e3) / 1e3 } this.debug('ONCOMPLETE %j %j', this.name, results) if (this.results) Object.keys(this.results).forEach(function (k) { results[k] = this.results[k] }, this) this.results = results this.emit('complete', results) var failures = results.failures.filter(function (f) { delete f.diag delete f.ok return f.tapError }) if (failures.length) this.options.failures = failures this.onbeforeend() this.emit('end') this.ondone() }
n/a
ondone = function () {}
n/a
online = function (line) { this.debug('LINE %j', line) return this.push(this.indent + line) }
n/a
passing = function () { return this.parser.ok }
n/a
push = function (c, e) { assert.equal(typeof c, 'string') assert.equal(c.substr(-1), '\n') if (this.buffered) { this.output += c return true } // We *always* want data coming out immediately. Test runners have a // very special relationship with zalgo. It's more important to ensure // that any console.log() lines that appear in the midst of tests are // not taken out of context if (this._readableState) { this._readableState.sync = false } // this.debug(this._readableState) return Readable.prototype.push.call(this, c, e) }
...
if ((options.coverageReport || options.checkCoverage) &&
options.files.length === 0)
return runCoverageReport(options)
if (options.files.length === 0) {
console.error('Reading TAP data from stdin (use "-" argument to suppress)')
options.files.push('-')
}
if (options.files.length === 1 && options.files[0] === '-') {
if (options.coverage)
console.error('Coverage disabled because stdin cannot be instrumented')
stdinOnly(options)
return
...
setTimeout = function (n) { if (!this.hrtime) this.hrtime = process.hrtime() if (!n) { clearTimeout(this.timer) this.timer = null } else { this.start = Date.now() this.timer = setTimeout(this.timeout.bind(this), n) if (this.timer.unref) this.timer.unref() } }
n/a
setupParser = function (options) { this.parser = new Parser({ bail: this.bail, strict: this.strict, omitVersion: this.omitVersion, preserveWhitespace: this.preserveWhitespace }) assert(this.parser.preserveWhitespace) this.parser.on('line', this.online.bind(this)) this.parser.once('bailout', this.onbail.bind(this)) this.parser.on('complete', this.oncomplete.bind(this)) }
n/a
threw = function (er, extra, proxy) { if (this.name && !proxy) er.test = this.name var message = er.message if (!extra) extra = extraFromError(er, extra, this.options) if (this.results || this.ended) { this.results.ok = false if (this.parent) this.parent.threw(er, extra, true) else if (!er.stack) console.error(er) else { er.message = message delete extra.stack delete extra.at console.error('%s: %s', er.name || 'Error', message) console.error(er.stack.split(/\n/).slice(1).join('\n')) console.error(extra) } } else this.parser.ok = false return extra }
n/a
timeout = function (options) { this.setTimeout(false) var er = new Error('timeout!') options = options || {} options.expired = options.expired || this.name this.threw(new Error('timeout!'), options) }
n/a
function Stdin(options) { options = options || {} if (!(this instanceof Stdin)) return new Stdin(options) options.name = ownOr(options, 'name', '/dev/stdin') Base.call(this, options) // This has to be here for node 0.10's wonky streams this.stream = ownOr(options, 'tapStream', process.stdin) this.stream.pause() }
n/a
function Base(options) { this.start = 0 this.hrtime = null this.time = null this.readyToProcess = false this.options = options this.parent = ownOr(options, 'parent', null) this.bail = ownOrEnv(options, 'bail', 'TAP_BAIL', true) this.name = ownOr(options, 'name', '') if (!this.name) this.name = '' else this.name = this.name.replace(/[\n\r\s\t]/g, ' ') this.indent = ownOr(options, 'indent', '') this.silent = !!options.silent this.buffered = !!options.buffered || !!options.silent this.finished = false this.strict = ownOrEnv(options, 'strict', 'TAP_STRICT', true) this.omitVersion = !!options.omitVersion this.preserveWhitespace = ownOr(options, 'preserveWhitespace', true) this.jobs = +ownOrEnv(options, 'jobs', 'TAP_JOBS') || 0 this.skip = ownOr(options, 'skip', false) this.todo = ownOr(options, 'todo', false) this.setupParser(options) this.finished = false this.output = '' this.results = null this.bailedOut = false if (this.skip || this.todo) this.main = Base.prototype.main Readable.apply(this, options) domain.create().add(this) this.domain.on('error', this.threw.bind(this)) if (typeof options.debug === 'boolean') this.debug = options.debug ? debug : nodebug }
n/a
main = function (cb) { this.domain.add(this.stream) this.setTimeout(this.options.timeout) this.stream.pipe(this.parser) this.stream.resume() this.once('end', cb) }
n/a
threw = function (er, extra, proxy) { extra = Base.prototype.threw.call(this, er, extra, proxy) this.options = extra this.parser.abort(er.message, extra) this.parser.end() }
n/a
function Test(options) { options = options || {} if (!(this instanceof Test)) return new Test(options) Base.call(this, options) this.pushedEnd = false this.jobs = ownOr(options, 'jobs', 1) this.subtests = [] this.pool = new Pool() this.queue = ['TAP version 13\n'] this.noparallel = false this.cb = this.domain.bind(options.cb) this.occupied = false this.currentAssert = null this.count = 0 this.n = 0 this.ended = false this.explicitEnded = false this.multiEndThrew = false this.currentAssert = null this.assertAt = null this.assertStack = null this.planEnd = -1 this.onBeforeEach = [] this.onAfterEach = [] 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) bindObj(this, this, bound) bindObj(this, Object.getPrototypeOf(this), bound) bindObj(this, Test.prototype, bound) }
n/a
function Base(options) { this.start = 0 this.hrtime = null this.time = null this.readyToProcess = false this.options = options this.parent = ownOr(options, 'parent', null) this.bail = ownOrEnv(options, 'bail', 'TAP_BAIL', true) this.name = ownOr(options, 'name', '') if (!this.name) this.name = '' else this.name = this.name.replace(/[\n\r\s\t]/g, ' ') this.indent = ownOr(options, 'indent', '') this.silent = !!options.silent this.buffered = !!options.buffered || !!options.silent this.finished = false this.strict = ownOrEnv(options, 'strict', 'TAP_STRICT', true) this.omitVersion = !!options.omitVersion this.preserveWhitespace = ownOr(options, 'preserveWhitespace', true) this.jobs = +ownOrEnv(options, 'jobs', 'TAP_JOBS') || 0 this.skip = ownOr(options, 'skip', false) this.todo = ownOr(options, 'todo', false) this.setupParser(options) this.finished = false this.output = '' this.results = null this.bailedOut = false if (this.skip || this.todo) this.main = Base.prototype.main Readable.apply(this, options) domain.create().add(this) this.domain.on('error', this.threw.bind(this)) if (typeof options.debug === 'boolean') this.debug = options.debug ? debug : nodebug }
n/a
addAssert = function (name, length, fn) { if (!name) throw new TypeError('name is required for addAssert') if (!(typeof length === 'number' && length >= 0)) throw new TypeError('number of args required') if (typeof fn !== 'function') throw new TypeError('function required for addAssert') if (Test.prototype[name] || this[name]) throw new TypeError('attempt to re-define `' + name + '` assert') this[name] = function ASSERT () { if (!this.currentAssert) { this.currentAssert = ASSERT } var args = new Array(length + 2) for (var i = 0; i < length; i++) { args[i] = arguments[i] } if (typeof arguments[length] === 'object') { args[length] = '' args[length + 1] = arguments[length] } else { args[length] = arguments[length] || '' args[length + 1] = arguments[length + 1] || {} } return fn.apply(this, args) } }
...
// typically, a plugin would do this on a specific instance, eg on
// the root test harness instance. but we do this here to add some
// useful prototype methods.
exports.decorate = decorate
function decorate (t) {
t.addAssert('ok', 1, function (obj, message, extra) {
message = message || 'expect truthy value'
if (obj) {
return this.pass(message, extra)
}
return this.fail(message, extra)
})
...
afterEach = function (fn) { this.onAfterEach.push(fn) }
n/a
autoend = function () { this.options.autoend = true this.maybeAutoend() }
n/a
bailout = function (message) { if (this.parent && (this.results || this.ended)) this.parent.bailout(message) else { this.process() message = message ? ' ' + ('' + message).trim() : '' message = message.replace(/[\r\n]/g, ' ') this.parser.write('Bail out!' + message + '\n') } this.end(IMPLICIT) this.process() }
n/a
beforeEach = function (fn) { this.onBeforeEach.push(fn) }
n/a
comment = function () { var message = util.format.apply(util, arguments) message = '# ' + message.split(/\r?\n/).join('\n# ') + '\n' if (this.results) this.push(message) else this.queue.push(message) this.process() }
n/a
current = function () { throw new Error('Test.current() as been removed and is no more') }
n/a
done = function (implicit) { this.debug('END implicit=%j', implicit === IMPLICIT) if (this.ended && implicit === IMPLICIT) return // beyond here we have to be actually done with things, or else // the semantic checks on counts and such will be off. if (!queueEmpty(this) || this.occupied) { if (!this.pushedEnd) this.queue.push(['end', implicit]) this.pushedEnd = true return this.process() } if (!this.ranAfterEach && this.parent) { this.ranAfterEach = true this.parent.runAfterEach(this, end.bind(this, implicit)) } else end.call(this, implicit) }
n/a
emitSubTeardown = function (p) { try { p.emit('teardown') } catch (er) { delete p.options.time p.threw(er) } }
n/a
end = function (implicit) { this.debug('END implicit=%j', implicit === IMPLICIT) if (this.ended && implicit === IMPLICIT) return // beyond here we have to be actually done with things, or else // the semantic checks on counts and such will be off. if (!queueEmpty(this) || this.occupied) { if (!this.pushedEnd) this.queue.push(['end', implicit]) this.pushedEnd = true return this.process() } if (!this.ranAfterEach && this.parent) { this.ranAfterEach = true this.parent.runAfterEach(this, end.bind(this, implicit)) } else end.call(this, implicit) }
...
if (options.outputFile !== null)
tap.pipe(fs.createWriteStream(options.outputFile)).write('TAP version 13\n')
saveFails(options, tap)
runAllFiles(options, saved, tap)
tap.end()
}
function parseRcFile (path) {
try {
var contents = fs.readFileSync(path, 'utf8')
return yaml.safeLoad(contents) || {}
} catch (er) {
...
endAll = function (sub) { this.processing = true if (this.occupied) { var p = this.occupied if (p.endAll) p.endAll(true) else { p.parser.abort('test unfinished') } } else if (sub) { this.process() if (queueEmpty(this)) { var options = Object.keys(this.options).reduce(function (o, k) { o[k] = this.options[k] return o }.bind(this), {}) this.options.at = null this.options.stack = '' options.test = this.name this.fail('test unfinished', options) } } if (this.promise && this.promise.tapAbortPromise) this.promise.tapAbortPromise() if (this.occupied) { this.queue.unshift(this.occupied) this.occupied = null } endAllQueue(this.queue) this.processing = false this.process() this.parser.end() }
n/a
function fail(message, extra) { if (!this.currentAssert) { this.currentAssert = fail } if (message && typeof message === 'object') { extra = message message = '' } else { if (!message) { message = '' } if (!extra) { extra = {} } } this.printResult(false, message, extra) var ret = true if (!extra.todo && !extra.skip) ret = false return ret }
...
function decorate (t) {
t.addAssert('ok', 1, function (obj, message, extra) {
message = message || 'expect truthy value'
if (obj) {
return this.pass(message, extra)
}
return this.fail(message, extra)
})
t.addAssert('notOk', 1, function (obj, message, extra) {
message = message || 'expect falsey value'
return this.ok(!obj, message, extra)
})
...
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) } if (ret && ret.then) { this.promise = ret ret.tapAbortPromise = done ret.then(end, done) } else done() function end () { self.debug(' > implicit end for promise') self.end(IMPLICIT) done() } function done (er) { if (er) self.threw(er) if (self.results || self.bailedOut) cb() else self.ondone = cb } this.debug('MAIN post', this) }
n/a
maybeAutoend = function () { if (this.autoendTimer) clearTimeout(this.autoendTimer) if (this.shouldAutoend()) { var self = this self.autoendTimer = setTimeout(function () { if (self.shouldAutoend()) { self.autoendTimer = setTimeout(function () { if (self.shouldAutoend()) { self.end(IMPLICIT) } }) } }) } }
n/a
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 if (dur && dur > to) p.timeout() else p.setTimeout(false) this.debug('%s.onbufferedend', this.name, p.name, p.results.bailout) this.pool.remove(p) p.options.tapChildBuffer = p.output || '' p.options.stack = '' if (p.time) p.options.time = p.time if (this.occupied === p) this.occupied = null if (er) this.threw(er) p.deferred.resolve(this) this.process() }
n/a
onindentedend = function (p, er) { delete p.ondone this.debug('onindentedend', p) this.noparallel = false var 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 if (dur && dur > to) p.timeout() else p.setTimeout(false) this.debug('onindentedend %s(%s)', this.name, p.name, er || 'ok') assert(this.occupied === p) this.occupied = null this.debug('OIE(%s) b>shift into queue', this.name, this.queue) p.options.stack = '' this.queue.unshift(['emitSubTeardown', p]) this.printResult(p.passing(), p.name, p.options, true) this.debug('OIE(%s) shifted into queue', this.name, this.queue) if (er) this.threw(er) p.deferred.resolve(this) this.process() }
n/a
function pass(message, extra) { if (!this.currentAssert) { this.currentAssert = pass } this.printResult(true, message || '(unnamed test)', extra) return true }
...
exports.decorate = decorate
function decorate (t) {
t.addAssert('ok', 1, function (obj, message, extra) {
message = message || 'expect truthy value'
if (obj) {
return this.pass(message, extra)
}
return this.fail(message, extra)
})
t.addAssert('notOk', 1, function (obj, message, extra) {
message = message || 'expect falsey value'
...
plan = function (n, comment) { if (this.bailedOut) return if (this.planEnd !== -1) { throw new Error('Cannot set plan more than once') } if (typeof n !== 'number' || n < 0) { throw new TypeError('plan must be a number') } // Cannot get any tests after a trailing plan, or a plan of 0 var ending = false if (this.count !== 0 || n === 0) { ending = true } if (n === 0) this.skip = comment || true this.planEnd = n comment = comment ? ' # ' + comment.trim() : '' this.queue.push('1..' + n + comment + '\n') if (ending) this.end(IMPLICIT) else this.process() }
n/a
pragma = function (set) { var p = '' Object.keys(set).forEach(function (i) { p += 'pragma ' + (set[i] ? '+' : '-') + i + '\n' }) this.queue.push(p) this.process() }
n/a
function pR(ok, message, extra, front) { var n = this.count + 1 if (this.planEnd !== -1 && n > this.planEnd) { if (!this.passing()) return var failMessage = this.explicitEnded ? 'test after end() was called' : 'test count exceeds plan' var er = new Error(failMessage) Error.captureStackTrace(er, this.currentAssert || pR) er.test = this.name er.plan = this.planEnd this.threw(er) return } extra = extra || {} if (this.assertAt) { extra.at = this.assertAt this.assertAt = null } if (this.assertStack) { extra.stack = this.assertStack this.assertStack = null } if (hasOwn(extra, 'stack') && !hasOwn(extra, 'at')) extra.at = stack.parseLine(extra.stack.split('\n')[0]) var fn = this.currentAssert || pR this.currentAssert = null if (!ok && !extra.skip && !hasOwn(extra, 'at')) { assert.equal(typeof fn, 'function') extra.at = stack.at(fn) if (!extra.todo) 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 if (diagnostic) extra.diagnostic = true this.count = n var res = { ok: ok, message: message, extra: extra } var output = new TestPoint(ok, message, extra) // when we jump the queue, skip an extra line if (front) output.message = output.message.trimRight() + '\n\n' if (front) { this.emit('result', res) this.parser.write(output.ok + (++this.n) + output.message) } else this.queue.push(['emit', 'result', res], output) if (this.planEnd === this.count) this.end(IMPLICIT) this.process() }
n/a
process = function () { if (this.processing) return this.debug(' < already processing') 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) if (p instanceof Base) { this.processSubtest(p) } else if (p === EOF) { this.debug(' > EOF', this.name) // I AM BECOME EOF, DESTROYER OF STREAMS this.parser.end() } else if (p instanceof TestPoint) { this.debug(' > TESTPOINT') this.parser.write(p.ok + (++this.n) + p.message) } else if (typeof p === 'string') { this.debug(' > STRING') this.parser.write(p) } else if (Array.isArray(p)) { this.debug(' > METHOD') var 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())) { if (!p.buffered) { this.noparallel = true break } this.debug('start subtest', p) this.pool.add(p) if (this.bailedOut) this.onbufferedend(p) else this.runBeforeEach(p, p.main.bind(p, this.onbufferedend.bind(this, p))) } this.debug('done processing', this.queue, this.occupied) this.processing = false // just in case any tests ended, and we have sync stuff still // waiting around in the queue to be processed if (!this.occupied && this.queue.length) this.process() this.maybeAutoend() }
n/a
processSubtest = function (p) { this.debug(' > subtest') this.occupied = p if (!p.buffered) { if (this.bailedOut) return this.onindentedend(p) this.debug(' > subtest indented') p.pipe(this.parser, { end: false }) this.runBeforeEach(p, this.writeSubComment.bind(this, p, p.main.bind(p, this.onindentedend.bind(this, p)))) } else if (p.readyToProcess) { this.debug(' > subtest buffered, finished') // finished! do the thing! this.occupied = null if (!p.passing() || !p.silent) { this.queue.unshift(['emitSubTeardown', p]) this.printResult(p.passing(), p.name, p.options, true) } } else { this.occupied = p this.debug(' > subtest buffered, unfinished', p) // unfinished buffered test. // nothing to do yet, just leave it there. this.queue.unshift(p) } }
n/a
runAfterEach = function (who, cb) { var self = this loop(who, self.onAfterEach, function () { if (self.parent) self.parent.runAfterEach(who, cb) else cb() }, who.threw) }
n/a
runBeforeEach = function (who, cb) { var self = this if (this.parent) this.parent.runBeforeEach(who, function () { loop(who, self.onBeforeEach, cb, who.threw) }) else loop(who, self.onBeforeEach, cb, who.threw) }
n/a
shouldAutoend = function () { var should = ( this.options.autoend && !this.ended && !this.occupied && queueEmpty(this) && !this.pool.length && !this.subtests.length && this.planEnd === -1 ) return should }
n/a
function spawn(cmd, args, options, name) { if (typeof args === 'string') { args = [ args ] } args = args || [] if (typeof options === 'string') { name = options options = {} } options = options || {} options.name = ownOr(options, 'name', name) options.command = cmd options.args = args return this.sub(Spawn, options, spawn) }
...
if (args.length === 1) {
var path = require('path')
var file = path.resolve(args[0])
tap.mochaGlobals()
require(file)
} else {
for (var i = 0; i < args.length; i++) {
tap.spawn(process.execPath, [__filename, args[i]])
}
}
...
function stdin(name, extra) { extra = parseTestArgs(name, extra, function () {}, '/dev/stdin') return this.sub(Stdin, extra || {}, stdin) }
...
}), 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)
}
if (doStdin)
tap.stdin()
}
function runTests (options) {
var saved = readSaveFile(options)
// At this point, we know we need to use the tap root,
// because there are 1 or more files to spawn.
...
sub = function (Class, extra, caller) { if (extra && (extra.todo || extra.skip)) { this.pass(extra.name, extra) return Promise.resolve(this) } extra.indent = ' ' if (this.jobs > 1 && process.env.TAP_BUFFER === undefined) extra.buffered = ownOr(extra, 'buffered', true) else extra.buffered = ownOrEnv(extra, 'buffered', 'TAP_BUFFER', true) extra.bail = ownOr(extra, 'bail', this.bail) extra.parent = this extra.stack = stack.captureString(80, caller) var t = new Class(extra) this.queue.push(t) this.subtests.push(t) var d = new Deferred() t.deferred = d this.process() return d.promise }
n/a
tearDown = function (fn) { this.on('teardown', fn) }
n/a
teardown = function (fn) { this.on('teardown', fn) }
n/a
function test(name, extra, cb) { extra = parseTestArgs(name, extra, cb) return this.sub(Test, extra, test) }
...
return files.reduce(function (acc, f) {
if (f === '-') {
acc.push(f)
return acc
}
// glob claims patterns MUST not include any '\'s
if (!/\\/.test(f))
f = glob.sync(f) || f
return acc.concat(f)
}, [])
}
function makeReporter (options) {
...
threw = function (er, extra, proxy) { this.debug('THREW', er.message, extra, proxy) // event emitters 'error' events need to re-throw so that they // can jump out of the flow like a normal throw. They'll just // end up back here once that happens, though, unless there's a // try/catch somewhere in the call stack. if (er.domainEmitter) { delete er.domainEmitter throw er } if (this.name && !proxy) er.test = this.name if (!proxy) extra = extraFromError(er, extra, this.options) Base.prototype.threw.call(this, er, extra, proxy) if (!this.results) { this.fail(extra.message || er.message, extra) if (!proxy) this.end(IMPLICIT) } this.process() }
n/a
timeout = function (options) { options = options || {} options.expired = options.expired || this.name if (this.occupied) this.occupied.timeout(options) else Base.prototype.timeout.call(this, options) this.end(IMPLICIT) }
n/a
writeSubComment = function (p, cb) { var comment = '# Subtest' if (p.name) comment += ': ' + p.name comment += '\n' this.parser.write(comment) cb() }
n/a
function decorate(t) { t.addAssert('ok', 1, function (obj, message, extra) { message = message || 'expect truthy value' if (obj) { return this.pass(message, extra) } return this.fail(message, extra) }) t.addAssert('notOk', 1, function (obj, message, extra) { message = message || 'expect falsey value' return this.ok(!obj, message, extra) }) t.addAssert('error', 1, function (er, message, extra) { if (!er) { return this.pass(message || 'should not error', extra) } if (!(er instanceof Error)) { extra.found = er return this.fail(message || 'non-Error error encountered', extra) } message = message || er.message extra.found = er return this.fail(message, extra) }) t.addAssert('equal', 2, function (f, w, m, e) { m = m || 'should be equal' if (f === w) { return this.pass(m, e) } e.found = f e.wanted = w e.compare = '===' if (typeof f === 'object' && typeof w === 'object' && f && w && shallower(f, w)) { e.note = 'Objects never === one another' } return this.fail(m, e) }) t.addAssert('not', 2, function (f, w, m, e) { m = m || 'should not be equal' if (f !== w) { return this.pass(m, e) } e.found = f e.doNotWant = w e.compare = '!==' return this.fail(m, e) }) t.addAssert('same', 2, function (f, w, m, e) { m = m || 'should be equivalent' e.found = f e.wanted = w return this.ok(shallower(f, w), m, e) }) t.addAssert('notSame', 2, function (f, w, m, e) { m = m || 'should not be equivalent' e.found = f e.doNotWant = w return this.notOk(shallower(f, w), m, e) }) t.addAssert('strictSame', 2, function (f, w, m, e) { m = m || 'should be equivalent strictly' e.found = f e.wanted = w return this.ok(deeper(f, w), m, e) }) t.addAssert('strictNotSame', 2, function (f, w, m, e) { m = m || 'should be equivalent strictly' e.found = f e.doNotWant = w return this.notOk(deeper(f, w), m, e) }) t.addAssert('match', 2, function (f, w, m, e) { m = m || 'should match pattern provided' e.found = f e.pattern = w return this.ok(tmatch(f, w), m, e) }) t.addAssert('notMatch', 2, function (f, w, m, e) { m = m || 'should not match pattern provided' e.found = f e.pattern = w return this.ok(!tmatch(f, w), m, e) }) t.addAssert('type', 2, function (obj, klass, m, e) { var name = klass if (typeof name === 'function') { name = name.name || '(anonymous constructor)' } m = m || 'type is ' + name // simplest case, it literally is the same thing if (obj === klass) { return this.pass(m, e) } var type = typeof obj if (!obj && type === 'object') { type = 'null' } if (type === 'object' && klass !== 'object') { if (typeof klass === 'function') { e.found = Object.getPrototypeOf(obj).constructor.name e.wanted = name return this.ok(obj instanceof klass, m, e) } // check prototype chain for name // 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 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] if (typeof arg === 'function') { if (arg === Error || arg.prototype instanceof Error) { wanted = arg } else if (!fn) { fn = arg } } else if (typeof arg === 'string' && arg) { m = arg } else if (typeof arg === 'object') { if ...
n/a
function after(name, fn) { var suite = suiteStack[ suiteStack.length - 1 ] if (!suite) throw new Error('cannot call "after" outside of describe()') if (fn) suite.after.push([name, fn]) else suite.after.push([name]) }
n/a
function afterEach(fn) { moment('afterEach', fn) }
n/a
function before(name, fn) { if (typeof name === 'function') 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 ] if (!name) name = '' t.test(name, { todo: todo, silent: true }, function (tt) { var ret = fn.call(suite, done(tt)) if (!ret && fn.length === 0) tt.end() else return ret }) function done (tt) { return function (er) { if (er) tt.threw(er) else tt.end() }} }
n/a
function beforeEach(fn) { moment('beforeEach', fn) }
n/a
function describe(name, fn) { new Suite(name, fn) }
n/a
function describe(name, fn) { new Suite(name, fn) }
n/a
global = function () { Object.keys(exports).forEach(function (g) { global[g] = exports[g] }) }
n/a
function it(name, fn) { if (typeof name === 'function') 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 ] if (!name) name = '' t.test(name, { todo: todo, tapMochaTest: true }, function (tt) { var ret = fn.call(tt, done(tt)) if (ret && ret.then) return ret else if (fn.length === 0) tt.end() }) function done (tt) { return function (er) { if (er) tt.threw(er) else tt.end() }} }
n/a
function it(name, fn) { if (typeof name === 'function') 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 ] if (!name) name = '' t.test(name, { todo: todo, tapMochaTest: true }, function (tt) { var ret = fn.call(tt, done(tt)) if (ret && ret.then) return ret else if (fn.length === 0) tt.end() }) function done (tt) { return function (er) { if (er) tt.threw(er) else tt.end() }} }
n/a
function wrapCallSite(frame) { if(frame.isNative()) { return frame; } // Most call sites will return the source file from getFileName(), but code // passed to eval() ending in "//# sourceURL=..." will return the source file // from getScriptNameOrSourceURL() instead var source = frame.getFileName() || frame.getScriptNameOrSourceURL(); if (source) { var line = frame.getLineNumber(); var column = frame.getColumnNumber() - 1; // Fix position in Node where some (internal) code is prepended. // See https://github.com/evanw/node-source-map-support/issues/36 if (line === 1 && !isInBrowser() && !frame.isEval()) { column -= 62; } var position = mapSourcePosition({ source: source, line: line, column: column }); frame = cloneCallSite(frame); frame.getFileName = function() { return position.source; }; frame.getLineNumber = function() { return position.line; }; frame.getColumnNumber = function() { return position.column + 1; }; frame.getScriptNameOrSourceURL = function() { return position.source; }; return frame; } // Code called using eval() needs special handling var origin = frame.isEval() && frame.getEvalOrigin(); if (origin) { origin = mapEvalOrigin(origin); frame = cloneCallSite(frame); frame.getEvalOrigin = function() { return origin; }; return frame; } // If we get here then we were unable to change the source position return frame; }
n/a