nodeunit-0.11.2/ 0000775 0000000 0000000 00000000000 13173432227 0013424 5 ustar 00root root 0000000 0000000 nodeunit-0.11.2/.gitignore 0000664 0000000 0000000 00000000073 13173432227 0015414 0 ustar 00root root 0000000 0000000 dist
node_modules
stamp-build
*~
gmon.out
v8.log
.DS_Store
nodeunit-0.11.2/.npmignore 0000664 0000000 0000000 00000000044 13173432227 0015421 0 ustar 00root root 0000000 0000000 dist
stamp-build
test/fixtures/dir2
nodeunit-0.11.2/.travis.yml 0000664 0000000 0000000 00000000146 13173432227 0015536 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- "stable"
- "6.5"
- "6.4"
- "6.3"
- "5.12"
- "4.4"
- "0.12"
nodeunit-0.11.2/CONTRIBUTORS.md 0000664 0000000 0000000 00000003254 13173432227 0015707 0 ustar 00root root 0000000 0000000 Nodeunit contributors (sorted alphabetically)
============================================
* **[Alex Gorbatchev](https://github.com/alexgorbatchev)**
* Deeper default object inspection
* Timeout to ensure flushing of console output (default reporter)
* **[Alex Wolfe](https://github.com/alexkwolfe)**
* HTML test reporter
* **[Caolan McMahon](https://github.com/caolan)**
* Author and maintainer
* Most features develpopment
* **[Carl Fürstenberg](https://github.com/azatoth)**
* Debian-friendly Makefile, supports both 'node' and 'nodejs' executables
* Sandbox utility
* Minimal test reporter
* **[Gerad Suyderhoud](https://github.com/gerad)**
* First comand-line tool
* **[Kadir Pekel](https://github.com/kadirpekel)**
* Improvements to default test reporter
* HTTP test utility
* **[Λlisue](https://github.com/lambdalisue)**
* Add machineout reporter
* **[Matthias Lübken](https://github.com/luebken)**
* Utility functions for tracking incomplete tests on exit
* **[Oleg Efimov](https://github.com/Sannis)**
* Adding 'make lint' and fixing nodelint errors
* Option parsing, --help text and config file support
* Reporters option for command-line tool
* **[Orlando Vazquez](https://github.com/orlandov)**
* Added jUnit XML reporter
* **[Ryan Dahl](https://github.com/ry)**
* Add package.json
* **[Sam Stephenson](https://github.com/sstephenson)**
* Coffee-script support
* **[Thomas Mayfield](https://github.com/thegreatape)**
* Async setUp and tearDown support for testCase
* **[Maciej Małecki](https://github.com/mmalecki)**
* Removal of `testCase`
**[Full contributors list](https://github.com/caolan/nodeunit/contributors).**
nodeunit-0.11.2/LICENSE 0000664 0000000 0000000 00000002042 13173432227 0014427 0 ustar 00root root 0000000 0000000 Copyright (c) 2010 Caolan McMahon
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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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.
nodeunit-0.11.2/Makefile 0000664 0000000 0000000 00000020403 13173432227 0015063 0 ustar 00root root 0000000 0000000 PACKAGE = nodeunit
NODEJS = $(if $(shell test -f /usr/bin/nodejs && echo "true"),nodejs,node)
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share
MANDIR ?= $(PREFIX)/share/man
LIBDIR ?= $(PREFIX)/lib
NODEJSLIBDIR ?= $(LIBDIR)/$(NODEJS)
BUILDDIR = dist
DOCS = $(shell find doc -name '*.md' \
|sed 's|.md|.1|g' \
|sed 's|doc/|man1/|g' \
)
$(shell if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi)
all: build doc
browser:
# super hacky build script for browser version!
mkdir -p $(BUILDDIR)/browser
rm -rf $(BUILDDIR)/browser/*
# build browser version of nodeunit.js
cat share/license.js >> $(BUILDDIR)/browser/nodeunit.js
echo "nodeunit = (function(){" >> $(BUILDDIR)/browser/nodeunit.js
cat deps/json2.js >> $(BUILDDIR)/browser/nodeunit.js
# make assert global
echo "var assert = this.assert = {};" >> $(BUILDDIR)/browser/nodeunit.js
echo "var types = {};" >> $(BUILDDIR)/browser/nodeunit.js
echo "var core = {};" >> $(BUILDDIR)/browser/nodeunit.js
echo "var nodeunit = {};" >> $(BUILDDIR)/browser/nodeunit.js
echo "var reporter = {};" >> $(BUILDDIR)/browser/nodeunit.js
cat deps/async.js >> $(BUILDDIR)/browser/nodeunit.js
echo "(function(exports){" >> $(BUILDDIR)/browser/nodeunit.js
cat lib/assert.js >> $(BUILDDIR)/browser/nodeunit.js
echo "})(assert);" >> $(BUILDDIR)/browser/nodeunit.js
echo "(function(exports){" >> $(BUILDDIR)/browser/nodeunit.js
cat lib/types.js >> $(BUILDDIR)/browser/nodeunit.js
echo "})(types);" >> $(BUILDDIR)/browser/nodeunit.js
echo "(function(exports){" >> $(BUILDDIR)/browser/nodeunit.js
cat lib/core.js >> $(BUILDDIR)/browser/nodeunit.js
echo "})(core);" >> $(BUILDDIR)/browser/nodeunit.js
echo "(function(exports){" >> $(BUILDDIR)/browser/nodeunit.js
cat lib/reporters/browser.js >> $(BUILDDIR)/browser/nodeunit.js
echo "})(reporter);" >> $(BUILDDIR)/browser/nodeunit.js
echo "nodeunit = core;" >> $(BUILDDIR)/browser/nodeunit.js
echo "nodeunit.assert = assert;" >> $(BUILDDIR)/browser/nodeunit.js
echo "nodeunit.reporter = reporter;" >> $(BUILDDIR)/browser/nodeunit.js
echo "nodeunit.run = reporter.run;" >> $(BUILDDIR)/browser/nodeunit.js
echo "return nodeunit; })();" >> $(BUILDDIR)/browser/nodeunit.js
cp $(BUILDDIR)/browser/nodeunit.js $(BUILDDIR)/browser/.nodeunit.js
sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.nodeunit.js > $(BUILDDIR)/browser/nodeunit.js
rm $(BUILDDIR)/browser/.nodeunit.js
# copy nodeunit.css
cp share/nodeunit.css $(BUILDDIR)/browser/nodeunit.css
# create nodeunit.min.js
node_modules/uglify-js/bin/uglifyjs $(BUILDDIR)/browser/nodeunit.js > $(BUILDDIR)/browser/nodeunit.min.js
# create test scripts
mkdir -p $(BUILDDIR)/browser/test
cp test/test.html $(BUILDDIR)/browser/test/test.html
# test-base.js
echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-base.js
cat test/test-base.js >> $(BUILDDIR)/browser/test/test-base.js
echo "})(this.test_base = {});" >> $(BUILDDIR)/browser/test/test-base.js
cp $(BUILDDIR)/browser/test/test-base.js $(BUILDDIR)/browser/.test-base.js
sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-base.js > $(BUILDDIR)/browser/test/test-base.js
rm $(BUILDDIR)/browser/.test-base.js
# test-runmodule.js
echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-runmodule.js
cat test/test-runmodule.js >> $(BUILDDIR)/browser/test/test-runmodule.js
echo "})(this.test_runmodule = {});" >> $(BUILDDIR)/browser/test/test-runmodule.js
cp $(BUILDDIR)/browser/test/test-runmodule.js $(BUILDDIR)/browser/.test-runmodule.js
sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-runmodule.js > $(BUILDDIR)/browser/test/test-runmodule.js
rm $(BUILDDIR)/browser/.test-runmodule.js
# test-runtest.js
echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-runtest.js
cat test/test-runtest.js >> $(BUILDDIR)/browser/test/test-runtest.js
echo "})(this.test_runtest = {});" >> $(BUILDDIR)/browser/test/test-runtest.js
cp $(BUILDDIR)/browser/test/test-runtest.js $(BUILDDIR)/browser/.test-runtest.js
sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-runtest.js > $(BUILDDIR)/browser/test/test-runtest.js
rm $(BUILDDIR)/browser/.test-runtest.js
# test-testcase.js
echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-testcase.js
cat test/test-testcase.js >> $(BUILDDIR)/browser/test/test-testcase.js
echo "})(this.test_testcase = {});" >> $(BUILDDIR)/browser/test/test-testcase.js
cp $(BUILDDIR)/browser/test/test-testcase.js $(BUILDDIR)/browser/.test-testcase.js
sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-testcase.js > $(BUILDDIR)/browser/test/test-testcase.js
rm $(BUILDDIR)/browser/.test-testcase.js
# test-testcase-legacy.js
echo "(function (exports) {" > $(BUILDDIR)/browser/test/test-testcase-legacy.js
cat test/test-testcase-legacy.js >> $(BUILDDIR)/browser/test/test-testcase-legacy.js
echo "})(this.test_testcase_legacy = {});" >> $(BUILDDIR)/browser/test/test-testcase-legacy.js
cp $(BUILDDIR)/browser/test/test-testcase-legacy.js $(BUILDDIR)/browser/.test-testcase-legacy.js
sed "/\@REMOVE_LINE_FOR_BROWSER/d" <$(BUILDDIR)/browser/.test-testcase-legacy.js > $(BUILDDIR)/browser/test/test-testcase-legacy.js
rm $(BUILDDIR)/browser/.test-testcase-legacy.js
# copy nodeunit.js to dist/browser/test to make it easier for me to host and
# run on windows VMs with IE
cp $(BUILDDIR)/browser/nodeunit.js $(BUILDDIR)/browser/test/nodeunit.js
cp $(BUILDDIR)/browser/nodeunit.css $(BUILDDIR)/browser/test/nodeunit.css
commonjs:
# super hacky build script for browser commonjs version!
##### make commonjs browser module ######
mkdir -p $(BUILDDIR)/commonjs
rm -rf $(BUILDDIR)/commonjs/*
mkdir -p $(BUILDDIR)/commonjs/deps
cp deps/json2.js $(BUILDDIR)/commonjs/deps
cp deps/async.js $(BUILDDIR)/commonjs/deps
echo "var async = require('async');" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "var assert = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "var types = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "var core = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "var nodeunit = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "var reporter = {};" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "(function(exports){" >> $(BUILDDIR)/commonjs/nodeunit.js
cat lib/assert.js >> $(BUILDDIR)/commonjs/nodeunit.js
echo "})(assert);" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "(function(exports){" >> $(BUILDDIR)/commonjs/nodeunit.js
cat lib/types.js >> $(BUILDDIR)/commonjs/nodeunit.js
echo "})(types);" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "(function(exports){" >> $(BUILDDIR)/commonjs/nodeunit.js
cat lib/core.js >> $(BUILDDIR)/commonjs/nodeunit.js
echo "})(core);" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "module.exports = core;" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "(function(exports, nodeunit){" >> $(BUILDDIR)/commonjs/nodeunit.js
cat lib/reporters/browser.js >> $(BUILDDIR)/commonjs/nodeunit.js
echo "})(reporter, module.exports);" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "module.exports.assert = assert;" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "module.exports.reporter = reporter;" >> $(BUILDDIR)/commonjs/nodeunit.js
echo "module.exports.run = reporter.run;" >> $(BUILDDIR)/commonjs/nodeunit.js
sed -i "/\@REMOVE_LINE_FOR_BROWSER/d" $(BUILDDIR)/commonjs/nodeunit.js
sed -i "/\@REMOVE_LINE_FOR_COMMONJS/d" $(BUILDDIR)/commonjs/nodeunit.js
##### end of commonjs browser module #####
build: stamp-build
stamp-build: $(wildcard deps/* lib/*.js)
touch $@;
mkdir -p $(BUILDDIR)/nodeunit
cp -R bin node_modules deps index.js lib package.json share $(BUILDDIR)/nodeunit
printf '#!/bin/sh\n$(NODEJS) $(NODEJSLIBDIR)/$(PACKAGE)/bin/nodeunit $$@' > $(BUILDDIR)/nodeunit.sh
test:
$(NODEJS) ./bin/nodeunit test
install: build
install -d $(NODEJSLIBDIR)
cp -a $(BUILDDIR)/nodeunit $(NODEJSLIBDIR)
install -m 0755 $(BUILDDIR)/nodeunit.sh $(BINDIR)/nodeunit
install -d $(MANDIR)/man1/
cp -a man1/nodeunit.1 $(MANDIR)/man1/
uninstall:
rm -rf $(NODEJSLIBDIR)/nodeunit $(NODEJSLIBDIR)/nodeunit.js $(BINDIR)/nodeunit
rm -rf $(MANDIR)/man1/nodeunit.1
clean:
rm -rf $(BUILDDIR) stamp-build
lint:
nodelint --config nodelint.cfg ./index.js ./bin/nodeunit ./bin/nodeunit.json ./lib/*.js ./lib/reporters/*.js ./test/*.js
doc: man1 $(DOCS)
@true
man1:
@if ! test -d man1 ; then mkdir -p man1 ; fi
# use `npm install ronn` for this to work.
man1/%.1: doc/%.md
ronn --roff $< > $@
.PHONY: browser test install uninstall build all
nodeunit-0.11.2/README.md 0000664 0000000 0000000 00000040700 13173432227 0014704 0 ustar 00root root 0000000 0000000 Nodeunit
========
[](https://travis-ci.org/caolan/nodeunit)
Simple syntax, powerful tools. Nodeunit provides easy async unit testing for
node.js and the browser.
* Simple to use
* Just export the tests from a module
* Works with node.js and in the browser
* Helps you avoid common pitfalls when testing asynchronous code
* Easy to add test cases with setUp and tearDown functions if you wish
* Flexible reporters for custom output, built-in support for HTML and jUnit XML
* Allows the use of mocks and stubs
__Contributors__
* [alexgorbatchev](https://github.com/alexgorbatchev)
* [alexkwolfe](https://github.com/alexkwolfe)
* [azatoth](https://github.com/azatoth)
* [kadirpekel](https://github.com/kadirpekel)
* [lambdalisue](https://github.com/lambdalisue)
* [luebken](https://github.com/luebken)
* [orlandov](https://github.com/orlandov)
* [Sannis](https://github.com/Sannis)
* [sstephenson](https://github.com/sstephenson)
* [thegreatape](https://github.com/thegreatape)
* [mmalecki](https://github.com/mmalecki)
* and thanks to [cjohansen](https://github.com/cjohansen) for input and advice
on implementing setUp and tearDown functions. See
[cjohansen's fork](https://github.com/cjohansen/nodeunit).
Also, check out gerad's [nodeunit-dsl](https://github.com/gerad/nodeunit-dsl)
project, which implements a 'pretty dsl on top of nodeunit'.
More contributor information can be found in the
[CONTRIBUTORS.md](https://github.com/caolan/nodeunit/blob/master/CONTRIBUTORS.md)
file.
Usage
-----
Here is an example unit test module:
exports.testSomething = function(test) {
test.expect(1);
test.ok(true, "this assertion should pass");
test.done();
};
exports.testSomethingElse = function(test) {
test.ok(false, "this assertion should fail");
test.done();
};
When run using the included test runner, this will output the following:
Installation
------------
There are two options for installing nodeunit:
1. Clone / download nodeunit from [github](https://github.com/caolan/nodeunit),
then:
make && sudo make install
2. Install via npm:
npm install nodeunit -g
API Documentation
-----------------
Nodeunit uses the functions available in the node.js
[assert module](http://nodejs.org/docs/v0.4.2/api/assert.html):
* __ok(value, [message])__ - Tests if value is a true value.
* __equal(actual, expected, [message])__ - Tests shallow, coercive equality
with the equal comparison operator ( == ).
* __notEqual(actual, expected, [message])__ - Tests shallow, coercive
non-equality with the not equal comparison operator ( != ).
* __deepEqual(actual, expected, [message])__ - Tests for deep equality.
* __notDeepEqual(actual, expected, [message])__ - Tests for any deep
inequality.
* __strictEqual(actual, expected, [message])__ - Tests strict equality, as
determined by the strict equality operator ( === )
* __notStrictEqual(actual, expected, [message])__ - Tests strict non-equality,
as determined by the strict not equal operator ( !== )
* __throws(block, [error], [message])__ - Expects block to throw an error.
* __doesNotThrow(block, [error], [message])__ - Expects block not to throw an
error.
* __ifError(value)__ - Tests if value is not a false value, throws if it is a
true value. Useful when testing the first argument, error in callbacks.
Nodeunit also provides the following functions within tests:
* __expect(amount)__ - Specify how many assertions are expected to run within a
test. Very useful for ensuring that all your callbacks and assertions are
run.
* __done()__ - Finish the current test function, and move on to the next. ALL
tests should call this!
Nodeunit aims to be simple and easy to learn. This is achieved through using
existing structures (such as node.js modules) to maximum effect, and reducing
the API where possible, to make it easier to digest.
Tests are simply exported from a module, but they are still run in the order
they are defined.
__Note:__ Users of old nodeunit versions may remember using `ok`, `equals` and
`same` in the style of qunit, instead of the assert functions above. These
functions still exist for backwards compatibility, and are simply aliases to
their assert module counterparts.
Asynchronous Testing
--------------------
When testing asynchronous code, there are a number of sharp edges to watch out
for. Thankfully, nodeunit is designed to help you avoid as many of these
pitfalls as possible. For the most part, testing asynchronous code in nodeunit
_just works_.
### Tests run in series
While running tests in parallel seems like a good idea for speeding up your
test suite, in practice I've found it means writing much more complicated
tests. Because of node's module cache, running tests in parallel means mocking
and stubbing is pretty much impossible. One of the nicest things about testing
in javascript is the ease of doing stubs:
var _readFile = fs.readFile;
fs.readFile = function(path, callback) {
// it's a stub!
};
// test function that uses fs.readFile
// we're done
fs.readFile = _readFile;
You cannot do this when running tests in parallel. In order to keep testing as
simple as possible, nodeunit avoids it. Thankfully, most unit-test suites run
fast anyway.
### Explicit ending of tests
When testing async code it's important that tests end at the correct point, not
just after a given number of assertions. Otherwise your tests can run short,
ending before all assertions have completed. It's important to detect too
many assertions as well as too few. Combining explicit ending of tests with
an expected number of assertions helps to avoid false test passes, so be sure
to use the `test.expect()` method at the start of your test functions, and
`test.done()` when finished.
Groups, setUp and tearDown
--------------------------
Nodeunit allows the nesting of test functions:
exports.test1 = function (test) {
...
}
exports.group = {
test2: function (test) {
...
},
test3: function (test) {
...
}
}
This would be run as:
test1
group - test2
group - test3
Using these groups, Nodeunit allows you to define a `setUp` function, which is
run before each test, and a `tearDown` function, which is run after each test
calls `test.done()`:
module.exports = {
setUp: function (callback) {
this.foo = 'bar';
callback();
},
tearDown: function (callback) {
// clean up
callback();
},
test1: function (test) {
test.equals(this.foo, 'bar');
test.done();
}
};
In this way, it's possible to have multiple groups of tests in a module, each
group with its own setUp and tearDown functions.
Running Tests
-------------
Nodeunit comes with a basic command-line test runner, which can be installed
using `sudo make install`. Example usage:
nodeunit testmodule1.js testfolder [...]
If no entry file specified, `test` defaults.
The default test reporter uses color output, because I think that's more fun :) I
intend to add a no-color option in future. To give you a feeling of the fun you'll
be having writing tests, lets fix the example at the start of the README:
Ahhh, Doesn't that feel better?
When using the included test runner, it will exit using the failed number of
assertions as the exit code. This means it exits with 0 when all tests pass.
### Command-line Options
* __--reporter FILE__ - you can set the test reporter to a custom module or
on of the modules in nodeunit/lib/reporters, when omitted, the default test runner
is used.
* __--list-reporters__ - list available built-in reporters.
* __--config FILE__ - load config options from a JSON file, allows
the customisation of color schemes for the default test reporter etc. See
bin/nodeunit.json for current available options.
* __-t testName__ - run specific test only.
* __-f fullTestName__ - run specific test only. fullTestName is built so: "outerGroup - .. - innerGroup - testName".
* __--version__ or __-v__ - report nodeunit version
* __--help__ - show nodeunit help
Running tests in the browser
----------------------------
Nodeunit tests can also be run inside the browser. For example usage, see
the examples/browser folder. The basic syntax is as follows:
__test.html__