@@ -287,14 +287,17 @@ async function mergePackageJson(pluginExports: Array<{ exportPath: string; shimF
287287 destPkg . exports [ './client' ] = {
288288 default : './dist/client.js' ,
289289 } ;
290+ // Point to @vitest /browser/context.js so that tests and init scripts share the same module
291+ // This is critical: the init script (locators.js) calls page.extend() on this module,
292+ // and tests must use the SAME module instance to see the extended methods
290293 destPkg . exports [ './context' ] = {
291294 types : './browser/context.d.ts' ,
292- default : './dist/context.js' ,
295+ default : './dist/@vitest/browser/ context.js' ,
293296 } ;
294297 // Also export ./browser/context for users importing @voidzero -dev/vite-plus/test/browser/context
295298 destPkg . exports [ './browser/context' ] = {
296299 types : './browser/context.d.ts' ,
297- default : './dist/context.js' ,
300+ default : './dist/@vitest/browser/ context.js' ,
298301 } ;
299302 destPkg . exports [ './locators' ] = {
300303 default : './dist/locators.js' ,
@@ -327,6 +330,21 @@ async function mergePackageJson(pluginExports: Array<{ exportPath: string; shimF
327330 default : './dist/@vitest/browser-preview/index.js' ,
328331 } ;
329332
333+ // Add browser/providers/* alias exports for compatibility
334+ // Some vitest examples use the nested path format
335+ destPkg . exports [ './browser/providers/playwright' ] = {
336+ types : './dist/@vitest/browser-playwright/index.d.ts' ,
337+ default : './dist/@vitest/browser-playwright/index.js' ,
338+ } ;
339+ destPkg . exports [ './browser/providers/webdriverio' ] = {
340+ types : './dist/@vitest/browser-webdriverio/index.d.ts' ,
341+ default : './dist/@vitest/browser-webdriverio/index.js' ,
342+ } ;
343+ destPkg . exports [ './browser/providers/preview' ] = {
344+ types : './dist/@vitest/browser-preview/index.d.ts' ,
345+ default : './dist/@vitest/browser-preview/index.js' ,
346+ } ;
347+
330348 // Add plugin exports for all bundled @vitest /* packages
331349 // This allows pnpm overrides to redirect: @vitest /runner -> vitest/plugins/runner
332350 for ( const { exportPath, shimFile } of pluginExports ) {
@@ -1343,8 +1361,11 @@ async function patchVitestBrowserPackage() {
13431361 // - tailwindcss: pulls in @tailwindcss/oxide
13441362 // Also exclude @vitest /ui (optional peer dependency) and its subpath
13451363 // Also exclude @vitest /mocker/node which imports @voidzero -dev/vite-plus-core
1364+ // Also exclude our package aliases to preserve module identity with init scripts
1365+ // This prevents Vite from pre-bundling our browser context, ensuring both init scripts
1366+ // (loaded via /@fs/) and tests use the same page singleton
13461367 const excludeReplacement =
1347- '$1\n "@vitest/browser",\n "@vitest/ui",\n "@vitest/ui/reporter",\n "@vitest/mocker/node",\n "vite",\n "@voidzero-dev/vite-plus-core",\n "@voidzero-dev/vite-plus-core/module-runner",\n "lightningcss",\n "@tailwindcss/oxide",\n "tailwindcss",$2' ;
1368+ '$1\n "@vitest/browser",\n "@vitest/ui",\n "@vitest/ui/reporter",\n "@vitest/mocker/node",\n "@voidzero-dev/vite-plus-test",\n "@voidzero-dev/vite-plus-test/browser",\n "@voidzero-dev/vite-plus-test/browser/context",\n "@voidzero-dev/vite-plus/test",\n "@voidzero-dev/vite-plus/test/browser",\n "@voidzero-dev/vite-plus/test/browser/context",\n " vite",\n "@voidzero-dev/vite-plus-core",\n "@voidzero-dev/vite-plus-core/module-runner",\n "lightningcss",\n "@tailwindcss/oxide",\n "tailwindcss",$2' ;
13481369 if ( excludePattern . test ( content ) ) {
13491370 content = content . replace ( excludePattern , excludeReplacement ) ;
13501371 console . log ( ' Patched exclude list with native deps' ) ;
0 commit comments