-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Docs: Add App Router Testing Guides and update /examples #59268
Conversation
All broken links are now fixed, thank you! |
This looks really promising :) The explanation of how to replicate some (?) of what the Next compiler does for Jest is really useful. Would it be possible to add a section for people who want to switch to Vitest but are a bit worried about moving away from At a guess, I imagine it'd be very similar to the Jest config below, plus the mock files for images, CSS etc, but using the Vitest config keys rather than Jest's? module.exports = {
collectCoverage: true,
// on node 14.x coverage provider v8 offers good speed and more or less good report
coverageProvider: 'v8',
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**',
'!<rootDir>/out/**',
'!<rootDir>/.next/**',
'!<rootDir>/*.config.js',
'!<rootDir>/coverage/**',
],
moduleNameMapper: {
// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
// Handle CSS imports (without CSS modules)
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$/i': `<rootDir>/__mocks__/fileMock.js`,
// Handle module aliases
'^@/components/(.*)$': '<rootDir>/components/$1',
},
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
testEnvironment: 'jsdom',
transform: {
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
} |
- @types/testing-library__jest-dom is deprecated - The other packages are not used in demo tests
- include was updated to add '.next/types/**/*.ts' - plugins was updated to add { name: 'next' }
- Move 'server-only' into its own file/test (e.g. server-only shouldn't be in a server component) - Delete extra folders
@philwolstenholme thank you for the feedback. Good news! While updating the Vitest example, I didn't need to do a lot of configuration as Vitest handles most of it by default. E.g. Handling CSS imports, images, etc. |
Since this PR removed ESLint, we don't need the file: #36787
- fix route conflicts when running dev - separate 'server-only' into its own test
- Use TS - Add app router example
- Use TypeScript - Add E2E test for pages
This PR fixes a wrong link introduced in #59268 --------- Co-authored-by: JJ Kasper <[email protected]>
This PR updates the testing guides to use App Router and TypeScript, also updates
/examples
to showapp
andpages
examples.Overview
app
andpages
.async
components as currently none of the tools support it.app
andpages
./examples
: use TS, showapp
andpages
examples, match docs configCypress
async
componentsBlockers:
Option 'bundler' can only be used when 'module' is set to 'es2015' or later
. In tsconfig.json compilerOptions, Next.js uses "moduleResolution": "bundler", changing it to "node" fixes the issue but it can have repercussions.Playwright
Jest
async
components: Support for React Server Components testing-library/react-testing-library#1209Blockers:
Vitest
async
componentsOther