From 8064d51cc79dc849ead9ebf7c95654535707d7a1 Mon Sep 17 00:00:00 2001 From: Christophe Sailly Date: Wed, 13 Dec 2017 13:47:46 +0100 Subject: [PATCH] feat(sourceMap): Make source-mapping of multi-files component working for codeCoverage --- lib/process.js | 7 ++++- test/Babel.spec.js | 7 +++++ test/__snapshots__/Babel.spec.js.snap | 37 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/process.js b/lib/process.js index a6b284e7..0d70621b 100644 --- a/lib/process.js +++ b/lib/process.js @@ -50,7 +50,12 @@ module.exports = function (src, path) { const script = result.code const inputMap = result.sourceMap - const map = generateSourceMap(script, '', path, src, inputMap) + let scriptSrc = src + if (parts.script && parts.script.src) { + scriptSrc = parts.script.content + } + + const map = generateSourceMap(script, '', path, scriptSrc, inputMap) let output = ';(function(){\n' + script + '\n})()\n' + 'if (module.exports.__esModule) module.exports = module.exports.default\n' + 'var __vue__options__ = (typeof module.exports === "function"' + diff --git a/test/Babel.spec.js b/test/Babel.spec.js index 87b99fe5..63e4b4a9 100644 --- a/test/Babel.spec.js +++ b/test/Babel.spec.js @@ -104,3 +104,10 @@ test('generates inline sourcemap', () => { const output = jestVue.process(fileString, filePath) expect(output.map).toMatchSnapshot() }) + +test('generates inline sourcemap for .vue files using src attributes', () => { + const filePath = resolve(__dirname, './resources/BasicSrc.vue') + const fileString = readFileSync(filePath, { encoding: 'utf8' }) + const output = jestVue.process(fileString, filePath) + expect(output.map).toMatchSnapshot() +}) diff --git a/test/__snapshots__/Babel.spec.js.snap b/test/__snapshots__/Babel.spec.js.snap index fa860ab1..c31b8c61 100644 --- a/test/__snapshots__/Babel.spec.js.snap +++ b/test/__snapshots__/Babel.spec.js.snap @@ -44,3 +44,40 @@ Object { "version": 3, } `; + +exports[`generates inline sourcemap for .vue files using src attributes 1`] = ` +Object { + "mappings": ";;;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAHA;AAKA;AAPA;AASA;AACA;AACA;AACA;AAFA;AAIA;AACA;AACA;AACA;AACA;AAHA;AAjBA", + "names": Array [], + "sources": Array [ + "BasicSrc.vue", + ], + "sourcesContent": Array [ + "export default { + name: 'basic', + computed: { + headingClasses: function headingClasses () { + return { + red: this.isCrazy, + blue: !this.isCrazy, + shadow: this.isCrazy + } + } + }, + data: function data () { + return { + msg: 'Welcome to Your Vue.js App', + isCrazy: false + } + }, + methods: { + toggleClass: function toggleClass () { + this.isCrazy = !this.isCrazy + } + } +} +", + ], + "version": 3, +} +`;