From 2211fd2b69b1c9b7616ef74e91d0bf5b9fadec4d Mon Sep 17 00:00:00 2001 From: Jonas Aschenbrenner Date: Thu, 7 Nov 2024 09:45:45 +0100 Subject: [PATCH] Docs: Vitest: Support for import aliases when using TypeScript (#72430) Related to https://github.com/vercel/next.js/discussions/72424. I wasn't able to test if the added "Terminal" switcher works, because I don't know how to run the docs locally. --------- Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com> --- .../08-testing/01-vitest.mdx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/01-app/02-building-your-application/08-testing/01-vitest.mdx b/docs/01-app/02-building-your-application/08-testing/01-vitest.mdx index df955c8b250c7..4c1ae50441a65 100644 --- a/docs/01-app/02-building-your-application/08-testing/01-vitest.mdx +++ b/docs/01-app/02-building-your-application/08-testing/01-vitest.mdx @@ -20,24 +20,22 @@ npx create-next-app@latest --example with-vitest with-vitest-app To manually set up Vitest, install `vitest` and the following packages as dev dependencies: -```bash filename="Terminal" +```bash filename="Terminal" switcher +# Using TypeScript +npm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths +# Using JavaScript npm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom -# or -yarn add -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom -# or -pnpm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom -# or -bun add -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom ``` -Create a `vitest.config.ts|js` file in the root of your project, and add the following options: +Create a `vitest.config.mts|js` file in the root of your project, and add the following options: -```ts filename="vitest.config.ts" switcher +```ts filename="vitest.config.mts" switcher import { defineConfig } from 'vitest/config' import react from '@vitejs/plugin-react' +import tsconfigPaths from 'vite-tsconfig-paths' export default defineConfig({ - plugins: [react()], + plugins: [tsconfigPaths(), react()], test: { environment: 'jsdom', },