-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.cjs
125 lines (107 loc) · 2.91 KB
/
jest.config.cjs
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* This file is managed by backtrack
*
* source: @backtrack/preset-jest
* namespace: jest
*
* DO NOT MODIFY
*/
'use strict';
const fs = require('fs');
const { Backtrack } = require('@backtrack/core');
const { configManager, pkg } = new Backtrack();
const packageId = '@backtrack/preset-jest';
/**
* https://jestjs.io/docs/en/configuration
*/
const jest = {
testEnvironment: 'node',
collectCoverage: false,
coveragePathIgnorePatterns: [
'<rootDir>/(.*/?)__sandbox__',
'<rootDir>/jest.*.(js|ts|mjs)',
],
testPathIgnorePatterns: ['<rootDir>/(.*/?)__sandbox__'],
snapshotSerializers: [
pkg.resolve(packageId, 'jest-serializer-path'),
pkg.resolve(packageId, 'jest-snapshot-serializer-function-name'),
],
/**
* Automatically reset mock state between every test.
* Equivalent to calling jest.resetAllMocks() between each test.
*
* Sane default with resetModules: true because mocks need to be inside beforeEach
* for them to work correctly
*
* https://jestjs.io/docs/en/configuration#resetmocks-boolean
*/
resetMocks: true,
/**
* The module registry for every test file will be reset before running each individual test.
* This is useful to isolate modules for every test so that local module state doesn't conflict between tests.
*
* https://jestjs.io/docs/en/configuration#resetmodules-boolean
*/
resetModules: true,
/**
* Equivalent to calling jest.restoreAllMocks() between each test.
*
* Resets jest.spyOn mocks only
*
* https://jestjs.io/docs/en/configuration#restoremocks-boolean
*/
restoreMocks: true,
};
function getFile(file) {
const jsFile = `${file}.js`;
const jsFileExists = fs.existsSync(jsFile);
if (jsFileExists) {
return jsFile;
}
const tsFile = `${file}.ts`;
const tsFileExists = fs.existsSync(tsFile);
if (tsFileExists) {
return tsFile;
}
return null;
}
/**
* globalSetup: ran once before all tests
*
* https://jestjs.io/docs/en/configuration#globalsetup-string
*/
const globalSetup = getFile('jest.global-setup');
if (globalSetup !== null) {
jest.globalSetup = `<rootDir>/${globalSetup}`;
}
/**
* setupFiles: ran once per test file before all tests
*
* https://jestjs.io/docs/en/configuration#setupfiles-array
*/
const setupFiles = getFile('jest.setup-test-file');
if (setupFiles !== null) {
jest.setupFiles = [`<rootDir>/${setupFiles}`];
}
/**
* setupFilesAfterEnv: ran before each test
*
* https://jestjs.io/docs/en/configuration#setupfilesafterenv-array
*/
const setupFilesAfterEnv = getFile('jest.setup-test');
if (setupFilesAfterEnv !== null) {
jest.setupFilesAfterEnv = [`<rootDir>/${setupFilesAfterEnv}`];
}
/**
* globalTeardown: ran once after all tests
*
* https://jestjs.io/docs/en/configuration#globalteardown-string
*/
const globalTeardown = getFile('jest.global-teardown');
if (globalTeardown !== null) {
jest.globalTeardown = `<rootDir>/${globalTeardown}`;
}
module.exports = configManager({
namespace: 'jest',
config: jest,
});