diff --git a/e2e/presets/__tests__/presets.spec.ts b/e2e/presets/__tests__/presets.spec.ts index e0e2905fd9..88d62cbc4d 100644 --- a/e2e/presets/__tests__/presets.spec.ts +++ b/e2e/presets/__tests__/presets.spec.ts @@ -1,74 +1,54 @@ -import { JS_EXT_TO_TREAT_AS_ESM, TS_EXT_TO_TREAT_AS_ESM } from 'ts-jest' +import { + JS_EXT_TO_TREAT_AS_ESM, + TS_EXT_TO_TREAT_AS_ESM, + createDefaultPreset, + createDefaultEsmPreset, + createJsWithTsPreset, + createJsWithTsEsmPreset, + createJsWithBabelPreset, + createJsWithBabelEsmPreset, +} from 'ts-jest' +// @ts-expect-error we have this file but we don't have type definition for it +import defaultPreset from 'ts-jest/jest-preset' import presets from 'ts-jest/presets' import extendedJestConfig from '../extended-jest-config' -const defaultPreset = require('ts-jest/jest-preset') - test('presets', () => { - expect(defaultPreset).toEqual({ - transform: { - '^.+\\.tsx?$': ['ts-jest', {}], - }, - }) + expect(defaultPreset).toEqual(createDefaultPreset()) expect(presets.defaultsLegacy).toEqual({ transform: { '^.+\\.tsx?$': ['ts-jest/legacy', {}], }, }) - expect(presets.defaultsESM).toEqual({ - extensionsToTreatAsEsm: [...TS_EXT_TO_TREAT_AS_ESM], - transform: { - '^.+\\.tsx?$': ['ts-jest', { useESM: true }], - }, - }) + expect(presets.defaultsESM).toEqual(createDefaultEsmPreset()) expect(presets.defaultsESMLegacy).toEqual({ extensionsToTreatAsEsm: [...TS_EXT_TO_TREAT_AS_ESM], transform: { '^.+\\.tsx?$': ['ts-jest/legacy', { useESM: true }], }, }) - expect(presets.jsWithTs).toEqual({ - transform: { - '^.+\\.[tj]sx?$': ['ts-jest', {}], - }, - }) + expect(presets.jsWithTs).toEqual(createJsWithTsPreset()) expect(presets.jsWithTsLegacy).toEqual({ transform: { '^.+\\.[tj]sx?$': ['ts-jest/legacy', {}], }, }) - expect(presets.jsWithTsESM).toEqual({ - extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM], - transform: { - '^.+\\.m?[tj]sx?$': ['ts-jest', { useESM: true }], - }, - }) + expect(presets.jsWithTsESM).toEqual(createJsWithTsEsmPreset()) expect(presets.jsWithTsESMLegacy).toEqual({ extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM], transform: { '^.+\\.m?[tj]sx?$': ['ts-jest/legacy', { useESM: true }], }, }) - expect(presets.jsWithBabel).toEqual({ - transform: { - '^.+\\.tsx?$': ['ts-jest', {}], - '^.+\\.jsx?$': 'babel-jest', - }, - }) + expect(presets.jsWithBabel).toEqual(createJsWithBabelPreset()) expect(presets.jsWithBabelLegacy).toEqual({ transform: { '^.+\\.tsx?$': ['ts-jest/legacy', {}], '^.+\\.jsx?$': 'babel-jest', }, }) - expect(presets.jsWithBabelESM).toEqual({ - extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM], - transform: { - '^.+\\.tsx?$': ['ts-jest', { useESM: true }], - '^.+\\.m?[j]sx?$': 'babel-jest', - }, - }) + expect(presets.jsWithBabelESM).toEqual(createJsWithBabelEsmPreset()) expect(presets.jsWithBabelESMLegacy).toEqual({ extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM], transform: { diff --git a/presets/index.js b/presets/index.js index b000651d2b..4c66274c4a 100644 --- a/presets/index.js +++ b/presets/index.js @@ -1,29 +1,35 @@ const { JS_EXT_TO_TREAT_AS_ESM, TS_EXT_TO_TREAT_AS_ESM } = require('../dist/constants') -const { createJestPreset } = require('../dist/presets/create-jest-preset') +const { + createJestPreset, + createDefaultPreset, + createDefaultEsmPreset, + createJsWithTsPreset, + createJsWithTsEsmPreset, + createJsWithBabelPreset, + createJsWithBabelEsmPreset, +} = require('../dist/presets/create-jest-preset') module.exports = { get defaults() { - return createJestPreset() + return createDefaultPreset() }, get defaultsLegacy() { return createJestPreset(true, false) }, get defaultsESM() { - return createJestPreset(false, false, { extensionsToTreatAsEsm: TS_EXT_TO_TREAT_AS_ESM }) + return createDefaultEsmPreset() }, get defaultsESMLegacy() { return createJestPreset(true, false, { extensionsToTreatAsEsm: TS_EXT_TO_TREAT_AS_ESM }) }, get jsWithTs() { - return createJestPreset(false, true) + return createJsWithTsPreset() }, get jsWithTsLegacy() { return createJestPreset(true, true) }, get jsWithTsESM() { - return createJestPreset(false, true, { - extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM], - }) + return createJsWithTsEsmPreset() }, get jsWithTsESMLegacy() { return createJestPreset(true, true, { @@ -31,11 +37,7 @@ module.exports = { }) }, get jsWithBabel() { - return createJestPreset(false, false, { - transform: { - '^.+\\.jsx?$': 'babel-jest', - }, - }) + return createJsWithBabelPreset() }, get jsWithBabelLegacy() { return createJestPreset(true, false, { @@ -45,12 +47,7 @@ module.exports = { }) }, get jsWithBabelESM() { - return createJestPreset(false, false, { - extensionsToTreatAsEsm: [...JS_EXT_TO_TREAT_AS_ESM, ...TS_EXT_TO_TREAT_AS_ESM], - transform: { - '^.+\\.m?[j]sx?$': 'babel-jest', - }, - }) + return createJsWithBabelEsmPreset() }, get jsWithBabelESMLegacy() { return createJestPreset(true, false, {