Repository navigation
fix: destructured test members and a framework version in a nested package - #71
Merged
Merged
Conversation
`const { beforeEach } = test` made every call through `beforeEach` read as
`test(...)`, as the alias lookup took the whole value the variable was
destructured from. Payload's e2e files do this: their hooks became tests
without a body, so whole files were reported as not loaded, and their
describes became single tests that hid the tests inside.
Playwright binds every member of `test`, so all of them work destructured.
In Vitest, `each`, `for`, `skipIf`, `runIf` and `extend` read `this` and
throw when destructured (checked on Vitest 3.2.4, 4.1.12 and 5.0.5); their
calls are never read through a variable, so they need no special case.
Chose: read the member from the destructuring pattern in alias(); over
binding destructured names in the bindings classes, which only know names
bound to Playwright or Vitest itself and not to local aliases.
Storybook declares Vitest only in `code/package.json` and locks it in `code/yarn.lock`; the root and the folders above it have nothing. The scan gave a null version, applied Vitest 5's rules, and refused a file that calls `vi.mock` in a block, though Storybook ran Vitest 3.2.4. When the root and above have no version, the shallowest package.json below the root that declares the framework and holds scanned files is read the same way, from its folder up: installed copy, lockfile, then the declaration. The files are found before the version now, which needs no version to find them. Chose: one version per scan from the shallowest declaring package that holds scanned files; over a version per config or test file, which would be exact for monorepos that mix versions but needs a new field in the output format (TI-56).
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.
What changed
Two false
notLoadedresults found while scanning a year of public projects with 0.6.1. Each fix has a test that failed first.Names destructured from a test object (Playwright and Vitest).
const { describe, beforeEach } = testmade every such name read astestitself:beforeEach(...)became a test without a body (test-without-body, every test of the filenotLoaded), anddescribe(...)became one test that hid the tests inside it. Each name is now read as its member, also nested (const { describe: { serial } } = test) and through the rest of an object. Checked against the runners: Playwright 1.64.1 binds every member oftest; in Vitest 3.2, 4.1 and 5.0, hooks,describeand the modifiers work destructured, whileeach,for,skipIf,runIfandextendreadthisand throw, and their calls aren't read.Framework version in a nested package. When the root and the folders above it have no version, the scan now reads the shallowest
package.jsonbelow the root that declares the framework and holds scanned files, with its lockfile or installed copy first. Storybook declares Vitest only incode/package.json, so the version wasnull, Vitest 5's rules applied, and a file withvi.mockin a block was refused, though Storybook ran Vitest 3.2.4.Rescans, 0.6.1 against this branch:
notLoadednotLoadednull, 3476 tests, 71notLoadednotLoadedPayload's jump comes from 73 spec files that destructure
describefromtest. Storybook's 9 fewer tests are incode/presets/react-webpack, which no project of itsvitest.workspace.tsruns; Vitest 3 reads that file, Vitest 4 dropped it.Left for later: a version per config for monorepos that mix versions (needs a new output field), and reporting the Vitest members that throw when destructured.
Checklist
npm run coveragereports 100%.npm run changeset), or the change does not affect them.