fix(vitest)!: resolve reportsDirectory against workspace root#34720
fix(vitest)!: resolve reportsDirectory against workspace root#34720
Conversation
When reportsDirectory is set with {workspaceRoot} token in nx.json
targetDefaults, Nx's resolveNxTokensInOptions strips the token and
produces a workspace-root-relative path. The vitest executor then
passed this path directly to vitest, which resolved it relative to
the project root, causing coverage output to land in the wrong
location (e.g. apps/my-app/coverage/apps/my-app/ instead of
coverage/apps/my-app/).
This fix resolves non-absolute reportsDirectory paths against the
workspace root before passing them to vitest, ensuring coverage
output goes to the intended location.
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 1b73565
☁️ Nx Cloud last updated this comment at |
The reportsDirectory option is now resolved relative to the workspace root
instead of the project root. This migration prepends {projectRoot}/ to
existing reportsDirectory values so the resolved path remains the same.
1d60b83 to
a820b13
Compare
| @@ -17,6 +17,11 @@ | |||
| }, | |||
| "description": "Create AI Instructions to help migrate users workspaces past breaking changes for Vitest 4.", | |||
| "implementation": "./src/migrations/update-22-1-0/create-ai-instructions-for-vitest-4" | |||
| }, | |||
| "update-22-6-0-prefix-reports-directory": { | |||
There was a problem hiding this comment.
Not a huge deal, but targeting the next beta (22.6.0-beta.10) would help anyone who already updated to beta.0. Mostly it's just us.
…rojectRoot}
Previously the migration checked if {projectRoot} appeared anywhere in
the path, which incorrectly skipped paths like coverage/{projectRoot}.
…paceRoot}
Paths starting with {workspaceRoot} already indicate the user intended
workspace-root-relative resolution, so they should not be prefixed with
{projectRoot}.
The generator was producing project-root-relative reportsDirectory paths (e.g., ../../coverage/libs/my-lib) but the executor now resolves these against the workspace root, causing coverage output to land outside the workspace. Remove the offsetFromRoot prefix so the generated path is workspace-root-relative (e.g., coverage/libs/my-lib). Also update the e2e test to use workspace-root-relative path.
There was a problem hiding this comment.
Nx Cloud is proposing a fix for your failed CI:
These changes fix the failing vue:test by updating the test snapshot to reflect the new workspace-root-relative behavior for reportsDirectory. The PR changed the vitest generator to produce paths like "coverage/my-lib" instead of "../coverage/my-lib", and this test needs to expect the new format.
Warning
❌ We could not verify this fix.
diff --git a/packages/vue/src/generators/library/library.spec.ts b/packages/vue/src/generators/library/library.spec.ts
index 9df5db693e..40d53d5450 100644
--- a/packages/vue/src/generators/library/library.spec.ts
+++ b/packages/vue/src/generators/library/library.spec.ts
@@ -586,7 +586,7 @@ module.exports = [
"{options.reportsDirectory}"
],
"options": {
- "reportsDirectory": "../coverage/my-lib"
+ "reportsDirectory": "coverage/my-lib"
}
}
}
🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
Or Apply changes locally with:
npx nx-cloud apply-locally juld-AVbR
Apply fix locally with your editor ↗ View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
…34766) ## Current Behavior The webpack legacy e2e test (`e2e-webpack:e2e-ci--src/webpack.legacy.test.ts`) fails with a snapshot mismatch because the `reportsDirectory` value changed from `../coverage/app3224373` to `coverage/app3224373`. ## Expected Behavior The snapshot should match the new `reportsDirectory` path format introduced by #34720. ## Related Issue(s) Fixes the e2e test breakage introduced by #34720 (`fix(vitest)!: resolve reportsDirectory against workspace root`).
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
When
reportsDirectoryis configured with{workspaceRoot}token innx.jsontargetDefaults:Coverage output lands in the wrong location. For example, with a project at
apps/my-app, coverage goes toapps/my-app/coverage/apps/my-app/instead of the intendedcoverage/apps/my-app/.Expected Behavior
Coverage output should be written to
<workspaceRoot>/coverage/apps/my-app/.Root Cause
Nx's
resolveNxTokensInOptionsstrips{workspaceRoot}/from option values and replaces{projectRoot}, producing a workspace-root-relative path (e.g.coverage/apps/my-app). The vitest executor then passed this directly to vitest, which resolved it relative to the project root — not the workspace root.Fix
Resolve non-absolute
reportsDirectorypaths against the workspace root before passing them to vitest, so vitest writes coverage to the correct location.Test Plan
resolveReportsDirectoryhelper