Skip to content

fix(vitest): make argosScreenshot and auto-naming work on Vitest 4.0 - #390

Merged
gregberge merged 1 commit into
mainfrom
claude/focused-lovelace-9a04fd
Oct 4, 2026
Merged

gregberge merged 1 commit into
mainfrom
claude/focused-lovelace-9a04fd

Conversation

@gregberge

Copy link
Copy Markdown
Member

Description

What

  • On Vitest 4.0, which has no 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 the vitest/suite import. It works the same in Node and in the browser, and Vitest 4.0's own page.screenshot() reads the same field. Vitest ≥ 4.1 still goes through TestRunner.getCurrentTest().
  • When a task has no fullName (Vitest 4.0.0 to 4.0.13), automatic names rebuild it from the title path, the way Vitest's own getFullName() did before. The result is the same name fullName gives on later versions, so upgrading Vitest doesn't rename screenshots.
  • CI: e2e-vitest-compat now runs on vitest-version: ["4.0.0", "4"]. 4.0.0 is the oldest supported release and runs both fallbacks; 4 is the latest 4.x, as before. The e2e-compat build 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 with TypeError: 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 raw import("vitest/suite"). Node mode was unaffected, since Node resolves the specifier itself.

Vitest added task fullName in 4.0.14, so argosScreenshot() and argosSnapshot() without a name also threw Cannot 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 has TestRunner and fullName.

Type of changes

Bug fix (bug label).

Checklist

  • I have read the CONTRIBUTING doc (there is no CONTRIBUTING doc in this repo)
  • The commits message follows the Conventional Commits' policy
  • Lint and unit tests pass locally
  • I have added tests if needed

Optional checks:

  • My changes requires a change to the documentation
  • I have updated the documentation accordingly

Further comments

Testing

  • Repo e2e suite (browser), downgraded the way CI does it: on Vitest 4.0.0, the previous code fails 13 of 20 tests with the vitest/suite error; this branch passes 20/20. It also passes 20/20 on 4.0.18 and 4.1.11.
  • Vitest 5.0.2 (workspace): unit and e2e pass, 69/69.
  • Standalone project with the packed build: the reported repro (argosScreenshot("hello") on a button) and an auto-named screenshot, plus Node tests: auto-naming inside nested describes, a beforeEach snapshot attributed to its test, and no test during beforeAll. 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).
  • Node pools: forks, threads and vmThreads, on 4.0.18, 4.1.11 and 5.0.2.
  • New unit test: covers the rebuilt fullName, comparing it with the real one. It fails without the fallback.
  • tsc, eslint and prettier pass for the package.

For reviewers

  • __vitest_worker__ is internal to Vitest. It is only read when TestRunner is missing, which means Vitest 4.0.x, a release line that no longer changes.
  • The compat check is renamed from 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.
  • The 4.0.0 run uploads as a new Argos build, argos-vitest4.0.0-e2e-node-lts/*-ubuntu-latest, which has no baseline until it runs on main. The 4 run keeps argos-vitest4-e2e-node-lts/*-ubuntu-latest.
  • CI on 4.0.0 covers browser mode only, like the compat job did for 4.x before. Vitest 4.0.0 can't run any Node-mode test with the workspace's Vite 7.3.6 (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.
  • feat(vitest): report screenshots of Storybook stories as Storybook #389 also changes test-context.ts. Whichever lands second: in loadGetCurrentTest(), the fallback becomes return 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

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>
@gregberge gregberge added the bug Something isn't working label Oct 4, 2026
@vercel

vercel Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
argos-js-sdk-reference Ready Ready Preview Oct 4, 2026 7:42am UTC

Request Review

@gregberge
gregberge merged commit ad112ad into main Oct 4, 2026
79 checks passed
@gregberge
gregberge deleted the claude/focused-lovelace-9a04fd branch October 4, 2026 07:58

This branch was successfully deployed

1 active deployment
Preview — 57255a94 Deployed Oct 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant