Skip to content

Commit 835602e

Browse files
TheCycoONEeddyerburgh
authored andcommitted
feat: generate inline source map (#115)
1 parent 4ac913d commit 835602e

File tree

3 files changed

+63
-61
lines changed

3 files changed

+63
-61
lines changed

lib/process.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,8 @@ module.exports = function (src, filePath, jestConfig) {
127127
}
128128
}
129129

130-
return { code: output, map }
130+
const base64Map = Buffer.from(JSON.stringify(map)).toString('base64')
131+
output += `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`
132+
133+
return { code: output }
131134
}

test/Babel.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ test('generates inline sourcemap', () => {
112112
const filePath = resolve(__dirname, './resources/Basic.vue')
113113
const fileString = readFileSync(filePath, { encoding: 'utf8' })
114114
const output = jestVue.process(fileString, filePath)
115-
expect(output.map).toMatchSnapshot()
115+
expect(output.code).toMatchSnapshot()
116116
})
117117

118118
test('generates inline sourcemap for .vue files using src attributes', () => {
119119
const filePath = resolve(__dirname, './resources/BasicSrc.vue')
120120
const fileString = readFileSync(filePath, { encoding: 'utf8' })
121121
const output = jestVue.process(fileString, filePath)
122-
expect(output.map).toMatchSnapshot()
122+
expect(output.code).toMatchSnapshot()
123123
})

test/__snapshots__/Babel.spec.js.snap

+57-58
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,82 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`generates inline sourcemap 1`] = `
4-
Object {
5-
"mappings": ";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AAHA;AAKA;AAPA;AASA;AACA;AACA;AACA;AAFA;AAIA;AACA;AACA;AACA;AACA;AAHA;AAjBA",
6-
"names": Array [],
7-
"sources": Array [
8-
"Basic.vue",
9-
],
10-
"sourcesContent": Array [
11-
"<template>
12-
<div class=\\"hello\\">
13-
<h1 :class=\\"headingClasses\\">{{ msg }}</h1>
14-
</div>
15-
</template>
4+
";(function(){
5+
'use strict';
166
17-
<script>
18-
export default {
19-
name: 'basic',
20-
computed: {
21-
headingClasses: function headingClasses() {
22-
return {
23-
red: this.isCrazy,
24-
blue: !this.isCrazy,
25-
shadow: this.isCrazy,
26-
};
27-
},
28-
},
29-
data: function data() {
7+
Object.defineProperty(exports, \\"__esModule\\", {
8+
value: true
9+
});
10+
//
11+
//
12+
//
13+
//
14+
//
15+
//
16+
17+
exports.default = {
18+
name: 'basic',
19+
computed: {
20+
headingClasses: function headingClasses() {
3021
return {
31-
msg: 'Welcome to Your Vue.js App',
32-
isCrazy: false,
22+
red: this.isCrazy,
23+
blue: !this.isCrazy,
24+
shadow: this.isCrazy
3325
};
34-
},
35-
methods: {
36-
toggleClass: function toggleClass() {
37-
this.isCrazy = !this.isCrazy;
38-
},
39-
},
40-
};
41-
</script>
42-
",
43-
],
44-
"version": 3,
45-
}
26+
}
27+
},
28+
data: function data() {
29+
return {
30+
msg: 'Welcome to Your Vue.js App',
31+
isCrazy: false
32+
};
33+
},
34+
methods: {
35+
toggleClass: function toggleClass() {
36+
this.isCrazy = !this.isCrazy;
37+
}
38+
}
39+
};
40+
})()
41+
var defaultExport = (module.exports.__esModule) ? module.exports.default : module.exports;var __vue__options__ = (typeof defaultExport === \\"function\\"? defaultExport.options: defaultExport)
42+
__vue__options__.render = function render () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:\\"hello\\"},[_c('h1',{class:_vm.headingClasses},[_vm._v(_vm._s(_vm.msg))])])}
43+
__vue__options__.staticRenderFns = []
44+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2ljLnZ1ZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7OztBQUdBO0FBQ0E7QUFDQTtBQUNBO0FBQ0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lzLmlzQ3Jhenk7XG4gICAgICAgICAgICB9LFxuICAgICAgICB9LFxuICAgIH07XG48L3NjcmlwdD5cbiJdfQ=="
4645
`;
4746

