-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(kit): add TypeScript path alias support for test files #33672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(kit): add TypeScript path alias support for test files #33672
Conversation
|
|
WalkthroughAdds guidance to the docs describing TypeScript support for tests placed under Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (2)📓 Common learnings📚 Learning: 2024-11-11T12:34:22.648ZApplied to files:
🪛 LanguageTooldocs/1.getting-started/17.testing.md[style] ~156-~156: Would you like to use the Oxford spelling “recognize”? The spelling ‘recognise’ is also correct. (OXFORD_SPELLING_Z_NOT_S) [uncategorized] ~157-~157: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION) [uncategorized] ~159-~159: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION) [uncategorized] ~180-~180: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION) [uncategorized] ~182-~182: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
🔇 Additional comments (2)
Tip 📝 Customizable high-level summaries are now available!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example:
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. Comment |
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docs/1.getting-started/17.testing.md(1 hunks)packages/kit/src/template.ts(1 hunks)packages/kit/test/generate-types.spec.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/kit/src/template.tspackages/kit/test/generate-types.spec.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Write unit tests for core functionality using
vitest
Files:
packages/kit/test/generate-types.spec.ts
🧠 Learnings (8)
📓 Common learnings
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : Write unit tests for core functionality using `vitest`
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/e2e/**/*.{ts,js} : Write end-to-end tests using Playwright and `nuxt/test-utils`
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : Write unit tests for core functionality using `vitest`
Applied to files:
docs/1.getting-started/17.testing.mdpackages/kit/src/template.tspackages/kit/test/generate-types.spec.ts
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/e2e/**/*.{ts,js} : Write end-to-end tests using Playwright and `nuxt/test-utils`
Applied to files:
docs/1.getting-started/17.testing.mdpackages/kit/src/template.tspackages/kit/test/generate-types.spec.ts
📚 Learning: 2024-11-11T12:34:22.648Z
Learnt from: Tofandel
Repo: nuxt/nuxt PR: 0
File: :0-0
Timestamp: 2024-11-11T12:34:22.648Z
Learning: Ensure that AI-generated summaries accurately reflect the key changes in the PR, focusing on notable changes such as the removal of unused imports and variables starting with underscores.
Applied to files:
docs/1.getting-started/17.testing.md
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/*.{ts,tsx} : Follow standard TypeScript conventions and best practices
Applied to files:
docs/1.getting-started/17.testing.md
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
Repo: nuxt/nuxt PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/*.vue : Use `<script setup lang="ts">` and the composition API when creating Vue components
Applied to files:
docs/1.getting-started/17.testing.md
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Applied to files:
packages/kit/src/template.tspackages/kit/test/generate-types.spec.ts
📚 Learning: 2024-11-28T21:22:40.496Z
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 29661
File: packages/kit/src/template.ts:227-229
Timestamp: 2024-11-28T21:22:40.496Z
Learning: In `packages/kit/src/template.ts`, when updating the `EXTENSION_RE` regular expression for TypeScript configuration, avoid using patterns like `(\.\w+)+$` as they can result in catastrophic backtracking.
Applied to files:
packages/kit/src/template.tspackages/kit/test/generate-types.spec.ts
🪛 GitHub Actions: docs
docs/1.getting-started/17.testing.md
[error] 1-1: Vitest environment error: Network error: Connection reset by server.
🪛 LanguageTool
docs/1.getting-started/17.testing.md
[uncategorized] ~157-~157: Loose punctuation mark.
Context: ...iases like ~/, @/, and #imports. ::important This provides **TypeScript ty...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~159-~159: Loose punctuation mark.
Context: ... nuxt environment as described above. :: **Example - Unit test with path alias...
(UNLIKELY_OPENING_PUNCTUATION)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: codeql (javascript-typescript)
- GitHub Check: build
- GitHub Check: code
🔇 Additional comments (2)
packages/kit/test/generate-types.spec.ts (1)
151-152: LGTM!The test expectations correctly validate that
resolveLayerPathsnow includestest/**/*andtests/**/*patterns in the Nuxt-specific layer paths.packages/kit/src/template.ts (1)
183-184: LGTM!The implementation correctly adds
test/**/*andtests/**/*patterns to the Nuxt layer paths, enabling TypeScript path alias resolution for test files. The use ofrelativeRootDirappropriately targets test directories at the project root.
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #33672 will not alter performanceComparing Summary
|
Co-authored-by: Daniel Roe <[email protected]>
Co-authored-by: Daniel Roe <[email protected]>
|
I will rework the documentation to make it a bit more clearer, this evening. |
|
What if we could use vitest as the source of truth here? If someone wants to include or exclude files within their vitest projects configuration, they have to add or exclude the paths in Perhaps we could try resolving the vitest config and include/exclude all paths for projects with |
|
@OrbisK I think that would be great: I think it could be overlapping strategies:
|
🔗 Linked issue
Fixes: #33593
Description
Test files in
test/andtests/directories now automatically have TypeScript path alias support(~/, @/, #imports)without requiring manual configuration.Previously, developers had to use relative paths or manually configure
typescript.tsConfig.includein theirnuxt.config.tsto use path aliases in test files.Changes
Code Changes
packages/kit/src/template.ts: Addedtest/**/*andtests/**/*to the default TypeScript include patterns inresolveLayerPaths()Documentation
Benefits