@nuxt/docs-nightly 4.2.2-29390217.2579639 → 4.2.2-29390287.ffa14fe8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -151,6 +151,37 @@ test/
|
|
|
151
151
|
|
|
152
152
|
You can of course opt for any test structure, but keeping the Nuxt runtime environment separated from Nuxt end-to-end tests is important for test stability.
|
|
153
153
|
|
|
154
|
+
#### TypeScript Support in Tests
|
|
155
|
+
|
|
156
|
+
By default, test files in `test/nuxt/` and `tests/nuxt/` directories are included in the [Nuxt app TypeScript context](/docs/4.x/guide/concepts/typescript#how-nuxt-uses-project-references). That means they will recognise Nuxt aliases (like `~/`, `@/`, `#imports`) and TypeScript will be aware of auto-imports that work in your Nuxt app.
|
|
157
|
+
|
|
158
|
+
::tip
|
|
159
|
+
This matches the recommended structure where only tests that need the Nuxt runtime environment are placed in these directories. Unit tests in other directories like `test/unit/` can be added manually if needed.
|
|
160
|
+
::
|
|
161
|
+
|
|
162
|
+
##### Adding other test directories
|
|
163
|
+
|
|
164
|
+
If you have tests in other directories that you will be running in the Nuxt Vitest environment, you can include them in the Nuxt app TypeScript context by adding them to your configuration:
|
|
165
|
+
|
|
166
|
+
<!-- @case-police-ignore tsConfig -->
|
|
167
|
+
|
|
168
|
+
```ts [nuxt.config.ts]
|
|
169
|
+
export default defineNuxtConfig({
|
|
170
|
+
typescript: {
|
|
171
|
+
tsConfig: {
|
|
172
|
+
include: [
|
|
173
|
+
// this path is relative to the generated .nuxt/tsconfig.json
|
|
174
|
+
'../test/other-nuxt-context/**/*',
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
::important
|
|
182
|
+
Unit tests should not depend on Nuxt runtime features like auto-imports or composables. Only add TypeScript path alias support if your tests import from your source files (e.g., `~/utils/helpers`), not for Nuxt-specific features.
|
|
183
|
+
::
|
|
184
|
+
|
|
154
185
|
#### Running Tests
|
|
155
186
|
|
|
156
187
|
With the project setup, you can run different test suites:
|