-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
.jest.config.js
72 lines (62 loc) · 2.42 KB
/
.jest.config.js
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
// @flow strict
// Please note: this file should be named `.jest.config.js` because this way
// we can prevent calling `yarn jest` directly. It wouldn't work with config
// name `jest.config.js` because this config is being loaded automatically.
require('@babel/register'); // to be able to use non-transpiled '@adeira/monorepo-utils' here
const fs = require('fs');
const path = require('path');
const { Workspaces } = require('@adeira/monorepo-utils');
const TESTS_GLOB = '__tests__/**/?(*.)+(spec|test).js';
// we have to set __DEV__ even to JS globals since it's not being transpiled in
// test environment but it's used even before Jest starts testing (when looking for workspaces)
global.__DEV__ = true;
// SEE: https://jestjs.io/docs/en/configuration.html
const commonProjectConfig = {
// runs before each test (after test framework is installed)
setupFilesAfterEnv: [path.join(__dirname, 'scripts/jest/setupTests.js')],
// set global __DEV__ since RN expects non-transpiled version in test environment
globals: {
__DEV__: true,
},
transform: {
'^.+\\.js$': ['babel-jest', { rootMode: 'upward' }],
},
fakeTimers: {
enableGlobally: false,
},
};
function tryToLoadWorkspaceConfig(configPath /*: string */) /*: Object */ {
if (fs.existsSync(configPath)) {
return require(configPath);
}
return {};
}
module.exports = {
bail: 100,
errorOnDeprecated: true,
moduleFileExtensions: ['js', 'json'],
reporters: ['default', 'github-actions'],
rootDir: __dirname,
verbose: false,
testEnvironment: 'node',
setupFilesAfterEnv: commonProjectConfig.setupFilesAfterEnv, // specified here so it triggers all tests to run if changed.
projects: Workspaces.getWorkspacesSync().map((packageJSONLocation) => {
const packageJSON = require(packageJSONLocation);
const workspaceDirname = path.dirname(packageJSONLocation);
const projectConfig = tryToLoadWorkspaceConfig(path.join(workspaceDirname, 'jest.config.js'));
if (projectConfig.setupFilesAfterEnv != null) {
// Adding setup files in workspace will overwrite the root one
// So rather merge them together
projectConfig.setupFilesAfterEnv = projectConfig.setupFilesAfterEnv.concat(
commonProjectConfig.setupFilesAfterEnv,
);
}
return {
displayName: packageJSON.name,
rootDir: workspaceDirname,
testMatch: ['**/' + TESTS_GLOB],
...commonProjectConfig,
...projectConfig,
};
}),
};