2021-11-11 01:16:15 +01:00
|
|
|
const nextJest = require('next/jest')
|
2021-11-08 17:35:04 +01:00
|
|
|
|
2021-11-11 01:16:15 +01:00
|
|
|
const createJestConfig = nextJest()
|
|
|
|
|
|
|
|
// Any custom config you want to pass to Jest
|
2022-09-27 22:37:28 +02:00
|
|
|
/** @type {import('jest').Config} */
|
2021-11-11 01:16:15 +01:00
|
|
|
const customJestConfig = {
|
2023-09-05 14:55:10 +02:00
|
|
|
testMatch: ['**/*.test.js', '**/*.test.ts', '**/*.test.jsx', '**/*.test.tsx'],
|
2021-09-13 14:36:25 +02:00
|
|
|
setupFilesAfterEnv: ['<rootDir>/jest-setup-after-env.ts'],
|
2018-10-12 15:32:17 +02:00
|
|
|
verbose: true,
|
|
|
|
rootDir: 'test',
|
2023-03-02 00:31:45 +01:00
|
|
|
roots: [
|
|
|
|
'<rootDir>',
|
|
|
|
'<rootDir>/../packages/next/src/',
|
|
|
|
'<rootDir>/../packages/font/src/',
|
|
|
|
],
|
2023-06-07 00:37:05 +02:00
|
|
|
modulePathIgnorePatterns: ['/\\.next/'],
|
2018-10-12 15:32:17 +02:00
|
|
|
modulePaths: ['<rootDir>/lib'],
|
2021-12-21 19:52:07 +01:00
|
|
|
transformIgnorePatterns: ['/next[/\\\\]dist/', '/\\.next/'],
|
2022-09-27 22:37:28 +02:00
|
|
|
globals: {
|
|
|
|
AbortSignal: global.AbortSignal,
|
|
|
|
},
|
2022-11-03 19:12:46 +01:00
|
|
|
moduleNameMapper: {
|
|
|
|
'@next/font/(.*)': '@next/font/$1',
|
|
|
|
},
|
2018-10-12 15:32:17 +02:00
|
|
|
}
|
2021-11-11 01:16:15 +01:00
|
|
|
|
2023-06-12 19:14:13 +02:00
|
|
|
// Check if the environment variable is set to enable test trace,
|
|
|
|
// Insert a reporter to generate a junit report to upload.
|
|
|
|
// This won't count for the retry to avoid duplicated test being reported twice
|
|
|
|
// - which means our test trace will report test results for the flaky test as failed without retry.
|
|
|
|
const shouldEnableTestTrace =
|
2023-08-14 21:58:56 +02:00
|
|
|
process.env.DATADOG_API_KEY && process.env.DATADOG_TRACE_NEXTJS_TEST
|
2023-06-12 19:14:13 +02:00
|
|
|
|
|
|
|
if (shouldEnableTestTrace) {
|
|
|
|
if (!customJestConfig.reporters) {
|
|
|
|
customJestConfig.reporters = ['default']
|
|
|
|
}
|
|
|
|
|
2023-09-06 19:46:54 +02:00
|
|
|
const outputDirectory = process.env.TURBOPACK
|
|
|
|
? '<rootDir>/turbopack-test-junit-report'
|
|
|
|
: '<rootDir>/test-junit-report'
|
2023-08-09 07:48:54 +02:00
|
|
|
|
2023-06-12 19:14:13 +02:00
|
|
|
customJestConfig.reporters.push([
|
|
|
|
'jest-junit',
|
|
|
|
{
|
|
|
|
outputDirectory,
|
|
|
|
reportTestSuiteErrors: 'true',
|
|
|
|
uniqueOutputName: 'true',
|
|
|
|
outputName: 'nextjs-test-junit',
|
|
|
|
},
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2021-11-11 01:16:15 +01:00
|
|
|
// createJestConfig is exported in this way to ensure that next/jest can load the Next.js config which is async
|
|
|
|
module.exports = createJestConfig(customJestConfig)
|