Skip to content

Conversation

@Flo0806
Copy link
Collaborator

@Flo0806 Flo0806 commented Nov 6, 2025

🔗 Linked issue

Fixes: #33593

Description

Test files in test/ and tests/ 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.include in their nuxt.config.ts to use path aliases in test files.

Changes

Code Changes

  • packages/kit/src/template.ts: Added test/**/* and tests/**/* to the default TypeScript include patterns in resolveLayerPaths()

Documentation

  • docs/getting-started/testing.md: Added new section explaining:
  • TypeScript path alias support in test files
  • Difference between unit tests (TypeScript only) and Nuxt tests (with runtime)
  • How to add custom test directories

Benefits

  • ✅ Works out of the box - no configuration needed
  • ✅ Supports both test/ and tests/ conventions
  • ✅ Includes test helpers, fixtures, and utilities (not just .test.ts files)
  • ✅ Clear documentation about unit vs integration testing

@Flo0806 Flo0806 requested a review from danielroe as a code owner November 6, 2025 20:36
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

Walkthrough

Adds guidance to the docs describing TypeScript support for tests placed under test/nuxt/ and tests/nuxt/ (the guidance is duplicated in two doc locations). Updates packages/kit/src/template.ts to include join(relativeRootDir, "test/nuxt/**/*") and join(relativeRootDir, "tests/nuxt/**/*") among the Nuxt target layer path globs. Updates packages/kit/test/generate-types.spec.ts expected Nuxt path array to include the two new glob patterns. No public API signatures or runtime behaviour are changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the two new globs are added only to the Nuxt target path list and correctly use relativeRootDir.
  • Confirm generate-types.spec.ts expectations match the actual ordering/format of the Nuxt paths.
  • Review the duplicated documentation block and consider consolidating or clarifying that the described behaviour is about TypeScript type context (not runtime).

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change—adding TypeScript path alias support for test files, which is the primary objective.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, solution, code changes, and documentation updates.
Linked Issues check ✅ Passed The changes address the core requirement from #33593: enabling TypeScript path aliases in test files without manual configuration by adding test directories to default includes.
Out of Scope Changes check ✅ Passed All changes directly support the objective of enabling TypeScript path aliases in test files; no out-of-scope modifications detected.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 577d902 and 338c5d4.

📒 Files selected for processing (1)
  • docs/1.getting-started/17.testing.md (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
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.
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.
📚 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
🪛 LanguageTool
docs/1.getting-started/17.testing.md

[style] ~156-~156: Would you like to use the Oxford spelling “recognize”? The spelling ‘recognise’ is also correct.
Context: ...oject-references). That means they will recognise Nuxt aliases (like ~/, @/, `#import...

(OXFORD_SPELLING_Z_NOT_S)


[uncategorized] ~157-~157: Loose punctuation mark.
Context: ...to-imports that work in your Nuxt app. ::tip This matches the recommended struct...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~159-~159: Loose punctuation mark.
Context: ...unit/` can be added manually if needed. :: ##### Adding other test directories ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~180-~180: Loose punctuation mark.
Context: ...ext/**/*', ], }, }, }) ``` ::important Unit tests should not depend ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~182-~182: Loose punctuation mark.
Context: ...pers`), not for Nuxt-specific features. :: #### Running Tests With the project ...

(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)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite-env-api, default, manifest-on, json, lts/-1)
  • GitHub Check: test-benchmark
  • GitHub Check: release-pkg-pr-new
  • GitHub Check: test-size
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: code
🔇 Additional comments (2)
docs/1.getting-started/17.testing.md (2)

154-184: Clarify the claim of duplicated guidance in the AI summary.

The AI-generated summary states the TypeScript Support guidance is "duplicated in a second location, resulting in two identical blocks", but only one "TypeScript Support in Tests" section appears in the complete file provided (lines 154–184). Please verify whether the duplication exists elsewhere in the PR or if this is a summary inaccuracy.


156-183: Documentation content is clear and well-structured.

The new TypeScript Support section clearly explains the automatic inclusion of test/nuxt/ and tests/nuxt/ directories in the Nuxt app TypeScript context, provides a practical example for adding custom test directories, and appropriately cautions against depending on Nuxt runtime features in unit tests. The configuration example is accurate, and the distinction between unit and Nuxt tests is pedagogically sound.

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.

  • Provide custom instructions to shape the summary (bullet lists, tables, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example:

"Create a concise high-level summary as a bullet-point list. Then include a Markdown table showing lines added and removed by each contributing author."


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

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8539fe4 and 5277fb9.

📒 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.ts
  • packages/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.md
  • packages/kit/src/template.ts
  • packages/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.md
  • packages/kit/src/template.ts
  • packages/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.ts
  • packages/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.ts
  • packages/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 resolveLayerPaths now includes test/**/* and tests/**/* patterns in the Nuxt-specific layer paths.

packages/kit/src/template.ts (1)

183-184: LGTM!

The implementation correctly adds test/**/* and tests/**/* patterns to the Nuxt layer paths, enabling TypeScript path alias resolution for test files. The use of relativeRootDir appropriately targets test directories at the project root.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 6, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33672

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@33672

nuxt

npm i https://pkg.pr.new/nuxt@33672

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33672

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33672

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33672

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33672

commit: 338c5d4

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 6, 2025

CodSpeed Performance Report

Merging #33672 will not alter performance

Comparing Flo0806:fix/typescript-aliases-in-test-files (338c5d4) with main (5bf66d4)

Summary

✅ 10 untouched

@Flo0806
Copy link
Collaborator Author

Flo0806 commented Nov 7, 2025

I will rework the documentation to make it a bit more clearer, this evening.

@OrbisK
Copy link
Member

OrbisK commented Nov 8, 2025

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 nuxt.config.ts/tsconfig.json and vitest.config.ts.

Perhaps we could try resolving the vitest config and include/exclude all paths for projects with environment: 'nuxt'. This way, we will always be in sync with vitest, with vitest as source of truth.

@danielroe
Copy link
Member

@OrbisK I think that would be great:

I think it could be overlapping strategies:

  1. include test/nuxt/** by default
  2. infobox in docs explains how to 'add' files to the app context
  3. @nuxt/test-utils/module adds whatever paths are configured with nuxt environment to the generated tsconfig.app.json

@danielroe danielroe merged commit ef4faf2 into nuxt:main Nov 17, 2025
99 of 102 checks passed
@github-actions github-actions bot mentioned this pull request Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nuxt 4 - TS Issue 'cannot find module X' in test files

3 participants