@@ -7,6 +7,15 @@ const url = new URL(window.location.href);
77 * @typedef {import('@duckduckgo/messaging/lib/test-utils.mjs').SubscriptionEvent } SubscriptionEvent
88 */
99
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+
1019export function mockTransport ( ) {
1120 /** @type {Map<string, (d: any)=>void> } */
1221 const subscriptions = new Map ( ) ;
@@ -18,20 +27,20 @@ export function mockTransport() {
1827 } ;
1928 }
2029
21- let memory = structuredClone ( historyMocks . few ) . value ;
30+ let memory = clone ( historyMocks . few ) . value ;
2231
2332 if ( url . searchParams . has ( 'history' ) ) {
2433 const key = url . searchParams . get ( 'history' ) ;
2534 if ( key && key in historyMocks ) {
26- memory = structuredClone ( historyMocks [ key ] ) . value ;
35+ memory = clone ( historyMocks [ key ] ) . value ;
2736 } else if ( key ?. match ( / ^ \d + $ / ) ) {
2837 memory = generateSampleData ( { count : parseInt ( key ) , offset : 0 } ) ;
2938 }
3039 }
3140 // console.log(memory);
3241 return new TestTransportConfig ( {
3342 notify ( _msg ) {
34- window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : structuredClone ( _msg ) } ) ;
43+ window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : clone ( _msg ) } ) ;
3544 /** @type {import('../../types/history.ts').HistoryMessages['notifications'] } */
3645 const msg = /** @type {any } */ ( _msg ) ;
3746 console . warn ( 'unhandled notification' , msg ) ;
@@ -40,7 +49,7 @@ export function mockTransport() {
4049 const sub = /** @type {any } */ ( _msg . subscriptionName ) ;
4150
4251 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 ) } ) ;
4453 subscriptions . set ( sub , cb ) ;
4554 return ( ) => {
4655 subscriptions . delete ( sub ) ;
@@ -53,7 +62,7 @@ export function mockTransport() {
5362 } ,
5463 // eslint-ignore-next-line require-await
5564 request ( _msg ) {
56- window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : structuredClone ( _msg ) } ) ;
65+ window . __playwright_01 ?. mocks ?. outgoing ?. push ?. ( { payload : clone ( _msg ) } ) ;
5766 /** @type {import('../../types/history.ts').HistoryMessages['requests'] } */
5867 const msg = /** @type {any } */ ( _msg ) ;
5968
0 commit comments