-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjest.config.base.js
129 lines (115 loc) · 4.25 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { isCI } from '@terascope/utils';
const dirname = path.dirname(fileURLToPath(import.meta.url));
export default (projectDir) => {
let parentFolder;
let workspaceName;
let packageRoot;
let rootDir;
const name = path.basename(projectDir);
const runInDir = process.cwd() !== dirname;
if (name === 'e2e') {
parentFolder = name;
workspaceName = name;
if (runInDir) {
packageRoot = '<rootDir>';
rootDir = './';
} else {
packageRoot = `<rootDir>/${name}`;
rootDir = '../';
}
} else {
parentFolder = 'packages';
workspaceName = `packages/${name}`;
packageRoot = `<rootDir>/${workspaceName}`;
rootDir = '../../';
}
const coverageReporters = ['lcov'];
if (!isCI) {
coverageReporters.push('text-summary');
}
const config = {
rootDir,
displayName: name,
testEnvironment: 'node',
testTimeout: 60 * 1000,
setupFilesAfterEnv: ['jest-extended/all'],
testMatch: [`${packageRoot}/test/**/*-spec.{ts,js}`, `${packageRoot}/test/*-spec.{ts,js}`],
testPathIgnorePatterns: [
'<rootDir>/assets',
`<rootDir>/${parentFolder}/*/node_modules`,
`<rootDir>/${parentFolder}/*/dist`,
`<rootDir>/${parentFolder}/teraslice-cli/test/fixtures/`
],
// do not run transforms on node_modules or pnp files
transformIgnorePatterns: [
'/node_modules/',
'\\.pnp\\.[^\\/]+$'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
moduleFileExtensions: ['ts', 'js', 'json', 'node', 'pegjs', 'mjs'],
extensionsToTreatAsEsm: ['.ts'],
coveragePathIgnorePatterns: ['/node_modules/', '/test/'],
watchPathIgnorePatterns: [],
coverageDirectory: `${packageRoot}/coverage`,
workerIdleMemoryLimit: '200MB',
globals: {
availableExtensions: ['.js', '.ts', '.mjs', 'cjs'],
},
transform: {
['^.+\\.(t|j)sx?$']: ['@swc/jest',
{
jsc: {
loose: true,
parser: {
syntax: 'typescript',
tsx: false,
decorators: true
},
transform: {
legacyDecorator: true,
decoratorMetadata: true
},
target: 'esnext'
},
module: {
type: 'es6',
strictMode: false,
noInterop: false,
ignoreDynamic: true
}
}]
},
roots: [`${packageRoot}/test`],
collectCoverage: true,
coverageReporters: coverageReporters
};
if (fs.existsSync(path.join(projectDir, 'test/global.setup.js'))) {
config.globalSetup = `${packageRoot}/test/global.setup.js`;
} else if (fs.existsSync(path.join(projectDir, 'test/global.setup.ts'))) {
config.globalSetup = `${packageRoot}/dist/test/global.setup.js`;
}
if (fs.existsSync(path.join(projectDir, 'test/global.teardown.js'))) {
config.globalTeardown = `${packageRoot}/test/global.teardown.js`;
} else if (fs.existsSync(path.join(projectDir, 'test/global.teardown.ts'))) {
config.globalTeardown = `${packageRoot}/dist/test/global.teardown.js`;
}
if (fs.existsSync(path.join(projectDir, 'test/test.setup.js'))) {
config.setupFilesAfterEnv.push(`${packageRoot}/test/test.setup.js`);
}
if (fs.existsSync(path.join(projectDir, 'lib'))) {
config.roots.push(`${packageRoot}/lib`);
} else if (fs.existsSync(path.join(projectDir, 'index.js'))) {
config.roots.push(`${packageRoot}`);
}
if (fs.existsSync(path.join(projectDir, 'src'))) {
config.roots.push(`${packageRoot}/src`);
}
if (fs.existsSync(path.join(projectDir, 'peg'))) {
config.roots.push(`${packageRoot}/peg`);
}
return config;
};