From 72000806f5144a62045b807e94406e30f5b26967 Mon Sep 17 00:00:00 2001 From: rchaser53 Date: Wed, 14 Mar 2018 18:44:56 +0900 Subject: [PATCH 1/3] use empty string when sourceMapText is undefined --- lib/compilers/typescript-compiler.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/compilers/typescript-compiler.js b/lib/compilers/typescript-compiler.js index 1cb7c118..98cdaab3 100644 --- a/lib/compilers/typescript-compiler.js +++ b/lib/compilers/typescript-compiler.js @@ -52,6 +52,9 @@ module.exports = function compileTypescript (scriptContent) { const tsConfig = getTypescriptConfig() const res = typescript.transpileModule(scriptContent, tsConfig) + const inputSourceMap = (res.sourceMapText !== undefined) + ? JSON.parse(res.sourceMapText) + : '' // handle ES modules in TS source code in case user uses non commonjs module // output and there is no .babelrc. @@ -64,5 +67,5 @@ module.exports = function compileTypescript (scriptContent) { } } - return compileBabel(res.outputText, JSON.parse(res.sourceMapText), inlineBabelConfig) + return compileBabel(res.outputText, inputSourceMap, inlineBabelConfig) } From 440572fb070f54143d2924bc9655ea366260fa18 Mon Sep 17 00:00:00 2001 From: rchaser53 Date: Wed, 14 Mar 2018 22:37:09 +0900 Subject: [PATCH 2/3] add test for no sourcemap --- test/TypeScript.spec.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/TypeScript.spec.js b/test/TypeScript.spec.js index 4ab00fe3..c9a0d39f 100644 --- a/test/TypeScript.spec.js +++ b/test/TypeScript.spec.js @@ -2,7 +2,7 @@ import { shallow } from 'vue-test-utils' import { resolve } from 'path' import TypeScript from './resources/TypeScript.vue' import jestVue from '../vue-jest' -import { readFileSync, renameSync } from 'fs' +import { readFileSync, renameSync, writeFileSync } from 'fs' import cache from '../lib/cache' beforeEach(() => { @@ -28,3 +28,17 @@ test.skip('generates inline sourcemap', () => { const output = jestVue.process(fileString, filePath) expect(output).toContain(expectedMap) }) + +test('processes without sourcemap', () => { + const configPath = resolve(__dirname, '../tsconfig.json') + const tsconfigString = readFileSync(configPath, { encoding: 'utf8' }) + const tsconfig = JSON.parse(tsconfigString) + tsconfig.compilerOptions.sourceMap = false + writeFileSync(configPath, JSON.stringify(tsconfig)) + const filePath = resolve(__dirname, './resources/TypeScript.vue') + const fileString = readFileSync(filePath, { encoding: 'utf8' }) + + expect(() => jestVue.process(fileString, filePath)).not.toThrow() + + writeFileSync(configPath, tsconfigString) +}) From 3c199c0d8d61f6739c0473226214f68ca6333897 Mon Sep 17 00:00:00 2001 From: rchaser53 Date: Wed, 14 Mar 2018 23:20:47 +0900 Subject: [PATCH 3/3] add try catch for the case of test failure --- test/TypeScript.spec.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/TypeScript.spec.js b/test/TypeScript.spec.js index c9a0d39f..eac46722 100644 --- a/test/TypeScript.spec.js +++ b/test/TypeScript.spec.js @@ -38,7 +38,12 @@ test('processes without sourcemap', () => { const filePath = resolve(__dirname, './resources/TypeScript.vue') const fileString = readFileSync(filePath, { encoding: 'utf8' }) - expect(() => jestVue.process(fileString, filePath)).not.toThrow() + try { + expect(() => jestVue.process(fileString, filePath)).not.toThrow() + } catch (err) { + writeFileSync(configPath, tsconfigString) + throw err + } writeFileSync(configPath, tsconfigString) })