Testing Vue Template Compilation Features in dcloudio/uni-app
This test suite evaluates the Vue template compilation functionality in the uni-app framework, focusing on the transformation of view components and property bindings. It verifies the correct compilation of template code using Vue’s compiler-sfc package while incorporating uni-app specific compiler options.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-app-vite/__tests__/vue/compiler.spec.ts
import { compileTemplate } from '@vue/compiler-sfc'
import { uniOptions } from '../../src/plugin/uni/index'
const { compilerOptions } = uniOptions('vue')!
const filename = 'foo.vue'
function compile(source: string) {
return compileTemplate({
source,
filename,
id: filename,
compilerOptions: {
...compilerOptions,
},
})
}
function genCode(source: string) {
return compile(source).code
}
const codes = [
`<view :prop="options" :change:prop="renderScript.updateOptions"/>`,
]
describe('app-vue: compiler', () => {
codes.forEach((code) => {
test(code, () => {
expect(genCode(code)).toMatchSnapshot()
})
})
})