-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[Feature]: testInfo.abort() / test.abort() to immediately mark a test as failed and terminate it #39965
Copy link
Copy link
Open
Description
🚀 Feature Request
We have test.fail() and test.skip() (and TestInfo equivalents) that can change the outcome of a test ("should fail" or "skipped"). It seems that there's a gap here for aborting the test ("definitely fail").
Example
Like test.fail() or test.skip(), I expect test.abort() to be mostly useful in fixtures. Personally, I'm trying to prevent a scenario with our app tests where an engineer could introduce a race condition by making changes to a test page:
// Since the page is not being cloned, we will block any requests to the publish or draft
// endpoints to prevent test collisions.
for (const endpointRegex of autoFailEndpoints) {
await page.route(endpointRegex, route => {
testInfo.abort(
true,
"Test failed due to attempting to publish or save a page without cloning. " +
"This is to prevent tests from accidentally publishing or saving changes to shared pages. " +
"Add the`clone` option to the test's `testPage` configuration to allow requests to this endpoint."
);
return route.abort();
});
}Motivation
This will provide more flexibility for test projects to limit the scope of tests based on certain conditions.
Note: I eventually worked around this by calling page.close({ reason }) to achieve the same end result, but I think test.abort() would be better for discoverability and semantics.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels