-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added --no-timeout option (#26)
* feat: added --no-timeout option Closes #20 * test(timeout): resolve windows failures
- Loading branch information
1 parent
702833d
commit 090e94e
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ok } from 'node:assert' | ||
import { test } from 'node:test' | ||
|
||
test('this will take a long time', (t, done) => { | ||
setTimeout(() => { | ||
ok(true) | ||
done() | ||
}, 1e3) | ||
console.log('test:waiting') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import FakeTimers from '@sinonjs/fake-timers' | ||
|
||
let clock | ||
|
||
if (process.argv[1].endsWith('borp.js')) { | ||
clock = FakeTimers.install({ | ||
node: Date.now(), | ||
shouldAdvanceTime: true, | ||
advanceTimeDelta: 100 | ||
}) | ||
process.on('message', listener) | ||
} | ||
|
||
function listener ([fn, ...args]) { | ||
clock[fn](...args) | ||
if (fn === 'uninstall') { | ||
process.off('message', listener) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { test } from 'node:test' | ||
import { once } from 'node:events' | ||
import { pathToFileURL } from 'node:url' | ||
import { fork } from 'node:child_process' | ||
import { tspl } from '@matteo.collina/tspl' | ||
import { join } from 'desm' | ||
|
||
const borp = join(import.meta.url, '..', 'borp.js') | ||
const clock = join(import.meta.url, '..', 'test-utils', 'clock.js') | ||
const forkOpts = { | ||
cwd: join(import.meta.url, '..', 'fixtures', 'long'), | ||
env: { NODE_OPTIONS: `--import=${pathToFileURL(clock)}` }, | ||
stdio: ['pipe', 'pipe', 'pipe', 'ipc'] | ||
} | ||
|
||
test('times out after 30s by default', async (t) => { | ||
const { ok, equal } = tspl(t, { plan: 4 }) | ||
const borpProcess = fork(borp, forkOpts) | ||
let stdout = '' | ||
borpProcess.stdout.on('data', (data) => { | ||
stdout += data | ||
if (data.includes('test:waiting')) { | ||
borpProcess.send(['tick', 30e3]) | ||
borpProcess.send(['uninstall']) | ||
} | ||
}) | ||
const [code] = await once(borpProcess, 'exit') | ||
equal(code, 1) | ||
ok(stdout.includes('test timed out after 30000ms')) | ||
ok(stdout.includes('tests 1')) | ||
ok(stdout.includes('cancelled 1')) | ||
}) | ||
|
||
test('does not timeout when setting --no-timeout', async (t) => { | ||
const { ok, equal } = tspl(t, { plan: 4 }) | ||
const borpProcess = fork(borp, ['--no-timeout'], forkOpts) | ||
borpProcess.stderr.pipe(process.stderr) | ||
let stdout = '' | ||
borpProcess.stdout.on('data', (data) => { | ||
stdout += data | ||
if (data.includes('test:waiting')) { | ||
borpProcess.send(['tick', 30e3]) | ||
borpProcess.send(['uninstall']) | ||
} | ||
}) | ||
const [code] = await once(borpProcess, 'exit') | ||
equal(code, 0) | ||
ok(stdout.includes('✔ this will take a long time')) | ||
ok(stdout.includes('tests 1')) | ||
ok(stdout.includes('pass 1')) | ||
}) | ||
|
||
test('timeout is configurable', async (t) => { | ||
const { ok, equal } = tspl(t, { plan: 4 }) | ||
const borpProcess = fork(borp, ['--timeout', '10000'], forkOpts) | ||
let stdout = '' | ||
borpProcess.stdout.on('data', (data) => { | ||
stdout += data | ||
if (data.includes('test:waiting')) { | ||
borpProcess.send(['tick', 10e3]) | ||
borpProcess.send(['uninstall']) | ||
} | ||
}) | ||
const [code] = await once(borpProcess, 'exit') | ||
equal(code, 1) | ||
ok(stdout.includes('test timed out after 10000ms')) | ||
ok(stdout.includes('tests 1')) | ||
ok(stdout.includes('cancelled 1')) | ||
}) |