@@ -22,6 +22,7 @@ let mockWarn;
22
22
let patchConsole ;
23
23
let unpatchConsole ;
24
24
let rendererID ;
25
+ let supportsOwnerStacks = false ;
25
26
26
27
describe ( 'console' , ( ) => {
27
28
beforeEach ( ( ) => {
@@ -62,6 +63,12 @@ describe('console', () => {
62
63
} ;
63
64
64
65
React = require ( 'react' ) ;
66
+ if (
67
+ React . version . startsWith ( '19' ) &&
68
+ React . version . includes ( 'experimental' )
69
+ ) {
70
+ supportsOwnerStacks = true ;
71
+ }
65
72
ReactDOMClient = require ( 'react-dom/client' ) ;
66
73
67
74
const utils = require ( './utils' ) ;
@@ -224,13 +231,17 @@ describe('console', () => {
224
231
expect ( mockWarn . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
225
232
expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'warn' ) ;
226
233
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 0 ] [ 1 ] ) ) . toEqual (
227
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
234
+ supportsOwnerStacks
235
+ ? '\n in Parent (at **)'
236
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
228
237
) ;
229
238
expect ( mockError ) . toHaveBeenCalledTimes ( 1 ) ;
230
239
expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
231
240
expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'error' ) ;
232
241
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 0 ] [ 1 ] ) ) . toBe (
233
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
242
+ supportsOwnerStacks
243
+ ? '\n in Parent (at **)'
244
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
234
245
) ;
235
246
} ) ;
236
247
@@ -267,23 +278,31 @@ describe('console', () => {
267
278
expect ( mockWarn . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
268
279
expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'active warn' ) ;
269
280
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 0 ] [ 1 ] ) ) . toEqual (
270
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
281
+ supportsOwnerStacks
282
+ ? '\n in Parent (at **)'
283
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
271
284
) ;
272
285
expect ( mockWarn . mock . calls [ 1 ] ) . toHaveLength ( 2 ) ;
273
286
expect ( mockWarn . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'passive warn' ) ;
274
287
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 1 ] [ 1 ] ) ) . toEqual (
275
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
288
+ supportsOwnerStacks
289
+ ? '\n in Parent (at **)'
290
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
276
291
) ;
277
292
expect ( mockError ) . toHaveBeenCalledTimes ( 2 ) ;
278
293
expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
279
294
expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'active error' ) ;
280
295
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 0 ] [ 1 ] ) ) . toBe (
281
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
296
+ supportsOwnerStacks
297
+ ? '\n in Parent (at **)'
298
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
282
299
) ;
283
300
expect ( mockError . mock . calls [ 1 ] ) . toHaveLength ( 2 ) ;
284
301
expect ( mockError . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'passive error' ) ;
285
302
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 1 ] [ 1 ] ) ) . toBe (
286
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
303
+ supportsOwnerStacks
304
+ ? '\n in Parent (at **)'
305
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
287
306
) ;
288
307
} ) ;
289
308
@@ -325,23 +344,31 @@ describe('console', () => {
325
344
expect ( mockWarn . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
326
345
expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'didMount warn' ) ;
327
346
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 0 ] [ 1 ] ) ) . toEqual (
328
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
347
+ supportsOwnerStacks
348
+ ? '\n in Parent (at **)'
349
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
329
350
) ;
330
351
expect ( mockWarn . mock . calls [ 1 ] ) . toHaveLength ( 2 ) ;
331
352
expect ( mockWarn . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'didUpdate warn' ) ;
332
353
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 1 ] [ 1 ] ) ) . toEqual (
333
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
354
+ supportsOwnerStacks
355
+ ? '\n in Parent (at **)'
356
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
334
357
) ;
335
358
expect ( mockError ) . toHaveBeenCalledTimes ( 2 ) ;
336
359
expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
337
360
expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'didMount error' ) ;
338
361
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 0 ] [ 1 ] ) ) . toBe (
339
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
362
+ supportsOwnerStacks
363
+ ? '\n in Parent (at **)'
364
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
340
365
) ;
341
366
expect ( mockError . mock . calls [ 1 ] ) . toHaveLength ( 2 ) ;
342
367
expect ( mockError . mock . calls [ 1 ] [ 0 ] ) . toBe ( 'didUpdate error' ) ;
343
368
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 1 ] [ 1 ] ) ) . toBe (
344
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
369
+ supportsOwnerStacks
370
+ ? '\n in Parent (at **)'
371
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
345
372
) ;
346
373
} ) ;
347
374
@@ -375,13 +402,17 @@ describe('console', () => {
375
402
expect ( mockWarn . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
376
403
expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'warn' ) ;
377
404
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 0 ] [ 1 ] ) ) . toEqual (
378
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
405
+ supportsOwnerStacks
406
+ ? '\n in Parent (at **)'
407
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
379
408
) ;
380
409
expect ( mockError ) . toHaveBeenCalledTimes ( 1 ) ;
381
410
expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
382
411
expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'error' ) ;
383
412
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 0 ] [ 1 ] ) ) . toBe (
384
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
413
+ supportsOwnerStacks
414
+ ? '\n in Parent (at **)'
415
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
385
416
) ;
386
417
} ) ;
387
418
@@ -465,13 +496,17 @@ describe('console', () => {
465
496
expect ( mockWarn . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
466
497
expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'warn' ) ;
467
498
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 0 ] [ 1 ] ) ) . toEqual (
468
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
499
+ supportsOwnerStacks
500
+ ? '\n in Parent (at **)'
501
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
469
502
) ;
470
503
expect ( mockError ) . toHaveBeenCalledTimes ( 1 ) ;
471
504
expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
472
505
expect ( mockError . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'error' ) ;
473
506
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 0 ] [ 1 ] ) ) . toBe (
474
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
507
+ supportsOwnerStacks
508
+ ? '\n in Parent (at **)'
509
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
475
510
) ;
476
511
} ) ;
477
512
@@ -996,29 +1031,37 @@ describe('console', () => {
996
1031
expect ( mockWarn ) . toHaveBeenCalledTimes ( 2 ) ;
997
1032
expect ( mockWarn . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
998
1033
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 0 ] [ 1 ] ) ) . toEqual (
999
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
1034
+ supportsOwnerStacks
1035
+ ? '\n in Parent (at **)'
1036
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
1000
1037
) ;
1001
1038
expect ( mockWarn . mock . calls [ 1 ] ) . toHaveLength ( 3 ) ;
1002
1039
expect ( mockWarn . mock . calls [ 1 ] [ 0 ] ) . toEqual (
1003
1040
'\x1b[2;38;2;124;124;124m%s %o\x1b[0m' ,
1004
1041
) ;
1005
1042
expect ( mockWarn . mock . calls [ 1 ] [ 1 ] ) . toMatch ( 'warn' ) ;
1006
1043
expect ( normalizeCodeLocInfo ( mockWarn . mock . calls [ 1 ] [ 2 ] ) . trim ( ) ) . toEqual (
1007
- 'in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
1044
+ supportsOwnerStacks
1045
+ ? 'in Parent (at **)'
1046
+ : 'in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
1008
1047
) ;
1009
1048
1010
1049
expect ( mockError ) . toHaveBeenCalledTimes ( 2 ) ;
1011
1050
expect ( mockError . mock . calls [ 0 ] ) . toHaveLength ( 2 ) ;
1012
1051
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 0 ] [ 1 ] ) ) . toEqual (
1013
- '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
1052
+ supportsOwnerStacks
1053
+ ? '\n in Parent (at **)'
1054
+ : '\n in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
1014
1055
) ;
1015
1056
expect ( mockError . mock . calls [ 1 ] ) . toHaveLength ( 3 ) ;
1016
1057
expect ( mockError . mock . calls [ 1 ] [ 0 ] ) . toEqual (
1017
1058
'\x1b[2;38;2;124;124;124m%s %o\x1b[0m' ,
1018
1059
) ;
1019
1060
expect ( mockError . mock . calls [ 1 ] [ 1 ] ) . toEqual ( 'error' ) ;
1020
1061
expect ( normalizeCodeLocInfo ( mockError . mock . calls [ 1 ] [ 2 ] ) . trim ( ) ) . toEqual (
1021
- 'in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
1062
+ supportsOwnerStacks
1063
+ ? 'in Parent (at **)'
1064
+ : 'in Child (at **)\n in Intermediate (at **)\n in Parent (at **)' ,
1022
1065
) ;
1023
1066
} ) ;
1024
1067
} ) ;
0 commit comments