Skip to content

Commit 449dd4c

Browse files
refactor: [*] prepare for move to chaijs gh org
- move lib to index.js - package/component: change github url - refactor browser tests without mocha/chai
1 parent 6dc2a3b commit 449dd4c

11 files changed

Lines changed: 259 additions & 232 deletions

File tree

Makefile

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,38 @@
11

2-
TESTS = test/*.js
3-
REPORTER = spec
4-
52
#
63
# Tests
74
#
85

96
test: test-node
107

118
test-node:
12-
@printf "\n ==> [Node.js]"
13-
@NODE_ENV=test node ./test/runner.js
9+
@printf "\n ==> [Node.js]\n"
10+
@NODE_ENV=test node ./test/index.js
1411

15-
test-cov: lib-cov
16-
@assertion-error_COV=1 NODE_ENV=test node ./test/runner.js
12+
test-browser:
13+
@printf "\n ==> [Browser]\n"
14+
@make build
15+
@printf "\n\n Open 'test/index.html' in your browser to test.\n\n"
1716

1817
#
1918
# Components
2019
#
2120

22-
build: components lib/*
21+
build: components
2322
@./node_modules/.bin/component-build --dev
2423

2524
components: component.json
2625
@./node_modules/.bin/component-install --dev
2726

28-
#
29-
# Coverage
30-
#
31-
32-
lib-cov:
33-
@rm -rf lib-cov
34-
@jscoverage lib lib-cov
35-
3627
#
3728
# Clean up
3829
#
3930

40-
clean: clean-components clean-cov
31+
clean: clean-components
4132

4233
clean-components:
4334
@rm -rf build
4435
@rm -rf components
4536

46-
clean-cov:
47-
@rm -rf lib-cov
48-
@rm -f coverage.html
49-
50-
51-
.PHONY: clean clean-components clean-cov test test-cov test-node lib-cov
37+
.PHONY: test test-node test-browser
38+
.PHONY: clean clean-components

component.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
{
22
"name": "assertion-error"
3-
, "repo": "qualiancy/assertion-error"
3+
, "repo": "chaijs/assertion-error"
44
, "version": "0.1.0"
55
, "description": "Error constructor for test and validation frameworks that implements standardized AssertionError specification."
66
, "license": "MIT"
77
, "keywords": [
8+
"test"
9+
, "assertion"
10+
, "assertion-error"
811
]
9-
, "main": "lib/assertion-error.js"
12+
, "main": "index.js"
1013
, "scripts": [
11-
"lib/assertion-error.js"
14+
"index.js"
1215
]
1316
, "dependencies": {}
1417
, "development": {}

index.js

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,110 @@
1-
module.exports = process.env.AssertionError_COV
2-
? require('./lib-cov/assertion-error')
3-
: require('./lib/assertion-error');
1+
/*!
2+
* assertion-error
3+
* Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
4+
* MIT Licensed
5+
*/
6+
7+
/*!
8+
* Return a function that will copy properties from
9+
* one object to another excluding any originally
10+
* listed. Returned function will create a new `{}`.
11+
*
12+
* @param {String} excluded properties ...
13+
* @return {Function}
14+
*/
15+
16+
function exclude () {
17+
var excludes = [].slice.call(arguments);
18+
19+
function excludeProps (res, obj) {
20+
Object.keys(obj).forEach(function (key) {
21+
if (!~excludes.indexOf(key)) res[key] = obj[key];
22+
});
23+
}
24+
25+
return function extendExclude () {
26+
var args = [].slice.call(arguments)
27+
, i = 0
28+
, res = {};
29+
30+
for (; i < args.length; i++) {
31+
excludeProps(res, args[i]);
32+
}
33+
34+
return res;
35+
};
36+
};
37+
38+
/*!
39+
* Primary Exports
40+
*/
41+
42+
module.exports = AssertionError;
43+
44+
/**
45+
* ### AssertionError
46+
*
47+
* An extension of the JavaScript `Error` constructor for
48+
* assertion and validation scenarios.
49+
*
50+
* @param {String} message
51+
* @param {Object} properties to include (optional)
52+
* @param {callee} start stack function (optional)
53+
*/
54+
55+
function AssertionError (message, _props, ssf) {
56+
var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
57+
, props = extend(_props || {});
58+
59+
// default values
60+
this.message = message || 'Unspecified AssertionError';
61+
this.showDiff = false;
62+
63+
// copy from properties
64+
for (var key in props) {
65+
this[key] = props[key];
66+
}
67+
68+
// capture stack trace
69+
ssf = ssf || arguments.callee;
70+
if (ssf && Error.captureStackTrace) {
71+
Error.captureStackTrace(this, ssf);
72+
}
73+
}
74+
75+
/*!
76+
* Inherit from Error.prototype
77+
*/
78+
79+
AssertionError.prototype = Object.create(Error.prototype);
80+
81+
/*!
82+
* Statically set name
83+
*/
84+
85+
AssertionError.prototype.name = 'AssertionError';
86+
87+
/*!
88+
* Ensure correct constructor
89+
*/
90+
91+
AssertionError.prototype.constructor = AssertionError;
92+
93+
/**
94+
* Allow errors to be converted to JSON for static transfer.
95+
*
96+
* @param {Boolean} include stack (default: `true`)
97+
* @return {Object} object that can be `JSON.stringify`
98+
*/
99+
100+
AssertionError.prototype.toJSON = function (stack) {
101+
var extend = exclude('constructor', 'toJSON', 'stack')
102+
, props = extend({ name: this.name }, this);
103+
104+
// include stack if exists and not turned off
105+
if (false !== stack && this.stack) {
106+
props.stack = this.stack;
107+
}
108+
109+
return props;
110+
};

lib/assertion-error.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
, "author": "Jake Luer <jake@qualiancy.com> (http://qualiancy.com)"
66
, "license": "MIT"
77
, "keywords": [
8+
"test"
9+
, "assertion"
10+
, "assertion-error"
811
]
912
, "repository": {
1013
"type": "git"
11-
, "url": "git@github.com:qualiancy/assertion-error.git"
14+
, "url": "git@github.com:chaijs/assertion-error.git"
1215
}
1316
, "engines": {
1417
"node": "*"

test/browser/index.html

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)