-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
jest.config.js
69 lines (64 loc) · 2.09 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
67
68
69
'use strict'
const os = require('os')
const path = require('path')
const runtimeDir = path.dirname(require.resolve('../../runtime'))
const packagesDir = path.resolve('..', '..', '..')
module.exports = () => {
const configCommon = {
testMatch: ['**/*.ts', '!(**/*.d.ts)', '!(**/_utils/**)', '!(**/_*.ts)', '!(**/.generated/**)'],
// By default, jest passes every file it loads thorough a transform and caches result both on disk and in memory
// That includes all generated clients as well. So, unless we ignore them, they'd be kept in memory until test process
// is finished, even though they are needed for 1 test only
transformIgnorePatterns: [
'[\\/]node_modules[\\/]',
escapeRegex(runtimeDir),
`${escapeRegex(packagesDir)}[\\/][^\\/]+[\\/]dist[\\/]`,
],
reporters: [
'default',
[
'jest-junit',
{
addFileAttribute: 'true',
ancestorSeparator: ' › ',
classNameTemplate: '{classname}',
titleTemplate: '{title}',
},
],
],
globalSetup: './_utils/globalSetup.js',
snapshotSerializers: ['@prisma/internals/src/utils/jestSnapshotSerializer'],
setupFilesAfterEnv: ['./_utils/setupFilesAfterEnv.ts'],
testTimeout: 60_000,
collectCoverage: process.env.CI ? true : false,
}
if (os.platform() === 'win32') {
// swc sometimes produces incorrect source maps, in our case on windows only
// https://github.com/swc-project/swc/issues/3180
// this causes error stack traces to point to incorrect lines and all enriched errors
// snapshots to fail. Until this is fixed, on windows we will be still using ts-jest
return {
...configCommon,
preset: 'ts-jest/presets/js-with-babel-legacy',
globals: {
'ts-jest': {
isolatedModules: true,
},
},
}
}
return {
...configCommon,
transform: {
'^.+\\.(m?j|t)s$': '@swc/jest',
},
}
}
/**
* https://stackoverflow.com/a/6969486
* @param {string} str
* @returns {string}
*/
function escapeRegex(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}