|
|
@ -3,7 +3,31 @@ |
|
|
|
const { isPromise } = require('../../util/helpers'); |
|
|
|
const { pass, fail } = require('./constants'); |
|
|
|
|
|
|
|
const runTests = tests => Promise.all(tests.map(each => { |
|
|
|
const runTests = instance => { |
|
|
|
|
|
|
|
const beforeAll = () => Promise.map( |
|
|
|
instance.__hooks__.before['@start'], |
|
|
|
hook => hook.run(), |
|
|
|
); |
|
|
|
|
|
|
|
const beforeEvery = () => Promise.mapSeries( |
|
|
|
instance.__hooks__.before['*'] || [], |
|
|
|
hook => hook.run(), |
|
|
|
); |
|
|
|
|
|
|
|
const runner = () => Promise.mapSeries(instance.__tests__, each => { |
|
|
|
|
|
|
|
const beforeThis = () => Promise.mapSeries( |
|
|
|
instance.__hooks__.before[each.description] || [], |
|
|
|
hook => hook.run(), |
|
|
|
); |
|
|
|
|
|
|
|
const afterThis = () => Promise.mapSeries( |
|
|
|
instance.__hooks__.after[each.description] || [], |
|
|
|
hook => hook.run(), |
|
|
|
); |
|
|
|
|
|
|
|
return beforeEvery().then(() => beforeThis()).then(() => { |
|
|
|
|
|
|
|
const pred = each.test(); |
|
|
|
|
|
|
@ -24,6 +48,20 @@ const runTests = tests => Promise.all(tests.map(each => { |
|
|
|
.then(() => ({ description: each.description, result: pass })) |
|
|
|
.catch(e => ({ description: each.description, result: fail, error: e })); |
|
|
|
|
|
|
|
})); |
|
|
|
}) |
|
|
|
.then(result => afterThis().then(() => result)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
const afterAll = () => Promise.mapSeries( |
|
|
|
instance.__hooks__.before['@end'], |
|
|
|
hook => hook.run(), |
|
|
|
); |
|
|
|
|
|
|
|
return beforeAll() |
|
|
|
.then(() => runner()) |
|
|
|
.then(results => afterAll().then(() => results)); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = runTests; |
|
|
|