From 005ef56798c71bf024a555abf17e16e794cf151c Mon Sep 17 00:00:00 2001 From: smack0007 Date: Thu, 26 Jan 2023 12:42:32 +0100 Subject: [PATCH] fix(transformer): allow transforming of .cts/.mts extensions. (#3996) --- src/constants.ts | 4 ++-- src/legacy/ts-jest-transformer.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index bbf6727984..d7330d1187 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,8 +1,8 @@ export const LINE_FEED = '\n' export const DECLARATION_TYPE_EXT = '.d.ts' export const JS_JSX_EXTENSIONS = ['.js', '.jsx'] -export const TS_TSX_REGEX = /\.m?tsx?$/ -export const JS_JSX_REGEX = /\.m?jsx?$/ +export const TS_TSX_REGEX = /\.[cm]?tsx?$/ +export const JS_JSX_REGEX = /\.[cm]?jsx?$/ // `extensionsToTreatAsEsm` will throw error with `.mjs` export const TS_EXT_TO_TREAT_AS_ESM = ['.ts', '.tsx', '.mts'] export const JS_EXT_TO_TREAT_AS_ESM = ['.jsx'] diff --git a/src/legacy/ts-jest-transformer.spec.ts b/src/legacy/ts-jest-transformer.spec.ts index 849e2d3041..8663981eaf 100644 --- a/src/legacy/ts-jest-transformer.spec.ts +++ b/src/legacy/ts-jest-transformer.spec.ts @@ -376,7 +376,7 @@ describe('TsJestTransformer', () => { expect(process.env.TS_JEST).toBe('1') }) - test.each(['foo.ts', 'foo.tsx', 'foo.mts', 'foo.mtsx'])('should process ts/tsx file', (filePath) => { + test.each(['foo.ts', 'foo.tsx', 'foo.cts', 'foo.mts', 'foo.mtsx'])('should process ts/tsx file', (filePath) => { const fileContent = 'const foo = 1' const output = 'var foo = 1' tr.getCacheKey(fileContent, filePath, baseTransformOptions) @@ -391,7 +391,7 @@ describe('TsJestTransformer', () => { }) }) - test.each(['foo.js', 'foo.jsx', 'foo.mjs', 'foo.mjsx'])( + test.each(['foo.js', 'foo.jsx', 'foo.cjs', 'foo.mjs', 'foo.mjsx'])( 'should process js/jsx file with allowJs true', (filePath) => { const fileContent = 'const foo = 1'