Comparing version 0.4.4 to 0.5.1
@@ -1,8 +0,1 @@ | ||
/* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
/*jshint asi: true newcap: true undef: true es5: true node: true devel: true | ||
forin: false */ | ||
/*global define: true */ | ||
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) { | ||
"use strict"; | ||
@@ -149,3 +142,3 @@ | ||
* assert.notDeepEqual({ a: "foo" }, Object.create({ a: "foo" }), | ||
* "object's inherit from different prototypes"); | ||
* "object"s inherit from different prototypes"); | ||
*/ | ||
@@ -208,3 +201,3 @@ notDeepEqual: function notDeepEqual(actual, expected, message) { | ||
* The assertion whether or not given `block` throws an exception. If optional | ||
* `Error` argument is provided and it's type of function thrown error is | ||
* `Error` argument is provided and it"s type of function thrown error is | ||
* asserted to be an instance of it, if type of `Error` is string then message | ||
@@ -257,3 +250,3 @@ * of throw exception is asserted to contain it. | ||
(Error == exception) || | ||
// If passed `Error` is RegExp using it's test method to | ||
// If passed `Error` is RegExp using it"s test method to | ||
// assert thrown exception message. | ||
@@ -336,3 +329,1 @@ (utils.isRegExp(Error) && Error.test(exception.message)) || | ||
} | ||
}); |
@@ -1,3 +0,15 @@ | ||
# Changes # | ||
# Changes | ||
## 0.5.1 / 2012-10-31 | ||
- Fix bug introduced in 0.5.0 that exited process with a wrong code. | ||
- Add `assert.end` function as an alternative to `done` callback. | ||
- Change module layout to match better node conventions. | ||
## 0.5.0 / 2012-10-31 | ||
- Switch to logging via `console.log` instead of `process.stdout` for | ||
better compatibility with browserify. | ||
- Exit process with error code if test fails, or with `0` if not. | ||
## 0.4.4 / 2012-01-15 | ||
@@ -4,0 +16,0 @@ |
@@ -1,6 +0,11 @@ | ||
{ | ||
{ | ||
"name": "test", | ||
"version": "0.4.4", | ||
"description": "UncommonJS test runner.", | ||
"keywords": [ "test", "commonjs", "unit test" ], | ||
"version": "0.5.1", | ||
"description": "(Un)CommonJS test runner.", | ||
"keywords": [ | ||
"test", | ||
"commonjs", | ||
"uncommonjs", | ||
"unit" | ||
], | ||
"homepage": "https://github.com/Gozala/test-commonjs/", | ||
@@ -22,13 +27,18 @@ "author": "Irakli Gozalishvili <rfobic@gmail.com> (http://jeditoolkit.com)", | ||
}, | ||
"bugs": { "url": "http://github.com/Gozala/test-commonjs/issues/" }, | ||
"bugs": { | ||
"url": "http://github.com/Gozala/test-commonjs/issues/" | ||
}, | ||
"scripts": { | ||
"test": "node tests/engines/node/test.js", | ||
"test-browser": "open tests/engines/browser/index.html" | ||
"test": "node ./test/index.js" | ||
}, | ||
"main": "./engines/node/test.js", | ||
"engines": { "node": ">=0.4.x" }, | ||
"licenses": [{ | ||
"type" : "MIT", | ||
"url" : "http://jeditoolkit.com/LICENSE" | ||
}] | ||
"main": "./test.js", | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/Gozala/test-commonjs/License.md" | ||
} | ||
], | ||
"dependencies": { | ||
"ansi-font": "0.0.2" | ||
} | ||
} |
164
Readme.md
@@ -1,7 +0,9 @@ | ||
# UncommonJS unit test runner # | ||
# (Un)commonJS unit test runner | ||
Implementation of [UncommonJS unit test runner]. | ||
Implementation of [(Un)commonJS unit test runner][UncommonJS unit test runner]. | ||
## Testing ## | ||
[![build status](https://secure.travis-ci.org/Gozala/test-commonjs.png)](http://travis-ci.org/Gozala/test-commonjs) | ||
## Testing | ||
In order to make your package testable from [npm] you should: | ||
@@ -17,96 +19,97 @@ | ||
####Example#### | ||
## Example | ||
- package.json | ||
### package.json | ||
```js | ||
{ "name": "mypackage", | ||
"version": "0.7.0", | ||
"description": "Sample package", | ||
"scripts": { "test": "node test/all.js" }, | ||
"devDependencies": { "test": ">=0.0.5" } | ||
} | ||
``` | ||
```js | ||
{ | ||
"name": "mypackage", | ||
"version": "0.7.0", | ||
"description": "Sample package", | ||
"scripts": { "test": "node test/all.js" }, | ||
"devDependencies": { "test": ">=0.0.5" } | ||
} | ||
``` | ||
- test/fail-slow.js | ||
### Async test | ||
```js | ||
// if test function expects second named argument it will be executed | ||
// in async mode and test will be complete only after callback is called | ||
exports['test my async foo'] = function(assert, done) { | ||
var http = require('http') | ||
var google = http.createClient(80, 'www.jeditoolkit.com') | ||
var request = google.request('GET', '/', {'host': 'www.jeditoolkit.com'}) | ||
request.end() | ||
request.on('response', function (response) { | ||
assert.equal(response.statusCode, 302, 'must redirect') // will log result | ||
response.setEncoding('utf8') | ||
response.on('data', function (chunk) { | ||
assert.notEqual(chunk, 'helo world', 'must be something more inteligent') | ||
done() // telling test runner that we're done with this test | ||
}) | ||
}) | ||
} | ||
```js | ||
// if test function expects second named argument it will be executed | ||
// in async mode and test will be complete only after callback is called | ||
exports['test my async foo'] = function(assert, done) { | ||
var http = require('http') | ||
var google = http.createClient(80, 'www.jeditoolkit.com') | ||
var request = google.request('GET', '/', {'host': 'www.jeditoolkit.com'}) | ||
request.end() | ||
request.on('response', function (response) { | ||
assert.equal(response.statusCode, 302, 'must redirect') // will log result | ||
response.setEncoding('utf8') | ||
response.on('data', function (chunk) { | ||
assert.notEqual(chunk, 'helo world', 'must be something more inteligent') | ||
done() // telling test runner that we're done with this test | ||
}) | ||
}) | ||
} | ||
if (module == require.main) require('test').run(exports) | ||
``` | ||
if (module == require.main) require('test').run(exports) | ||
``` | ||
- test/fail-slow.js | ||
### Sync test | ||
```js | ||
// using assert passed to the test function that just logs failures | ||
exports['test that logs all failures'] = function(assert) { | ||
assert.equal(2 + 2, 5, 'assert failure is logged') | ||
assert.equal(3 + 2, 5, 'assert pass is logged') | ||
} | ||
```js | ||
// using assert passed to the test function that just logs failures | ||
exports['test that logs all failures'] = function(assert) { | ||
assert.equal(2 + 2, 5, 'assert failure is logged') | ||
assert.equal(3 + 2, 5, 'assert pass is logged') | ||
} | ||
if (module == require.main) require('test').run(exports) | ||
``` | ||
if (module == require.main) require('test').run(exports) | ||
``` | ||
- test/fail-fast.js | ||
### Fast fail | ||
```js | ||
// using nodejs's build in asserts that throw on failure | ||
var assert = require('assert') | ||
```js | ||
// using nodejs's build in asserts that throw on failure | ||
var assert = require('assert') | ||
exports['test that stops execution on first failure'] = function() { | ||
assert.equal(2 + 2, 5, 'assert fails and test execution stop here') | ||
assert.equal(3 + 2, 5, 'will never pass this since test failed above') | ||
} | ||
exports['test that stops execution on first failure'] = function() { | ||
assert.equal(2 + 2, 5, 'assert fails and test execution stop here') | ||
assert.equal(3 + 2, 5, 'will never pass this since test failed above') | ||
} | ||
if (module == require.main) require('test').run(exports) | ||
``` | ||
if (module == require.main) require('test').run(exports) | ||
``` | ||
- test/custom-assert.js | ||
### Custom assertions | ||
```js | ||
var AssertBase = require('assert').Assert | ||
var AssertDescriptor = { | ||
constructor: { value: Assert }, | ||
inRange: { value: function (lower, inner, upper, message) { | ||
if (lower < inner && inner < upper) { | ||
this.fail({ | ||
actual: inner, | ||
expected: lower + '> ' + ' < ' + upper, | ||
operator: "inRange", | ||
message: message | ||
}) | ||
} else { | ||
this.pass(message); | ||
} | ||
}, enumerable: true } | ||
```js | ||
var AssertBase = require('assert').Assert | ||
var AssertDescriptor = { | ||
constructor: { value: Assert }, | ||
inRange: { value: function (lower, inner, upper, message) { | ||
if (lower < inner && inner < upper) { | ||
this.fail({ | ||
actual: inner, | ||
expected: lower + '> ' + ' < ' + upper, | ||
operator: "inRange", | ||
message: message | ||
}) | ||
} else { | ||
this.pass(message); | ||
} | ||
function Assert() { | ||
return Object.create(AssertBase.apply(null, arguments), AssertDescriptor) | ||
} | ||
}, enumerable: true } | ||
} | ||
function Assert() { | ||
return Object.create(AssertBase.apply(null, arguments), AssertDescriptor) | ||
} | ||
// bundling custom asserts with test suite | ||
exports.Assert = Assert | ||
exports['test with custom asserts'] = function(assert) { | ||
assert.inRange(2, 3, 5, 'passes assert and logs') | ||
assert.equal(3 + 2, 5, 'assert pass is logged') | ||
} | ||
// bundling custom asserts with test suite | ||
exports.Assert = Assert | ||
exports['test with custom asserts'] = function(assert) { | ||
assert.inRange(2, 3, 5, 'passes assert and logs') | ||
assert.equal(3 + 2, 5, 'assert pass is logged') | ||
} | ||
if (module == require.main) require('test').run(exports) | ||
``` | ||
if (module == require.main) require('test').run(exports) | ||
``` | ||
@@ -118,2 +121,1 @@ For more examples checkout tests for this package and for more details see | ||
[npm]:http://npmjs.org/ | ||
71
test.js
@@ -1,14 +0,10 @@ | ||
/* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
/*jshint asi: true undef: true es5: true node: true devel: true | ||
forin: true */ | ||
/*global define: true */ | ||
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) { | ||
"use strict"; | ||
'use strict'; | ||
var Assert = require("./assert").Assert | ||
var Logger = require("./logger").Logger | ||
var Assert = require('./assert').Assert | ||
var ERR_COMPLETED_ASSERT = 'Assert in completed test' | ||
var ERR_COMPLETED_COMPLETE = 'Attemt to complete test more then one times' | ||
var ERR_EXPECT = 'AssertionError' | ||
var ERR_COMPLETED_ASSERT = "Assert in completed test" | ||
var ERR_COMPLETED_COMPLETE = "Attemt to complete test more then one times" | ||
var ERR_EXPECT = "AssertionError" | ||
@@ -26,21 +22,22 @@ | ||
var assert = Assert(logger) | ||
function done() { | ||
if (isDone) return logger.error(new Error(ERR_COMPLETED_COMPLETE)) | ||
assert.end = function end() { | ||
if (isDone) return logger.error(Error(ERR_COMPLETED_COMPLETE)) | ||
isDone = true | ||
next() | ||
} | ||
try { | ||
var result = unit(assert, done) | ||
// If it's async test that returns a promise. | ||
if (result && typeof(result.then) === 'function') { | ||
var result = unit(assert, assert.end) | ||
// If it"s async test that returns a promise. | ||
if (result && typeof(result.then) === "function") { | ||
result.then(function passed() { | ||
logger.pass('passed') | ||
done() | ||
logger.pass("passed") | ||
assert.end() | ||
}, function failed(reason) { | ||
logger.fail(reason) | ||
done() | ||
assert.end() | ||
}) | ||
} else { | ||
if (isFailFast) logger.pass('passed') | ||
if (isSync) done() | ||
if (isFailFast) logger.pass("passed") | ||
if (isSync) assert.end() | ||
} | ||
@@ -50,3 +47,3 @@ } catch (exception) { | ||
else logger.error(exception) | ||
done() | ||
assert.end() | ||
} | ||
@@ -56,2 +53,3 @@ } | ||
function isTest(name) { return name.indexOf("test") === 0 } | ||
@@ -64,18 +62,19 @@ /** | ||
// Collecting properties that represent test functions or suits. | ||
var names = Object.keys(units).filter(function isTest(name) { | ||
return 0 === name.indexOf('test') | ||
}) | ||
// Returning a function that executes all test in this suite and all it's | ||
var names = Object.keys(units).filter(isTest) | ||
Assert = units.Assert || Assert | ||
// Returning a function that executes all test in this suite and all it"s | ||
// sub-suits. | ||
return function suite(done) { | ||
return function suite(end) { | ||
// Chaining test / suits so that each is executed after last is done. | ||
(function next() { | ||
function next() { | ||
if (!names.length) return end() | ||
var name = names.shift() | ||
if (name) Unit(name, units[name], logger, units.Assert || Assert)(next) | ||
else done() | ||
})(logger = logger.section(name)) | ||
var unit = Unit(name, units[name], logger, units.Assert || Assert) | ||
unit(next) | ||
} | ||
next((logger = logger.section(name))) | ||
} | ||
} | ||
function Unit(name, units, logger, Assert) { | ||
return typeof(units) === 'function' ? Test(name, units, logger, Assert) | ||
return typeof(units) === "function" ? Test(name, units, logger, Assert) | ||
: Suite(name, units, logger, Assert) | ||
@@ -89,8 +88,10 @@ } | ||
exports.run = function run(units, logger) { | ||
Unit('Running all tests:', units, logger, Assert)(function done() { | ||
var exit = logger ? false : true | ||
logger = logger || new Logger() | ||
var unit = Unit("Running all tests:", units, logger, Assert) | ||
unit(function done() { | ||
logger.report() | ||
var failed = logger.errors.length !== 0 || logger.fails.length !== 0 | ||
if (exit) process.exit(failed ? 1 : 0) | ||
}) | ||
} | ||
}); |
31
utils.js
@@ -1,8 +0,1 @@ | ||
/* vim:set ts=2 sw=2 sts=2 expandtab */ | ||
/*jshint asi: true newcap: true undef: true es5: true node: true devel: true | ||
forin: false */ | ||
/*global define: true */ | ||
(typeof define === "undefined" ? function ($) { $(require, exports, module) } : define)(function (require, exports, module, undefined) { | ||
"use strict"; | ||
@@ -98,3 +91,3 @@ | ||
* isArray([1, 2, 3]) // true | ||
* isArray({ 0: 'foo', length: 1 }) // false | ||
* isArray({ 0: "foo", length: 1 }) // false | ||
*/ | ||
@@ -122,3 +115,3 @@ var isArray = Array.isArray || function isArray(value) { | ||
* isPrimitive(3) // true | ||
* isPrimitive('foo') // true | ||
* isPrimitive("foo") // true | ||
* isPrimitive({ bar: 3 }) // false | ||
@@ -165,3 +158,3 @@ */ | ||
(visited || (visited = [])).push(value); | ||
// If `value` is an atom return `true` cause it's valid JSON. | ||
// If `value` is an atom return `true` cause it"s valid JSON. | ||
return isPrimitive(value) || | ||
@@ -174,10 +167,10 @@ // If `value` is an array of JSON values that has not been visited | ||
// If `value` is a plain object containing properties with a JSON | ||
// values it's a valid JSON. | ||
// values it"s a valid JSON. | ||
(isFlat(value) && Object.keys(value).every(function(key) { | ||
var $ = Object.getOwnPropertyDescriptor(value, key); | ||
// Check every proprety of a plain object to verify that | ||
// it's neither getter nor setter, but a JSON value, that | ||
// it"s neither getter nor setter, but a JSON value, that | ||
// has not been visited yet. | ||
return ((!isObject($.value) || !~visited.indexOf($.value)) && | ||
!('get' in $) && !('set' in $) && | ||
!("get" in $) && !("set" in $) && | ||
isJSON($.value, visited)); | ||
@@ -205,3 +198,3 @@ })); | ||
// from a different sandbox. If a constructor of the `value` or a constructor | ||
// of the value's prototype has same name and source we assume that it's an | ||
// of the value"s prototype has same name and source we assume that it"s an | ||
// instance of the Type. | ||
@@ -244,3 +237,3 @@ if (!isInstanceOf && value) { | ||
else if (isString(value)) { | ||
result += '"' + value + '"'; | ||
result += "\"" + value + "\""; | ||
} | ||
@@ -290,3 +283,3 @@ else if (isFunction(value)) { | ||
if (0 <= name.indexOf(" ")) | ||
name = '"' + name + '"'; | ||
name = "\"" + name + "\""; | ||
@@ -316,3 +309,3 @@ if (descriptor.writable) | ||
if (descriptor.set) { | ||
if (descriptor.get) result += ',\n'; | ||
if (descriptor.get) result += ",\n"; | ||
result += offset + indent + "set " + name + " "; | ||
@@ -336,3 +329,3 @@ accessor = source(descriptor.set, indent, _limit, indent + offset, | ||
result += "\n" + offset + indent + '"__proto__": '; | ||
result += "\n" + offset + indent + "\"__proto__\": "; | ||
result += source(Object.getPrototypeOf(value), indent, 0, | ||
@@ -353,3 +346,1 @@ offset + indent); | ||
}; | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 14 instances in 1 package
1663462
120
4
1
42
1069
+ Addedansi-font@0.0.2
+ Addedansi-font@0.0.2(transitive)