Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have the global timeout take into account t.timeout() durations #2758

Merged
merged 12 commits into from Jun 19, 2021
7 changes: 7 additions & 0 deletions lib/api.js
Expand Up @@ -232,6 +232,13 @@ class Api extends Emittery {
}

const worker = fork(file, options, apiOptions.nodeArguments);
worker.onStateChange(data => {
if (data.Timeout && !apiOptions.debug)
OhYash marked this conversation as resolved.
Show resolved Hide resolved
{
// Console.log for now as debouce value is not getting updated.
console.log(`Timeout: ${data.Timeout}\n`);
}
});
runStatus.observeWorker(worker, file, {selectingLines: lineNumbers.length > 0});
deregisteredSharedWorkers.push(sharedWorkers.observeWorkerProcess(worker, runStatus));

Expand Down
28 changes: 17 additions & 11 deletions lib/runner.js
Expand Up @@ -65,6 +65,10 @@ class Runner extends Emittery {
return true;
};

this.emitStateChange = evt => {
this.emit('stateChange', Object.assign(evt));
OhYash marked this conversation as resolved.
Show resolved Hide resolved
};

let hasStarted = false;
let scheduledStart = false;
const meta = Object.freeze({
Expand Down Expand Up @@ -115,7 +119,7 @@ class Runner extends Emittery {
}

this.tasks.todo.push({title: rawTitle, metadata});
this.emit('stateChange', {
this.emitStateChange({
type: 'declared-test',
title: rawTitle,
knownFailing: false,
Expand Down Expand Up @@ -168,7 +172,7 @@ class Runner extends Emittery {

this.snapshots.touch(title, metadata.taskIndex);

this.emit('stateChange', {
this.emitStateChange({
type: 'declared-test',
title,
knownFailing: metadata.failing,
Expand Down Expand Up @@ -289,19 +293,20 @@ class Runner extends Emittery {
powerAssert: this.powerAssert,
title: `${task.title}${titleSuffix || ''}`,
isHook: true,
testPassed
testPassed,
emitStateChange: this.emitStateChange
OhYash marked this conversation as resolved.
Show resolved Hide resolved
}));
const outcome = await this.runMultiple(hooks, this.serial);
for (const result of outcome.storedResults) {
if (result.passed) {
this.emit('stateChange', {
this.emitStateChange({
type: 'hook-finished',
title: result.title,
duration: result.duration,
logs: result.logs
});
} else {
this.emit('stateChange', {
this.emitStateChange({
type: 'hook-failed',
title: result.title,
err: serializeError('Hook failure', true, result.error),
Expand Down Expand Up @@ -340,14 +345,15 @@ class Runner extends Emittery {
metadata: task.metadata,
powerAssert: this.powerAssert,
title: task.title,
registerUniqueTitle: this.registerUniqueTitle
registerUniqueTitle: this.registerUniqueTitle,
emitStateChange: this.emitStateChange
});

const result = await this.runSingle(test);
testOk = result.passed;

if (testOk) {
this.emit('stateChange', {
this.emitStateChange({
type: 'test-passed',
title: result.title,
duration: result.duration,
Expand All @@ -363,7 +369,7 @@ class Runner extends Emittery {
testPassed: testOk
});
} else {
this.emit('stateChange', {
this.emitStateChange({
type: 'test-failed',
title: result.title,
err: serializeError('Test failure', true, result.error, this.file),
Expand Down Expand Up @@ -399,7 +405,7 @@ class Runner extends Emittery {
continue;
}

this.emit('stateChange', {
this.emitStateChange({
type: 'selected-test',
title: task.title,
knownFailing: task.metadata.failing,
Expand All @@ -425,7 +431,7 @@ class Runner extends Emittery {
continue;
}

this.emit('stateChange', {
this.emitStateChange({
type: 'selected-test',
title: task.title,
knownFailing: task.metadata.failing,
Expand All @@ -451,7 +457,7 @@ class Runner extends Emittery {
continue;
}

this.emit('stateChange', {
this.emitStateChange({
type: 'selected-test',
title: task.title,
knownFailing: false,
Expand Down
2 changes: 2 additions & 0 deletions lib/test.js
Expand Up @@ -208,6 +208,7 @@ class Test {
this.registerUniqueTitle = options.registerUniqueTitle;
this.logs = [];
this.teardowns = [];
this.emitStateChange = options.emitStateChange;

const {snapshotBelongsTo = this.title, nextSnapshotIndex = 0} = options;
this.snapshotBelongsTo = snapshotBelongsTo;
Expand Down Expand Up @@ -431,6 +432,7 @@ class Test {
this.finishDueToTimeout();
}
}, ms);
this.emitStateChange({Timeout: this.timeoutMs});
}

refreshTimeout() {
Expand Down