@@ -7,6 +7,15 @@ const url = new URL(window.location.href);
7
7
* @typedef {import('@duckduckgo/messaging/lib/test-utils.mjs').SubscriptionEvent } SubscriptionEvent
8
8
*/
9
9
10
+ /**
11
+ * @template T
12
+ * @param {T } value
13
+ * @return {T }
14
+ */
15
+ function clone ( value ) {
16
+ return window . structuredClone ?. ( value ) ?? JSON . parse ( JSON . stringify ( value ) ) ;
17
+ }
18
+
10
19
export function mockTransport ( ) {
11
20
/** @type {Map<string, (d: any)=>void> } */
12
21
const subscriptions = new Map ( ) ;
@@ -18,20 +27,20 @@ export function mockTransport() {
18
27
} ;
19
28
}
20
29
21
- let memory = structuredClone ( historyMocks . few ) . value ;
30
+ let memory = clone ( historyMocks . few ) . value ;
22
31
23
32
if ( url . searchParams . has ( 'history' ) ) {
24
33
const key = url . searchParams . get ( 'history' ) ;
25
34
if ( key && key in historyMocks ) {
26
- memory = structuredClone ( historyMocks [ key ] ) . value ;
35
+ memory = clone ( historyMocks [ key ] ) . value ;
27
36
} else if ( key ?. match ( / ^ \d + $ / ) ) {
28
37
memory = generateSampleData ( { count : parseInt ( key ) , offset : 0 } ) ;
29
38
}
30
39
}
31
40
// console.log(memory);
32
41
return new TestTransportConfig ( {
33
42
notify ( _msg ) {
34
- window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : structuredClone ( _msg ) } ) ;
43
+ window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : clone ( _msg ) } ) ;
35
44
/** @type {import('../../types/history.ts').HistoryMessages['notifications'] } */
36
45
const msg = /** @type {any } */ ( _msg ) ;
37
46
console . warn ( 'unhandled notification' , msg ) ;
@@ -40,7 +49,7 @@ export function mockTransport() {
40
49
const sub = /** @type {any } */ ( _msg . subscriptionName ) ;
41
50
42
51
if ( '__playwright_01' in window ) {
43
- window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : structuredClone ( _msg ) } ) ;
52
+ window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : clone ( _msg ) } ) ;
44
53
subscriptions . set ( sub , cb ) ;
45
54
return ( ) => {
46
55
subscriptions . delete ( sub ) ;
@@ -53,7 +62,7 @@ export function mockTransport() {
53
62
} ,
54
63
// eslint-ignore-next-line require-await
55
64
request ( _msg ) {
56
- window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : structuredClone ( _msg ) } ) ;
65
+ window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : clone ( _msg ) } ) ;
57
66
/** @type {import('../../types/history.ts').HistoryMessages['requests'] } */
58
67
const msg = /** @type {any } */ ( _msg ) ;
59
68
0 commit comments