rsnext/jest.config.js

59 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

const nextJest = require('next/jest')
const createJestConfig = nextJest()
// Any custom config you want to pass to Jest
feat(experimental): option to polyfill `fetch` using `undici` in Node.js <18 (#40318) This PR adds a new `experimental.enableUndici` option to let the developer switch from `next-fetch` to `undici` as the underlying polyfill for `fetch` in Node.js. In the current implementation, Next.js makes sure that `fetch` is always available by using `node-fetch`. However, we do not polyfill in Node.js 18+, since those versions come with their own `fetch` implementation already, built-in. Node.js 18+ uses `undici` under the hood, so letting the developer use `undici` earlier could make the migration easier later on. Eventually, we hope to be able to stop polyfilling `fetch` in an upcoming major version of Next.js, shipping less code. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have 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 - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Balázs Orbán <info@balazsorban.com> Co-authored-by: Sukka <isukkaw@gmail.com> Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: Steven <steven@ceriously.com>
2022-09-27 22:37:28 +02:00
/** @type {import('jest').Config} */
const customJestConfig = {
testMatch: ['**/*.test.js', '**/*.test.ts', '**/*.test.jsx', '**/*.test.tsx'],
setupFilesAfterEnv: ['<rootDir>/jest-setup-after-env.ts'],
verbose: true,
rootDir: 'test',
roots: [
'<rootDir>',
'<rootDir>/../packages/next/src/',
'<rootDir>/../packages/font/src/',
],
modulePathIgnorePatterns: ['/\\.next/'],
modulePaths: ['<rootDir>/lib'],
transformIgnorePatterns: ['/next[/\\\\]dist/', '/\\.next/'],
moduleNameMapper: {
'@next/font/(.*)': '@next/font/$1',
},
}
if (process.env.RECORD_REPLAY) {
customJestConfig.testRunner = '@replayio/jest/runner'
}
// Check if the environment variable is set to enable test report,
// Insert a reporter to generate a junit report to upload.
//
// This won't count retries to avoid tests being reported twice.
// Our test report will report test results for flaky tests as failed without retry.
const enableTestReport = !!process.env.NEXT_JUNIT_TEST_REPORT
if (enableTestReport) {
if (!customJestConfig.reporters) {
customJestConfig.reporters = ['default']
}
const outputDirectory = process.env.TURBOPACK
? '<rootDir>/turbopack-test-junit-report'
: '<rootDir>/test-junit-report'
customJestConfig.reporters.push([
'jest-junit',
{
outputDirectory,
reportTestSuiteErrors: 'true',
uniqueOutputName: 'true',
outputName: 'nextjs-test-junit',
addFileAttribute: 'true',
},
])
}
// createJestConfig is exported in this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)