slicejs-web-framework 3.3.7 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,728 +1,738 @@
1
- import test from 'node:test';
2
- import assert from 'node:assert/strict';
3
- import { mkdtemp, rm, writeFile } from 'node:fs/promises';
4
- import { tmpdir } from 'node:os';
5
- import path from 'node:path';
6
- import { register } from 'node:module';
7
- import { pathToFileURL } from 'node:url';
8
-
9
- test('validateBundleModule rejects module missing Bundling V2 exports contract', async () => {
10
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
11
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
12
- await writeFile(
13
- loaderPath,
14
- `export async function resolve(specifier, context, nextResolve) {
15
- if (specifier === '/Components/components.js') {
16
- return {
17
- shortCircuit: true,
18
- url: 'data:text/javascript,export default {};',
19
- };
20
- }
21
- return nextResolve(specifier, context);
22
- }
23
- `,
24
- 'utf8'
25
- );
26
- register(pathToFileURL(loaderPath).href);
27
-
28
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
29
- const { default: Controller } = await import(controllerModuleUrl);
30
- const controller = new Controller();
31
- const originalWindow = globalThis.window;
32
-
33
- try {
34
- globalThis.window = {
35
- __slicePendingRegistrations: [],
36
- };
37
-
38
- assert.equal(
39
- typeof controller.validateBundleModule,
40
- 'function',
41
- 'Controller must expose validateBundleModule for Bundling V2 runtime contract checks'
42
- );
43
-
44
- if (typeof controller.validateBundleModule === 'function') {
45
- await assert.rejects(
46
- () => Promise.resolve(controller.validateBundleModule({ default: {} }, 'critical.js')),
47
- /missing bundling v2 exports contract/i
48
- );
49
- }
50
- } finally {
51
- globalThis.window = originalWindow;
52
- await rm(tempDir, { recursive: true, force: true });
53
- }
54
- });
55
-
56
- test('loadBundle marks requested bundle key and metadata bundleKey as loaded', async () => {
57
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
58
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
59
- await writeFile(
60
- loaderPath,
61
- `export async function resolve(specifier, context, nextResolve) {
62
- if (specifier === '/Components/components.js') {
63
- return {
64
- shortCircuit: true,
65
- url: 'data:text/javascript,export default {};',
66
- };
67
- }
68
- return nextResolve(specifier, context);
69
- }
70
- `,
71
- 'utf8'
72
- );
73
- register(pathToFileURL(loaderPath).href);
74
-
75
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
76
- const { default: Controller } = await import(controllerModuleUrl);
77
- const controller = new Controller();
78
- const originalSlice = globalThis.slice;
79
-
80
- controller.bundleConfig = {
81
- bundles: {
82
- routes: {
83
- dashboard: {
84
- file: 'dashboard.js',
85
- },
86
- },
87
- },
88
- };
89
-
90
- controller.importBundleOnce = async () => ({});
91
- controller.validateBundleModule = async () => ({
92
- metadata: {
93
- bundleKey: 'routes.dashboard.v2',
94
- type: 'route',
95
- },
96
- registerAll: async () => {},
97
- });
98
-
99
- try {
100
- globalThis.slice = {
101
- stylesManager: {},
102
- };
103
-
104
- await controller.loadBundle('dashboard');
105
-
106
- assert.equal(controller.loadedBundles.has('dashboard'), true);
107
- assert.equal(controller.loadedBundles.has('routes.dashboard.v2'), true);
108
- assert.equal(controller.criticalBundleLoaded, false);
109
- } finally {
110
- globalThis.slice = originalSlice;
111
- await rm(tempDir, { recursive: true, force: true });
112
- }
113
- });
114
-
115
- test('loadBundle resolves dependencies first and registers vendor-shared exports once', async () => {
116
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
117
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
118
- await writeFile(
119
- loaderPath,
120
- `export async function resolve(specifier, context, nextResolve) {
121
- if (specifier === '/Components/components.js') {
122
- return {
123
- shortCircuit: true,
124
- url: 'data:text/javascript,export default {};',
125
- };
126
- }
127
- return nextResolve(specifier, context);
128
- }
129
- `,
130
- 'utf8'
131
- );
132
- register(pathToFileURL(loaderPath).href);
133
-
134
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
135
- const { default: Controller } = await import(controllerModuleUrl);
136
- const controller = new Controller();
137
- const originalSlice = globalThis.slice;
138
- const originalWindow = globalThis.window;
139
-
140
- controller.bundleConfig = {
141
- bundles: {
142
- shared: {
143
- 'vendor-shared': {
144
- file: 'slice-bundle.vendor-shared.js',
145
- },
146
- },
147
- routes: {
148
- dashboard: {
149
- file: 'slice-bundle.dashboard.js',
150
- dependencies: ['vendor-shared'],
151
- },
152
- },
153
- },
154
- };
155
-
156
- const importOrder = [];
157
- const registerOrder = [];
158
- const importsByPath = {
159
- '/bundles/slice-bundle.vendor-shared.js': {
160
- SLICE_BUNDLE_META: {
161
- bundleKey: 'vendor-shared',
162
- type: 'shared',
163
- },
164
- SLICE_SHARED_DEPS: {
165
- 'vendors/dompurify': {
166
- sanitize: () => 'ok',
167
- },
168
- },
169
- registerAll: async () => {
170
- registerOrder.push('vendor-shared');
171
- },
172
- },
173
- '/bundles/slice-bundle.dashboard.js': {
174
- SLICE_BUNDLE_META: {
175
- bundleKey: 'dashboard',
176
- type: 'route',
177
- },
178
- registerAll: async () => {
179
- registerOrder.push('dashboard');
180
- },
181
- },
182
- };
183
-
184
- controller.importBundleOnce = async (bundlePath) => {
185
- importOrder.push(bundlePath);
186
- return importsByPath[bundlePath];
187
- };
188
-
189
- try {
190
- globalThis.slice = {
191
- stylesManager: {},
192
- };
193
- globalThis.window = {
194
- __SLICE_SHARED_DEPS__: {},
195
- };
196
-
197
- await controller.loadBundle('dashboard');
198
- await controller.loadBundle('dashboard');
199
-
200
- assert.deepEqual(importOrder, ['/bundles/slice-bundle.vendor-shared.js', '/bundles/slice-bundle.dashboard.js']);
201
- assert.deepEqual(registerOrder, ['vendor-shared', 'dashboard']);
202
- assert.equal(typeof globalThis.window.__SLICE_SHARED_DEPS__['vendors/dompurify']?.sanitize, 'function');
203
- } finally {
204
- globalThis.slice = originalSlice;
205
- globalThis.window = originalWindow;
206
- await rm(tempDir, { recursive: true, force: true });
207
- }
208
- });
209
-
210
- test('loadBundle resolves vendor-shared dependency from bundles.vendorShared config shape', async () => {
211
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
212
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
213
- await writeFile(
214
- loaderPath,
215
- `export async function resolve(specifier, context, nextResolve) {
216
- if (specifier === '/Components/components.js') {
217
- return {
218
- shortCircuit: true,
219
- url: 'data:text/javascript,export default {};',
220
- };
221
- }
222
- return nextResolve(specifier, context);
223
- }
224
- `,
225
- 'utf8'
226
- );
227
- register(pathToFileURL(loaderPath).href);
228
-
229
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
230
- const { default: Controller } = await import(controllerModuleUrl);
231
- const controller = new Controller();
232
- const originalSlice = globalThis.slice;
233
- const originalWindow = globalThis.window;
234
-
235
- controller.bundleConfig = {
236
- bundles: {
237
- vendorShared: {
238
- file: 'slice-bundle.vendor-shared.js',
239
- },
240
- routes: {
241
- dashboard: {
242
- file: 'slice-bundle.dashboard.js',
243
- dependencies: ['vendor-shared'],
244
- },
245
- },
246
- },
247
- };
248
-
249
- const importOrder = [];
250
- const registerOrder = [];
251
- const importsByPath = {
252
- '/bundles/slice-bundle.vendor-shared.js': {
253
- SLICE_BUNDLE_META: {
254
- bundleKey: 'vendor-shared',
255
- type: 'shared',
256
- },
257
- SLICE_SHARED_DEPS: {
258
- 'vendors/dompurify': {
259
- sanitize: () => 'ok',
260
- },
261
- },
262
- registerAll: async () => {
263
- registerOrder.push('vendor-shared');
264
- },
265
- },
266
- '/bundles/slice-bundle.dashboard.js': {
267
- SLICE_BUNDLE_META: {
268
- bundleKey: 'dashboard',
269
- type: 'route',
270
- },
271
- registerAll: async () => {
272
- registerOrder.push('dashboard');
273
- },
274
- },
275
- };
276
-
277
- controller.importBundleOnce = async (bundlePath) => {
278
- importOrder.push(bundlePath);
279
- return importsByPath[bundlePath];
280
- };
281
-
282
- try {
283
- globalThis.slice = {
284
- stylesManager: {},
285
- };
286
- globalThis.window = {
287
- __SLICE_SHARED_DEPS__: {},
288
- };
289
-
290
- await controller.loadBundle('dashboard');
291
-
292
- assert.deepEqual(importOrder, ['/bundles/slice-bundle.vendor-shared.js', '/bundles/slice-bundle.dashboard.js']);
293
- assert.deepEqual(registerOrder, ['vendor-shared', 'dashboard']);
294
- assert.equal(typeof globalThis.window.__SLICE_SHARED_DEPS__['vendors/dompurify']?.sanitize, 'function');
295
- } finally {
296
- globalThis.slice = originalSlice;
297
- globalThis.window = originalWindow;
298
- await rm(tempDir, { recursive: true, force: true });
299
- }
300
- });
301
-
302
- test('loadBundle registers vendor-shared dependencies from registerAll return when SLICE_SHARED_DEPS export is absent', async () => {
303
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
304
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
305
- await writeFile(
306
- loaderPath,
307
- `export async function resolve(specifier, context, nextResolve) {
308
- if (specifier === '/Components/components.js') {
309
- return {
310
- shortCircuit: true,
311
- url: 'data:text/javascript,export default {};',
312
- };
313
- }
314
- return nextResolve(specifier, context);
315
- }
316
- `,
317
- 'utf8'
318
- );
319
- register(pathToFileURL(loaderPath).href);
320
-
321
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
322
- const { default: Controller } = await import(controllerModuleUrl);
323
- const controller = new Controller();
324
- const originalSlice = globalThis.slice;
325
- const originalWindow = globalThis.window;
326
-
327
- controller.bundleConfig = {
328
- bundles: {
329
- vendorShared: {
330
- file: 'slice-bundle.vendor-shared.js',
331
- },
332
- routes: {
333
- dashboard: {
334
- file: 'slice-bundle.dashboard.js',
335
- dependencies: ['vendor-shared'],
336
- },
337
- },
338
- },
339
- };
340
-
341
- const importsByPath = {
342
- '/bundles/slice-bundle.vendor-shared.js': {
343
- SLICE_BUNDLE_META: {
344
- bundleKey: 'vendor-shared',
345
- type: 'shared',
346
- },
347
- registerAll: async () => ({
348
- 'vendors/dompurify': {
349
- sanitize: () => 'ok',
350
- },
351
- }),
352
- },
353
- '/bundles/slice-bundle.dashboard.js': {
354
- SLICE_BUNDLE_META: {
355
- bundleKey: 'dashboard',
356
- type: 'route',
357
- },
358
- registerAll: async () => {},
359
- },
360
- };
361
-
362
- controller.importBundleOnce = async (bundlePath) => importsByPath[bundlePath];
363
-
364
- try {
365
- globalThis.slice = {
366
- stylesManager: {},
367
- };
368
- globalThis.window = {
369
- __SLICE_SHARED_DEPS__: {},
370
- };
371
-
372
- await controller.loadBundle('dashboard');
373
-
374
- assert.equal(typeof globalThis.window.__SLICE_SHARED_DEPS__['vendors/dompurify']?.sanitize, 'function');
375
- } finally {
376
- globalThis.slice = originalSlice;
377
- globalThis.window = originalWindow;
378
- await rm(tempDir, { recursive: true, force: true });
379
- }
380
- });
381
-
382
- test('loadBundle appends bundle hash as query param when importing bundle files', async () => {
383
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
384
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
385
- await writeFile(
386
- loaderPath,
387
- `export async function resolve(specifier, context, nextResolve) {
388
- if (specifier === '/Components/components.js') {
389
- return {
390
- shortCircuit: true,
391
- url: 'data:text/javascript,export default {};',
392
- };
393
- }
394
- return nextResolve(specifier, context);
395
- }
396
- `,
397
- 'utf8'
398
- );
399
- register(pathToFileURL(loaderPath).href);
400
-
401
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
402
- const { default: Controller } = await import(controllerModuleUrl);
403
- const controller = new Controller();
404
- const originalSlice = globalThis.slice;
405
-
406
- controller.bundleConfig = {
407
- bundles: {
408
- routes: {
409
- dashboard: {
410
- file: 'slice-bundle.dashboard.js',
411
- hash: 'abc123hash',
412
- },
413
- },
414
- },
415
- };
416
-
417
- let importedPath = null;
418
- controller.importBundleOnce = async (bundlePath) => {
419
- importedPath = bundlePath;
420
- return {
421
- SLICE_BUNDLE_META: {
422
- bundleKey: 'dashboard',
423
- type: 'route',
424
- },
425
- registerAll: async () => {},
426
- };
427
- };
428
-
429
- try {
430
- globalThis.slice = {
431
- stylesManager: {},
432
- };
433
-
434
- await controller.loadBundle('dashboard');
435
- assert.equal(importedPath, '/bundles/slice-bundle.dashboard.js?v=abc123hash');
436
- } finally {
437
- globalThis.slice = originalSlice;
438
- await rm(tempDir, { recursive: true, force: true });
439
- }
440
- });
441
-
442
- test('loadBundle dedupes concurrent and repeated alias/case requests using canonical bundle key', async () => {
443
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
444
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
445
- await writeFile(
446
- loaderPath,
447
- `export async function resolve(specifier, context, nextResolve) {
448
- if (specifier === '/Components/components.js') {
449
- return {
450
- shortCircuit: true,
451
- url: 'data:text/javascript,export default {};',
452
- };
453
- }
454
- return nextResolve(specifier, context);
455
- }
456
- `,
457
- 'utf8'
458
- );
459
- register(pathToFileURL(loaderPath).href);
460
-
461
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
462
- const { default: Controller } = await import(controllerModuleUrl);
463
- const controller = new Controller();
464
- const originalSlice = globalThis.slice;
465
-
466
- controller.bundleConfig = {
467
- bundles: {
468
- routes: {
469
- dashboard: {
470
- file: 'slice-bundle.dashboard.js',
471
- },
472
- },
473
- },
474
- };
475
-
476
- let registerCallCount = 0;
477
- controller.importBundleOnce = async () => ({
478
- SLICE_BUNDLE_META: {
479
- bundleKey: 'routes.dashboard.v2',
480
- type: 'route',
481
- },
482
- registerAll: async () => {
483
- registerCallCount += 1;
484
- await new Promise((resolve) => setTimeout(resolve, 10));
485
- },
486
- });
487
-
488
- try {
489
- globalThis.slice = {
490
- stylesManager: {},
491
- };
492
-
493
- await Promise.all([
494
- controller.loadBundle('dashboard'),
495
- controller.loadBundle('DASHBOARD'),
496
- ]);
497
-
498
- await controller.loadBundle('Dashboard');
499
-
500
- assert.equal(registerCallCount, 1);
501
- assert.equal(controller.loadedBundles.has('dashboard'), true);
502
- assert.equal(controller.loadedBundles.has('routes.dashboard.v2'), true);
503
- assert.equal(controller.bundleLoadPromises.size, 0);
504
- } finally {
505
- globalThis.slice = originalSlice;
506
- await rm(tempDir, { recursive: true, force: true });
507
- }
508
- });
509
-
510
- test('registerVendorSharedDependencies only runs for vendor-shared canonical bundle or explicit metadata flag', async () => {
511
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
512
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
513
- await writeFile(
514
- loaderPath,
515
- `export async function resolve(specifier, context, nextResolve) {
516
- if (specifier === '/Components/components.js') {
517
- return {
518
- shortCircuit: true,
519
- url: 'data:text/javascript,export default {};',
520
- };
521
- }
522
- return nextResolve(specifier, context);
523
- }
524
- `,
525
- 'utf8'
526
- );
527
- register(pathToFileURL(loaderPath).href);
528
-
529
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
530
- const { default: Controller } = await import(controllerModuleUrl);
531
- const controller = new Controller();
532
- const originalWindow = globalThis.window;
533
-
534
- try {
535
- globalThis.window = {
536
- __SLICE_SHARED_DEPS__: {},
537
- };
538
-
539
- controller.registerVendorSharedDependencies(
540
- {
541
- SLICE_SHARED_DEPS: {
542
- shouldNotLoad: true,
543
- },
544
- },
545
- {
546
- type: 'shared',
547
- bundleKey: 'app-shared',
548
- },
549
- 'app-shared'
550
- );
551
-
552
- assert.equal(globalThis.window.__SLICE_SHARED_DEPS__.shouldNotLoad, undefined);
553
-
554
- controller.registerVendorSharedDependencies(
555
- {
556
- SLICE_SHARED_DEPS: {
557
- explicitFlagDependency: true,
558
- },
559
- },
560
- {
561
- type: 'shared',
562
- bundleKey: 'app-shared',
563
- registerVendorSharedDependencies: true,
564
- },
565
- 'app-shared'
566
- );
567
-
568
- assert.equal(globalThis.window.__SLICE_SHARED_DEPS__.explicitFlagDependency, true);
569
- } finally {
570
- globalThis.window = originalWindow;
571
- await rm(tempDir, { recursive: true, force: true });
572
- }
573
- });
574
-
575
- test('Slice init fails fast with contextual error on invalid Bundling V2 contract path', async () => {
576
- const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-init-loader-'));
577
- const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
578
- await writeFile(
579
- loaderPath,
580
- `export async function resolve(specifier, context, nextResolve) {
581
- if (specifier === '/Components/components.js') {
582
- return {
583
- shortCircuit: true,
584
- url: 'data:text/javascript,export default {};',
585
- };
586
- }
587
- return nextResolve(specifier, context);
588
- }
589
- `,
590
- 'utf8'
591
- );
592
- register(pathToFileURL(loaderPath).href);
593
-
594
- const originalWindow = globalThis.window;
595
- const originalDocument = globalThis.document;
596
- const originalFetch = globalThis.fetch;
597
- const originalAlert = globalThis.alert;
598
- const originalSliceDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'slice');
599
- const originalConsoleLog = console.log;
600
- const originalConsoleWarn = console.warn;
601
- const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
602
- const { default: Controller } = await import(controllerModuleUrl);
603
- const originalLoadBundle = Controller.prototype.loadBundle;
604
-
605
- const loggedMessages = [];
606
-
607
- try {
608
- globalThis.window = {
609
- location: {
610
- pathname: '/dashboard',
611
- origin: 'http://localhost',
612
- },
613
- };
614
-
615
- Object.defineProperty(globalThis, 'slice', {
616
- configurable: true,
617
- get() {
618
- return globalThis.window?.slice;
619
- },
620
- set(value) {
621
- if (!globalThis.window) {
622
- globalThis.window = {};
623
- }
624
- globalThis.window.slice = value;
625
- },
626
- });
627
-
628
- Controller.prototype.loadBundle = async () => {
629
- throw new Error(
630
- 'Bundle "critical" missing Bundling V2 exports contract: requires SLICE_BUNDLE_META and registerAll'
631
- );
632
- };
633
-
634
- globalThis.document = {
635
- head: {
636
- appendChild() {},
637
- },
638
- body: {
639
- appendChild() {},
640
- },
641
- createElement() {
642
- return {
643
- appendChild() {},
644
- innerHTML: '',
645
- id: '',
646
- };
647
- },
648
- createTextNode() {
649
- return {};
650
- },
651
- addEventListener() {},
652
- };
653
-
654
- globalThis.alert = () => {};
655
- console.log = (...args) => {
656
- loggedMessages.push(args.map(String).join(' '));
657
- };
658
- console.warn = () => {};
659
-
660
- globalThis.fetch = async (url) => {
661
- if (url === '/sliceConfig.json') {
662
- return {
663
- ok: true,
664
- json: async () => ({
665
- paths: {
666
- routesFile: '/routes.js',
667
- components: {},
668
- },
669
- themeManager: { enabled: false },
670
- stylesManager: { requestedStyles: [] },
671
- logger: { enabled: false },
672
- debugger: { enabled: false },
673
- loading: { enabled: false },
674
- events: { enabled: false },
675
- context: { enabled: false },
676
- }),
677
- };
678
- }
679
-
680
- if (url === '/slice-env.json') {
681
- return {
682
- ok: true,
683
- json: async () => ({ mode: 'production' }),
684
- };
685
- }
686
-
687
- if (url === '/bundles/bundle.config.json') {
688
- return {
689
- ok: true,
690
- json: async () => ({
691
- production: true,
692
- bundles: {
693
- critical: { file: 'critical.js' },
694
- routes: {},
695
- },
696
- routeBundles: {},
697
- }),
698
- };
699
- }
700
-
701
- throw new Error(`Unexpected fetch URL: ${url}`);
702
- };
703
-
704
- const sliceModuleUrl = new URL(`../Slice.js?fail-fast-test=${Date.now()}`, import.meta.url).href;
705
-
706
- await assert.rejects(() => import(sliceModuleUrl), /Bundling V2 initialization failed/i);
707
-
708
- assert.equal(
709
- loggedMessages.some((message) => message.includes('Using individual component loading (no bundles found)')),
710
- false,
711
- 'init must not log fallback bundle message on Bundling V2 contract failure'
712
- );
713
- } finally {
714
- Controller.prototype.loadBundle = originalLoadBundle;
715
- globalThis.window = originalWindow;
716
- globalThis.document = originalDocument;
717
- globalThis.fetch = originalFetch;
718
- globalThis.alert = originalAlert;
719
- if (originalSliceDescriptor) {
720
- Object.defineProperty(globalThis, 'slice', originalSliceDescriptor);
721
- } else {
722
- delete globalThis.slice;
723
- }
724
- console.log = originalConsoleLog;
725
- console.warn = originalConsoleWarn;
726
- await rm(tempDir, { recursive: true, force: true });
727
- }
728
- });
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { mkdtemp, rm, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import path from 'node:path';
6
+ import { register } from 'node:module';
7
+ import { pathToFileURL } from 'node:url';
8
+
9
+ test('validateBundleModule rejects module missing Bundling V2 exports contract', async () => {
10
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
11
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
12
+ await writeFile(
13
+ loaderPath,
14
+ `export async function resolve(specifier, context, nextResolve) {
15
+ if (specifier === '/Components/components.js') {
16
+ return {
17
+ shortCircuit: true,
18
+ url: 'data:text/javascript,export default {};',
19
+ };
20
+ }
21
+ return nextResolve(specifier, context);
22
+ }
23
+ `,
24
+ 'utf8'
25
+ );
26
+ register(pathToFileURL(loaderPath).href);
27
+
28
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
29
+ const { default: Controller } = await import(controllerModuleUrl);
30
+ const controller = new Controller();
31
+ const originalWindow = globalThis.window;
32
+
33
+ try {
34
+ globalThis.window = {
35
+ __slicePendingRegistrations: [],
36
+ };
37
+
38
+ assert.equal(
39
+ typeof controller.validateBundleModule,
40
+ 'function',
41
+ 'Controller must expose validateBundleModule for Bundling V2 runtime contract checks'
42
+ );
43
+
44
+ if (typeof controller.validateBundleModule === 'function') {
45
+ await assert.rejects(
46
+ () => Promise.resolve(controller.validateBundleModule({ default: {} }, 'critical.js')),
47
+ /missing bundling v2 exports contract/i
48
+ );
49
+ }
50
+ } finally {
51
+ globalThis.window = originalWindow;
52
+ await rm(tempDir, { recursive: true, force: true });
53
+ }
54
+ });
55
+
56
+ test('loadBundle marks requested bundle key and metadata bundleKey as loaded', async () => {
57
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
58
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
59
+ await writeFile(
60
+ loaderPath,
61
+ `export async function resolve(specifier, context, nextResolve) {
62
+ if (specifier === '/Components/components.js') {
63
+ return {
64
+ shortCircuit: true,
65
+ url: 'data:text/javascript,export default {};',
66
+ };
67
+ }
68
+ return nextResolve(specifier, context);
69
+ }
70
+ `,
71
+ 'utf8'
72
+ );
73
+ register(pathToFileURL(loaderPath).href);
74
+
75
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
76
+ const { default: Controller } = await import(controllerModuleUrl);
77
+ const controller = new Controller();
78
+ const originalSlice = globalThis.slice;
79
+
80
+ controller.bundleConfig = {
81
+ bundles: {
82
+ routes: {
83
+ dashboard: {
84
+ file: 'dashboard.js',
85
+ },
86
+ },
87
+ },
88
+ };
89
+
90
+ controller.importBundleOnce = async () => ({});
91
+ controller.validateBundleModule = async () => ({
92
+ metadata: {
93
+ bundleKey: 'routes.dashboard.v2',
94
+ type: 'route',
95
+ },
96
+ registerAll: async () => {},
97
+ });
98
+
99
+ try {
100
+ globalThis.slice = {
101
+ stylesManager: {},
102
+ };
103
+
104
+ await controller.loadBundle('dashboard');
105
+
106
+ assert.equal(controller.loadedBundles.has('dashboard'), true);
107
+ assert.equal(controller.loadedBundles.has('routes.dashboard.v2'), true);
108
+ assert.equal(controller.criticalBundleLoaded, false);
109
+ } finally {
110
+ globalThis.slice = originalSlice;
111
+ await rm(tempDir, { recursive: true, force: true });
112
+ }
113
+ });
114
+
115
+ test('loadBundle resolves dependencies first and registers vendor-shared exports once', async () => {
116
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
117
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
118
+ await writeFile(
119
+ loaderPath,
120
+ `export async function resolve(specifier, context, nextResolve) {
121
+ if (specifier === '/Components/components.js') {
122
+ return {
123
+ shortCircuit: true,
124
+ url: 'data:text/javascript,export default {};',
125
+ };
126
+ }
127
+ return nextResolve(specifier, context);
128
+ }
129
+ `,
130
+ 'utf8'
131
+ );
132
+ register(pathToFileURL(loaderPath).href);
133
+
134
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
135
+ const { default: Controller } = await import(controllerModuleUrl);
136
+ const controller = new Controller();
137
+ const originalSlice = globalThis.slice;
138
+ const originalWindow = globalThis.window;
139
+
140
+ controller.bundleConfig = {
141
+ bundles: {
142
+ shared: {
143
+ 'vendor-shared': {
144
+ file: 'slice-bundle.vendor-shared.js',
145
+ },
146
+ },
147
+ routes: {
148
+ dashboard: {
149
+ file: 'slice-bundle.dashboard.js',
150
+ dependencies: ['vendor-shared'],
151
+ },
152
+ },
153
+ },
154
+ };
155
+
156
+ const importOrder = [];
157
+ const registerOrder = [];
158
+ const importsByPath = {
159
+ '/bundles/slice-bundle.vendor-shared.js': {
160
+ SLICE_BUNDLE_META: {
161
+ bundleKey: 'vendor-shared',
162
+ type: 'shared',
163
+ },
164
+ SLICE_SHARED_DEPS: {
165
+ 'vendors/dompurify': {
166
+ sanitize: () => 'ok',
167
+ },
168
+ },
169
+ registerAll: async () => {
170
+ registerOrder.push('vendor-shared');
171
+ },
172
+ },
173
+ '/bundles/slice-bundle.dashboard.js': {
174
+ SLICE_BUNDLE_META: {
175
+ bundleKey: 'dashboard',
176
+ type: 'route',
177
+ },
178
+ registerAll: async () => {
179
+ registerOrder.push('dashboard');
180
+ },
181
+ },
182
+ };
183
+
184
+ controller.importBundleOnce = async (bundlePath) => {
185
+ importOrder.push(bundlePath);
186
+ return importsByPath[bundlePath];
187
+ };
188
+
189
+ try {
190
+ globalThis.slice = {
191
+ stylesManager: {},
192
+ };
193
+ globalThis.window = {
194
+ __SLICE_SHARED_DEPS__: {},
195
+ };
196
+
197
+ await controller.loadBundle('dashboard');
198
+ await controller.loadBundle('dashboard');
199
+
200
+ assert.deepEqual(importOrder, ['/bundles/slice-bundle.vendor-shared.js', '/bundles/slice-bundle.dashboard.js']);
201
+ assert.deepEqual(registerOrder, ['vendor-shared', 'dashboard']);
202
+ assert.equal(typeof globalThis.window.__SLICE_SHARED_DEPS__['vendors/dompurify']?.sanitize, 'function');
203
+ } finally {
204
+ globalThis.slice = originalSlice;
205
+ globalThis.window = originalWindow;
206
+ await rm(tempDir, { recursive: true, force: true });
207
+ }
208
+ });
209
+
210
+ test('loadBundle resolves vendor-shared dependency from bundles.vendorShared config shape', async () => {
211
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
212
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
213
+ await writeFile(
214
+ loaderPath,
215
+ `export async function resolve(specifier, context, nextResolve) {
216
+ if (specifier === '/Components/components.js') {
217
+ return {
218
+ shortCircuit: true,
219
+ url: 'data:text/javascript,export default {};',
220
+ };
221
+ }
222
+ return nextResolve(specifier, context);
223
+ }
224
+ `,
225
+ 'utf8'
226
+ );
227
+ register(pathToFileURL(loaderPath).href);
228
+
229
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
230
+ const { default: Controller } = await import(controllerModuleUrl);
231
+ const controller = new Controller();
232
+ const originalSlice = globalThis.slice;
233
+ const originalWindow = globalThis.window;
234
+
235
+ controller.bundleConfig = {
236
+ bundles: {
237
+ vendorShared: {
238
+ file: 'slice-bundle.vendor-shared.js',
239
+ },
240
+ routes: {
241
+ dashboard: {
242
+ file: 'slice-bundle.dashboard.js',
243
+ dependencies: ['vendor-shared'],
244
+ },
245
+ },
246
+ },
247
+ };
248
+
249
+ const importOrder = [];
250
+ const registerOrder = [];
251
+ const importsByPath = {
252
+ '/bundles/slice-bundle.vendor-shared.js': {
253
+ SLICE_BUNDLE_META: {
254
+ bundleKey: 'vendor-shared',
255
+ type: 'shared',
256
+ },
257
+ SLICE_SHARED_DEPS: {
258
+ 'vendors/dompurify': {
259
+ sanitize: () => 'ok',
260
+ },
261
+ },
262
+ registerAll: async () => {
263
+ registerOrder.push('vendor-shared');
264
+ },
265
+ },
266
+ '/bundles/slice-bundle.dashboard.js': {
267
+ SLICE_BUNDLE_META: {
268
+ bundleKey: 'dashboard',
269
+ type: 'route',
270
+ },
271
+ registerAll: async () => {
272
+ registerOrder.push('dashboard');
273
+ },
274
+ },
275
+ };
276
+
277
+ controller.importBundleOnce = async (bundlePath) => {
278
+ importOrder.push(bundlePath);
279
+ return importsByPath[bundlePath];
280
+ };
281
+
282
+ try {
283
+ globalThis.slice = {
284
+ stylesManager: {},
285
+ };
286
+ globalThis.window = {
287
+ __SLICE_SHARED_DEPS__: {},
288
+ };
289
+
290
+ await controller.loadBundle('dashboard');
291
+
292
+ assert.deepEqual(importOrder, ['/bundles/slice-bundle.vendor-shared.js', '/bundles/slice-bundle.dashboard.js']);
293
+ assert.deepEqual(registerOrder, ['vendor-shared', 'dashboard']);
294
+ assert.equal(typeof globalThis.window.__SLICE_SHARED_DEPS__['vendors/dompurify']?.sanitize, 'function');
295
+ } finally {
296
+ globalThis.slice = originalSlice;
297
+ globalThis.window = originalWindow;
298
+ await rm(tempDir, { recursive: true, force: true });
299
+ }
300
+ });
301
+
302
+ test('loadBundle registers vendor-shared dependencies from registerAll return when SLICE_SHARED_DEPS export is absent', async () => {
303
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
304
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
305
+ await writeFile(
306
+ loaderPath,
307
+ `export async function resolve(specifier, context, nextResolve) {
308
+ if (specifier === '/Components/components.js') {
309
+ return {
310
+ shortCircuit: true,
311
+ url: 'data:text/javascript,export default {};',
312
+ };
313
+ }
314
+ return nextResolve(specifier, context);
315
+ }
316
+ `,
317
+ 'utf8'
318
+ );
319
+ register(pathToFileURL(loaderPath).href);
320
+
321
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
322
+ const { default: Controller } = await import(controllerModuleUrl);
323
+ const controller = new Controller();
324
+ const originalSlice = globalThis.slice;
325
+ const originalWindow = globalThis.window;
326
+
327
+ controller.bundleConfig = {
328
+ bundles: {
329
+ vendorShared: {
330
+ file: 'slice-bundle.vendor-shared.js',
331
+ },
332
+ routes: {
333
+ dashboard: {
334
+ file: 'slice-bundle.dashboard.js',
335
+ dependencies: ['vendor-shared'],
336
+ },
337
+ },
338
+ },
339
+ };
340
+
341
+ const importsByPath = {
342
+ '/bundles/slice-bundle.vendor-shared.js': {
343
+ SLICE_BUNDLE_META: {
344
+ bundleKey: 'vendor-shared',
345
+ type: 'shared',
346
+ },
347
+ registerAll: async () => ({
348
+ 'vendors/dompurify': {
349
+ sanitize: () => 'ok',
350
+ },
351
+ }),
352
+ },
353
+ '/bundles/slice-bundle.dashboard.js': {
354
+ SLICE_BUNDLE_META: {
355
+ bundleKey: 'dashboard',
356
+ type: 'route',
357
+ },
358
+ registerAll: async () => {},
359
+ },
360
+ };
361
+
362
+ controller.importBundleOnce = async (bundlePath) => importsByPath[bundlePath];
363
+
364
+ try {
365
+ globalThis.slice = {
366
+ stylesManager: {},
367
+ };
368
+ globalThis.window = {
369
+ __SLICE_SHARED_DEPS__: {},
370
+ };
371
+
372
+ await controller.loadBundle('dashboard');
373
+
374
+ assert.equal(typeof globalThis.window.__SLICE_SHARED_DEPS__['vendors/dompurify']?.sanitize, 'function');
375
+ } finally {
376
+ globalThis.slice = originalSlice;
377
+ globalThis.window = originalWindow;
378
+ await rm(tempDir, { recursive: true, force: true });
379
+ }
380
+ });
381
+
382
+ test('loadBundle appends bundle hash as query param when importing bundle files', async () => {
383
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
384
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
385
+ await writeFile(
386
+ loaderPath,
387
+ `export async function resolve(specifier, context, nextResolve) {
388
+ if (specifier === '/Components/components.js') {
389
+ return {
390
+ shortCircuit: true,
391
+ url: 'data:text/javascript,export default {};',
392
+ };
393
+ }
394
+ return nextResolve(specifier, context);
395
+ }
396
+ `,
397
+ 'utf8'
398
+ );
399
+ register(pathToFileURL(loaderPath).href);
400
+
401
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
402
+ const { default: Controller } = await import(controllerModuleUrl);
403
+ const controller = new Controller();
404
+ const originalSlice = globalThis.slice;
405
+
406
+ controller.bundleConfig = {
407
+ bundles: {
408
+ routes: {
409
+ dashboard: {
410
+ file: 'slice-bundle.dashboard.js',
411
+ hash: 'abc123hash',
412
+ },
413
+ },
414
+ },
415
+ };
416
+
417
+ let importedPath = null;
418
+ controller.importBundleOnce = async (bundlePath) => {
419
+ importedPath = bundlePath;
420
+ return {
421
+ SLICE_BUNDLE_META: {
422
+ bundleKey: 'dashboard',
423
+ type: 'route',
424
+ },
425
+ registerAll: async () => {},
426
+ };
427
+ };
428
+
429
+ try {
430
+ globalThis.slice = {
431
+ stylesManager: {},
432
+ };
433
+
434
+ await controller.loadBundle('dashboard');
435
+ assert.equal(importedPath, '/bundles/slice-bundle.dashboard.js?v=abc123hash');
436
+ } finally {
437
+ globalThis.slice = originalSlice;
438
+ await rm(tempDir, { recursive: true, force: true });
439
+ }
440
+ });
441
+
442
+ test('loadBundle dedupes concurrent and repeated alias/case requests using canonical bundle key', async () => {
443
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
444
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
445
+ await writeFile(
446
+ loaderPath,
447
+ `export async function resolve(specifier, context, nextResolve) {
448
+ if (specifier === '/Components/components.js') {
449
+ return {
450
+ shortCircuit: true,
451
+ url: 'data:text/javascript,export default {};',
452
+ };
453
+ }
454
+ return nextResolve(specifier, context);
455
+ }
456
+ `,
457
+ 'utf8'
458
+ );
459
+ register(pathToFileURL(loaderPath).href);
460
+
461
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
462
+ const { default: Controller } = await import(controllerModuleUrl);
463
+ const controller = new Controller();
464
+ const originalSlice = globalThis.slice;
465
+
466
+ controller.bundleConfig = {
467
+ bundles: {
468
+ routes: {
469
+ dashboard: {
470
+ file: 'slice-bundle.dashboard.js',
471
+ },
472
+ },
473
+ },
474
+ };
475
+
476
+ let registerCallCount = 0;
477
+ controller.importBundleOnce = async () => ({
478
+ SLICE_BUNDLE_META: {
479
+ bundleKey: 'routes.dashboard.v2',
480
+ type: 'route',
481
+ },
482
+ registerAll: async () => {
483
+ registerCallCount += 1;
484
+ await new Promise((resolve) => setTimeout(resolve, 10));
485
+ },
486
+ });
487
+
488
+ try {
489
+ globalThis.slice = {
490
+ stylesManager: {},
491
+ };
492
+
493
+ await Promise.all([
494
+ controller.loadBundle('dashboard'),
495
+ controller.loadBundle('DASHBOARD'),
496
+ ]);
497
+
498
+ await controller.loadBundle('Dashboard');
499
+
500
+ assert.equal(registerCallCount, 1);
501
+ assert.equal(controller.loadedBundles.has('dashboard'), true);
502
+ assert.equal(controller.loadedBundles.has('routes.dashboard.v2'), true);
503
+ assert.equal(controller.bundleLoadPromises.size, 0);
504
+ } finally {
505
+ globalThis.slice = originalSlice;
506
+ await rm(tempDir, { recursive: true, force: true });
507
+ }
508
+ });
509
+
510
+ test('registerVendorSharedDependencies only runs for vendor-shared canonical bundle or explicit metadata flag', async () => {
511
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-controller-loader-'));
512
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
513
+ await writeFile(
514
+ loaderPath,
515
+ `export async function resolve(specifier, context, nextResolve) {
516
+ if (specifier === '/Components/components.js') {
517
+ return {
518
+ shortCircuit: true,
519
+ url: 'data:text/javascript,export default {};',
520
+ };
521
+ }
522
+ return nextResolve(specifier, context);
523
+ }
524
+ `,
525
+ 'utf8'
526
+ );
527
+ register(pathToFileURL(loaderPath).href);
528
+
529
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
530
+ const { default: Controller } = await import(controllerModuleUrl);
531
+ const controller = new Controller();
532
+ const originalWindow = globalThis.window;
533
+
534
+ try {
535
+ globalThis.window = {
536
+ __SLICE_SHARED_DEPS__: {},
537
+ };
538
+
539
+ controller.registerVendorSharedDependencies(
540
+ {
541
+ SLICE_SHARED_DEPS: {
542
+ shouldNotLoad: true,
543
+ },
544
+ },
545
+ {
546
+ type: 'shared',
547
+ bundleKey: 'app-shared',
548
+ },
549
+ 'app-shared'
550
+ );
551
+
552
+ assert.equal(globalThis.window.__SLICE_SHARED_DEPS__.shouldNotLoad, undefined);
553
+
554
+ controller.registerVendorSharedDependencies(
555
+ {
556
+ SLICE_SHARED_DEPS: {
557
+ explicitFlagDependency: true,
558
+ },
559
+ },
560
+ {
561
+ type: 'shared',
562
+ bundleKey: 'app-shared',
563
+ registerVendorSharedDependencies: true,
564
+ },
565
+ 'app-shared'
566
+ );
567
+
568
+ assert.equal(globalThis.window.__SLICE_SHARED_DEPS__.explicitFlagDependency, true);
569
+ } finally {
570
+ globalThis.window = originalWindow;
571
+ await rm(tempDir, { recursive: true, force: true });
572
+ }
573
+ });
574
+
575
+ test('Slice init fails fast with contextual error on invalid Bundling V2 contract path', async () => {
576
+ const tempDir = await mkdtemp(path.join(tmpdir(), 'slice-init-loader-'));
577
+ const loaderPath = path.join(tempDir, 'components-alias-loader.mjs');
578
+ await writeFile(
579
+ loaderPath,
580
+ `export async function resolve(specifier, context, nextResolve) {
581
+ if (specifier === '/Components/components.js') {
582
+ return {
583
+ shortCircuit: true,
584
+ url: 'data:text/javascript,export default {};',
585
+ };
586
+ }
587
+ return nextResolve(specifier, context);
588
+ }
589
+ `,
590
+ 'utf8'
591
+ );
592
+ register(pathToFileURL(loaderPath).href);
593
+
594
+ const originalWindow = globalThis.window;
595
+ const originalDocument = globalThis.document;
596
+ const originalFetch = globalThis.fetch;
597
+ const originalAlert = globalThis.alert;
598
+ const originalSliceDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'slice');
599
+ const originalConsoleLog = console.log;
600
+ const originalConsoleWarn = console.warn;
601
+ const originalConsoleError = console.error;
602
+ const controllerModuleUrl = new URL('../Components/Structural/Controller/Controller.js', import.meta.url).href;
603
+ const { default: Controller } = await import(controllerModuleUrl);
604
+ const originalLoadBundle = Controller.prototype.loadBundle;
605
+
606
+ const loggedMessages = [];
607
+
608
+ try {
609
+ globalThis.window = {
610
+ location: {
611
+ pathname: '/dashboard',
612
+ origin: 'http://localhost',
613
+ },
614
+ };
615
+
616
+ Object.defineProperty(globalThis, 'slice', {
617
+ configurable: true,
618
+ get() {
619
+ return globalThis.window?.slice;
620
+ },
621
+ set(value) {
622
+ if (!globalThis.window) {
623
+ globalThis.window = {};
624
+ }
625
+ globalThis.window.slice = value;
626
+ },
627
+ });
628
+
629
+ Controller.prototype.loadBundle = async () => {
630
+ throw new Error(
631
+ 'Bundle "critical" missing Bundling V2 exports contract: requires SLICE_BUNDLE_META and registerAll'
632
+ );
633
+ };
634
+
635
+ globalThis.document = {
636
+ head: {
637
+ appendChild() {},
638
+ },
639
+ body: {
640
+ appendChild() {},
641
+ },
642
+ createElement() {
643
+ return {
644
+ appendChild() {},
645
+ innerHTML: '',
646
+ id: '',
647
+ };
648
+ },
649
+ createTextNode() {
650
+ return {};
651
+ },
652
+ addEventListener() {},
653
+ };
654
+
655
+ globalThis.alert = () => {};
656
+ console.log = (...args) => {
657
+ loggedMessages.push(args.map(String).join(' '));
658
+ };
659
+ console.warn = () => {};
660
+ console.error = (...args) => {
661
+ loggedMessages.push(args.map(String).join(' '));
662
+ };
663
+
664
+ globalThis.fetch = async (url) => {
665
+ if (url === '/sliceConfig.json') {
666
+ return {
667
+ ok: true,
668
+ json: async () => ({
669
+ paths: {
670
+ routesFile: '/routes.js',
671
+ components: {},
672
+ },
673
+ themeManager: { enabled: false },
674
+ stylesManager: { requestedStyles: [] },
675
+ logger: { enabled: false },
676
+ debugger: { enabled: false },
677
+ loading: { enabled: false },
678
+ events: { enabled: false },
679
+ context: { enabled: false },
680
+ }),
681
+ };
682
+ }
683
+
684
+ if (url === '/slice-env.json') {
685
+ return {
686
+ ok: true,
687
+ json: async () => ({ mode: 'production' }),
688
+ };
689
+ }
690
+
691
+ if (url === '/bundles/bundle.config.json') {
692
+ return {
693
+ ok: true,
694
+ json: async () => ({
695
+ production: true,
696
+ bundles: {
697
+ critical: { file: 'critical.js' },
698
+ routes: {},
699
+ },
700
+ routeBundles: {},
701
+ }),
702
+ };
703
+ }
704
+
705
+ throw new Error(`Unexpected fetch URL: ${url}`);
706
+ };
707
+
708
+ const sliceModuleUrl = new URL(`../Slice.js?fail-fast-test=${Date.now()}`, import.meta.url).href;
709
+
710
+ await import(sliceModuleUrl);
711
+
712
+ assert.ok(
713
+ loggedMessages.some((message) => /Bundling V2 initialization failed/i.test(message)),
714
+ 'init must log contextual error on Bundling V2 contract failure'
715
+ );
716
+
717
+ assert.equal(
718
+ loggedMessages.some((message) => message.includes('Using individual component loading (no bundles found)')),
719
+ false,
720
+ 'init must not log fallback bundle message on Bundling V2 contract failure'
721
+ );
722
+ } finally {
723
+ Controller.prototype.loadBundle = originalLoadBundle;
724
+ globalThis.window = originalWindow;
725
+ globalThis.document = originalDocument;
726
+ globalThis.fetch = originalFetch;
727
+ globalThis.alert = originalAlert;
728
+ if (originalSliceDescriptor) {
729
+ Object.defineProperty(globalThis, 'slice', originalSliceDescriptor);
730
+ } else {
731
+ delete globalThis.slice;
732
+ }
733
+ console.log = originalConsoleLog;
734
+ console.warn = originalConsoleWarn;
735
+ console.error = originalConsoleError;
736
+ await rm(tempDir, { recursive: true, force: true });
737
+ }
738
+ });