-
Notifications
You must be signed in to change notification settings - Fork 8
/
jest.config.js
66 lines (54 loc) · 1.65 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
const { execSync } = require('child_process');
const path = require('path');
const TEST_ENV_ALL = 'all';
const TEST_ENV_E2E = 'e2e';
const TEST_ENV_UNIT = 'unit';
const TEST_ENV_OPTIONS = [TEST_ENV_ALL, TEST_ENV_E2E, TEST_ENV_UNIT];
if (!TEST_ENV_OPTIONS.includes(process.env.TEST_ENV)) {
console.info(`[ERROR] please set TEST_ENV to one of [${TEST_ENV_OPTIONS}]`);
process.exit(1);
}
buildWebsite(process.env.TEST_ENV);
module.exports = {
bail: getBail(process.env.TEST_ENV),
cacheDirectory: './.cache/jest',
preset: getPreset(process.env.TEST_ENV),
globals: {
ARTIFACTS_DIR: path.resolve(__dirname, 'tests/_artifacts'),
},
testMatch: [...getTestMatch(process.env.TEST_ENV)],
testPathIgnorePatterns: [
'/node_modules/',
...getIgnorePattern(process.env.TEST_ENV),
],
};
function buildWebsite(env) {
const buildWebsiteEnvs = [TEST_ENV_ALL, TEST_ENV_E2E];
if (buildWebsiteEnvs.includes(env)) {
console.info('building website for end-to-end tests...');
execSync('npm run clean');
execSync('npm run build');
}
}
function getBail(env) {
const bailEarlyEnvs = [TEST_ENV_ALL, TEST_ENV_E2E];
return bailEarlyEnvs.includes(env) ? 1 : 0;
}
function getIgnorePattern(env) {
const ignorePaths = [];
const ignoreE2eEnvs = [TEST_ENV_UNIT];
if (ignoreE2eEnvs.includes(env)) {
ignorePaths.push('e2e.test.js');
}
return ignorePaths;
}
function getPreset(env) {
const jestPuppeteerEnvs = [TEST_ENV_ALL, TEST_ENV_E2E];
return jestPuppeteerEnvs.includes(env) ? 'jest-puppeteer' : undefined;
}
function getTestMatch(env) {
if (env === TEST_ENV_E2E) {
return ['**/tests/e2e.test.js'];
}
return ['**/tests/*.test.js'];
}