-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use correct source map names for script files imported over src (#…
…131)
- Loading branch information
1 parent
52b2d1a
commit 2ff90ee
Showing
3 changed files
with
63 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template src="./BasicSrc.html"></template> | ||
|
||
<script src="./BasicSrc.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { resolve } from 'path' | ||
import { readFileSync } from 'fs' | ||
import clearModule from 'clear-module' | ||
import cache from '../lib/cache' | ||
import jestVue from '../vue-jest' | ||
|
||
beforeEach(() => { | ||
cache.flushAll() | ||
clearModule.all() | ||
}) | ||
|
||
const getSourceMaps = code => { | ||
const sourceMapBase64 = /\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,(.*)/gim | ||
|
||
let matches | ||
let values = [] | ||
|
||
while ((matches = sourceMapBase64.exec(code)) !== null) { | ||
values.push(JSON.parse(Buffer.from(matches[1], 'base64').toString('ascii'))) | ||
} | ||
|
||
return values | ||
} | ||
|
||
test('generates source maps for .vue files', () => { | ||
const filePath = resolve(__dirname, './resources/Basic.vue') | ||
const fileString = readFileSync(filePath, { encoding: 'utf8' }) | ||
|
||
const { code } = jestVue.process(fileString, filePath, { | ||
moduleFileExtensions: ['js', 'vue'] | ||
}) | ||
|
||
const [template, js] = getSourceMaps(code) | ||
|
||
expect(js.sources[0]).toBe('Basic.vue') | ||
expect(template.sources[0]).toBe('Basic.vue') | ||
}) | ||
|
||
test('generates source maps using src attributes', () => { | ||
const filePath = resolve(__dirname, './resources/SourceMapsSrc.vue') | ||
const fileString = readFileSync(filePath, { encoding: 'utf8' }) | ||
|
||
const { code } = jestVue.process(fileString, filePath, { | ||
moduleFileExtensions: ['js', 'vue'] | ||
}) | ||
|
||
const [template, js] = getSourceMaps(code) | ||
|
||
expect(js.sources[0]).toBe('BasicSrc.js') | ||
expect(template.sources[0]).toBe('SourceMapsSrc.vue') | ||
}) |