Skip to content

Commit ba016c8

Browse files
committed
test: add sourcemap test
1 parent d6a0c3b commit ba016c8

File tree

5 files changed

+25
-45
lines changed

5 files changed

+25
-45
lines changed

jest-vue.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const sourceMap = require('source-map')
44
const path = require('path')
55
const compileTemplate = require('./template-compiler')
66
const convert = require('convert-source-map')
7-
7+
const fs = require('fs')
88
const splitRE = /\r?\n/g
99

1010
function generateSourceMap (script, output, filePath, content, inputMap) {
@@ -54,6 +54,7 @@ function addTemplateMapping (content, parts, output, map, beforeLines) {
5454
})
5555
}
5656
}
57+
5758
module.exports = {
5859
process (src, path) {
5960
var parts = vueCompiler.parseComponent(src, { pad: true })
@@ -87,10 +88,10 @@ module.exports = {
8788
if (map) {
8889
output += '\n' + convert.fromJSON(map.toString()).toComment()
8990
}
91+
var wstream = fs.createWriteStream('myOutput.txt')
92+
wstream.write(convert.fromJSON(map.toString()).toComment())
93+
wstream.end()
9094

91-
return {
92-
code: output,
93-
map: map
94-
}
95+
return output
9596
}
9697
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"jest": {
3434
"moduleFileExtensions": [
3535
"js",
36+
"json",
3637
"vue"
3738
],
3839
"transform": {

test/Hello.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Vue from 'vue'
2+
import Hello from './resources/Hello.vue'
3+
import jestVue from '../jest-vue'
4+
import { resolve } from 'path'
5+
import { readFileSync } from 'fs'
6+
7+
test('processes .vue files', () => {
8+
const vm = new Vue(Hello).$mount()
9+
expect(typeof vm.$el).toBe('object')
10+
})
11+
12+
test('generates inline sourcemap', () => {
13+
const expectedMap = '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkhlbGxvLnZ1ZSJdLCJuYW1lcyI6W10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ICAgIG1ldGhvZHM6IHtcbiAgICAgICAgICAgIHRvZ2dsZUNsYXNzOiBmdW5jdGlvbiB0b2dnbGVDbGFzcygpIHtcbiAgICAgICAgICAgICAgICB0aGlzLmlzQ3JhenkgPSAhdGhpcy5pc0NyYXp5O1xuICAgICAgICAgICAgfSxcbiAgICAgICAgfSxcbiAgICB9O1xuPC9zY3JpcHQ+Il19'
14+
const filePath = resolve(__dirname, './resources/Hello.vue')
15+
const fileString = readFileSync(filePath, { encoding: 'utf8' })
16+
const output = jestVue.process(fileString, filePath)
17+
expect(output).toContain(expectedMap)
18+
})

test/HelloJs.spec.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/HelloVue.spec.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)