forked from terascope/teraslice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.config.base.js
102 lines (90 loc) · 3.09 KB
/
jest.config.base.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
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
'use strict';
const path = require('path');
const fs = require('fs-extra');
const { jest: lernaAliases } = require('lerna-alias');
module.exports = (projectDir) => {
const name = path.basename(projectDir);
const workspaceName = name === 'e2e' ? 'e2e' : 'packages';
const rootDir = name === 'e2e' ? '../' : '../../';
const projectRoot = name === 'e2e' ? '<rootDir>/e2e' : `<rootDir>/${workspaceName}/${name}`;
const isTypescript = fs.pathExistsSync(path.join(projectDir, 'tsconfig.json'));
const runInPackage = projectDir === process.cwd();
const config = {
rootDir,
name: `${workspaceName}/${name}`,
displayName: name,
verbose: true,
testEnvironment: 'node',
setupTestFrameworkScriptFile: 'jest-extended',
testMatch: [
`${projectRoot}/test/**/*-spec.{ts,js}`,
`${projectRoot}/test/*-spec.{ts,js}`
],
testPathIgnorePatterns: [
'<rootDir>/assets',
`<rootDir>/${workspaceName}/*/node_modules`,
`<rootDir>/${workspaceName}/*/dist`,
],
moduleNameMapper: lernaAliases({ mainFields: ['srcMain', 'main'] }),
moduleFileExtensions: [
'ts',
'js',
'json',
'node'
],
collectCoverage: true,
coveragePathIgnorePatterns: [
'/node_modules/',
'/test/',
],
coverageReporters: ['lcov', 'text', 'html'],
coverageDirectory: `${projectRoot}/coverage`,
preset: 'ts-jest'
};
if (fs.pathExistsSync(path.join(projectDir, 'test/global.setup.js'))) {
config.globalSetup = `${projectRoot}/test/global.setup.js`;
}
if (fs.pathExistsSync(path.join(projectDir, 'test/global.teardown.js'))) {
config.globalTeardown = `${projectRoot}/test/global.teardown.js`;
}
if (fs.pathExistsSync(path.join(projectDir, 'test/test.setup.js'))) {
config.setupTestFrameworkScriptFile = `${projectRoot}/test/test.setup.js`;
}
config.globals = {
availableExtensions: ['.js', '.ts']
};
if (isTypescript) {
if (runInPackage) {
config.globals['ts-jest'] = {
tsConfig: './tsconfig.json',
diagnostics: true,
pretty: true,
};
} else {
config.globals['ts-jest'] = {
tsConfig: `./${workspaceName}/${name}/tsconfig.json`,
diagnostics: {
warnOnly: true
},
pretty: true
};
}
} else {
config.globals['ts-jest'] = {
diagnostics: false,
pretty: true
};
}
config.roots = [
`${projectRoot}/test`
];
if (fs.pathExistsSync(path.join(projectDir, 'lib'))) {
config.roots.push(`${projectRoot}/lib`);
} else if (fs.pathExistsSync(path.join(projectDir, 'index.js'))) {
config.roots.push(`${projectRoot}`);
}
if (fs.pathExistsSync(path.join(projectDir, 'src'))) {
config.roots.push(`${projectRoot}/src`);
}
return config;
};