-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.ts
99 lines (90 loc) · 2.87 KB
/
jest.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import assert from 'node:assert';
import path from 'node:path';
import type {Config} from '@jest/types';
import {globSync} from 'glob';
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
import pkg from './package.json';
// This is a hack to get around the fact that no one seems to be maintaining the
// Jest types https://github.com/facebook/jest/issues/11640
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace NodeJS {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Global {}
}
}
const commonProjectConfig: Partial<Config.ProjectConfig> = {
clearMocks: true,
modulePathIgnorePatterns: ['.nx/'],
prettierPath: require.resolve('prettier-2'),
setupFilesAfterEnv: ['./jest.d/setup-files-after-env/faker.ts'],
testEnvironment: 'node',
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
transformIgnorePatterns: ['.*\\.mjs'],
};
const CI = !!process.env.CI;
const {workspaces} = pkg;
assert(
workspaces,
'This Jest config is intended only for Monorepos and cannot work without a `workspaces` field in package.json'
);
const config: Config.GlobalConfig = {
bail: 0,
collectCoverage: CI,
coverageDirectory: 'reports/coverage',
projects: [
// @ts-expect-error - types seem wrong
{
...commonProjectConfig,
displayName: 'Unit Tests',
testMatch: workspaces
.flatMap((ws) => globSync(ws))
.filter(
(packagePath) => !packagePath.split(path.sep).includes('examples')
)
.flatMap((packagePath) => [
`<rootDir>/${packagePath}/**/?(*.)+(test).?(m)[tj]s?(x)`,
]),
},
// @ts-expect-error - types seem wrong
{
...commonProjectConfig,
displayName: 'Examples',
testEnvironment: './jest.d/environments/example.ts',
testMatch: workspaces
.flatMap((ws) => globSync(ws))
.filter((packagePath) =>
packagePath.split(path.sep).includes('examples')
)
.filter(
(packagePath) =>
process.env.TEST_ENV === 'aws' || !packagePath.includes('aws-')
)
.flatMap((packagePath) => [
`<rootDir>/${packagePath}/**/?(*.)+(test).[tj]s?(x)`,
]),
},
],
// @ts-expect-error - types seem wrong
reporters: [
!CI && 'default',
CI && ['github-actions', {silent: false}],
CI && [
'jest-junit',
{
addFileAttribute: 'true', // Yep, it really needs to be a string
ancestorSeparator: ' › ',
classNameTemplate: '{classname}',
includeConsoleOutput: true,
outputDirectory: 'reports/junit',
outputName: `jest.xml`,
reportTestSuiteErrors: true,
titleTemplate: '{title}',
},
],
CI && 'summary',
].filter(Boolean),
testLocationInResults: true,
};
export default config;