Skip to content

Commit

Permalink
Avoid late start message after test has finished in --runInBand mode
Browse files Browse the repository at this point in the history
The start message that is sent over a test's MessageChannel may arrive after
the tests' Promise has already resolved, i.e. the finished callback has
already been executed. This results in excessive status message logging,
as the late start event does activate the test as "running" even though
it has already finished, rendering it in the "running" state forever (and
consequently generating excessive status messages as more and more tests become
considered "running").

Fixes #76
  • Loading branch information
JoostK committed Nov 28, 2023
1 parent ef7456c commit 6746298
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ export default class LightRunner {
{ transferList: [mc.port1] }
)
.then(
result => void onResult(test, result),
error => void onFailure(test, error)
result => {
// When `--runInBand` is enabled, `InBandTinypool` executes tasks
// in a microtask which may complete prior to having received the
// start message on the `MessageChannel`. As such, disconnect the
// start callback to avoid late invocations.
mc.port2.onmessage = null;
onResult(test, result);
},
error => {
mc.port2.onmessage = null;
onFailure(test, error);
}
);
})
);
Expand Down

0 comments on commit 6746298

Please sign in to comment.