Skip to content

Commit

Permalink
fix: allow slots in vitest-browser-vue (#7120)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jan 13, 2025
1 parent cc39efc commit 2319f84
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/browser/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,15 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
}

// since we override the resolution in the esbuild plugin, Vite can no longer optimizer it
// have ?. until Vitest 3.0 for backwards compatibility
const vue = isPackageExists('vitest-browser-vue', fileRoot)
if (vue) {
// we override them in the esbuild plugin so optimizer can no longer intercept it
include.push(
'vitest-browser-vue',
'vitest-browser-vue > @vue/test-utils',
'vitest-browser-vue > @vue/test-utils > @vue/compiler-core',
)
}
const vueTestUtils = isPackageExists('@vue/test-utils', fileRoot)
if (vueTestUtils) {
include.push('@vue/test-utils')
Expand Down Expand Up @@ -522,10 +530,10 @@ body {
{
name: 'test-utils-rewrite',
setup(build) {
build.onResolve({ filter: /^@vue\/test-utils$/ }, (args) => {
const _require = getRequire()
// resolve to CJS instead of the browser because the browser version expects a global Vue object
const resolved = _require.resolve(args.path, {
// test-utils: resolve to CJS instead of the browser because the browser version expects a global Vue object
// compiler-core: only CJS version allows slots as strings
build.onResolve({ filter: /^@vue\/(test-utils|compiler-core)$/ }, (args) => {
const resolved = getRequire().resolve(args.path, {
paths: [args.importer],
})
return { path: resolved }
Expand Down

0 comments on commit 2319f84

Please sign in to comment.