Commit 18f66a55 authored by Jérémy Lal's avatar Jérémy Lal

Imported Upstream version 4.0.0

parent 4d553523
node_modules/
coverage/
coverage-example/coverage/
.nyc_output/
nyc_output/
sudo: false
language: node_js
node_js:
- '0.10'
- '0.12'
- '4'
......@@ -9,3 +9,4 @@ Trent Mick <trentm@gmail.com>
Corey Richardson <kb1pkl@aim.com>
Raynos <raynos2@gmail.com>
Siddharth Mahendraker <siddharth_mahen@me.com>
Ryan Graham <r.m.graham@gmail.com>
## 4.0
Raise an error if `t.end()` is explicitly called more than once. This
is a breaking change, because it can cause previously-passing tests to
fail, if they did `t.end()` in multiple places.
Support promises returned by mochalike functions.
## 3.1
Support sending coverage output to both codecov.io and coveralls.io.
## 3.0
Upgrade to nyc 5. This means that `config.nyc.exclude` arrays in
`package.json` now take globs instead of regular expressions.
## 2.3
Use the name of the function supplied to `t.test(fn)` as the test name
if a string name is not provided.
Better support for sparse arrays.
## 2.2
Add support for Codecov.io as well as Coveralls.io.
Catch failures that come after an otherwise successful test set.
Fix timing of `t.on('end')` so that event fires *before* the next
child test is started, instead of immediately after it.
`t.throws()` can now be supplied a regexp for the expected Error
message.
## 2.1
Exit in failure on root test bailout.
Support promises returned by `t.test(fn)` function.
## 2.0
Update matching behavior using [tmatch](http://npm.im/tmatch). This
is a breaking change to `t.match`, `t.similar`, `t.has`, etc., but
brings them more in line with what people epirically seem to expect
these functions to do.
Deal with pending handles left open when a child process gets a
`SIGTERM` on timeout.
Remove domains in favor of more reliable and less invasive state and
error-catching bookkeeping.
## 1.4
Add `t.contains()` alias for `t.match()`.
Use `deeper` for deep object similarity testing.
Treat unfinished tests as failures.
Add support for pragmas in TAP output.
## 1.3
Bind all Test methods to object.
Add `t.tearDown()`, `t.autoend()`, so that the root export is Just
Another Test Object, which just happens to be piping to stdout.
Support getting an error object in bailout()
## 1.2
Better support for exit status codes.
## 1.1
Add coverage using nyc.
If a `COVERALLS_REPO_TOKEN` is provided, then run tests with coverage,
and pipe to coveralls.
## 1.0
Complete rewrite from 0.x.
Child tests implemented as nested TAP output, similar to Perl's `Test::More`.
## 0.x
The 0.x versions used a "flattened" approach to child tests, which
requires some bookkeeping.
It worked, mostly, but its primary success was inspiring
[tape](http://npm.im/tape) and tap v1 and beyond.
- Check the `TODO.md` file to see stuff that is likely to be accepted.
- Every patch should have a new test that fails without the patch and
passes with the patch.
- All tests should pass on Node 0.8 and above. If some tests have to
be skipped for very old Node versions that's fine, but the
functionality should still work as intended.
- Run `node scripts/generate-test-test.js test/test/*.js` to
re-generate the output tests whenever output is changed. However,
when you do this, make sure to check the change to ensure that it's
what you intended, and that it didn't cause any other inadvertent
changes.
- Prefer adding cases to an existing test rather than writing a new
one from scratch. For example, add a new test in `test/test/*.js`
rather than create a new test that validates test output.
Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
All rights reserved.
The ISC License
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
Copyright (c) Isaac Z. Schlueter and Contributors
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
This diff is collapsed.
- fix the markdown reporter
- make it faster (seems like mostly this is just node spawn() overhead)
- read a config file at ~/.taprc for setting default colors,
reporters, etc
- make colors (and diff colors) configurable
- tests for reporter output
- split lib/stack.js out into a separate module
- Add more of the mocha globals when you call tap.mochaGlobals()
if (process.platform === 'win32') {
// On windows, there is no good way to check that a file is executable
module.exports = function isExe () {
return true
}
} else {
module.exports = function isExe (stat) {
var mod = stat.mode
var uid = stat.uid
var gid = stat.gid
var u = parseInt('100', 8)
var g = parseInt('010', 8)
var o = parseInt('001', 8)
var ug = u | g
var ret = (mod & o) ||
(mod & g) && process.getgid && gid === process.getgid() ||
(mod & u) && process.getuid && uid === process.getuid() ||
(mod & ug) && process.getuid && process.getuid() === 0
return ret
}
}
#!/usr/bin/env node
var tap = require('../lib/root.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]])
}
}
This diff is collapsed.
#!/usr/bin/env node
// just an example, really
// Run with `node tap-http.js path/to/tests/`
var argv = process.argv.slice(2)
, path = require("path")
, Runner = require("../lib/tap-runner")
, http = require("http")
, server = http.createServer(function (req, res) {
// it'd be nice to return a non-200 if the tests fail, but we don't
// know the status until it's done, so that would mean not being able
// to pipe the output
res.writeHead(200, {'content-type': 'text/plain'})
new Runner(argv, null).pipe(res)
})
server.listen(1337)
#!/usr/bin/env node
// read a tap stream from stdin.
var TapConsumer = require("../lib/tap-consumer")
, TapProducer = require("../lib/tap-producer")
var tc = new TapConsumer
, tp = new TapProducer
//process.stdin.pipe(tc)
process.stdin.on("data", function (c) {
c = c + ""
// console.error(JSON.stringify(c).substr(0, 100))
tc.write(c)
})
process.stdin.on("end", function () { tc.end() })
process.stdin.resume()
//tc.pipe(tp)
tc.on("data", function (c) {
tp.write(c)
})
tc.on("end", function () { tp.end() })
tp.on("data", function (c) {
console.error(["output write", c])
process.stdout.write(c)
})
tp.on("end", function (er, total, ok) {
if (er) throw er
process.exit(total - ok)
})
#!/usr/bin/env node
var argv = process.argv.slice(2)
, path = require("path")
, Runner = require("../lib/tap-runner")
, nopt = require("nopt")
, knownOpts =
{ cover: [path, false]
, "cover-dir": path
, stderr: Boolean
, stdout: Boolean
, diag: Boolean
, version: Boolean
, tap: Boolean
, timeout: Number
, gc: Boolean
, debug: Boolean
, "debug-brk": Boolean
, strict: Boolean
, harmony: Boolean
}
, shorthands =
// debugging 1: show stderr
{ d: ["--stderr"]
// debugging 2: show stderr and tap
, dd: ["--stderr", "--tap"]
// debugging 3: show stderr, tap, AND always show diagnostics.
, ddd: ["--stderr", "--tap", "--diag"]
, "expose-gc": ["--gc"]
, g: ["--gc"]
, e: ["--stderr"]
, t: ["--timeout"]
, o: ["--tap"]
, c: ["--cover"]
, v: ["--version"]
, "?": ["--help"]
, h: ["--help"]
}
, defaults =
{ cover: "./lib"
, "cover-dir": "./coverage"
, stderr: process.env.TAP_STDERR !== '0'
, tap: process.env.TAP
, diag: process.env.TAP_DIAG
, timeout: +process.env.TAP_TIMEOUT || 30
, gc: false
, debug: false
, "debug-brk": false
, strict: false
, harmony: false
, version: false
, help: false }
, options = nopt(knownOpts, shorthands)
if (options.version) {
console.log(require("../package.json").version)
process.exit(0)
}
if (options.help) {
console.log(function(){/*
Usage:
tap <options> <files>
Run the files as tap tests, parse the output, and report the results
Options:
--stderr Print standard error output of tests to standard error.
--tap Print raw tap output.
--diag Print diagnostic output for passed tests, as well as failed.
(Implies --tap)
--gc Expose the garbage collector to tests.
--timeout Maximum time to wait for a subtest, in seconds. Default: 30
--debug Pass the '--debug' flag to node for debugging
--debug-brk Pass the '--debug-brk' flag to node for debugging
--strict Enforce strict mode when running tests.
--harmony Enable harmony features for tests.
--version Print the version of node tap.
--help Print this help.
Please report bugs! https://github.com/isaacs/node-tap/issues
*/}.toString().split(/\n/).slice(1, -1).join("\n"))
process.exit(0)
}
Object.keys(defaults).forEach(function (k) {
if (!options.hasOwnProperty(k)) options[k] = defaults[k]
})
// other tests that might rely on these
if (options.diag) process.env.TAP_DIAG = true
if (options.tap) process.env.TAP = true
if (options.timeout) process.env.TAP_TIMEOUT = options.timeout
var r = new Runner(options)
, TapProducer = require("../lib/tap-producer")
if (options.tap || options.diag) {
r.pipe(process.stdout)
} else {
r.on("file", function (file, results, details) {
var s = (details.ok ? "" : "not ") + "ok "+results.name
, n = details.pass + "/" + details.testsTotal
, dots = new Array(Math.max(1, 60 - s.length - n.length)).join(".")
console.log("%s %s %s", s, dots, n)
if (details.ok) {
if (details.skip) {
console.log(" skipped: %s", details.skip)
}
if (details.todo) {
console.log(" todo: %s", details.todo)
}
} else {
// console.error(details)
console.log(" Command: %s", results.command)
console.log(" " + TapProducer.encode(details.list)
.split(/\n/).join("\n "))
}
})
r.on("end", function () {
//console.log(r)
var s = "total"
, n = r.results.pass + "/" + r.results.testsTotal
, dots = new Array(60 - s.length - n.length).join(".")
, ok = r.results.ok ? "ok" : "not ok"
console.log("%s %s %s\n\n%s", s, dots, n, ok)
if (r.doCoverage) {
console.error( "\nCoverage: %s\n"
, path.resolve(r.coverageOutDir, "index.html") )
}
})
}
r.on("end", function () {
process.exit(r.results.ok ? 0 : 1)
})
Usage:
tap [options] <files>
Executes all the files and interprets their output as TAP
formatted test result data.
To parse TAP data from stdin, specify "-" as a filename.
Short options are parsed gnu-style, so for example '-bCRspec' would be
equivalent to '--bail --no-color --reporter=spec'
Options:
-c --color Use colors (Default for TTY)
-C --no-color Do not use colors (Default for non-TTY)
-b --bail Bail out on first failure
-B --no-bail Do not bail out on first failure (Default)
-R<type> --reporter=<type> Use the specified reporter. Defaults to
'classic' when colors are in use, or 'tap'
when colors are disabled.
Available reporters:
@@REPORTERS@@
-s<file> --save=<file> If <file> exists, then it should be a line-
delimited list of test files to run. If
<file> is not present, then all command-line
positional arguments are run.
After the set of test files are run, any
failed test files are written back to the
save file.
This way, repeated runs with -s<file> will
re-run failures until all the failures are
passing, and then once again run all tests.
It's a good idea to .gitignore the file
used for this purpose, as it will churn a
lot.
--coverage --cov Capture coverage information using 'nyc'
If a COVERALLS_REPO_TOKEN environment
variable is set, then coverage is
captured by default and sent to the
coveralls.io service. If a CODECOV_TOKEN
environment variable is set, then coverage is
captured by default and sent to the
codecov.io service.
--no-coverage --no-cov Do not capture coverage information.
Note that if nyc is already loaded, then
the coverage info will still be captured.
--coverage-report=<type> Output coverage information using the
specified istanbul/nyc reporter type.
Default is 'text' when running on the
command line, or 'text-lcov' when piping
to coveralls or codecov.
If 'lcov' is used, then the report will
be opened in a web browser after running.
This can be run on its own at any time
after a test run that included coverage.
-t<n> --timeout=<n> Time out test files after <n> seconds.
Defaults to 30, or the value of the
TAP_TIMEOUT environment variable.
-h --help print this thing you're looking at
-v --version show the version of this program
-gc --expose-gc Expose the gc() function to Node tests
--debug Run JavaScript tests with node --debug
--debug-brk Run JavaScript tests with node --debug-brk
--harmony Enable all Harmony flags in JavaScript tests
--strict Run JS tests in 'use strict' mode
-- Stop parsing flags, and treat any additional
command line arguments as filenames.
var Bar = module.exports = function(str) {
this.bar = str;
this.str = str;
};
Bar.prototype.foo = function() {
var self = this;
return self.bar;
};
Bar.prototype.baz = function() {
var self = this;
return self.str;
};
var Foo = module.exports = function(str) {
this.foo = str;
this.str = str;
};
Foo.prototype.bar = function() {
var self = this;
return self.foo;
};
Foo.prototype.baz = function() {
var self = this;
return self.str;
};
var test = require('tap').test,
Bar = require('../lib/bar'),
bar;
test('setup', function(t) {
bar = new Bar('baz');
t.ok(bar);
t.end();
});
test('bar', function(t) {
t.equal('baz', bar.foo());
t.end();
});
test('teardown', function(t) {
t.ok(true);
t.end();
});
var test = require('tap').test,
Foo = require('../lib/foo'),
Bar = require('../lib/bar'),
foo, bar;
test('setup', function(t) {
foo = new Foo('baz');
t.ok(foo);
bar = new Bar('baz');
t.ok(bar);
t.end();
});
test('baz from Foo', function(t) {
t.equal('baz', foo.baz());
t.end();
});
test('baz from Bar', function(t) {
t.equal('baz', bar.baz());
t.end();
});
test('teardown', function(t) {
t.ok(true);
t.end();
});
var test = require('tap').test,
Foo = require('../lib/foo'),
foo;
test('setup', function(t) {
foo = new Foo('baz');
t.ok(foo);
t.end();
});
test('bar', function(t) {
t.equal('baz', foo.bar());
t.end();
});
test('teardown', function(t) {
t.ok(true);
t.end();
});
var t = require('../lib/root.js')
t.plan(2)
t.test('gun show', function (t) {
t.plan(100)
var n = 0
var i = setInterval(function () {
if (n % 123 === 5) {
t.fail('FIRE!')
t.fail('THE BUILDING IS ON FIRE')
} else {
t.pass('this is ok')
t.pass('i am ok with how things are proceeding')
}
if (++n === 50) {
return clearInterval(i)
}
}, 100)
})
t.test('wondermark', function (t) {
t.plan(500)
var n = 0
var j = setInterval(function () {
if (n % 123 === 35) {
t.fail('I AM EATING BREAKFAST')
t.fail('FUCKING SEALIONS')
} else {
t.pass('excuse me')
t.pass('pardon me')
}
if (++n === 250) {