-
Notifications
You must be signed in to change notification settings - Fork 11
/
jest.config.ts
85 lines (73 loc) · 3.04 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
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/en/configuration.html
*/
import type { Config } from '@jest/types'
import { glob } from 'glob'
import * as Path from 'path'
export async function getBrowserPathMapping(): Promise<{ [aliasNodeReference: string]: string }> {
return await new Promise<{ [aliasNodeReference: string]: string }>((resolve, reject) => {
glob('src/**/*.browser.ts', (err, browserSourceCodes) => {
if (err) reject(err)
browserSourceCodes = browserSourceCodes.map(match => Path.resolve(__dirname, match))
const codePathMapping: { [nodeFullPath: string]: string } = {}
browserSourceCodes.map(browserFullPath => {
const filePathArray = browserFullPath.split('.')
filePathArray.pop()
filePathArray.pop() //remove 'browser.ts' from '**/*.browser.ts'
const nodeFullPath = filePathArray.join('.')
const aliasNodeReference = `/${nodeFullPath.split('/').pop()}$` //keep the last bit of node file referencing e.g. '/file-source$'
codePathMapping[aliasNodeReference] = browserFullPath
})
resolve(codePathMapping)
})
})
}
export default async (): Promise<Config.InitialOptions> => {
return {
// Setup the prerequisites for the tests to run
globalSetup: './tests-setup.ts',
// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
// Custom sequencer that priorities running unit tests before integration tests
testSequencer: '<rootDir>/test-type-sequencer.js',
// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['/node_modules/'],
// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: ['node_modules'],
testTimeout: 180000,
// Run tests from one or more projects
projects: [
{
displayName: 'node:unit',
testEnvironment: 'node',
testRegex: 'test/unit/((?!\\.browser).)*\\.spec\\.ts',
},
{
displayName: 'dom:integration',
testRegex: 'test/integration/.*\\.browser\\.spec\\.ts',
moduleNameMapper: await getBrowserPathMapping(),
preset: 'jest-puppeteer',
},
{
displayName: 'node:fairos',
testEnvironment: 'node',
testRegex: 'test/integration/.*\\.fairos\\.spec\\.ts',
},
{
displayName: 'node:integration',
testEnvironment: 'node',
testRegex: 'test/integration/((?!\\.(browser|fairos)).)*\\.spec\\.ts',
},
{
displayName: 'node:migration',
testEnvironment: 'node',
testRegex: 'test/migration/((?!\\.(browser|fairos)).)*\\.spec\\.ts',
},
] as unknown[] as string[], // bad types
// The root directory that Jest should scan for tests and modules within
rootDir: 'test',
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: ['/node_modules/'],
}
}