Skip to content

test(build): migrate error tests to vitest#7043

Open
43081j wants to merge 4 commits into
netlify:mainfrom
43081j:avagone-error-tests
Open

test(build): migrate error tests to vitest#7043
43081j wants to merge 4 commits into
netlify:mainfrom
43081j:avagone-error-tests

Conversation

@43081j
Copy link
Copy Markdown
Contributor

@43081j 43081j commented May 1, 2026

Migrates the error tests to vitest and alters the testing package such that Fixture is the ava-flavoured class (i.e. it imports ava). Temporarily, the package exports now declare fixture.js so non-ava consumers can import the base Fixture without importing ava.

The omit.js dependency causes CJS interop problems in vitest, so has been dropped and replaced with a basic Object.fromEntries map.

NOTE: If you'd rather we just go all-in and update Fixture directly, I can also do that. It means the diff will be pretty big because i'll have to update each Fixture(p) to Fixture(testFile, p) basically.

FYI i compared the snapshots using this script i threw together:
https://gist.github.com/43081j/e085304049ee734d7531dcb1855fa53f

they do match

@43081j 43081j requested a review from a team as a code owner May 1, 2026 13:24
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

@43081j has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 51 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6d04cf40-2bb6-4520-b6e6-c61259fc2cc9

📥 Commits

Reviewing files that changed from the base of the PR and between e84ee0b and 6c5c01c.

📒 Files selected for processing (2)
  • eslint.config.js
  • packages/build/tests/error/error.test.ts
📝 Walkthrough

Walkthrough

Adds a new Vitest test suite at packages/build/tests/error/error.test.ts covering many build-error scenarios, tracing-attribute mappings, and trusted-plugin severity checks. Removes legacy AVA test and its snapshots (packages/build/tests/error/tests.js and snapshots). Changes testing fixtures: Fixture constructor now requires an explicit test file path; a new AvaFixture subclass supplies AVA-specific behavior; testing package exports updated to expose fixture and normalize modules. Refactors cleanUserEnv in packages/config to filter READONLY_ENV directly and removes the unused omit.js dependency. No public API types were changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: migrating error tests from AVA to Vitest, which is the primary objective of this PR.
Description check ✅ Passed The description explains the migration rationale, addresses the dependency change (omit.js removal), mentions alternative approaches, and includes snapshot validation, but does not explicitly reference an issue number or follow the repository template structure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/build/tests/error/error.test.ts (1)

263-268: 💤 Low value

Consider using test.each for parameterized tests.

Vitest provides test.each for data-driven tests, which offers better IDE integration and clearer test reporting.

♻️ Optional refactor using test.each
-testMatrixAttributeTracing.forEach(({ description, input, expects }) => {
-  test(`Tracing attributes - ${description}`, async () => {
-    const attributes = buildErrorToTracingAttributes(input)
-    expect(attributes).toEqual(expects)
-  })
-})
+test.each(testMatrixAttributeTracing)(
+  'Tracing attributes - $description',
+  ({ input, expects }) => {
+    const attributes = buildErrorToTracingAttributes(input)
+    expect(attributes).toEqual(expects)
+  }
+)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/build/tests/error/error.test.ts` around lines 263 - 268, The test
uses a forEach loop over testMatrixAttributeTracing to generate parameterized
tests; replace it with Vitest's test.each to improve IDE integration and test
reporting. Update the block that iterates testMatrixAttributeTracing so it calls
test.each(testMatrixAttributeTracing) with a callback using the tuple/object
shape (description, input, expects) and inside assert
buildErrorToTracingAttributes(input) toEqual expects; keep the same symbols
testMatrixAttributeTracing and buildErrorToTracingAttributes so locating and
adapting the existing tests is straightforward.
packages/testing/package.json (1)

5-9: 💤 Low value

Subpath exports enable Vitest usage, but TypeScript consumers may lack type hints.

The exports map correctly enables direct imports like @netlify/testing/lib/fixture.js. However, TypeScript consumers using these subpath exports won't automatically resolve type declarations since there's no corresponding types field for each subpath.

If TypeScript support for subpath imports is needed:

♻️ Optional: Add types for subpath exports
   "exports": {
     ".": "./lib/index.js",
-    "./lib/fixture.js": "./lib/fixture.js",
-    "./lib/normalize.js": "./lib/normalize.js"
+    "./lib/fixture.js": {
+      "types": "./lib/fixture.d.ts",
+      "default": "./lib/fixture.js"
+    },
+    "./lib/normalize.js": {
+      "types": "./lib/normalize.d.ts",
+      "default": "./lib/normalize.js"
+    }
   },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/testing/package.json` around lines 5 - 9, The exports map exposes
