@@ -166,15 +166,23 @@ describe("request tracing", function () {
166
166
167
167
afterEach ( ( ) => {
168
168
// Restore the original values after each test
169
- ( global as any ) . navigator = originalNavigator ;
169
+ // global.navigator was added in node 21, https://nodejs.org/api/globals.html#navigator_1
170
+ // global.navigator only has a getter, so we have to use Object.defineProperty to modify it
171
+ Object . defineProperty ( global , "navigator" , {
172
+ value : originalNavigator ,
173
+ configurable : true
174
+ } ) ;
170
175
( global as any ) . WorkerNavigator = originalWorkerNavigator ;
171
176
( global as any ) . WorkerGlobalScope = originalWorkerGlobalScope ;
172
177
( global as any ) . importScripts = originalImportScripts ;
173
178
} ) ;
174
179
175
180
it ( "should identify WebWorker environment" , async ( ) => {
176
181
( global as any ) . WorkerNavigator = function WorkerNavigator ( ) { } ;
177
- ( global as any ) . navigator = new ( global as any ) . WorkerNavigator ( ) ;
182
+ Object . defineProperty ( global , "navigator" , {
183
+ value : new ( global as any ) . WorkerNavigator ( ) ,
184
+ configurable : true
185
+ } ) ;
178
186
( global as any ) . WorkerGlobalScope = function WorkerGlobalScope ( ) { } ;
179
187
( global as any ) . importScripts = function importScripts ( ) { } ;
180
188
@@ -188,7 +196,10 @@ describe("request tracing", function () {
188
196
} ) ;
189
197
190
198
it ( "is not WebWorker when WorkerNavigator is undefined" , async ( ) => {
191
- ( global as any ) . navigator = { userAgent : "node.js" } as any ; // Mock navigator
199
+ Object . defineProperty ( global , "navigator" , {
200
+ value : { userAgent : "node.js" } as any , // Mock navigator
201
+ configurable : true
202
+ } ) ;
192
203
( global as any ) . WorkerNavigator = undefined ;
193
204
( global as any ) . WorkerGlobalScope = function WorkerGlobalScope ( ) { } ;
194
205
( global as any ) . importScripts = function importScripts ( ) { } ;
@@ -203,7 +214,10 @@ describe("request tracing", function () {
203
214
} ) ;
204
215
205
216
it ( "is not WebWorker when navigator is not an instance of WorkerNavigator" , async ( ) => {
206
- ( global as any ) . navigator = { userAgent : "node.js" } as any ; // Mock navigator but not an instance of WorkerNavigator
217
+ Object . defineProperty ( global , "navigator" , {
218
+ value : { userAgent : "node.js" } as any , // Mock navigator but not an instance of WorkerNavigator
219
+ configurable : true
220
+ } ) ;
207
221
( global as any ) . WorkerNavigator = function WorkerNavigator ( ) { } ;
208
222
( global as any ) . WorkerGlobalScope = function WorkerGlobalScope ( ) { } ;
209
223
( global as any ) . importScripts = function importScripts ( ) { } ;
@@ -219,7 +233,10 @@ describe("request tracing", function () {
219
233
220
234
it ( "is not WebWorker when WorkerGlobalScope is undefined" , async ( ) => {
221
235
( global as any ) . WorkerNavigator = function WorkerNavigator ( ) { } ;
222
- ( global as any ) . navigator = new ( global as any ) . WorkerNavigator ( ) ;
236
+ Object . defineProperty ( global , "navigator" , {
237
+ value : new ( global as any ) . WorkerNavigator ( ) ,
238
+ configurable : true
239
+ } ) ;
223
240
( global as any ) . WorkerGlobalScope = undefined ;
224
241
( global as any ) . importScripts = function importScripts ( ) { } ;
225
242
@@ -234,7 +251,10 @@ describe("request tracing", function () {
234
251
235
252
it ( "is not WebWorker when importScripts is undefined" , async ( ) => {
236
253
( global as any ) . WorkerNavigator = function WorkerNavigator ( ) { } ;
237
- ( global as any ) . navigator = new ( global as any ) . WorkerNavigator ( ) ;
254
+ Object . defineProperty ( global , "navigator" , {
255
+ value : new ( global as any ) . WorkerNavigator ( ) ,
256
+ configurable : true
257
+ } ) ;
238
258
( global as any ) . WorkerGlobalScope = function WorkerGlobalScope ( ) { } ;
239
259
( global as any ) . importScripts = undefined ;
240
260
@@ -345,4 +365,4 @@ describe("request tracing", function () {
345
365
expect ( correlationContext . includes ( "Host=Web" ) ) . eq ( false ) ;
346
366
} ) ;
347
367
} ) ;
348
- } ) ;
368
+ } ) ;
0 commit comments