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: allow .mts to be processed #3713

Merged
merged 1 commit into from Jul 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/constants.ts
@@ -1,10 +1,10 @@
export const LINE_FEED = '\n'
export const DECLARATION_TYPE_EXT = '.d.ts'
export const JS_JSX_EXTENSIONS = ['.js', '.jsx']
export const TS_TSX_REGEX = /\.tsx?$/
export const JS_JSX_REGEX = /\.jsx?$/
// `extensionsToTreatAsEsm` only accepts `.ts`, `.tsx` and `.jsx`. `.js`, `.cjs`, `.mjs` will throw error
export const TS_EXT_TO_TREAT_AS_ESM = ['.ts', '.tsx']
export const TS_TSX_REGEX = /\.m?tsx?$/
export const JS_JSX_REGEX = /\.m?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']
/**
* @internal
Expand Down
47 changes: 25 additions & 22 deletions src/legacy/ts-jest-transformer.spec.ts
Expand Up @@ -376,7 +376,7 @@ describe('TsJestTransformer', () => {
expect(process.env.TS_JEST).toBe('1')
})

test.each(['foo.ts', 'foo.tsx'])('should process ts/tsx file', (filePath) => {
test.each(['foo.ts', 'foo.tsx', '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)
Expand All @@ -391,30 +391,33 @@ describe('TsJestTransformer', () => {
})
})

test.each(['foo.js', 'foo.jsx'])('should process js/jsx file with allowJs true', (filePath) => {
const fileContent = 'const foo = 1'
const output = 'var foo = 1'
const transformOptions = {
...baseTransformOptions,
config: {
...baseTransformOptions.config,
globals: {
'ts-jest': { tsconfig: { allowJs: true } },
test.each(['foo.js', 'foo.jsx', 'foo.mjs', 'foo.mjsx'])(
'should process js/jsx file with allowJs true',
(filePath) => {
const fileContent = 'const foo = 1'
const output = 'var foo = 1'
const transformOptions = {
...baseTransformOptions,
config: {
...baseTransformOptions.config,
globals: {
'ts-jest': { tsconfig: { allowJs: true } },
},
},
},
}
tr.getCacheKey(fileContent, filePath, transformOptions)
logTarget.clear()
jest.spyOn(TsJestCompiler.prototype, 'getCompiledOutput').mockReturnValueOnce({
code: output,
})
}
tr.getCacheKey(fileContent, filePath, transformOptions)
logTarget.clear()
jest.spyOn(TsJestCompiler.prototype, 'getCompiledOutput').mockReturnValueOnce({
code: output,
})

const result = tr.process(fileContent, filePath, transformOptions)
const result = tr.process(fileContent, filePath, transformOptions)

expect(result).toEqual({
code: output,
})
})
expect(result).toEqual({
code: output,
})
},
)

test('should process file with unknown extension and show warning message without babel-jest', () => {
const fileContent = 'foo'
Expand Down
Expand Up @@ -61,6 +61,7 @@ Object {
".jsx",
".ts",
".tsx",
".mts",
],
"moduleFileExtensions": Array [
"bar",
Expand Down