Skip to content

Commit

Permalink
fix(browser): support @testing-library/vue in browser mode out of the…
Browse files Browse the repository at this point in the history
… box
  • Loading branch information
sheremet-va committed Jun 3, 2024
1 parent 087fa87 commit 76b82e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
26 changes: 26 additions & 0 deletions packages/browser/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fileURLToPath } from 'node:url'
import { readFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import { basename, join, resolve } from 'pathe'
import sirv from 'sirv'
import type { ViteDevServer } from 'vite'
Expand Down Expand Up @@ -209,6 +210,31 @@ export default (project: WorkspaceProject, base = '/'): Plugin[] => {
},
BrowserContext(project),
DynamicImport(),
// TODO: remove this when @testing-library/vue supports ESM
{
name: 'vitest:browser:support-vue-testing-library',
config() {
return {
optimizeDeps: {
esbuildOptions: {
plugins: [
{
name: 'test-utils-rewrite',
setup(build) {
const _require = createRequire(import.meta.url)
build.onResolve({ filter: /@vue\/test-utils/ }, (args) => {
// resolve to CJS instead of the browser because the browser version expects a global Vue object
const resolved = _require.resolve(args.path, { paths: [args.importer] })
return { path: resolved }
})
},
},
],
},
},
}
},
},
]
}

Expand Down
16 changes: 0 additions & 16 deletions packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createRequire } from 'node:module'
import { resolve } from 'pathe'
import type { UserConfig } from 'vite'
import { defineConfig } from 'vite'
Expand Down Expand Up @@ -87,21 +86,6 @@ export const config: UserConfig = {
'vue',
'@vue/test-utils',
],
esbuildOptions: {
plugins: [
{
name: 'test-utils-rewrite',
setup(build) {
const _require = createRequire(import.meta.url)
build.onResolve({ filter: /@vue\/test-utils/ }, (args) => {
// resolve to CJS instead of the browser because the browser version expects a global Vue object
const resolved = _require.resolve(args.path, { paths: [args.importer] })
return { path: resolved }
})
},
},
],
},
},
test: {
browser: {
Expand Down

0 comments on commit 76b82e5

Please sign in to comment.