From 80d3e4dc417f718ddf46bb5eaf9f88a712f2e767 Mon Sep 17 00:00:00 2001 From: ahnpnl Date: Sat, 22 Feb 2025 12:02:32 +0100 Subject: [PATCH] fix: escape dot for `TS_TRANSFORM_PATTERN` regex Fixes #4579 --- src/cli/__snapshots__/cli.spec.ts.snap | 28 +++++++++---------- src/cli/cli.spec.ts | 10 +++---- src/constants.ts | 2 +- .../create-jest-preset.spec.ts.snap | 8 +++--- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/cli/__snapshots__/cli.spec.ts.snap b/src/cli/__snapshots__/cli.spec.ts.snap index 8756b87501..c313b4c500 100644 --- a/src/cli/__snapshots__/cli.spec.ts.snap +++ b/src/cli/__snapshots__/cli.spec.ts.snap @@ -5,7 +5,7 @@ exports[`config init should create a jest config file with cli options for confi module.exports = { testEnvironment: "node", transform: { - "^.+.tsx?$": ["ts-jest",{}], + "^.+\\.tsx?$": ["ts-jest",{}], }, };" `; @@ -15,7 +15,7 @@ exports[`config init should create a jest config file with cli options for confi export default { testEnvironment: "node", transform: { - "^.+.tsx?$": ["ts-jest",{}], + "^.+\\.tsx?$": ["ts-jest",{}], }, };" `; @@ -66,7 +66,7 @@ exports[`config init should update package.json for config type default when use "version": "0.0.0-mock.0", "jest": { "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] @@ -82,7 +82,7 @@ exports[`config init should update package.json for config type js-with-babel-fu "jest": { "transform": { "^.+.jsx?$": "babel-jest", - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", { "tsconfig": "tsconfig.test.json" @@ -114,7 +114,7 @@ exports[`config migrate should generate transform config with existing transform "module.exports = { transform: { '^.+.jsx?$': 'babel-jest', - '^.+.tsx?$': [ + '^.+\\\\.tsx?$': [ 'ts-jest', {}, ], @@ -130,7 +130,7 @@ exports[`config migrate should generate transform config with existing transform 'ts-jest', {}, ], - '^.+.tsx?$': [ + '^.+\\\\.tsx?$': [ 'ts-jest', {}, ], @@ -142,7 +142,7 @@ exports[`config migrate should generate transform config with existing transform exports[`config migrate should migrate preset if valid preset value is used 1`] = ` ""jest": { "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] @@ -154,7 +154,7 @@ exports[`config migrate should migrate preset if valid preset value is used 1`] exports[`config migrate should migrate preset if valid preset value is used 2`] = ` ""jest": { "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] @@ -166,7 +166,7 @@ exports[`config migrate should migrate preset if valid preset value is used 2`] exports[`config migrate should migrate preset if valid preset value is used 3`] = ` ""jest": { "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] @@ -179,7 +179,7 @@ exports[`config migrate should reset testMatch if testRegex is used 1`] = ` ""jest": { "testRegex": "foo-pattern", "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] @@ -194,7 +194,7 @@ exports[`config migrate should reset testMatch if testRegex is used 2`] = ` "foo-pattern" ], "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] @@ -210,7 +210,7 @@ exports[`config migrate should reset testMatch if testRegex is used 3`] = ` "**/__tests__/**/*.(spec|test).[tj]s?(x)" ], "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] @@ -225,7 +225,7 @@ exports[`config migrate should reset testMatch if testRegex is used 4`] = ` "**/__tests__/**/*.(spec|test).[tj]s?(x)" ], "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] @@ -238,7 +238,7 @@ exports[`config migrate should reset testMatch if testRegex is used 5`] = ` ""jest": { "testRegex": "foo-pattern", "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] diff --git a/src/cli/cli.spec.ts b/src/cli/cli.spec.ts index 071b0df75f..556c17e022 100644 --- a/src/cli/cli.spec.ts +++ b/src/cli/cli.spec.ts @@ -285,7 +285,7 @@ describe('config', () => { ", "stdout": ""jest": { "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", { "tsconfig": { @@ -386,7 +386,7 @@ describe('config', () => { "**/__tests__/**/*.ts?(x)" ], "transform": { - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", { "tsconfig": { @@ -475,7 +475,7 @@ describe('config', () => { expect(res.stdout).toMatchInlineSnapshot(` "module.exports = { transform: { - '^.+.tsx?$': [ + '^.+\\\\.tsx?$': [ 'ts-jest', {}, ], @@ -556,7 +556,7 @@ describe('config', () => { 'ts-jest', {}, ], - '^.+.tsx?$': [ + '^.+\\\\.tsx?$': [ 'ts-jest', {}, ], @@ -600,7 +600,7 @@ describe('config', () => { "ts-jest", {} ], - "^.+.tsx?$": [ + "^.+\\\\.tsx?$": [ "ts-jest", {} ] diff --git a/src/constants.ts b/src/constants.ts index cd79cfdf2d..9d7eb53814 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -3,7 +3,7 @@ export const DECLARATION_TYPE_EXT = '.d.ts' export const JS_JSX_EXTENSIONS = ['.js', '.jsx'] export const TS_TSX_REGEX = /\.[cm]?tsx?$/ export const JS_JSX_REGEX = /\.[cm]?jsx?$/ -export const TS_TRANSFORM_PATTERN = '^.+.tsx?$' +export const TS_TRANSFORM_PATTERN = '^.+\\.tsx?$' export const ESM_TS_TRANSFORM_PATTERN = '^.+\\.m?tsx?$' export const TS_JS_TRANSFORM_PATTERN = '^.+.[tj]sx?$' export const ESM_TS_JS_TRANSFORM_PATTERN = '^.+\\.m?[tj]sx?$' diff --git a/src/presets/__snapshots__/create-jest-preset.spec.ts.snap b/src/presets/__snapshots__/create-jest-preset.spec.ts.snap index d21e6e47b8..6712788706 100644 --- a/src/presets/__snapshots__/create-jest-preset.spec.ts.snap +++ b/src/presets/__snapshots__/create-jest-preset.spec.ts.snap @@ -3,7 +3,7 @@ exports[`create-jest-preset CJS presets createDefaultLegacyPreset should return preset config 1`] = ` { "transform": { - "^.+.tsx?$": [ + "^.+\\.tsx?$": [ "ts-jest", { "tsconfig": "tsconfig.spec.json", @@ -16,7 +16,7 @@ exports[`create-jest-preset CJS presets createDefaultLegacyPreset should return exports[`create-jest-preset CJS presets createDefaultPreset should return preset config 1`] = ` { "transform": { - "^.+.tsx?$": [ + "^.+\\.tsx?$": [ "ts-jest", { "tsconfig": "tsconfig.spec.json", @@ -30,7 +30,7 @@ exports[`create-jest-preset CJS presets createJsWithBabelLegacyPreset should ret { "transform": { "^.+.jsx?$": "babel-jest", - "^.+.tsx?$": [ + "^.+\\.tsx?$": [ "ts-jest/legacy", { "babelConfig": { @@ -47,7 +47,7 @@ exports[`create-jest-preset CJS presets createJsWithBabelPreset should return pr { "transform": { "^.+.jsx?$": "babel-jest", - "^.+.tsx?$": [ + "^.+\\.tsx?$": [ "ts-jest", { "babelConfig": {