-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Allow bailing early when test fails #52717
Comments
this will only work as expected in case of no parallelism/concurrency. otherwise, there is just the option for a best effort where as soon as the orchestrator knows of a failed test it tries its best to stop other processes from executing tests. |
That is exactly right. Parallelisation messes up with a lot of other potential options - sorted tests being another case it doesn't play with. I do not see parallelism as a first-class concern - I'm much more inclined to get fed up with running tests if I have to mindlessly scroll through pages of stack traces over and over. I like parallelisation because it forces me to rethink about potential state leaks between tests but that's pretty much it. The test runner is fast enough as it is. |
My previous (failed) attempt: #48919 |
Sorry It's not quite clear to me what's going on there. The spawned process phantoms out? Can I take a stab at it? |
Go ahead 🙂 |
@MoLow Why do you consider your approach naive? So, here: module.exports = async function* bail(source) {
for await (const event of source) {
if (event.type === 'test:fail') {
/* c8 ignore start */
yield `\n\u001b[31m✖ Bailing on failed test: ${event.data.name}\u001b[0m\n`;
throw new Error('Bail');
}
/* c8 ignore stop */
}
}; This line:
This won't report the failure, won't it? Is this why you consider this naive? I remember I had some issues back in 2017 with the Does it reliably detect exceptions in the spawns or does it still need special handling in case the IPC signalling get disconnected? |
The issue I see is that test will continue to run, this will only hide the result from the reporter. |
Thanks 🎯 , I suppose the main stuff lives in runner/harness. Just off the top of my head, my plan is this:
I also have big concerns about errant children - I remember working with Last:
|
For reference, seems related: #42990 |
For a quick temporary solution (using node \
--test-reporter='data:text/javascript,
export default async function* bail(source) {
for await (const event of source) {
if (event.type === "test:fail") {
yield `\n\u001b[31m✖ Bailing on failed test: ${event.data.name}\u001b[0m\n`
;throw new Error("Bail")
}
}
}' \
--test-reporter=spec \
--test-reporter-destination=stdout \
--test-reporter-destination=stdout \
--test A base64 encoded version is not shorter (but perhaps more usable for your situation). node \
--test-reporter='data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQgYXN5bmMgZnVuY3Rpb24qIGJhaWwoc291cmNlKSB7Zm9yIGF3YWl0IChjb25zdCBldmVudCBvZiBzb3VyY2UpIHtpZiAoZXZlbnQudHlwZSA9PT0gInRlc3Q6ZmFpbCIpIHt5aWVsZCBgChtbMzFt4pyWIEJhaWxpbmcgb24gZmFpbGVkIHRlc3Q6ICR7ZXZlbnQuZGF0YS5uYW1lfRtbMG0KYDt0aHJvdyBuZXcgRXJyb3IoIkJhaWwiKX19fQ==' \
--test-reporter=spec \
--test-reporter-destination=stdout \
--test-reporter-destination=stdout \
--test For completeness, the base64 was generated using the following command. printf 'export default async function* bail(source) {for await (const event of source) {if (event.type === "test:fail") {yield `\n\u001b[31m✖ Bailing on failed test: ${event.data.name}\u001b[0m\n`;throw new Error("Bail")}}}' |
base64 --wrap 0 |
Yes, this may be a duplicate of #42990 |
Needs a Bail Out/Fail Fast strategy
What is the problem this feature will solve?
Not having to sift through a jumbled up mess of stack traces as I'm cleaning up tests after significant refactoring of the unit i'm testing.
Spit out the failing test and it's stack trace, then Exit 1 as soon as a test fails
Proposal
A bail flag, i.e
--bail
that hints to the runner that a failure should report and exit.Alternatives
Cooking up an Abort Signal wiring but that's really me writing machinery code to test.. the code... which is just bad taste, at least in most cases.
The text was updated successfully, but these errors were encountered: