File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,32 @@ import { defineConfig } from 'vitest/config'
22import { fileURLToPath } from 'node:url'
33import AutoImport from 'unplugin-auto-import/vite'
44import vue from '@vitejs/plugin-vue'
5+ import type { Plugin } from 'vite'
6+
7+ // During tests, SFC custom blocks with `lang="md"` (e.g. <spec lang="md">)
8+ // may be requested as `?vue&type=spec&index=0&lang.md` and Vite/Rollup can
9+ // attempt to parse them as JS modules, causing parse errors. Add a small
10+ // Vite plugin for the test config that returns a no-op module for those ids.
11+ function ignoreVueSpecBlocks ( ) {
12+ return {
13+ name : 'ignore-vue-spec-blocks' as const ,
14+ enforce : 'pre' ,
15+ transform ( code : string , id : string ) {
16+ try {
17+ if ( id && / [ ? & ] t y p e = s p e c (?: & | $ ) / . test ( id ) ) {
18+ // return an empty module so Rollup/Vite won't try to parse markdown
19+ return {
20+ code : 'export default {}' ,
21+ map : { mappings : '' }
22+ }
23+ }
24+ } catch {
25+ // noop
26+ }
27+ return null
28+ }
29+ } as Plugin
30+ }
531
632export default defineConfig ( {
733 test : {
@@ -21,6 +47,7 @@ export default defineConfig({
2147 imports : [ 'vue' , 'vue-i18n' ] ,
2248 dts : false
2349 } ) ,
50+ ignoreVueSpecBlocks ( ) ,
2451 vue ( )
2552 ]
2653} )
You can’t perform that action at this time.
0 commit comments