Skip to content

use empty string when sourceMapText is undefined #68

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

Merged
merged 3 commits into from
Mar 14, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/compilers/typescript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -64,5 +67,5 @@ module.exports = function compileTypescript (scriptContent) {
}
}

return compileBabel(res.outputText, JSON.parse(res.sourceMapText), inlineBabelConfig)
return compileBabel(res.outputText, inputSourceMap, inlineBabelConfig)
}
21 changes: 20 additions & 1 deletion test/TypeScript.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -28,3 +28,22 @@ 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' })

try {
expect(() => jestVue.process(fileString, filePath)).not.toThrow()
} catch (err) {
writeFileSync(configPath, tsconfigString)
throw err
}

writeFileSync(configPath, tsconfigString)
})