Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: escape dot for several transform regex constants #4698

Merged
merged 4 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/enum/jest-compiler-cjs.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest'
import { type JestConfigWithTsJest, ESM_TS_JS_TRANSFORM_PATTERN } from 'ts-jest'

export default {
displayName: 'enum-compiler-cjs',
transform: {
[TS_JS_TRANSFORM_PATTERN]: [
[ESM_TS_JS_TRANSFORM_PATTERN]: [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig-cjs.spec.json',
Expand Down
4 changes: 2 additions & 2 deletions e2e/enum/jest-transpiler-cjs.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest'
import { type JestConfigWithTsJest, ESM_TS_JS_TRANSFORM_PATTERN } from 'ts-jest'

export default {
displayName: 'enum-transpiler-cjs',
transform: {
[TS_JS_TRANSFORM_PATTERN]: [
[ESM_TS_JS_TRANSFORM_PATTERN]: [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig-cjs.spec.json',
Expand Down
4 changes: 2 additions & 2 deletions e2e/transform-js/jest-compiler-cjs.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest'
import { type JestConfigWithTsJest, ESM_TS_JS_TRANSFORM_PATTERN } from 'ts-jest'

export default {
displayName: 'transform-js-compiler-cjs',
transform: {
[TS_JS_TRANSFORM_PATTERN]: [
[ESM_TS_JS_TRANSFORM_PATTERN]: [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig-cjs.spec.json',
Expand Down
4 changes: 2 additions & 2 deletions e2e/transform-js/jest-transpiler-cjs.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type JestConfigWithTsJest, TS_JS_TRANSFORM_PATTERN } from 'ts-jest'
import { type JestConfigWithTsJest, ESM_TS_JS_TRANSFORM_PATTERN } from 'ts-jest'

export default {
displayName: 'transform-js-transpiler-cjs',
transform: {
[TS_JS_TRANSFORM_PATTERN]: [
[ESM_TS_JS_TRANSFORM_PATTERN]: [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig-cjs.spec.json',
Expand Down
44 changes: 22 additions & 22 deletions src/cli/__snapshots__/cli.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",{}],
},
};"
`;
Expand All @@ -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",{}],
},
};"
`;
Expand All @@ -25,7 +25,7 @@ exports[`config init should create a jest config file with cli options for confi
module.exports = {
testEnvironment: "jsdom",
transform: {
"^.+.jsx?$": "babel-jest",
"^.+\\.jsx?$": "babel-jest",
},
};"
`;
Expand All @@ -35,7 +35,7 @@ exports[`config init should create a jest config file with cli options for confi
export default {
testEnvironment: "jsdom",
transform: {
"^.+.jsx?$": "babel-jest",
"^.+\\.jsx?$": "babel-jest",
},
};"
`;
Expand All @@ -45,7 +45,7 @@ exports[`config init should create a jest config file with cli options for confi
module.exports = {
testEnvironment: "jsdom",
transform: {
"^.+.[tj]sx?$": ["ts-jest",{tsconfig:"tsconfig.test.json"}],
"^.+\\.[tj]sx?$": ["ts-jest",{tsconfig:"tsconfig.test.json"}],
},
};"
`;
Expand All @@ -55,7 +55,7 @@ exports[`config init should create a jest config file with cli options for confi
export default {
testEnvironment: "jsdom",
transform: {
"^.+.[tj]sx?$": ["ts-jest",{tsconfig:"tsconfig.test.json"}],
"^.+\\.[tj]sx?$": ["ts-jest",{tsconfig:"tsconfig.test.json"}],
},
};"
`;
Expand All @@ -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",
{}
]
Expand All @@ -81,8 +81,8 @@ exports[`config init should update package.json for config type js-with-babel-fu
"version": "0.0.0-mock.0",
"jest": {
"transform": {
"^.+.jsx?$": "babel-jest",
"^.+.tsx?$": [
"^.+\\\\.jsx?$": "babel-jest",
"^.+\\\\.tsx?$": [
"ts-jest",
{
"tsconfig": "tsconfig.test.json"
Expand All @@ -99,7 +99,7 @@ exports[`config init should update package.json for config type js-with-ts-full-
"version": "0.0.0-mock.0",
"jest": {
"transform": {
"^.+.[tj]sx?$": [
"^.+\\\\.[tj]sx?$": [
"ts-jest",
{
"tsconfig": "tsconfig.test.json"
Expand All @@ -113,8 +113,8 @@ exports[`config init should update package.json for config type js-with-ts-full-
exports[`config migrate should generate transform config with existing transform options for js-with-babel 1`] = `
"module.exports = {
transform: {
'^.+.jsx?$': 'babel-jest',
'^.+.tsx?$': [
'^.+\\\\.jsx?$': 'babel-jest',
'^.+\\\\.tsx?$': [
'ts-jest',
{},
],
Expand All @@ -126,11 +126,11 @@ exports[`config migrate should generate transform config with existing transform
exports[`config migrate should generate transform config with existing transform options for js-with-ts 1`] = `
"module.exports = {
transform: {
'^.+.[tj]sx?$': [
'^.+\\\\.[tj]sx?$': [
'ts-jest',
{},
],
'^.+.tsx?$': [
'^.+\\\\.tsx?$': [
'ts-jest',
{},
],
Expand All @@ -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",
{}
]
Expand All @@ -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",
{}
]
Expand All @@ -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",
{}
]
Expand All @@ -179,7 +179,7 @@ exports[`config migrate should reset testMatch if testRegex is used 1`] = `
""jest": {
"testRegex": "foo-pattern",
"transform": {
"^.+.tsx?$": [
"^.+\\\\.tsx?$": [
"ts-jest",
{}
]
Expand All @@ -194,7 +194,7 @@ exports[`config migrate should reset testMatch if testRegex is used 2`] = `
"foo-pattern"
],
"transform": {
"^.+.tsx?$": [
"^.+\\\\.tsx?$": [
"ts-jest",
{}
]
Expand All @@ -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",
{}
]
Expand All @@ -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",
{}
]
Expand All @@ -238,7 +238,7 @@ exports[`config migrate should reset testMatch if testRegex is used 5`] = `
""jest": {
"testRegex": "foo-pattern",
"transform": {
"^.+.tsx?$": [
"^.+\\\\.tsx?$": [
"ts-jest",
{}
]
Expand Down
14 changes: 7 additions & 7 deletions src/cli/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('config', () => {
",
"stdout": ""jest": {
"transform": {
"^.+.tsx?$": [
"^.+\\\\.tsx?$": [
"ts-jest",
{
"tsconfig": {
Expand Down Expand Up @@ -330,7 +330,7 @@ describe('config', () => {
",
"stdout": ""jest": {
"transform": {
"^.+.[tj]sx?$": [
"^.+\\\\.[tj]sx?$": [
"ts-jest",
{
"tsconfig": {
Expand Down Expand Up @@ -386,7 +386,7 @@ describe('config', () => {
"**/__tests__/**/*.ts?(x)"
],
"transform": {
"^.+.tsx?$": [
"^.+\\\\.tsx?$": [
"ts-jest",
{
"tsconfig": {
Expand Down Expand Up @@ -475,7 +475,7 @@ describe('config', () => {
expect(res.stdout).toMatchInlineSnapshot(`
"module.exports = {
transform: {
'^.+.tsx?$': [
'^.+\\\\.tsx?$': [
'ts-jest',
{},
],
Expand All @@ -495,7 +495,7 @@ describe('config', () => {
expect(res.stdout).toMatchInlineSnapshot(`
"module.exports = {
transform: {
'^.+.[tj]sx?$': [
'^.+\\\\.[tj]sx?$': [
'ts-jest',
{},
],
Expand Down Expand Up @@ -556,7 +556,7 @@ describe('config', () => {
'ts-jest',
{},
],
'^.+.tsx?$': [
'^.+\\\\.tsx?$': [
'ts-jest',
{},
],
Expand Down Expand Up @@ -600,7 +600,7 @@ describe('config', () => {
"ts-jest",
{}
],
"^.+.tsx?$": [
"^.+\\\\.tsx?$": [
"ts-jest",
{}
]
Expand Down
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ 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 TS_JS_TRANSFORM_PATTERN = '^.+\\.[tj]sx?$'
export const ESM_TS_JS_TRANSFORM_PATTERN = '^.+\\.m?[tj]sx?$'
export const JS_TRANSFORM_PATTERN = '^.+.jsx?$'
export const JS_TRANSFORM_PATTERN = '^.+\\.jsx?$'
export const ESM_JS_TRANSFORM_PATTERN = '^.+\\.m?jsx?$'
// `extensionsToTreatAsEsm` will throw error with `.mjs`
export const TS_EXT_TO_TREAT_AS_ESM = ['.ts', '.tsx', '.mts']
Expand Down
16 changes: 8 additions & 8 deletions src/presets/__snapshots__/create-jest-preset.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -29,8 +29,8 @@ exports[`create-jest-preset CJS presets createDefaultPreset should return preset
exports[`create-jest-preset CJS presets createJsWithBabelLegacyPreset should return preset config 1`] = `
{
"transform": {
"^.+.jsx?$": "babel-jest",
"^.+.tsx?$": [
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tsx?$": [
"ts-jest/legacy",
{
"babelConfig": {
Expand All @@ -46,8 +46,8 @@ exports[`create-jest-preset CJS presets createJsWithBabelLegacyPreset should ret
exports[`create-jest-preset CJS presets createJsWithBabelPreset should return preset config 1`] = `
{
"transform": {
"^.+.jsx?$": "babel-jest",
"^.+.tsx?$": [
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tsx?$": [
"ts-jest",
{
"babelConfig": {
Expand All @@ -63,7 +63,7 @@ exports[`create-jest-preset CJS presets createJsWithBabelPreset should return pr
exports[`create-jest-preset CJS presets createJsWithTsLegacyPreset should return preset config 1`] = `
{
"transform": {
"^.+.[tj]sx?$": [
"^.+\\.[tj]sx?$": [
"ts-jest/legacy",
{
"isolatedModules": true,
Expand All @@ -77,7 +77,7 @@ exports[`create-jest-preset CJS presets createJsWithTsLegacyPreset should return
exports[`create-jest-preset CJS presets createJsWithTsPreset should return preset config 1`] = `
{
"transform": {
"^.+.[tj]sx?$": [
"^.+\\.[tj]sx?$": [
"ts-jest",
{
"isolatedModules": true,
Expand Down
Loading