88 * - externals resolve through the module system's seed branch (the stable,
99 * version-independent part), once per page,
1010 * - resetChunks drops the cache and the externals memo (HMR).
11- * The production path runs against a fake `window.__DSH_MODULES__` and a
12- * stub script loader that simulates the executed chunk script by assigning
13- * the plugin-owned global factory registry.
11+ * The production path runs against a fake module system injected via
12+ * {@link setChunkModuleSystem} (mirroring the client half's `ctx.modules`
13+ * injection) and a stub script loader that simulates the executed chunk
14+ * script by assigning the plugin-owned global factory registry.
1415 */
1516import { beforeEach , describe , expect , it , vi } from 'vitest'
1617import './browser-globals.ts'
@@ -33,14 +34,10 @@ function installModuleSystem(): FakeModuleSystem {
3334 const fake : FakeModuleSystem = {
3435 import : vi . fn ( async ( specifier : string ) => ( { seed : specifier } ) ) ,
3536 }
36- ; ( globalThis as Record < string , unknown > ) . __DSH_MODULES__ = fake
37+ setChunkModuleSystem ( fake )
3738 return fake
3839}
3940
40- function removeModuleSystem ( ) : void {
41- delete ( globalThis as Record < string , unknown > ) . __DSH_MODULES__
42- }
43-
4441/** Simulate a chunk script executing: it assigns its factory to the registry. */
4542function simulateScript ( name : string , factory : ( require : ( spec : string ) => unknown ) => ChunkExports ) : void {
4643 const g = globalThis as { __dshChunks__ ?: Record < string , unknown > }
@@ -49,7 +46,6 @@ function simulateScript(name: string, factory: (require: (spec: string) => unkno
4946}
5047
5148beforeEach ( ( ) => {
52- removeModuleSystem ( )
5349 setChunkModuleSystem ( undefined )
5450 delete ( globalThis as Record < string , unknown > ) . __dshChunks__
5551 resetChunks ( )
@@ -89,9 +85,6 @@ describe('test-registry path (vitest / jsdom-less environments)', () => {
8985describe ( 'production path (script injection + global registry + externals require)' , ( ) => {
9086 it ( 'resolves externals through an injected ctx.modules system (rc.8 — no page global)' , async ( ) => {
9187 const modules = installModuleSystem ( )
92- // rc.8 drops window.__DSH_MODULES__; the client half injects ctx.modules.
93- removeModuleSystem ( )
94- setChunkModuleSystem ( modules )
9588 const loaded : string [ ] = [ ]
9689 setChunkScriptLoaderForTests ( async ( src ) => {
9790 loaded . push ( src )
0 commit comments