forked from chenlijun99/autoanki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.cjs
74 lines (69 loc) · 2.48 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
65
66
67
68
69
70
71
72
73
74
const path = require('node:path');
const { pathsToModuleNameMapper } = require('ts-jest');
const requireJSON5 = require('require-json5');
// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file
// which contains the path mapping (ie the `compilerOptions.paths` option):
const { compilerOptions } = requireJSON5('./packages/tsconfig.json');
const tsconfigPathMaps = pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/packages/',
});
delete tsconfigPathMaps['^@autoanki/utils/(.*)$'];
/*
* List of modules that ship ESM-only packages, which need to be transpiled
*/
const esModules = ['unified'].join('|');
function projectConfig(packageName) {
return {
displayName: packageName,
extensionsToTreatAsEsm: ['.ts'],
modulePaths: ['<rootDir>/packages/'],
moduleNameMapper: {
/*
* Map .bundled.js (used extensively in this project) and other non-JS
* modules to mock modules.
*
* See https://jestjs.io/docs/webpack
*/
'\\.bundled.js$': '<rootDir>/__mocks__/bundledFileMock.js',
'\\.(css|less)$': '<rootDir>/__mocks__/cssFileMock.js',
...tsconfigPathMaps,
'^@autoanki/utils/webcrypto\\.js$':
'<rootDir>/packages//autoanki-utils/src/webcrypto.node',
'^@autoanki/utils/hash-sync\\.js$':
'<rootDir>/packages//autoanki-utils/src/hash-sync.node',
'^@autoanki/utils/(.*)\\.js$':
'<rootDir>/packages//autoanki-utils/src/$1',
'^#webcrypto\\.js$':
'<rootDir>/packages//autoanki-utils/src/webcrypto.node',
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
// '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
'^.+\\.m?[tj]sx?$': [
'ts-jest',
{
tsconfig: '<rootDir>/packages/tsconfig.json',
useESM: true,
isolatedModules: true,
},
],
},
// some node_modules need also to be transformed
transformIgnorePatterns: [`node_modules/(?!(${esModules}))/`],
testEnvironment: 'node',
testMatch: [
`<rootDir>/packages/${packageName}/**/?(*.)+(spec|test).[t]s?(x)`,
],
};
}
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
projects: [
projectConfig('autoanki-sync'),
projectConfig('autoanki-core'),
projectConfig('autoanki-utils'),
projectConfig('autoanki-config'),
projectConfig('autoanki-plugin-content-local-media-extractor'),
],
};