@@ -63,9 +63,7 @@ describe('Content Script UIs', () => {
63
63
} ) ;
64
64
ui . mount ( ) ;
65
65
66
- expect (
67
- document . querySelector ( 'div[data-wxt-integrated]' ) ,
68
- ) . not . toBeNull ( ) ;
66
+ expect ( document . body . children ) . toContain ( ui . wrapper ) ;
69
67
expect ( document . querySelector ( 'app' ) ) . not . toBeNull ( ) ;
70
68
} ) ;
71
69
@@ -77,9 +75,7 @@ describe('Content Script UIs', () => {
77
75
} ) ;
78
76
ui . mount ( ) ;
79
77
80
- expect (
81
- document . querySelector ( 'pre[data-wxt-integrated]' ) ,
82
- ) . not . toBeNull ( ) ;
78
+ expect ( document . querySelector ( 'pre' ) ) . toBe ( ui . wrapper ) ;
83
79
expect ( document . querySelector ( 'app' ) ) . not . toBeNull ( ) ;
84
80
} ) ;
85
81
} ) ;
@@ -92,7 +88,7 @@ describe('Content Script UIs', () => {
92
88
} ) ;
93
89
ui . mount ( ) ;
94
90
95
- expect ( document . querySelector ( 'div[data-wxt-iframe]' ) ) . toBeDefined ( ) ;
91
+ expect ( document . body . children ) . toContain ( ui . wrapper ) ;
96
92
expect ( document . querySelector ( 'iframe' ) ) . toBeDefined ( ) ;
97
93
} ) ;
98
94
} ) ;
@@ -108,9 +104,7 @@ describe('Content Script UIs', () => {
108
104
} ) ;
109
105
ui . mount ( ) ;
110
106
111
- expect (
112
- document . querySelector ( 'test-component[data-wxt-shadow-root]' ) ,
113
- ) . not . toBeNull ( ) ;
107
+ expect ( document . querySelector ( 'test-component' ) ) . toBe ( ui . shadowHost ) ;
114
108
expect ( ui . shadow . querySelector ( 'app' ) ) . not . toBeNull ( ) ;
115
109
} ) ;
116
110
@@ -143,7 +137,7 @@ describe('Content Script UIs', () => {
143
137
} ) ;
144
138
145
139
expect ( ui . wrapper . outerHTML ) . toMatchInlineSnapshot (
146
- `"<div data-wxt-iframe="" ><iframe src="chrome-extension://test-extension-id/page.html"></iframe></div>"` ,
140
+ `"<div><iframe src="chrome-extension://test-extension-id/page.html"></iframe></div>"` ,
147
141
) ;
148
142
} ) ;
149
143
} ) ;
@@ -157,7 +151,7 @@ describe('Content Script UIs', () => {
157
151
ui . mount ( ) ;
158
152
159
153
expect ( ui . wrapper . outerHTML ) . toMatchInlineSnapshot (
160
- `"<div data-wxt-iframe="" style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; top: 0px; left: 0px;"></iframe></div>"` ,
154
+ `"<div style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; top: 0px; left: 0px;"></iframe></div>"` ,
161
155
) ;
162
156
} ) ;
163
157
@@ -170,7 +164,7 @@ describe('Content Script UIs', () => {
170
164
ui . mount ( ) ;
171
165
172
166
expect ( ui . wrapper . outerHTML ) . toMatchInlineSnapshot (
173
- `"<div data-wxt-iframe="" style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; top: 0px; left: 0px;"></iframe></div>"` ,
167
+ `"<div style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; top: 0px; left: 0px;"></iframe></div>"` ,
174
168
) ;
175
169
} ) ;
176
170
@@ -183,7 +177,7 @@ describe('Content Script UIs', () => {
183
177
ui . mount ( ) ;
184
178
185
179
expect ( ui . wrapper . outerHTML ) . toMatchInlineSnapshot (
186
- `"<div data-wxt-iframe="" style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; top: 0px; right: 0px;"></iframe></div>"` ,
180
+ `"<div style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; top: 0px; right: 0px;"></iframe></div>"` ,
187
181
) ;
188
182
} ) ;
189
183
@@ -196,7 +190,7 @@ describe('Content Script UIs', () => {
196
190
ui . mount ( ) ;
197
191
198
192
expect ( ui . wrapper . outerHTML ) . toMatchInlineSnapshot (
199
- `"<div data-wxt-iframe="" style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; bottom: 0px; right: 0px;"></iframe></div>"` ,
193
+ `"<div style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; bottom: 0px; right: 0px;"></iframe></div>"` ,
200
194
) ;
201
195
} ) ;
202
196
@@ -209,7 +203,7 @@ describe('Content Script UIs', () => {
209
203
ui . mount ( ) ;
210
204
211
205
expect ( ui . wrapper . outerHTML ) . toMatchInlineSnapshot (
212
- `"<div data-wxt-iframe="" style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; bottom: 0px; left: 0px;"></iframe></div>"` ,
206
+ `"<div style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: absolute; bottom: 0px; left: 0px;"></iframe></div>"` ,
213
207
) ;
214
208
} ) ;
215
209
@@ -235,7 +229,7 @@ describe('Content Script UIs', () => {
235
229
ui . mount ( ) ;
236
230
237
231
expect ( ui . wrapper . outerHTML ) . toMatchInlineSnapshot (
238
- `"<div data-wxt-iframe="" style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: fixed; top: 0px; bottom: 0px; left: 0px; right: 0px;"></iframe></div>"` ,
232
+ `"<div style="overflow: visible; position: relative; width: 0px; height: 0px; display: block;"><iframe src="chrome-extension://test-extension-id/page.html" style="position: fixed; top: 0px; bottom: 0px; left: 0px; right: 0px;"></iframe></div>"` ,
239
233
) ;
240
234
} ) ;
241
235
@@ -262,9 +256,7 @@ describe('Content Script UIs', () => {
262
256
} ) ;
263
257
ui . mount ( ) ;
264
258
265
- expect (
266
- document . querySelector ( 'body > div[data-wxt-integrated]' ) ,
267
- ) . not . toBeNull ( ) ;
259
+ expect ( document . body . children ) . toContain ( ui . wrapper ) ;
268
260
} ) ;
269
261
} ) ;
270
262
@@ -277,9 +269,9 @@ describe('Content Script UIs', () => {
277
269
} ) ;
278
270
ui . mount ( ) ;
279
271
280
- expect (
281
- document . querySelector ( '#parent > div[data-wxt-integrated]' ) ,
282
- ) . not . toBeNull ( ) ;
272
+ expect ( document . querySelector ( '#parent' ) ! . children ) . toContain (
273
+ ui . wrapper ,
274
+ ) ;
283
275
} ) ;
284
276
285
277
it ( 'should append the element using an XPath string' , ( ) => {
@@ -295,9 +287,7 @@ describe('Content Script UIs', () => {
295
287
} ) ;
296
288
ui . mount ( ) ;
297
289
298
- expect (
299
- document . querySelector ( '#three > div[data-wxt-integrated]' ) ,
300
- ) . not . toBeNull ( ) ;
290
+ expect ( document . querySelector ( '#three' ) ! . children [ 0 ] ) . toBe ( ui . wrapper ) ;
301
291
} ) ;
302
292
} ) ;
303
293
@@ -310,9 +300,9 @@ describe('Content Script UIs', () => {
310
300
} ) ;
311
301
ui . mount ( ) ;
312
302
313
- expect (
314
- document . querySelector ( '#parent > div[data-wxt-integrated]' ) ,
315
- ) . not . toBeNull ( ) ;
303
+ expect ( document . querySelector ( '#parent' ) ! . children ) . toContain (
304
+ ui . wrapper ,
305
+ ) ;
316
306
} ) ;
317
307
} ) ;
318
308
@@ -325,9 +315,9 @@ describe('Content Script UIs', () => {
325
315
} ) ;
326
316
ui . mount ( ) ;
327
317
328
- expect (
329
- document . querySelector ( '#parent > div[data-wxt-integrated]' ) ,
330
- ) . not . toBeNull ( ) ;
318
+ expect ( document . querySelector ( '#parent' ) ! . children ) . toContain (
319
+ ui . wrapper ,
320
+ ) ;
331
321
} ) ;
332
322
} ) ;
333
323
@@ -354,9 +344,7 @@ describe('Content Script UIs', () => {
354
344
ui . mount ( ) ;
355
345
356
346
expect (
357
- document . querySelector (
358
- '#parent > div[data-wxt-integrated]:last-child' ,
359
- ) ,
347
+ document . querySelector ( '#parent' ) ! . lastElementChild ,
360
348
) . not . toBeNull ( ) ;
361
349
} ) ;
362
350
} ) ;
@@ -372,9 +360,7 @@ describe('Content Script UIs', () => {
372
360
ui . mount ( ) ;
373
361
374
362
expect (
375
- document . querySelector (
376
- '#parent > div[data-wxt-integrated]:first-child' ,
377
- ) ,
363
+ document . querySelector ( '#parent' ) ! . children [ 0 ] . firstElementChild ,
378
364
) . not . toBeNull ( ) ;
379
365
} ) ;
380
366
} ) ;
@@ -389,9 +375,7 @@ describe('Content Script UIs', () => {
389
375
} ) ;
390
376
ui . mount ( ) ;
391
377
392
- expect (
393
- document . querySelector ( 'body > div[data-wxt-integrated]' ) ,
394
- ) . not . toBeNull ( ) ;
378
+ expect ( document . body . children ) . toContain ( ui . wrapper ) ;
395
379
expect ( document . querySelector ( '#parent' ) ) . toBeNull ( ) ;
396
380
} ) ;
397
381
} ) ;
@@ -406,11 +390,9 @@ describe('Content Script UIs', () => {
406
390
} ) ;
407
391
ui . mount ( ) ;
408
392
409
- expect (
410
- document . querySelector (
411
- '#parent > div[data-wxt-integrated]:first-child' ,
412
- ) ,
413
- ) . not . toBeNull ( ) ;
393
+ expect ( document . querySelector ( '#parent' ) ! . firstElementChild ) . toBe (
394
+ ui . wrapper ,
395
+ ) ;
414
396
} ) ;
415
397
} ) ;
416
398
@@ -424,11 +406,9 @@ describe('Content Script UIs', () => {
424
406
} ) ;
425
407
ui . mount ( ) ;
426
408
427
- expect (
428
- document . querySelector (
429
- '#parent > div[data-wxt-integrated]:last-child' ,
430
- ) ,
431
- ) . not . toBeNull ( ) ;
409
+ expect ( document . querySelector ( '#parent' ) ! . lastElementChild ) . toBe (
410
+ ui . wrapper ,
411
+ ) ;
432
412
} ) ;
433
413
} ) ;
434
414
@@ -444,9 +424,8 @@ describe('Content Script UIs', () => {
444
424
} ) ;
445
425
ui . mount ( ) ;
446
426
447
- expect (
448
- document . querySelector ( 'body > div[data-wxt-integrated]' ) ,
449
- ) . not . toBeNull ( ) ;
427
+ expect ( document . body . children ) . toContain ( ui . wrapper ) ;
428
+
450
429
expect ( document . querySelector ( '#parent' ) ) . toBeNull ( ) ;
451
430
} ) ;
452
431
} ) ;
@@ -529,23 +508,29 @@ describe('Content Script UIs', () => {
529
508
{
530
509
name : 'integrated' ,
531
510
createUiFunction : createIntegratedUi ,
532
- uiSelector : 'div [data-wxt- integrated]' ,
511
+ uiSelector : '[data-wrapper-name=" integrated" ]' ,
533
512
} ,
534
513
{
535
514
name : 'iframe' ,
536
515
createUiFunction : createIframeUi ,
537
- uiSelector : 'div [data-wxt- iframe]' ,
516
+ uiSelector : ` [data-wrapper-name=" iframe"]` ,
538
517
} ,
539
518
{
540
519
name : 'shadow-root' ,
541
520
createUiFunction : createShadowRootUi ,
542
- uiSelector : 'test-component[data-wxt-shadow-root] ' ,
521
+ uiSelector : 'test-component' ,
543
522
} ,
544
523
] as const ) (
545
524
'built-in UI type: $name' ,
546
525
( { name, createUiFunction, uiSelector } ) => {
526
+ const onMount = vi . fn ( ( wrapper : HTMLElement ) => {
527
+ if ( name === 'shadow-root' ) return ;
528
+
529
+ wrapper . setAttribute ( 'data-wrapper-name' , name ) ;
530
+ appendTestApp ( wrapper ) ;
531
+ } ) ;
532
+
547
533
it ( 'should mount if an anchor already exists at the initialization' , async ( ) => {
548
- const onMount = vi . fn ( appendTestApp ) ;
549
534
ui = await createUiFunction ( ctx , {
550
535
position : 'inline' ,
551
536
onMount,
@@ -555,6 +540,7 @@ describe('Content Script UIs', () => {
555
540
} ) ;
556
541
557
542
appendTestElement ( { id : DYNAMIC_CHILD_ID } ) ;
543
+
558
544
ui . autoMount ( ) ;
559
545
await runMicrotasks ( ) ;
560
546
@@ -564,7 +550,6 @@ describe('Content Script UIs', () => {
564
550
} ) ;
565
551
566
552
it ( 'should mount when an anchor is dynamically added and unmount when an anchor is removed' , async ( ) => {
567
- const onMount = vi . fn ( appendTestApp ) ;
568
553
const onRemove = vi . fn ( ) ;
569
554
ui = await createUiFunction ( ctx , {
570
555
position : 'inline' ,
@@ -599,7 +584,6 @@ describe('Content Script UIs', () => {
599
584
600
585
describe ( 'options' , ( ) => {
601
586
it ( 'should auto-mount only once mount and remove when the `once` option is true' , async ( ) => {
602
- const onMount = vi . fn ( appendTestApp ) ;
603
587
const onRemove = vi . fn ( ) ;
604
588
ui = await createUiFunction ( ctx , {
605
589
position : 'inline' ,
@@ -644,7 +628,7 @@ describe('Content Script UIs', () => {
644
628
it ( 'should throw when anchor is set as type Element' , async ( ) => {
645
629
ui = await createUiFunction ( ctx , {
646
630
position : 'inline' ,
647
- onMount : appendTestApp ,
631
+ onMount : onMount ,
648
632
anchor : document . documentElement ,
649
633
page : name === 'iframe' ? '/page.html' : undefined ,
650
634
name : 'test-component' ,
@@ -657,7 +641,7 @@ describe('Content Script UIs', () => {
657
641
it ( 'should throw when anchor is set as type `() => Element`' , async ( ) => {
658
642
ui = await createUiFunction ( ctx , {
659
643
position : 'inline' ,
660
- onMount : appendTestApp ,
644
+ onMount : onMount ,
661
645
anchor : ( ) => document . documentElement ,
662
646
page : name === 'iframe' ? '/page.html' : undefined ,
663
647
name : 'test-component' ,
@@ -670,7 +654,6 @@ describe('Content Script UIs', () => {
670
654
671
655
describe ( 'StopAutoMount' , ( ) => {
672
656
it ( 'should stop auto-mounting and remove ui when `ui.remove` is called' , async ( ) => {
673
- const onMount = vi . fn ( appendTestApp ) ;
674
657
const onRemove = vi . fn ( ) ;
675
658
ui = await createUiFunction ( ctx , {
676
659
position : 'inline' ,
@@ -705,7 +688,6 @@ describe('Content Script UIs', () => {
705
688
} ) ;
706
689
707
690
it ( 'should call internal StopAutoMount when `ui.remove` is called' , async ( ) => {
708
- const onMount = vi . fn ( appendTestApp ) ;
709
691
const onRemove = vi . fn ( ) ;
710
692
const onStop = vi . fn ( ) ;
711
693
ui = await createUiFunction ( ctx , {
@@ -723,7 +705,6 @@ describe('Content Script UIs', () => {
723
705
} ) ;
724
706
725
707
it ( 'should allow calling automount again after internal StopAutoMount is called' , async ( ) => {
726
- const onMount = vi . fn ( appendTestApp ) ;
727
708
ui = await createUiFunction ( ctx , {
728
709
position : 'inline' ,
729
710
onMount,
0 commit comments