Merge remote-tracking branch 'origin/rewrite' into rewrite

This commit is contained in:
Leo Horie 2017-01-09 08:14:15 -05:00
commit 97b0fda1d0

View file

@ -1,12 +1,11 @@
"use strict"
module.exports = new function init() {
var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object"
var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty
function o(subject, predicate) {
subject = unique(subject, predicate)
ctx[subject] = predicate
if (predicate === undefined) return new Assert(subject)
ctx[unique(subject)] = predicate
}
o.before = hook("__before")
o.after = hook("__after")
@ -15,8 +14,7 @@ module.exports = new function init() {
o.new = init
o.spec = function(subject, predicate) {
var parent = ctx
subject = unique(subject, predicate)
ctx = ctx[subject] = {}
ctx = ctx[unique(subject)] = {}
predicate()
ctx = parent
}
@ -77,7 +75,7 @@ module.exports = new function init() {
var timeout = 0, delay = 200, s = new Date
var isDone = false
var body = fn.toString()
var arg = (body.match(/\(([\w_$]+)/) || body.match(/([\w_$]+)\s*=>/) || []).pop()
var arg = (body.match(/\(([\w$]+)/) || body.match(/([\w$]+)\s*=>/) || []).pop()
if (body.indexOf(arg) === body.lastIndexOf(arg)) throw new Error("`" + arg + "()` should be called at least once")
try {
fn(function done() {
@ -112,10 +110,10 @@ module.exports = new function init() {
}
}
}
function unique(subject, predicate) {
if (ctx.hasOwnProperty(subject) && predicate) {
console.warn("A test named `" + subject + "` was already defined")
subject = subject + "*"
function unique(subject) {
if (hasOwn.call(ctx, subject)) {
console.warn("A test or a spec named `" + subject + "` was already defined")
while (hasOwn.call(ctx, subject)) subject += '*'
}
return subject
}
@ -155,7 +153,7 @@ module.exports = new function init() {
var aKeys = Object.getOwnPropertyNames(a), bKeys = Object.getOwnPropertyNames(b)
if (aKeys.length !== bKeys.length) return false
for (var i = 0; i < aKeys.length; i++) {
if (!b.hasOwnProperty(aKeys[i]) || !deepEqual(a[aKeys[i]], b[aKeys[i]])) return false
if (!hasOwn.call(b, aKeys[i]) || !deepEqual(a[aKeys[i]], b[aKeys[i]])) return false
}
return true
}