next.js
45e2c1e0 - Switch to ESM Jest config in docs (#42144)

Commit
3 years ago
Switch to ESM Jest config in docs (#42144) Thanks again for Next.js 13! Finding a bunch of new ways to improve things 🙌 Just a quick PR to switch the Jest configuration file with `next/jest` to ESM to eliminate another instance of CommonJS. ESM requires a `.js` extension on the import. An alternative would be to switch to a TypeScript config file (`jest.config.ts`) which would (I am guessing) not require this file extension (but still allow switching to an ESM-style `import` syntax). New version in the diff: ```js // jest.config.mjs import nextJest from 'next/jest.js' const createJestConfig = nextJest({ // Provide the path to your Next.js app to load next.config.js and .env files in your test environment dir: './', }) // Add any custom config to be passed to Jest /** @type {import('jest').Config} */ const config = { // Add more setup options before each test is run // setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], // if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work moduleDirectories: ['node_modules', '<rootDir>/'], testEnvironment: 'jest-environment-jsdom', } // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async export default createJestConfig(config) ``` ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [x] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Author
Parents
Loading