Repository navigation
fix(vitest): make argosScreenshot and auto-naming work on Vitest 4.0 - #390
Merged
Merged
Conversation
On Vitest 4.0.x in browser mode, every argosScreenshot() call rejected with "Failed to resolve module specifier 'vitest/suite'". Without `TestRunner`, the SDK imported `vitest/suite` through a @vite-ignore'd dynamic import, and Vite leaves that bare specifier unresolved for the browser. It now reads the running test from Vitest's worker state (`__vitest_worker__.current`), where Vitest 4.0's own page.screenshot() reads it, in Node and in the browser alike. Tasks of Vitest 4.0.0 to 4.0.13 also have no `fullName`, so automatic names threw "Cannot read properties of undefined (reading 'startsWith')" in Node and in the browser. The name is rebuilt from the title path there, which gives the same name as `fullName` on later versions. CI only tested the latest 4.x, which has both. The compat job now also runs the e2e suite on Vitest 4.0.0, the oldest supported release, under its own build name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
3 of 6 tasks
This branch was successfully deployed
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.
Description
What
TestRunner,getCurrentTest()now reads the running test from Vitest's worker state (globalThis.__vitest_worker__.current) and keeps it only when it is a test. This replaces thevitest/suiteimport. It works the same in Node and in the browser, and Vitest 4.0's ownpage.screenshot()reads the same field. Vitest ≥ 4.1 still goes throughTestRunner.getCurrentTest().fullName(Vitest 4.0.0 to 4.0.13), automatic names rebuild it from the title path, the way Vitest's owngetFullName()did before. The result is the same namefullNamegives on later versions, so upgrading Vitest doesn't rename screenshots.e2e-vitest-compatnow runs onvitest-version: ["4.0.0", "4"]. 4.0.0 is the oldest supported release and runs both fallbacks;4is the latest 4.x, as before. Thee2e-compatbuild name now includes$VITEST_VERSION, which is added to the turbo task's env.Why
On Vitest 4.0.x in browser mode, every
argosScreenshot()call rejected withTypeError: Failed to resolve module specifier 'vitest/suite'. The specifier was held in a variable behind@vite-ignore, because written inline it fails Vite's dependency optimizer on Vitest 5, where that export is gone. But Vite does not rewrite bare specifiers in ignored dynamic imports, so the browser got a rawimport("vitest/suite"). Node mode was unaffected, since Node resolves the specifier itself.Vitest added task
fullNamein 4.0.14, soargosScreenshot()andargosSnapshot()without a name also threwCannot read properties of undefined (reading 'startsWith')on 4.0.0 to 4.0.13, in Node and in the browser.CI missed both: the compat job installed
vitest@^4, which resolves to 4.1.x, and 4.1.x hasTestRunnerandfullName.Type of changes
Bug fix (
buglabel).Checklist
Optional checks:
Further comments
Testing
vitest/suiteerror; this branch passes 20/20. It also passes 20/20 on 4.0.18 and 4.1.11.argosScreenshot("hello")on a button) and an auto-named screenshot, plus Node tests: auto-naming inside nesteddescribes, abeforeEachsnapshot attributed to its test, and no test duringbeforeAll. 5/5 on 4.0.0 (Vite 7.1.11), 4.0.18 (Vite 7.3.6), 4.1.11 and 5.0.3 (Vite 8.3.2). The published 0.7.1 fails on 4.0.0 (browser and Node) and on 4.0.18 (browser).fullName, comparing it with the real one. It fails without the fallback.tsc,eslintandprettierpass for the package.For reviewers
__vitest_worker__is internal to Vitest. It is only read whenTestRunneris missing, which means Vitest 4.0.x, a release line that no longer changes.e2e-vitest-compat (lts/*, ubuntu-latest)to… (lts/*, ubuntu-latest, 4.0.0)and… (lts/*, ubuntu-latest, 4). If the old name is a required check, branch protection needs updating.argos-vitest4.0.0-e2e-node-lts/*-ubuntu-latest, which has no baseline until it runs on main. The4run keepsargos-vitest4-e2e-node-lts/*-ubuntu-latest.Unknown method: getBuiltins), a Vitest/Vite mismatch unrelated to the SDK. Node mode on 4.0.0 was checked locally with Vite 7.1.11.test-context.ts. Whichever lands second: inloadGetCurrentTest(), the fallback becomesreturn getCurrentTestFromWorkerState;. The story recorder's.catch(() => null)still works, but its comment about Vitest 4.0 browser mode no longer applies.🤖 Generated with Claude Code