-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathjest.config.js
More file actions
85 lines (75 loc) · 2.18 KB
/
jest.config.js
File metadata and controls
85 lines (75 loc) · 2.18 KB
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
const jestPuppeteerConfig = require('./jest-puppeteer.config.js')
// Detect when browser has been launched headless
const { headless = true } = jestPuppeteerConfig.launch
/**
* Jest project config defaults
*
* @type {Config}
*/
const config = {
cacheDirectory: '<rootDir>/.cache/jest',
clearMocks: true,
coveragePathIgnorePatterns: ['fixtures.mjs', 'macro-options.mjs'],
// Enable Babel transforms until Jest supports ESM and `import()`
// See: https://jestjs.io/docs/ecmascript-modules
transform: {
'^.+\\.(js|mjs)$': ['babel-jest', { rootMode: 'upward' }]
},
// Enable Babel transforms for ESM-only node_modules
// See: https://jestjs.io/docs/ecmascript-modules
transformIgnorePatterns: [`<rootDir>/node_modules/(?!${['slug'].join('|')}/)`]
}
/**
* Jest config
*
* @type {Config}
*/
module.exports = {
collectCoverageFrom: [
'<rootDir>/packages/*/src/**/*.{js,mjs}',
'!<rootDir>/packages/*/src/**/*.test.{js,mjs}'
],
// Reduce CPU usage during project test runs
maxWorkers: headless
? '50%' // Matches Jest default (50%) via `--watch`
: 1, // Use only 1x browser window using `HEADLESS=false`
projects: [
{
...config,
displayName: 'JavaScript unit tests',
testEnvironment: 'node',
testMatch: ['<rootDir>/**/*.unit.test.{js,mjs}']
},
{
...config,
displayName: 'JavaScript behaviour tests',
preset: '@nhsuk/frontend-helpers/jest/environment/jsdom',
testMatch: ['<rootDir>/**/*.jsdom.test.{js,mjs}']
},
{
...config,
displayName: 'JavaScript component tests',
preset: '@nhsuk/frontend-helpers/jest/environment/puppeteer',
testMatch: [
'<rootDir>/**/*.puppeteer.test.{js,mjs}',
// Exclude accessibility tests
'!**/accessibility.puppeteer.test.mjs'
]
},
{
...config,
displayName: 'Accessibility tests',
preset: '@nhsuk/frontend-helpers/jest/environment/puppeteer',
testMatch: ['<rootDir>/**/accessibility.puppeteer.test.mjs']
}
],
// Enable GitHub Actions reporter UI
reporters: [
'default',
'jest-puppeteer-istanbul/lib/reporter',
'github-actions'
]
}
/**
* @import { Config } from 'jest'
*/