Skip to content

Commit 374dca1

Browse files
committedSep 20, 2018
fix(compile): js files were never transpiled thru TS
Closes #740
1 parent 6ccbff3 commit 374dca1

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed
 

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

+57-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('process', () => {
6464
typescript = { options: {} } as any
6565
})
6666

67-
it('should process input without babel', () => {
67+
it('should process ts input without babel', () => {
6868
expect(process()).toBe(`ts:${INPUT}`)
6969
expect(config.shouldStringifyContent.mock.calls).toMatchInlineSnapshot(`
7070
Array [
@@ -83,7 +83,28 @@ Array [
8383
`)
8484
})
8585

86-
it('should process input with babel', () => {
86+
it('should process js input without babel', () => {
87+
typescript.options.allowJs = true
88+
args[1] = '/foo/bar.js'
89+
expect(process()).toBe(`ts:${INPUT}`)
90+
expect(config.shouldStringifyContent.mock.calls).toMatchInlineSnapshot(`
91+
Array [
92+
Array [
93+
"/foo/bar.js",
94+
],
95+
]
96+
`)
97+
expect(config.tsCompiler.compile.mock.calls).toMatchInlineSnapshot(`
98+
Array [
99+
Array [
100+
"export default \\"foo\\"",
101+
"/foo/bar.js",
102+
],
103+
]
104+
`)
105+
})
106+
107+
it('should process ts input with babel', () => {
87108
babel = { process: jest.fn(s => `babel:${s}`) }
88109
expect(process()).toBe(`babel:ts:${INPUT}`)
89110
expect(config.shouldStringifyContent.mock.calls).toMatchInlineSnapshot(`
@@ -115,6 +136,40 @@ Array [
115136
`)
116137
})
117138

139+
it('should process js input with babel', () => {
140+
typescript.options.allowJs = true
141+
babel = { process: jest.fn(s => `babel:${s}`) }
142+
args[1] = '/foo/bar.js'
143+
expect(process()).toBe(`babel:ts:${INPUT}`)
144+
expect(config.shouldStringifyContent.mock.calls).toMatchInlineSnapshot(`
145+
Array [
146+
Array [
147+
"/foo/bar.js",
148+
],
149+
]
150+
`)
151+
expect(config.babelJestTransformer.process.mock.calls).toMatchInlineSnapshot(`
152+
Array [
153+
Array [
154+
"ts:export default \\"foo\\"",
155+
"/foo/bar.js",
156+
Object {},
157+
Object {
158+
"instrument": false,
159+
},
160+
],
161+
]
162+
`)
163+
expect(config.tsCompiler.compile.mock.calls).toMatchInlineSnapshot(`
164+
Array [
165+
Array [
166+
"export default \\"foo\\"",
167+
"/foo/bar.js",
168+
],
169+
]
170+
`)
171+
})
172+
118173
it('should return stringified version of file', () => {
119174
config.shouldStringifyContent.mockImplementation(() => true)
120175
expect(process()).toMatchInlineSnapshot(`"module.exports=\\"export default \\\\\\"foo\\\\\\"\\""`)

‎src/ts-jest-transformer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class TsJestTransformer implements jest.Transformer {
111111
// we've got a '.js' but the compiler option `allowJs` is not set or set to false
112112
this.logger.warn({ fileName: filePath }, interpolate(Errors.GotJsFileButAllowJsFalse, { path: filePath }))
113113
result = source
114-
} else if (isTsFile) {
114+
} else if (isJsFile || isTsFile) {
115115
// transpile TS code (source maps are included)
116116
result = configs.tsCompiler.compile(source, filePath)
117117
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.