-
Notifications
You must be signed in to change notification settings - Fork 473
Expand file tree
/
Copy pathcreate-jest-preset.ts
More file actions
23 lines (18 loc) · 921 Bytes
/
create-jest-preset.ts
File metadata and controls
23 lines (18 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type { Config } from '@jest/types'
import type { TsJestPresets } from '../types'
import { rootLogger } from '../utils/logger'
const logger = rootLogger.child({ namespace: 'jest-preset' })
export function createJestPreset(allowJs = false, extraOptions: Config.InitialOptions = {}): TsJestPresets {
logger.debug({ allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files')
const { extensionsToTreatAsEsm, moduleFileExtensions, testMatch } = extraOptions
const supportESM = extensionsToTreatAsEsm?.length
return {
...(extensionsToTreatAsEsm ? { extensionsToTreatAsEsm } : undefined),
...(moduleFileExtensions ? { moduleFileExtensions } : undefined),
...(testMatch ? { testMatch } : undefined),
transform: {
...extraOptions.transform,
[allowJs ? (supportESM ? '^.+\\.m?[tj]sx?$' : '^.+\\.[tj]sx?$') : '^.+\\.tsx?$']: 'ts-jest',
},
}
}