Skip to content

Commit effae71

Browse files
authoredJul 25, 2022
fix: allow .mts to be processed (#3713)
Fixes #3702
1 parent eef70f6 commit effae71

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed
 

‎src/constants.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export const LINE_FEED = '\n'
22
export const DECLARATION_TYPE_EXT = '.d.ts'
33
export const JS_JSX_EXTENSIONS = ['.js', '.jsx']
4-
export const TS_TSX_REGEX = /\.tsx?$/
5-
export const JS_JSX_REGEX = /\.jsx?$/
6-
// `extensionsToTreatAsEsm` only accepts `.ts`, `.tsx` and `.jsx`. `.js`, `.cjs`, `.mjs` will throw error
7-
export const TS_EXT_TO_TREAT_AS_ESM = ['.ts', '.tsx']
4+
export const TS_TSX_REGEX = /\.m?tsx?$/
5+
export const JS_JSX_REGEX = /\.m?jsx?$/
6+
// `extensionsToTreatAsEsm` will throw error with `.mjs`
7+
export const TS_EXT_TO_TREAT_AS_ESM = ['.ts', '.tsx', '.mts']
88
export const JS_EXT_TO_TREAT_AS_ESM = ['.jsx']
99
/**
1010
* @internal

‎src/legacy/ts-jest-transformer.spec.ts

+25-22
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ describe('TsJestTransformer', () => {
376376
expect(process.env.TS_JEST).toBe('1')
377377
})
378378

379-
test.each(['foo.ts', 'foo.tsx'])('should process ts/tsx file', (filePath) => {
379+
test.each(['foo.ts', 'foo.tsx', 'foo.mts', 'foo.mtsx'])('should process ts/tsx file', (filePath) => {
380380
const fileContent = 'const foo = 1'
381381
const output = 'var foo = 1'
382382
tr.getCacheKey(fileContent, filePath, baseTransformOptions)
@@ -391,30 +391,33 @@ describe('TsJestTransformer', () => {
391391
})
392392
})
393393

394-
test.each(['foo.js', 'foo.jsx'])('should process js/jsx file with allowJs true', (filePath) => {
395-
const fileContent = 'const foo = 1'
396-
const output = 'var foo = 1'
397-
const transformOptions = {
398-
...baseTransformOptions,
399-
config: {
400-
...baseTransformOptions.config,
401-
globals: {
402-
'ts-jest': { tsconfig: { allowJs: true } },
394+
test.each(['foo.js', 'foo.jsx', 'foo.mjs', 'foo.mjsx'])(
395+
'should process js/jsx file with allowJs true',
396+
(filePath) => {
397+
const fileContent = 'const foo = 1'
398+
const output = 'var foo = 1'
399+
const transformOptions = {
400+
...baseTransformOptions,
401+
config: {
402+
...baseTransformOptions.config,
403+
globals: {
404+
'ts-jest': { tsconfig: { allowJs: true } },
405+
},
403406
},
404-
},
405-
}
406-
tr.getCacheKey(fileContent, filePath, transformOptions)
407-
logTarget.clear()
408-
jest.spyOn(TsJestCompiler.prototype, 'getCompiledOutput').mockReturnValueOnce({
409-
code: output,
410-
})
407+
}
408+
tr.getCacheKey(fileContent, filePath, transformOptions)
409+
logTarget.clear()
410+
jest.spyOn(TsJestCompiler.prototype, 'getCompiledOutput').mockReturnValueOnce({
411+
code: output,
412+
})
411413

412-
const result = tr.process(fileContent, filePath, transformOptions)
414+
const result = tr.process(fileContent, filePath, transformOptions)
413415

414-
expect(result).toEqual({
415-
code: output,
416-
})
417-
})
416+
expect(result).toEqual({
417+
code: output,
418+
})
419+
},
420+
)
418421

419422
test('should process file with unknown extension and show warning message without babel-jest', () => {
420423
const fileContent = 'foo'

‎src/presets/__snapshots__/create-jest-preset.spec.ts.snap

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Object {
6161
".jsx",
6262
".ts",
6363
".tsx",
64+
".mts",
6465
],
6566
"moduleFileExtensions": Array [
6667
"bar",

0 commit comments

Comments
 (0)
Please sign in to comment.