Skip to content

Commit

Permalink
Support err as first argument for done callbacks in async tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanHoyer committed Aug 8, 2017
1 parent ec9a5d2 commit 2012c6a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 9 additions & 9 deletions ospec/ospec.js
Expand Up @@ -87,7 +87,13 @@ module.exports = new function init(name) {
var timeout = 0, delay = 200, s = new Date
var isDone = false

function done() {
function done(err) {
if (err) {
if (err.message) record(err.message, err)
else record(err)
subjects.pop()
next()
}
if (timeout !== undefined) {
timeout = clearTimeout(timeout)
if (delay !== Infinity) record(null)
Expand All @@ -114,9 +120,7 @@ module.exports = new function init(name) {
fn(done, function(t) {delay = t})
}
catch (e) {
record(e.message, e)
subjects.pop()
next()
done(e)
}
if (timeout === 0) {
startTimer()
Expand All @@ -126,11 +130,7 @@ module.exports = new function init(name) {
var p = fn()
if (p && p.then) {
startTimer()
p.then(done, e => {
record(e.message, e)
subjects.pop()
next()
})
p.then(() => done(), done)
} else {
nextTickish(next)
}
Expand Down
10 changes: 7 additions & 3 deletions ospec/tests/test-ospec.js
Expand Up @@ -153,10 +153,14 @@ o.spec("ospec", function() {
var a = 0, b = 0

function wrapPromise(fn) {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
callAsync(() => {
fn()
resolve()
try {
fn()
resolve()
} catch(e) {
reject(e)
}
})
})
}
Expand Down

0 comments on commit 2012c6a

Please sign in to comment.