Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I would like to easily be able to invert a test. Look at the tests for what this actually does, or if you want a very AI generated description:
Feature request:
failssupport intestActorThe use case
Sometimes a scraper relies on a platform-side behaviour that can silently stop working (e.g. sending an undocumented API intent token that Facebook used to honour but no longer does). When that happens, a test that was asserting correct behaviour starts failing. The desired response is:
The current workaround is to manually invert every assertion with
.not, add a prose comment explaining the inversion, and rename the test with a warning in the title. That's fragile and easy to misread.What Vitest already provides
Vitest has
test.fails(). A test wrapped with it is expected to throw/fail. If it does fail, the suite reports it as passed. If it unexpectedly passes, the suite reports it as failed — exactly the sentinel behaviour we want. The symmetry withtest.skip()/test.todo()makes the intent immediately legible to any Vitest user.Why it can't be used today
testActoris the only public entry point for platform tests, and internally it calls:vitestTest.runIf(condition)returns a plain callable; you can't chain.fails()onto it. So consumers have no way to reachvitestTest.fails.runIf(shouldRun)(…)without bypassingtestActorentirely — which means losing the build-pinning logic, therun()helper, and theannotatecalls.Proposed change
Add an optional
failsflag toActorTestOptions(which already extends Vitest'sTestOptions, so the pattern is familiar):Then in
testActorinlib.ts, swap the test function based on the flag:vitestTest.failsis itself a fullTestAPIobject (same shape asvitestTest), so.runIf()is available on it and the rest of the body is unchanged.What the call-site then looks like
The assertions stay in their natural (positive) form, the inversion is expressed as a single structured option rather than spread across comments and
.notcalls, and any Vitest user reading the test immediately understands the intent.