From b8f6eaa66662f6463c330645129c07a86722a2b2 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 167673e954..422efc40ba 100644 --- a/src/legacy/ts-jest-transformer.spec.ts +++ b/src/legacy/ts-jest-transformer.spec.ts @@ -330,7 +330,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) @@ -345,7 +345,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'