diff --git a/lib/api.js b/lib/api.js index ff0f0f74c..f43fad799 100644 --- a/lib/api.js +++ b/lib/api.js @@ -218,9 +218,8 @@ export default class Api extends Emittery { } runStatus.on('stateChange', record => { - if (record.testFile && !timedOutWorkerFiles.has(record.testFile)) { - // Debounce the timer whenever there is activity from workers that - // haven't already timed out. + if (record.testFile && !timedOutWorkerFiles.has(record.testFile) && record.type !== 'worker-stderr' && record.type !== 'worker-stdout') { + // Debounce the timer whenever there is test-related activity from workers that haven't already timed out. timeoutTrigger.debounce(); } diff --git a/test/idle-timeouts/fixtures/console-output.js b/test/idle-timeouts/fixtures/console-output.js new file mode 100644 index 000000000..af879f8ac --- /dev/null +++ b/test/idle-timeouts/fixtures/console-output.js @@ -0,0 +1,13 @@ +import {setTimeout as delay} from 'node:timers/promises'; +import test from 'ava'; + +test('timeout with console output', async t => { + t.timeout(1000, 'timeout despite console output'); + for (let i = 0; await delay(100, true); i++) { + if (i % 2 === 0) { + console.log('stdout'); + } else { + console.error('stderr'); + } + } +}); diff --git a/test/idle-timeouts/fixtures/package.json b/test/idle-timeouts/fixtures/package.json new file mode 100644 index 000000000..eceb819c7 --- /dev/null +++ b/test/idle-timeouts/fixtures/package.json @@ -0,0 +1,9 @@ +{ + "type": "module", + "ava": { + "files": [ + "*.js" + ], + "timeout": "500ms" + } +} diff --git a/test/idle-timeouts/test.js b/test/idle-timeouts/test.js new file mode 100644 index 000000000..635ad86ae --- /dev/null +++ b/test/idle-timeouts/test.js @@ -0,0 +1,9 @@ +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; + +test('idle timeouts are not blocked by console output', async t => { + const result = await t.throwsAsync(fixture(['console-output.js'])); + const error = result.stats.getError(result.stats.failed[0]); + t.is(error.message, 'timeout despite console output'); +});