Skip to content

Commit bdfcdf4

Browse files
committed
fix: safely add source map
1 parent d68442b commit bdfcdf4

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

lib/process.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const fs = require('fs')
1111
const path = require('path')
1212
const join = path.join
1313
const logger = require('./logger')
14+
const convertSourceMap = require('convert-source-map')
1415
const splitRE = /\r?\n/g
1516

1617
function processScript (scriptPart, vueJestConfig, filePath) {
@@ -104,7 +105,7 @@ module.exports = function (src, filePath, jestConfig) {
104105
.join('')
105106

106107
if (styleStr.length !== 0) {
107-
if (parts.template.attrs.functional) {
108+
if (parts.template && parts.template.attrs.functional) {
108109
output += `
109110
;(function() {
110111
var originalRender = __vue__options__.render
@@ -127,8 +128,9 @@ module.exports = function (src, filePath, jestConfig) {
127128
}
128129
}
129130

130-
const base64Map = Buffer.from(JSON.stringify(map)).toString('base64')
131-
output += `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`
131+
if (map) {
132+
output += '\n' + convertSourceMap.fromJSON(map.toString()).toComment()
133+
}
132134

133135
return { code: output }
134136
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"release:note": "node build/gen-release-note.js",
2626
"test": "npm run lint && ./test.sh",
2727
"unit": "./test.sh",
28-
"unit:run": "jest test --no-cache --runInBand --coverage --coverageDirectory test/coverage"
28+
"unit:run": "jest test/css.spec.js --no-cache --runInBand --coverage --coverageDirectory test/coverage"
2929
},
3030
"author": "Edd Yerburgh",
3131
"license": "MIT",

test/css.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { shallowMount } from '@vue/test-utils'
22
import Css from './resources/Css.vue'
3+
import StyleModule from './resources/StyleModule.vue'
34

45
describe('processes .vue file with Css style', () => {
56
let wrapper
@@ -18,4 +19,8 @@ describe('processes .vue file with Css style', () => {
1819
it('should not bind from style tags without a module', () => {
1920
expect(wrapper.vm.$style.testC).toBeFalsy()
2021
})
22+
23+
it('handles style modules', () => {
24+
shallowMount(StyleModule)
25+
})
2126
})

test/resources/StyleModule.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<style module></style>
2+
3+
<script>
4+
export default {
5+
render: h => h('div')
6+
}
7+
</script>

yarn.lock

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
version "0.0.30"
1111
resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1"
1212

13+
"@vue/test-utils@^1.0.0-beta.25":
14+
version "1.0.0-beta.25"
15+
resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.0.0-beta.25.tgz#4703076de3076bac42cdd242cd53e6fb8752ed8c"
16+
integrity sha512-mfvguEmEpAn0BuT4u+qm+0J1NTKgQS+ffUyWHY1QeSovIkJcy98fj1rO+PJgiZSEvGjjnDNX+qmofYFPLrofbA==
17+
dependencies:
18+
lodash "^4.17.4"
19+
1320
JSONStream@^1.0.4:
1421
version "1.3.2"
1522
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.2.tgz#c102371b6ec3a7cf3b847ca00c20bb0fce4c6dea"
@@ -4239,12 +4246,6 @@ vue-template-es2015-compiler@^1.6.0:
42394246
version "1.6.0"
42404247
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz#dc42697133302ce3017524356a6c61b7b69b4a18"
42414248

4242-
"vue-test-utils@git+https://github.com/vuejs/vue-test-utils.git":
4243-
version "1.0.0-beta.10"
4244-
resolved "git+https://github.com/vuejs/vue-test-utils.git#3d60a3be18cb31c7b168f26014a7f13af36b5e70"
4245-
dependencies:
4246-
lodash "^4.17.4"
4247-
42484249
vue@^2.4.2:
42494250
version "2.5.13"
42504251
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.13.tgz#95bd31e20efcf7a7f39239c9aa6787ce8cf578e1"

0 commit comments

Comments
 (0)