Merge remote-tracking branch 'origin/rewrite' into rewrite
Conflicts: docs/keys.md docs/signatures.md docs/v1.x-migration.md index.js ospec/bin/ospec.cmd request/request.js request/tests/test-xhr.js util/prop.js util/tests/index.html util/tests/test-prop.js
This commit is contained in:
commit
bce2abbffd
107 changed files with 1989 additions and 1970 deletions
|
|
@ -45,7 +45,7 @@ Assertions may have descriptions:
|
|||
```javascript
|
||||
o("addition", function() {
|
||||
o(1 + 1).equals(2)("addition should work")
|
||||
|
||||
|
||||
/* in ES6, the following syntax is also possible
|
||||
o(1 + 1).equals(2) `addition should work`
|
||||
*/
|
||||
|
|
@ -110,7 +110,7 @@ o.spec("call()", function() {
|
|||
o("works", function() {
|
||||
var spy = o.spy()
|
||||
call(spy, 1)
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.args[0]).equals(1)
|
||||
})
|
||||
|
|
@ -132,7 +132,7 @@ By default, asynchronous tests time out after 20ms. This can be changed on a per
|
|||
```javascript
|
||||
o("setTimeout calls callback", function(done, timeout) {
|
||||
timeout(50) //wait 50ms before bailing out of the test
|
||||
|
||||
|
||||
setTimeout(done, 30)
|
||||
})
|
||||
```
|
||||
|
|
@ -151,15 +151,15 @@ o.spec("math", function() {
|
|||
o.beforeEach(function() {
|
||||
acc = 0
|
||||
})
|
||||
|
||||
|
||||
o("addition", function() {
|
||||
acc += 1
|
||||
|
||||
|
||||
o(acc).equals(1)
|
||||
})
|
||||
o("subtraction", function() {
|
||||
acc -= 1
|
||||
|
||||
|
||||
o(acc).equals(-1)
|
||||
})
|
||||
})
|
||||
|
|
@ -180,16 +180,16 @@ o.spec("math", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
//tests only run after async hooks complete
|
||||
o("addition", function() {
|
||||
acc += 1
|
||||
|
||||
|
||||
o(acc).equals(1)
|
||||
})
|
||||
o("subtraction", function() {
|
||||
acc -= 1
|
||||
|
||||
|
||||
o(acc).equals(-1)
|
||||
})
|
||||
})
|
||||
|
|
@ -204,7 +204,7 @@ o.spec("math", function() {
|
|||
o("addition", function() {
|
||||
o(1 + 1).equals(2)
|
||||
})
|
||||
|
||||
|
||||
//only this test will be run, regardless of how many groups there are
|
||||
o.only("subtraction", function() {
|
||||
o(1 - 1).notEquals(2)
|
||||
|
|
|
|||
|
|
@ -43,4 +43,4 @@ traverseDirectory(".", function(pathname, stat, children) {
|
|||
|
||||
process.on("unhandledRejection", function(e) {
|
||||
console.log("Uncaught (in promise) " + e.stack)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
node ospec
|
||||
node ospec
|
||||
|
|
|
|||
|
|
@ -32,21 +32,21 @@ module.exports = new function init() {
|
|||
o.run = function() {
|
||||
start = new Date
|
||||
test(spec, [], [], report)
|
||||
|
||||
|
||||
function test(spec, pre, post, finalize) {
|
||||
pre = [].concat(pre, spec["__beforeEach"] || [])
|
||||
post = [].concat(spec["__afterEach"] || [], post)
|
||||
series([].concat(spec["__before"] || [], Object.keys(spec).map(function(key) {
|
||||
return function(done, timeout) {
|
||||
timeout(Infinity)
|
||||
|
||||
|
||||
if (key.slice(0, 2) === "__") return done()
|
||||
if (only !== null && spec[key] !== only && typeof only === typeof spec[key]) return done()
|
||||
subjects.push(key)
|
||||
var type = typeof spec[key]
|
||||
if (type === "object") test(spec[key], pre, post, pop)
|
||||
if (type === "function") series([].concat(pre, spec[key], post, pop))
|
||||
|
||||
|
||||
function pop() {
|
||||
subjects.pop()
|
||||
done()
|
||||
|
|
@ -58,11 +58,11 @@ module.exports = new function init() {
|
|||
function series(fns) {
|
||||
var cursor = 0
|
||||
next()
|
||||
|
||||
|
||||
function next() {
|
||||
stack++
|
||||
if (cursor === fns.length) return
|
||||
|
||||
|
||||
var fn = fns[cursor++]
|
||||
if (fn.length > 0) {
|
||||
var timeout = 0, delay = 40, s = new Date
|
||||
|
|
@ -109,12 +109,12 @@ module.exports = new function init() {
|
|||
ctx[name] = predicate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
define("equals", "should equal", function(a, b) {return a === b})
|
||||
define("notEquals", "should not equal", function(a, b) {return a !== b})
|
||||
define("deepEquals", "should deep equal", deepEqual)
|
||||
define("notDeepEquals", "should not deep equal", function(a, b) {return !deepEqual(a, b)})
|
||||
|
||||
|
||||
function isArguments(a) {
|
||||
if ("callee" in a) {
|
||||
for (var i in a) if (i === "callee") return false
|
||||
|
|
@ -185,7 +185,7 @@ module.exports = new function init() {
|
|||
function highlight(message) {
|
||||
return hasProcess ? "\x1b[31m" + message + "\x1b[0m" : "%c" + message + "%c "
|
||||
}
|
||||
|
||||
|
||||
function report() {
|
||||
var status = 0
|
||||
for (var i = 0, r; r = results[i]; i++) {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
<body>
|
||||
<script src="../../module/module.js"></script>
|
||||
<script src="../../test-utils/callAsync.js"></script>
|
||||
|
||||
|
||||
<script src="../../ospec/ospec.js"></script>
|
||||
<script src="test-ospec.js"></script>
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -21,22 +21,22 @@ new function(o) {
|
|||
o.spec("ospec", function() {
|
||||
o.spec("sync", function() {
|
||||
var a = 0, b = 0
|
||||
|
||||
|
||||
o.before(function test() {a = 1})
|
||||
o.after(function test() {a = 0})
|
||||
|
||||
|
||||
o.beforeEach(function test() {b = 1})
|
||||
o.afterEach(function test() {b = 0})
|
||||
|
||||
|
||||
o("assertions", function test() {
|
||||
var spy = o.spy()
|
||||
spy(a)
|
||||
|
||||
|
||||
o(a).equals(b)
|
||||
o(a).notEquals(2)
|
||||
o({a: [1, 2], b: 3}).deepEquals({a: [1, 2], b: 3})
|
||||
o([{a: 1, b: 2}, {c: 3}]).deepEquals([{a: 1, b: 2}, {c: 3}])
|
||||
|
||||
|
||||
var values = ["a", "", 1, 0, true, false, null, undefined, Date(0), ["a"], [], function() {return arguments}.call(), new Uint8Array(), {a: 1}, {}]
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
|
|
@ -44,7 +44,7 @@ o.spec("ospec", function() {
|
|||
else o(values[i]).notDeepEquals(values[j])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
o(spy.callCount).equals(1)
|
||||
o(spy.args.length).equals(1)
|
||||
o(spy.args[0]).equals(1)
|
||||
|
|
@ -52,7 +52,7 @@ o.spec("ospec", function() {
|
|||
})
|
||||
o.spec("async", function() {
|
||||
var a = 0, b = 0
|
||||
|
||||
|
||||
o.before(function test(done) {
|
||||
callAsync(function() {
|
||||
a = 1
|
||||
|
|
@ -65,7 +65,7 @@ o.spec("ospec", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o.beforeEach(function test(done) {
|
||||
callAsync(function() {
|
||||
b = 1
|
||||
|
|
@ -78,15 +78,15 @@ o.spec("ospec", function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
o("async hooks", function test(done) {
|
||||
callAsync(function() {
|
||||
var spy = o.spy()
|
||||
spy(a)
|
||||
|
||||
|
||||
o(a).equals(b)
|
||||
o(a).equals(1)("a and b should be initialized")
|
||||
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue