Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,61 @@ | ||
# REimplementing Unit Test | ||
|
||
Simply another unit test framework for node.js. | ||
Simply another unit test framework for [node.js](http://nodejs.org) | ||
|
||
## Design | ||
|
||
* QUnit-like API | ||
* Doesn't force you to use a flow control pattern | ||
* But try to support async tests | ||
* Does a little bit magic but not too much | ||
* Keep a \`right' design internally | ||
* Tries to support async tests | ||
* Saves typing | ||
* No scope or object shall be cluttered | ||
* __NO__ huge object literals or 7-level indentation | ||
* Keeps a "right" design internally (which you won't see) | ||
|
||
## Features | ||
|
||
### Implemented | ||
|
||
* Extended assertion method | ||
* Ensure callback's called and event's fired | ||
* Set timeout for tests | ||
* A better-than-nothing command line test runner | ||
* setup support | ||
|
||
### Upcoming | ||
|
||
* teardown support | ||
* Suite-wise setup/teardown (startup and shutdown would be good names) | ||
* Nested test suites | ||
|
||
### (Not So) Near Future | ||
|
||
* Colored output, web runner... | ||
* Watch mode? | ||
* Tagged tests and/or suites | ||
* Custom running policy for skipping/picking tests | ||
* Custom test result reporter (after the internal API stablized) | ||
* Any crazy idea(s) | ||
|
||
## Installation | ||
|
||
By using [npm](http://npmjs.org): | ||
|
||
$ npm install reut | ||
|
||
Install from repo: | ||
|
||
$ cp -r src ~/.node_libraries/reut | ||
# Assuming ~/bin is in your $PATH | ||
$ ln -s ~/.node_libraries/reut/bin/cli.js ~/bin/reut | ||
|
||
## Usage | ||
|
||
$ cat <<EOF >hello.js | ||
var reut = require("reut") | ||
reut.suite("Say hello!") | ||
reut.test("Chinese", function(test) { | ||
reut.test("Say hello in Chinese!", function(test) { | ||
test.ok(true, "你好") | ||
}) | ||
EOF | ||
# And here we go | ||
$ reut hello.js | ||
|
||
See `doc/api.mkd` for more. | ||
Document doc/api.mkd sucks. See example/\* instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var reut = require("reut") | ||
, EE = require("events").EventEmitter | ||
, fs = require("fs") | ||
|
||
reut.suite("A suite to contain 'em all") | ||
.setup(function(fixture, done) { | ||
fixture.answer = 42 | ||
done() | ||
}) | ||
.test("Native assert methods", function(test, fixture) { | ||
test.ok(!test.fail, "Not provided") | ||
test.ok(!test.ifError, "Others are ok to use") | ||
test.notStrictEqual(0/0, NaN) | ||
test.strictEqual(42, fixture.answer) | ||
test.equal([], 0) | ||
test.throws(function() { | ||
return someth1ngUndefined | ||
}, ReferenceError) | ||
}) | ||
.test("Extended assert methods", function(test, fixture) { | ||
test.typeOf(null, "object") | ||
test.instanceOf(Function, Function) | ||
|
||
test.include("foobar", "foo", "Works with string") | ||
test.include([3, 5, 6], 5, "And array") | ||
|
||
test.length([], 0) | ||
test.length("goofy", 5) | ||
|
||
test.match("holy shit", /hi/) | ||
|
||
test.in(1, ["o", "k"]) | ||
// Setup for fixture.stat is defined below | ||
test.in("stat", fixture) | ||
}) | ||
// Async setup | ||
.setup(function(fixture, done) { | ||
fs.stat("/", function(err, stat) { | ||
fixture.stat = stat | ||
done() | ||
}) | ||
}) | ||
.test("Something async", function(test, fixture) { | ||
var boy = new EE() | ||
test.instanceOf(fixture.stat, fs.Stats) | ||
// Ensured callback | ||
setTimeout(test.cb(function(theBoy) { | ||
theBoy.emit("cry") | ||
}), 10, boy) | ||
test.timeout = 20 // Longer than 10 | ||
|
||
// Ensured event | ||
test.emits(boy, "cry", function() { | ||
test.ok(false, "Expected to fail") | ||
test.equal(this, boy, "Still got tested") | ||
}) | ||
}) |