Testing WXS and RenderJS Parsing Implementation in dcloudio/uni-app
This test suite validates the parsing functionality for WXS (WeiXin Script) and RenderJS code within uni-app components. It focuses on ensuring proper handling of script modules and their integration within Vue template structures.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-cli-shared/__tests__/wxs.spec.ts
import { parseVue } from '../src/vite'
import { parseWxsCode, parseWxsNodes } from '../src/vue'
describe('wxs', () => {
test('parseWxsCode', () => {
const renderjsCode = `<template><view></view><view></view></template>
<script>
export default {}
</script>
<script lang="renderjs" module="echarts">
export default{
mounted(){
console.log('mounted')
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
`
expect(
parseWxsCode(parseWxsNodes(parseVue(renderjsCode, [])), renderjsCode)
).toMatchSnapshot()
const wxsCode = `<template><view></view><view></view></template>
<script>
export default {}
</script>
<script lang="wxs" module="echarts">
export default{
mounted(){
console.log('mounted')
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
`
expect(
parseWxsCode(parseWxsNodes(parseVue(wxsCode, [])), wxsCode)
).toMatchSnapshot()
})
})