Skip to content

Commit

Permalink
feat: jest.setTimeout, timeout option support
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Jul 11, 2024
1 parent 0c2e2b9 commit 76752e9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import './jest.snapshot.js'
import { getCallerLocation, installLocationInNextTest } from './dark.cjs'
import { expect } from 'expect'

let defaultTimeout = 5000

const makeEach = (impl) => (list) => (template, fn) => {
for (const args of list) {
let name = template
Expand All @@ -31,11 +33,12 @@ const makeEach = (impl) => (list) => (template, fn) => {
const forceExit = process.execArgv.map((x) => x.replaceAll('_', '-')).includes('--test-force-exit')

const describe = (...args) => nodeDescribe(...args)
const test = (name, fn) => {
const test = (name, fn, testTimeout) => {
const timeout = testTimeout ?? defaultTimeout
installLocationInNextTest(getCallerLocation())
if (fn.length > 0) return nodeTest(name, (t, c) => fn(c))
if (!forceExit) return nodeTest(name, fn)
return nodeTest(name, async (t) => {
return nodeTest(name, { timeout }, async (t) => {
const res = fn()
assert(
types.isPromise(res),
Expand Down Expand Up @@ -67,6 +70,11 @@ const jest = {
obj[name] = fn
return fn
},
setTimeout: (x) => {
assert.equal(typeof x, 'number')
defaultTimeout = x
return this
},
mock: jestmock,
requireMock,
requireActual,
Expand Down

0 comments on commit 76752e9

Please sign in to comment.