4847
exports[`generates inline sourcemap for .vue files using src attributes 1`] = `
49-
Object {
50-
"mappings": ";;;;;;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAHA;AAKA;AAPA;AASA;AACA;AACA;AACA;AAFA;AAIA;AACA;AACA;AACA;AACA;AAHA;AAjBA",
51-
"names": Array [],
52-
"sources": Array [
53-
"BasicSrc.vue",
54-
],
55-
"sourcesContent": Array [
56-
"export default {
48+
";(function(){
49+
'use strict';
50+
51+
Object.defineProperty(exports, \\"__esModule\\", {
52+
value: true
53+
});
54+
exports.default = {
5755
name: 'basic',
5856
computed: {
59-
headingClasses: function headingClasses () {
57+
headingClasses: function headingClasses() {
6058
return {
6159
red: this.isCrazy,
6260
blue: !this.isCrazy,
6361
shadow: this.isCrazy
64-
}
62+
};
6563
}
6664
},
67-
data: function data () {
65+
data: function data() {
6866
return {
6967
msg: 'Welcome to Your Vue.js App',
7068
isCrazy: false
71-
}
69+
};
7270
},
7371
methods: {
74-
toggleClass: function toggleClass () {
75-
this.isCrazy = !this.isCrazy
72+
toggleClass: function toggleClass() {
73+
this.isCrazy = !this.isCrazy;
7674
}
7775
}
78-
}
79-
",
80-
],
81-
"version": 3,
82-
}
76+
};
77+
})()
78+
var defaultExport = (module.exports.__esModule) ? module.exports.default : module.exports;var __vue__options__ = (typeof defaultExport === \\"function\\"? defaultExport.options: defaultExport)
79+
__vue__options__.render = function render () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:\\"hello\\"},[_c('h1',{class:_vm.headingClasses},[_vm._v(_vm._s(_vm.msg))])])}
80+
__vue__options__.staticRenderFns = []
81+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkJhc2ljU3JjLnZ1ZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7O0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFIQTtBQUtBO0FBUEE7QUFTQTtBQUNBO0FBQ0E7QUFDQTtBQUZBO0FBSUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUhBO0FBakJBIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGRlZmF1bHQge1xuICBuYW1lOiAnYmFzaWMnLFxuICBjb21wdXRlZDoge1xuICAgIGhlYWRpbmdDbGFzc2VzOiBmdW5jdGlvbiBoZWFkaW5nQ2xhc3NlcyAoKSB7XG4gICAgICByZXR1cm4ge1xuICAgICAgICByZWQ6IHRoaXMuaXNDcmF6eSxcbiAgICAgICAgYmx1ZTogIXRoaXMuaXNDcmF6eSxcbiAgICAgICAgc2hhZG93OiB0aGlzLmlzQ3JhenlcbiAgICAgIH1cbiAgICB9XG4gIH0sXG4gIGRhdGE6IGZ1bmN0aW9uIGRhdGEgKCkge1xuICAgIHJldHVybiB7XG4gICAgICBtc2c6ICdXZWxjb21lIHRvIFlvdXIgVnVlLmpzIEFwcCcsXG4gICAgICBpc0NyYXp5OiBmYWxzZVxuICAgIH1cbiAgfSxcbiAgbWV0aG9kczoge1xuICAgIHRvZ2dsZUNsYXNzOiBmdW5jdGlvbiB0b2dnbGVDbGFzcyAoKSB7XG4gICAgICB0aGlzLmlzQ3JhenkgPSAhdGhpcy5pc0NyYXp5XG4gICAgfVxuICB9XG59XG4iXX0="
8382
`;

0 commit comments

Comments
 (0)