// TODO need more thorough tests here
import { compileTemplate } from '../src/compileTemplate'
import { compile } from '@vue/compiler-dom'
import { parse, SFCTemplateBlock } from '../src/parse'
const compiler = { compile }
test('should work', () => {
const source = `
`
const result = compileTemplate({ filename: 'example.vue', source, compiler })
expect(result.errors.length).toBe(0)
expect(result.source).toBe(source)
// should expose render fn
expect(result.code).toMatch(`export default function render()`)
})
test('preprocess pug', () => {
const template = parse(
`
body
h1 Pug Examples
div.container
p Cool Pug example!
`,
{ filename: 'example.vue', needMap: true }
).template as SFCTemplateBlock
const result = compileTemplate({
filename: 'example.vue',
source: template.content,
preprocessLang: template.lang,
compiler
})
expect(result.errors.length).toBe(0)
})
test('warn missing preprocessor', () => {
const template = parse(`\n\n`, {
filename: 'example.vue',
needMap: true
}).template as SFCTemplateBlock
const result = compileTemplate({
filename: 'example.vue',
compiler,
source: template.content,
preprocessLang: template.lang
})
expect(result.errors.length).toBe(1)
})