-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_runner: call abort on test finish
PR-URL: #48827 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
- Loading branch information
Showing
5 changed files
with
166 additions
and
18 deletions.
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
25 changes: 25 additions & 0 deletions
25
test/fixtures/test-runner/aborts/failed-test-still-call-abort.js
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,25 @@ | ||
const {test, afterEach} = require('node:test'); | ||
const assert = require('node:assert'); | ||
const { waitForAbort } = require('./wait-for-abort-helper'); | ||
|
||
let testCount = 0; | ||
let signal; | ||
|
||
afterEach(() => { | ||
assert.equal(signal.aborted, false); | ||
|
||
waitForAbort({ testNumber: ++testCount, signal }); | ||
}); | ||
|
||
test("sync", (t) => { | ||
signal = t.signal; | ||
assert.equal(signal.aborted, false); | ||
throw new Error('failing the sync test'); | ||
}); | ||
|
||
test("async", async (t) => { | ||
await null; | ||
signal = t.signal; | ||
assert.equal(signal.aborted, false); | ||
throw new Error('failing the async test'); | ||
}); |
23 changes: 23 additions & 0 deletions
23
test/fixtures/test-runner/aborts/successful-test-still-call-abort.js
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,23 @@ | ||
const {test, afterEach} = require('node:test'); | ||
const assert = require('node:assert'); | ||
const {waitForAbort} = require("./wait-for-abort-helper"); | ||
|
||
let testCount = 0; | ||
let signal; | ||
|
||
afterEach(() => { | ||
assert.equal(signal.aborted, false); | ||
|
||
waitForAbort({ testNumber: ++testCount, signal }); | ||
}); | ||
|
||
test("sync", (t) => { | ||
signal = t.signal; | ||
assert.equal(signal.aborted, false); | ||
}); | ||
|
||
test("async", async (t) => { | ||
await null; | ||
signal = t.signal; | ||
assert.equal(signal.aborted, false); | ||
}); |
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 @@ | ||
module.exports = { | ||
waitForAbort: function ({ testNumber, signal }) { | ||
let retries = 0; | ||
|
||
const interval = setInterval(() => { | ||
retries++; | ||
if(signal.aborted) { | ||
console.log(`abort called for test ${testNumber}`); | ||
clearInterval(interval); | ||
return; | ||
} | ||
|
||
if(retries > 100) { | ||
clearInterval(interval); | ||
throw new Error(`abort was not called for test ${testNumber}`); | ||
} | ||
}, 10); | ||
} | ||
} |
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