-
Notifications
You must be signed in to change notification settings - Fork 10
/
jest.config.cjs
64 lines (58 loc) · 1.93 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
const tsconf = require('./tsconfig.json');
// convert tsconfig paths to jest moduleNameMapper
// { '@magicbell/core': [ 'packages/core/src' ] } > { '@magicbell/core': '<rootDir>/packages/core/src' }
const moduleNameMapper = Object.fromEntries(
Object.entries(tsconf.compilerOptions.paths)
.filter(x => x[1][0].startsWith('packages'))
.map(x => [x[0], x[1][0].replace(/^packages/, '<rootDir>/packages')])
);
// import foo.ts as foo.js
moduleNameMapper['(.+/.*)\\.js'] = '$1';
// { '@magicbell/core': '<rootDir>/packages/core/src' } > [['@magicbell/core', '<rootDir>/packages/core']]
const packages = Object.entries(moduleNameMapper)
.map(([pkg, dir]) => [pkg, dir.split('/').slice(0, 3).join('/')])
.sort(([a], [b]) => a.localeCompare(b))
// this package has a non-jest test runner
.filter(x => x[0] !== '@magicbell/in-app');
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const commonConfig = {
preset: 'ts-jest',
testEnvironment: 'jest-environment-jsdom',
transform: {
'\\.[jt]sx?$': ['ts-jest', {
tsconfig: 'tsconfig.test.json',
}]
},
resolver: './jest.resolver.cjs',
moduleFileExtensions: ['ts', 'tsx', 'cts', 'js', 'json'],
modulePathIgnorePatterns: ['<rootDir>/packages/magicbell/dist', '<rootDir>/packages/playground', '<rootDir>/packages/embeddable/cypress'],
globals: {
__PACKAGE_NAME__: 'TEST',
__PACKAGE_VERSION__: '0.0.0',
__DEV__: false,
},
setupFilesAfterEnv: [
'./jest.setup.ts',
],
clearMocks: true,
resetMocks: true,
moduleNameMapper,
};
const projectConfigs = {
'@magicbell/user-client': {
testEnvironment: 'node',
}
};
/** @type {import('jest').Config} */
module.exports = {
projects: packages.map(([name, dir]) => ({
...commonConfig,
displayName: name,
testMatch: [
`${dir}/src/**/*.test.[jt]s?(x)"`,
`${dir}/test/**/*.[jt]s?(x)"`,
`${dir}/tests/**/*.spec.[jt]s?(x)"`,
],
...projectConfigs[name],
}))
};