Skip to content

Commit 7d33cc2

Browse files
committed
Add timeout override feature to tests
1 parent 0709db4 commit 7d33cc2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ let promise = Promise.resolve()
99
const tests = {}
1010

1111
module.exports.not = () => ignored++
12-
module.exports.t = (...rest) => test(false, ...rest)
1312
module.exports.ot = (...rest) => (only = true, test(true, ...rest))
1413

15-
async function test(o, name, fn) {
14+
const t = module.exports.t = (...rest) => test(false, ...rest)
15+
t.timeout = 500
16+
17+
async function test(o, name, options, fn) {
18+
typeof options !== 'object' && (fn = options, options = {})
1619
const line = new Error().stack.split('\n')[3].split(':')[1]
1720
await 1
1821

@@ -21,7 +24,7 @@ async function test(o, name, fn) {
2124

2225
tests[line] = { fn, line, name }
2326
promise = promise.then(() => Promise.race([
24-
new Promise((resolve, reject) => fn.timer = setTimeout(() => reject('Timed out'), 500)),
27+
new Promise((resolve, reject) => fn.timer = setTimeout(() => reject('Timed out'), options.timeout || t.timeout)),
2528
fn()
2629
]))
2730
.then((x) => {

0 commit comments

Comments
 (0)