test(compiler-sfc): add real tests for source maps (#704)
This commit is contained in:
parent
782db6d7f5
commit
430d4e10bb
@ -1,23 +1,40 @@
|
|||||||
import { parse } from '../src'
|
import { parse } from '../src'
|
||||||
import { mockWarn } from '@vue/shared'
|
import { mockWarn } from '@vue/shared'
|
||||||
import { baseParse, baseCompile } from '@vue/compiler-core'
|
import { baseParse, baseCompile } from '@vue/compiler-core'
|
||||||
|
import { SourceMapConsumer } from 'source-map'
|
||||||
|
|
||||||
describe('compiler:sfc', () => {
|
describe('compiler:sfc', () => {
|
||||||
mockWarn()
|
mockWarn()
|
||||||
|
|
||||||
describe('source map', () => {
|
describe('source map', () => {
|
||||||
test('style block', () => {
|
test('style block', () => {
|
||||||
const style = parse(`<style>\n.color {\n color: red;\n }\n</style>\n`)
|
// Padding determines how many blank lines will there be before the style block
|
||||||
.descriptor.styles[0]
|
const padding = Math.round(Math.random() * 10)
|
||||||
// TODO need to actually test this with SourceMapConsumer
|
const style = parse(
|
||||||
|
`${'\n'.repeat(padding)}<style>\n.color {\n color: red;\n }\n</style>\n`
|
||||||
|
).descriptor.styles[0]
|
||||||
|
|
||||||
expect(style.map).not.toBeUndefined()
|
expect(style.map).not.toBeUndefined()
|
||||||
|
|
||||||
|
const consumer = new SourceMapConsumer(style.map!)
|
||||||
|
consumer.eachMapping(mapping => {
|
||||||
|
expect(mapping.originalLine - mapping.generatedLine).toBe(padding)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('script block', () => {
|
test('script block', () => {
|
||||||
const script = parse(`<script>\nconsole.log(1)\n }\n</script>\n`)
|
// Padding determines how many blank lines will there be before the style block
|
||||||
.descriptor.script
|
const padding = Math.round(Math.random() * 10)
|
||||||
// TODO need to actually test this with SourceMapConsumer
|
const script = parse(
|
||||||
|
`${'\n'.repeat(padding)}<script>\nconsole.log(1)\n }\n</script>\n`
|
||||||
|
).descriptor.script
|
||||||
|
|
||||||
expect(script!.map).not.toBeUndefined()
|
expect(script!.map).not.toBeUndefined()
|
||||||
|
|
||||||
|
const consumer = new SourceMapConsumer(script!.map!)
|
||||||
|
consumer.eachMapping(mapping => {
|
||||||
|
expect(mapping.originalLine - mapping.generatedLine).toBe(padding)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user