chore: fix tests

This commit is contained in:
Evan You 2022-06-14 15:35:30 +08:00
parent d6c0c2a992
commit 53a5ac9638
4 changed files with 37 additions and 13 deletions

View File

@ -87,6 +87,7 @@
"csstype": "^3.1.0"
},
"devDependencies": {
"@babel/parser": "^7.18.4",
"@microsoft/api-extractor": "^7.25.0",
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^22.0.0",
@ -109,10 +110,10 @@
"karma-esbuild": "^2.2.4",
"karma-jasmine": "^5.0.1",
"lint-staged": "^12.5.0",
"postcss": "^8.4.14",
"lodash": "^4.17.21",
"marked": "^4.0.16",
"minimist": "^1.2.6",
"postcss": "^8.4.14",
"prettier": "^2.6.2",
"puppeteer": "^14.3.0",
"rimraf": "^3.0.2",

View File

@ -56,8 +56,8 @@ export interface SFCDescriptor {
* a reload vs. re-render.
*
* Note: this comparison assumes the prev/next script are already identical,
* and only checks the special case where <script setup lang="ts"> unused import
* pruning result changes due to template changes.
* and only checks the special case where `<script setup lang="ts">` unused
* import pruning result changes due to template changes.
*/
shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean
}

View File

@ -3,7 +3,8 @@ import { parseComponent } from '../src/parseComponent'
describe('Single File Component parser', () => {
it('should parse', () => {
const res = parseComponent(`
const res = parseComponent(
`
<template>
<div>hi</div>
</template>
@ -24,7 +25,9 @@ describe('Single File Component parser', () => {
<div>
<style>nested should be ignored</style>
</div>
`)
`,
{ deindent: true }
)
expect(res.template!.content.trim()).toBe('<div>hi</div>')
expect(res.styles.length).toBe(4)
expect(res.styles[0].src).toBe('./test.css')
@ -72,7 +75,10 @@ describe('Single File Component parser', () => {
h1 { color: red }
</style>
`
const deindentDefault = parseComponent(content.trim(), { pad: false })
const deindentDefault = parseComponent(content.trim(), {
pad: false,
deindent: true
})
const deindentEnabled = parseComponent(content.trim(), {
pad: false,
deindent: true
@ -111,9 +117,18 @@ describe('Single File Component parser', () => {
h1 { color: red }
</style>
`
const padDefault = parseComponent(content.trim(), { pad: true })
const padLine = parseComponent(content.trim(), { pad: 'line' })
const padSpace = parseComponent(content.trim(), { pad: 'space' })
const padDefault = parseComponent(content.trim(), {
pad: true,
deindent: true
})
const padLine = parseComponent(content.trim(), {
pad: 'line',
deindent: true
})
const padSpace = parseComponent(content.trim(), {
pad: 'space',
deindent: true
})
expect(padDefault.script!.content).toBe(
Array(3 + 1).join('//\n') + '\nexport default {}\n'
@ -145,12 +160,15 @@ describe('Single File Component parser', () => {
})
it('should handle template blocks with lang as special text', () => {
const res = parseComponent(`
const res = parseComponent(
`
<template lang="pug">
div
h1(v-if='1 < 2') hello
</template>
`)
`,
{ deindent: true }
)
expect(res.template!.content.trim()).toBe(`div\n h1(v-if='1 < 2') hello`)
})
@ -164,7 +182,8 @@ describe('Single File Component parser', () => {
})
it('should handle custom blocks without parsing them', () => {
const res = parseComponent(`
const res = parseComponent(
`
<template>
<div></div>
</template>
@ -183,7 +202,9 @@ describe('Single File Component parser', () => {
}))
}
</test>
`)
`,
{ deindent: true }
)
expect(res.customBlocks.length).toBe(3)
const simpleExample = res.customBlocks[0]

View File

@ -4,6 +4,7 @@ importers:
.:
specifiers:
'@babel/parser': ^7.18.4
'@microsoft/api-extractor': ^7.25.0
'@rollup/plugin-alias': ^3.1.9
'@rollup/plugin-commonjs': ^22.0.0
@ -50,6 +51,7 @@ importers:
'@vue/compiler-sfc': link:packages/compiler-sfc
csstype: 3.1.0
devDependencies:
'@babel/parser': 7.18.4
'@microsoft/api-extractor': 7.25.0
'@rollup/plugin-alias': 3.1.9_rollup@2.75.6
'@rollup/plugin-commonjs': 22.0.0_rollup@2.75.6