Skip to content

Commit

Permalink
fix(compile): js files were never transpiled thru TS
Browse files Browse the repository at this point in the history
Closes #740
  • Loading branch information
huafu committed Sep 20, 2018
1 parent 6ccbff3 commit 374dca1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
59 changes: 57 additions & 2 deletions src/ts-jest-transformer.spec.ts
Expand Up @@ -64,7 +64,7 @@ describe('process', () => {
typescript = { options: {} } as any
})

it('should process input without babel', () => {
it('should process ts input without babel', () => {
expect(process()).toBe(`ts:${INPUT}`)
expect(config.shouldStringifyContent.mock.calls).toMatchInlineSnapshot(`
Array [
Expand All @@ -83,7 +83,28 @@ Array [
`)
})

it('should process input with babel', () => {
it('should process js input without babel', () => {
typescript.options.allowJs = true
args[1] = '/foo/bar.js'
expect(process()).toBe(`ts:${INPUT}`)
expect(config.shouldStringifyContent.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"/foo/bar.js",
],
]
`)
expect(config.tsCompiler.compile.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"export default \\"foo\\"",
"/foo/bar.js",
],
]
`)
})

it('should process ts input with babel', () => {
babel = { process: jest.fn(s => `babel:${s}`) }
expect(process()).toBe(`babel:ts:${INPUT}`)
expect(config.shouldStringifyContent.mock.calls).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -115,6 +136,40 @@ Array [
`)
})

it('should process js input with babel', () => {
typescript.options.allowJs = true
babel = { process: jest.fn(s => `babel:${s}`) }
args[1] = '/foo/bar.js'
expect(process()).toBe(`babel:ts:${INPUT}`)
expect(config.shouldStringifyContent.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"/foo/bar.js",
],
]
`)
expect(config.babelJestTransformer.process.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"ts:export default \\"foo\\"",
"/foo/bar.js",
Object {},
Object {
"instrument": false,
},
],
]
`)
expect(config.tsCompiler.compile.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"export default \\"foo\\"",
"/foo/bar.js",
],
]
`)
})

it('should return stringified version of file', () => {
config.shouldStringifyContent.mockImplementation(() => true)
expect(process()).toMatchInlineSnapshot(`"module.exports=\\"export default \\\\\\"foo\\\\\\"\\""`)
Expand Down
2 changes: 1 addition & 1 deletion src/ts-jest-transformer.ts
Expand Up @@ -111,7 +111,7 @@ export class TsJestTransformer implements jest.Transformer {
// we've got a '.js' but the compiler option `allowJs` is not set or set to false
this.logger.warn({ fileName: filePath }, interpolate(Errors.GotJsFileButAllowJsFalse, { path: filePath }))
result = source
} else if (isTsFile) {
} else if (isJsFile || isTsFile) {
// transpile TS code (source maps are included)
result = configs.tsCompiler.compile(source, filePath)
} else {
Expand Down

0 comments on commit 374dca1

Please sign in to comment.