subpaths like "./lib/fixture.js" and "./lib/normalize.js" but doesn’t provide
corresponding TypeScript declaration entries, so add type mappings for each
exported subpath (or a top-level "types" entry plus "typesVersions" if you need
path-specific resolution). Update package.json to include either per-subpath
"types" fields or a top-level "types" pointing to your bundled .d.ts (and/or add
a "typesVersions" map) so TypeScript consumers importing
"@netlify/testing/lib/fixture.js" will resolve declarations for
Fixture/normalize/index exports.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/build/tests/error/error.test.ts`:
- Around line 103-112: The TODO comment referencing "Ava v4" is stale after
migrating tests to Vitest; update the comment around the skipped "Early exit"
test (the block checking platform !== 'win32' and the test name 'Early exit'
that uses new Fixture(...).runWithBuild()) to reference Vitest instead of Ava,
re-evaluate whether the Windows-specific flakiness still occurs under Vitest,
and either adjust the skip logic or remove the outdated TODO so the comment
accurately describes the current test framework and next steps.

---

Nitpick comments:
In `@packages/build/tests/error/error.test.ts`:
- Around line 263-268: The test uses a forEach loop over
testMatrixAttributeTracing to generate parameterized tests; replace it with
Vitest's test.each to improve IDE integration and test reporting. Update the
block that iterates testMatrixAttributeTracing so it calls
test.each(testMatrixAttributeTracing) with a callback using the tuple/object
shape (description, input, expects) and inside assert
buildErrorToTracingAttributes(input) toEqual expects; keep the same symbols
testMatrixAttributeTracing and buildErrorToTracingAttributes so locating and
adapting the existing tests is straightforward.

In `@packages/testing/package.json`:
- Around line 5-9: The exports map exposes subpaths like "./lib/fixture.js" and
"./lib/normalize.js" but doesn’t provide corresponding TypeScript declaration
entries, so add type mappings for each exported subpath (or a top-level "types"
entry plus "typesVersions" if you need path-specific resolution). Update
package.json to include either per-subpath "types" fields or a top-level "types"
pointing to your bundled .d.ts (and/or add a "typesVersions" map) so TypeScript
consumers importing "@netlify/testing/lib/fixture.js" will resolve declarations
for Fixture/normalize/index exports.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6288e81a-ebc8-4ad3-a5f4-80cd15e27c75

📥 Commits

Reviewing files that changed from the base of the PR and between ed5ab4d and 41c3591.

⛔ Files ignored due to path filters (2)
  • packages/build/tests/error/__snapshots__/error.test.ts.snap is excluded by !**/*.snap
  • packages/build/tests/error/snapshots/tests.js.snap is excluded by !**/*.snap
📒 Files selected for processing (8)
  • packages/build/tests/error/error.test.ts
  • packages/build/tests/error/snapshots/tests.js.md
  • packages/build/tests/error/tests.js
  • packages/config/src/env/main.ts
  • packages/testing/package.json
  • packages/testing/src/fixture-ava.ts
  • packages/testing/src/fixture.ts
  • packages/testing/src/index.ts
💤 Files with no reviewable changes (2)
  • packages/build/tests/error/snapshots/tests.js.md
  • packages/build/tests/error/tests.js

Comment thread packages/build/tests/error/error.test.ts Outdated
Migrates the error tests to vitest and alters the `testing` package such that `Fixture` is the ava-flavoured class (i.e.
it imports `ava`). Temporarily, the package exports now declare `fixture.js` so non-ava consumers can import the base
`Fixture` without importing `ava`.

The `omit.js` dependency causes CJS interop problems in vitest, so has been dropped and replaced with a basic
`Object.fromEntries` map.
@43081j 43081j force-pushed the avagone-error-tests branch from 41c3591 to f6bf61a Compare May 1, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant