From 76752e9ee8422489b27a4456b4c222d3ef4c5afa Mon Sep 17 00:00:00 2001 From: Nikita Skovoroda Date: Thu, 11 Jul 2024 21:50:16 +0300 Subject: [PATCH] feat: jest.setTimeout, timeout option support --- src/jest.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/jest.js b/src/jest.js index 3079911..6fc6740 100644 --- a/src/jest.js +++ b/src/jest.js @@ -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 @@ -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), @@ -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,