Skip to content

Commit

Permalink
test_runner: differentiate test types in enqueue dequeue events
Browse files Browse the repository at this point in the history
PR-URL: #54049
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Pietro Marchini <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
EddieAbbondanzio authored Jan 5, 2025
1 parent 338d70b commit 383e1a2
Show file tree
Hide file tree
Showing 47 changed files with 517 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,7 @@ The corresponding declaration ordered events are `'test:pass'` and `'test:fail'`
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `type` {string} The test type. Either `'suite'` or `'test'`.

Emitted when a test is dequeued, right before it is executed.
This event is not guaranteed to be emitted in the same order as the tests are
Expand Down Expand Up @@ -2985,6 +2986,7 @@ defined.
`undefined` if the test was run through the REPL.
* `name` {string} The test name.
* `nesting` {number} The nesting level of the test.
* `type` {string} The test type. Either `'suite'` or `'test'`.

Emitted when a test is enqueued for execution.

Expand Down
8 changes: 5 additions & 3 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class SuiteContext {
}

class Test extends AsyncResource {
reportedType = 'test';
abortController;
outerSignal;
#reportedSubtest;
Expand Down Expand Up @@ -609,7 +610,7 @@ class Test extends AsyncResource {
while (this.pendingSubtests.length > 0 && this.hasConcurrency()) {
const deferred = ArrayPrototypeShift(this.pendingSubtests);
const test = deferred.test;
test.reporter.dequeue(test.nesting, test.loc, test.name);
test.reporter.dequeue(test.nesting, test.loc, test.name, this.reportedType);
await test.run();
deferred.resolve();
}
Expand Down Expand Up @@ -800,7 +801,7 @@ class Test extends AsyncResource {
// If there is enough available concurrency to run the test now, then do
// it. Otherwise, return a Promise to the caller and mark the test as
// pending for later execution.
this.reporter.enqueue(this.nesting, this.loc, this.name);
this.reporter.enqueue(this.nesting, this.loc, this.name, this.reportedType);
if (this.root.harness.buildPromise || !this.parent.hasConcurrency()) {
const deferred = PromiseWithResolvers();

Expand All @@ -809,7 +810,7 @@ class Test extends AsyncResource {
return deferred.promise;
}

this.reporter.dequeue(this.nesting, this.loc, this.name);
this.reporter.dequeue(this.nesting, this.loc, this.name, this.reportedType);
return this.run();
}

Expand Down Expand Up @@ -1179,6 +1180,7 @@ class Test extends AsyncResource {
}

class TestHook extends Test {
reportedType = 'hook';
#args;
constructor(fn, options) {
const { hookType, loc, parent, timeout, signal } = options;
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/test_runner/tests_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,22 @@ class TestsStream extends Readable {
return { __proto__: null, todo: reason ?? true };
}

enqueue(nesting, loc, name) {
enqueue(nesting, loc, name, type) {
this[kEmitMessage]('test:enqueue', {
__proto__: null,
nesting,
name,
type,
...loc,
});
}

dequeue(nesting, loc, name) {
dequeue(nesting, loc, name, type) {
this[kEmitMessage]('test:dequeue', {
__proto__: null,
nesting,
name,
type,
...loc,
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
const {test, suite} = require('node:test');

suite('this is a suite');
test('this is a test');
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AFTER
not ok 1 - test that aborts
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort-runs-after-hook.js:(LINE):1'
failureType: 'uncaughtException'
error: 'boom'
Expand Down
22 changes: 22 additions & 0 deletions test/fixtures/test-runner/output/abort.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ TAP version 13
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -33,6 +38,7 @@ TAP version 13
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -42,6 +48,7 @@ TAP version 13
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -63,6 +70,7 @@ TAP version 13
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -84,6 +92,7 @@ TAP version 13
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -105,6 +114,7 @@ TAP version 13
not ok 1 - promise timeout signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
Expand All @@ -120,6 +130,7 @@ not ok 1 - promise timeout signal
not ok 2 - promise abort signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -142,26 +153,31 @@ not ok 2 - promise abort signal
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -171,6 +187,7 @@ not ok 2 - promise abort signal
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -180,6 +197,7 @@ not ok 2 - promise abort signal
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -201,6 +219,7 @@ not ok 2 - promise abort signal
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -222,6 +241,7 @@ not ok 2 - promise abort signal
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -243,6 +263,7 @@ not ok 2 - promise abort signal
not ok 3 - callback timeout signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
Expand All @@ -258,6 +279,7 @@ not ok 3 - callback timeout signal
not ok 4 - callback abort signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/test-runner/output/abort_hooks.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ TAP version 13
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -21,6 +22,7 @@ TAP version 13
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand Down Expand Up @@ -53,11 +55,13 @@ not ok 1 - 1 before describe
ok 1 - test 1
---
duration_ms: *
type: 'test'
...
# Subtest: test 2
ok 2 - test 2
---
duration_ms: *
type: 'test'
...
1..2
not ok 2 - 2 after describe
Expand Down Expand Up @@ -86,6 +90,7 @@ not ok 2 - 2 after describe
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
Expand All @@ -107,6 +112,7 @@ not ok 2 - 2 after describe
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
Expand Down Expand Up @@ -139,6 +145,7 @@ not ok 3 - 3 beforeEach describe
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
Expand All @@ -160,6 +167,7 @@ not ok 3 - 3 beforeEach describe
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/test-runner/output/abort_suite.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ TAP version 13
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -33,6 +38,7 @@ TAP version 13
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
Expand All @@ -42,6 +48,7 @@ TAP version 13
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -63,6 +70,7 @@ TAP version 13
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand All @@ -84,6 +92,7 @@ TAP version 13
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TAP version 13
ok 1 - passing test
---
duration_ms: *
type: 'test'
...
1..1
# tests 1
Expand Down
Loading

0 comments on commit 383e1a2

Please sign in to comment.