9
9
10
10
'use strict' ;
11
11
12
- import { normalizeCodeLocInfo } from './utils' ;
12
+ import semver from 'semver' ;
13
+
14
+ import { getLegacyRenderImplementation , normalizeCodeLocInfo } from './utils' ;
15
+ import { ReactVersion } from '../../../../ReactVersions' ;
16
+
17
+ const ReactVersionTestingAgainst = process . env . REACT_VERSION || ReactVersion ;
13
18
14
19
describe ( 'Timeline profiler' , ( ) => {
15
20
let React ;
@@ -76,6 +81,13 @@ describe('Timeline profiler', () => {
76
81
}
77
82
78
83
beforeEach ( ( ) => {
84
+ // Mock react/jsx-dev-runtime for React 16.x
85
+ // Although there are no tests in this suite which will run for React 16,
86
+ // Jest will report an error trying to resolve this dependency
87
+ if ( semver . lt ( ReactVersionTestingAgainst , '17.0.0' ) ) {
88
+ jest . mock ( 'react/jsx-dev-runtime' , ( ) => { } ) ;
89
+ }
90
+
79
91
utils = require ( './utils' ) ;
80
92
utils . beforeEachProfiling ( ) ;
81
93
@@ -107,6 +119,8 @@ describe('Timeline profiler', () => {
107
119
setPerformanceMock ( null ) ;
108
120
} ) ;
109
121
122
+ const { render : legacyRender } = getLegacyRenderImplementation ( ) ;
123
+
110
124
describe ( 'getLanesFromTransportDecimalBitmask' , ( ) => {
111
125
let getLanesFromTransportDecimalBitmask ;
112
126
@@ -614,8 +628,10 @@ describe('Timeline profiler', () => {
614
628
` ) ;
615
629
} ) ;
616
630
631
+ // @reactVersion <= 18.2
632
+ // @reactVersion >= 18.0
617
633
it ( 'should process a sample legacy render sequence' , async ( ) => {
618
- utils . legacyRender ( < div /> , document . createElement ( 'div' ) ) ;
634
+ legacyRender ( < div /> ) ;
619
635
620
636
const data = await preprocessData ( [
621
637
...createBoilerplateEntries ( ) ,
@@ -629,31 +645,31 @@ describe('Timeline profiler', () => {
629
645
"batchUID": 0,
630
646
"depth": 0,
631
647
"duration": 0.01,
632
- "lanes": "0b0000000000000000000000000000001 ",
648
+ "lanes": "0b0000000000000000000000000000000 ",
633
649
"timestamp": 0.006,
634
650
"type": "render-idle",
635
651
},
636
652
{
637
653
"batchUID": 0,
638
654
"depth": 0,
639
655
"duration": 0.001,
640
- "lanes": "0b0000000000000000000000000000001 ",
656
+ "lanes": "0b0000000000000000000000000000000 ",
641
657
"timestamp": 0.006,
642
658
"type": "render",
643
659
},
644
660
{
645
661
"batchUID": 0,
646
662
"depth": 0,
647
663
"duration": 0.008,
648
- "lanes": "0b0000000000000000000000000000001 ",
664
+ "lanes": "0b0000000000000000000000000000000 ",
649
665
"timestamp": 0.008,
650
666
"type": "commit",
651
667
},
652
668
{
653
669
"batchUID": 0,
654
670
"depth": 1,
655
671
"duration": 0.001,
656
- "lanes": "0b0000000000000000000000000000001 ",
672
+ "lanes": "0b0000000000000000000000000000000 ",
657
673
"timestamp": 0.014,
658
674
"type": "layout-effects",
659
675
},
@@ -714,41 +730,41 @@ describe('Timeline profiler', () => {
714
730
30 => "Offscreen",
715
731
},
716
732
"laneToReactMeasureMap": Map {
717
- 0 => [],
718
- 1 => [
733
+ 0 => [
719
734
{
720
735
"batchUID": 0,
721
736
"depth": 0,
722
737
"duration": 0.01,
723
- "lanes": "0b0000000000000000000000000000001 ",
738
+ "lanes": "0b0000000000000000000000000000000 ",
724
739
"timestamp": 0.006,
725
740
"type": "render-idle",
726
741
},
727
742
{
728
743
"batchUID": 0,
729
744
"depth": 0,
730
745
"duration": 0.001,
731
- "lanes": "0b0000000000000000000000000000001 ",
746
+ "lanes": "0b0000000000000000000000000000000 ",
732
747
"timestamp": 0.006,
733
748
"type": "render",
734
749
},
735
750
{
736
751
"batchUID": 0,
737
752
"depth": 0,
738
753
"duration": 0.008,
739
- "lanes": "0b0000000000000000000000000000001 ",
754
+ "lanes": "0b0000000000000000000000000000000 ",
740
755
"timestamp": 0.008,
741
756
"type": "commit",
742
757
},
743
758
{
744
759
"batchUID": 0,
745
760
"depth": 1,
746
761
"duration": 0.001,
747
- "lanes": "0b0000000000000000000000000000001 ",
762
+ "lanes": "0b0000000000000000000000000000000 ",
748
763
"timestamp": 0.014,
749
764
"type": "layout-effects",
750
765
},
751
766
],
767
+ 1 => [],
752
768
2 => [],
753
769
3 => [],
754
770
4 => [],
@@ -785,7 +801,7 @@ describe('Timeline profiler', () => {
785
801
"reactVersion": "<filtered-version>",
786
802
"schedulingEvents": [
787
803
{
788
- "lanes": "0b0000000000000000000000000000001 ",
804
+ "lanes": "0b0000000000000000000000000000000 ",
789
805
"timestamp": 0.005,
790
806
"type": "schedule-render",
791
807
"warning": null,
@@ -1132,9 +1148,9 @@ describe('Timeline profiler', () => {
1132
1148
} ) ;
1133
1149
1134
1150
// @reactVersion >= 18.0
1151
+ // @reactVersion <= 18.2
1135
1152
it ( 'should error if events and measures are incomplete' , async ( ) => {
1136
- const container = document . createElement ( 'div' ) ;
1137
- utils . legacyRender ( < div /> , container ) ;
1153
+ legacyRender ( < div /> ) ;
1138
1154
1139
1155
const invalidMarks = clearedMarks . filter (
1140
1156
mark => ! mark . includes ( 'render-stop' ) ,
@@ -1150,9 +1166,9 @@ describe('Timeline profiler', () => {
1150
1166
} ) ;
1151
1167
1152
1168
// @reactVersion >= 18.0
1169
+ // @reactVersion <= 18.2
1153
1170
it ( 'should error if work is completed without being started' , async ( ) => {
1154
- const container = document . createElement ( 'div' ) ;
1155
- utils . legacyRender ( < div /> , container ) ;
1171
+ legacyRender ( < div /> ) ;
1156
1172
1157
1173
const invalidMarks = clearedMarks . filter (
1158
1174
mark => ! mark . includes ( 'render-start' ) ,
@@ -1262,6 +1278,7 @@ describe('Timeline profiler', () => {
1262
1278
describe ( 'warnings' , ( ) => {
1263
1279
describe ( 'long event handlers' , ( ) => {
1264
1280
// @reactVersion >= 18.0
1281
+ // @reactVersion <= 18.2
1265
1282
it ( 'should not warn when React scedules a (sync) update inside of a short event handler' , async ( ) => {
1266
1283
function App ( ) {
1267
1284
return null ;
@@ -1275,7 +1292,7 @@ describe('Timeline profiler', () => {
1275
1292
1276
1293
clearPendingMarks ( ) ;
1277
1294
1278
- utils . legacyRender ( < App /> , document . createElement ( 'div' ) ) ;
1295
+ legacyRender ( < App /> ) ;
1279
1296
1280
1297
testMarks . push ( ...createUserTimingData ( clearedMarks ) ) ;
1281
1298
@@ -1285,6 +1302,7 @@ describe('Timeline profiler', () => {
1285
1302
} ) ;
1286
1303
1287
1304
// @reactVersion >= 18.0
1305
+ // @reactVersion <= 18.2
1288
1306
it ( 'should not warn about long events if the cause was non-React JavaScript' , async ( ) => {
1289
1307
function App ( ) {
1290
1308
return null ;
@@ -1300,7 +1318,7 @@ describe('Timeline profiler', () => {
1300
1318
1301
1319
clearPendingMarks ( ) ;
1302
1320
1303
- utils . legacyRender ( < App /> , document . createElement ( 'div' ) ) ;
1321
+ legacyRender ( < App /> ) ;
1304
1322
1305
1323
testMarks . push ( ...createUserTimingData ( clearedMarks ) ) ;
1306
1324
@@ -1310,6 +1328,7 @@ describe('Timeline profiler', () => {
1310
1328
} ) ;
1311
1329
1312
1330
// @reactVersion >= 18.0
1331
+ // @reactVersion <= 18.2
1313
1332
it ( 'should warn when React scedules a long (sync) update inside of an event' , async ( ) => {
1314
1333
function App ( ) {
1315
1334
return null ;
@@ -1323,7 +1342,7 @@ describe('Timeline profiler', () => {
1323
1342
1324
1343
clearPendingMarks ( ) ;
1325
1344
1326
- utils . legacyRender ( < App /> , document . createElement ( 'div' ) ) ;
1345
+ legacyRender ( < App /> ) ;
1327
1346
1328
1347
clearedMarks . forEach ( markName => {
1329
1348
if ( markName === '--render-stop' ) {
@@ -1929,8 +1948,12 @@ describe('Timeline profiler', () => {
1929
1948
global . IS_REACT_ACT_ENVIRONMENT = true ;
1930
1949
} ) ;
1931
1950
1951
+ const { render : legacyRender } = getLegacyRenderImplementation ( ) ;
1952
+
1953
+ // @reactVersion <= 18.2
1954
+ // @reactVersion >= 18.0
1932
1955
it ( 'should process a sample legacy render sequence' , async ( ) => {
1933
- utils . legacyRender ( < div /> , document . createElement ( 'div' ) ) ;
1956
+ legacyRender ( < div /> ) ;
1934
1957
utils . act ( ( ) => store . profilerStore . stopProfiling ( ) ) ;
1935
1958
1936
1959
const data = store . profilerStore . profilingData ?. timelineData ;
@@ -1944,31 +1967,31 @@ describe('Timeline profiler', () => {
1944
1967
"batchUID": 1,
1945
1968
"depth": 0,
1946
1969
"duration": 0,
1947
- "lanes": "0b0000000000000000000000000000010 ",
1970
+ "lanes": "0b0000000000000000000000000000001 ",
1948
1971
"timestamp": 10,
1949
1972
"type": "render-idle",
1950
1973
},
1951
1974
{
1952
1975
"batchUID": 1,
1953
1976
"depth": 0,
1954
1977
"duration": 0,
1955
- "lanes": "0b0000000000000000000000000000010 ",
1978
+ "lanes": "0b0000000000000000000000000000001 ",
1956
1979
"timestamp": 10,
1957
1980
"type": "render",
1958
1981
},
1959
1982
{
1960
1983
"batchUID": 1,
1961
1984
"depth": 0,
1962
1985
"duration": 0,
1963
- "lanes": "0b0000000000000000000000000000010 ",
1986
+ "lanes": "0b0000000000000000000000000000001 ",
1964
1987
"timestamp": 10,
1965
1988
"type": "commit",
1966
1989
},
1967
1990
{
1968
1991
"batchUID": 1,
1969
1992
"depth": 1,
1970
1993
"duration": 0,
1971
- "lanes": "0b0000000000000000000000000000010 ",
1994
+ "lanes": "0b0000000000000000000000000000001 ",
1972
1995
"timestamp": 10,
1973
1996
"type": "layout-effects",
1974
1997
},
@@ -1979,13 +2002,13 @@ describe('Timeline profiler', () => {
1979
2002
"flamechart": [],
1980
2003
"internalModuleSourceToRanges": Map {},
1981
2004
"laneToLabelMap": Map {
1982
- 1 => "SyncHydrationLane ",
1983
- 2 => "Sync ",
1984
- 4 => "InputContinuousHydration ",
1985
- 8 => "InputContinuous ",
1986
- 16 => "DefaultHydration ",
1987
- 32 => "Default ",
1988
- 64 => "TransitionHydration ",
2005
+ 1 => "Sync ",
2006
+ 2 => "InputContinuousHydration ",
2007
+ 4 => "InputContinuous ",
2008
+ 8 => "DefaultHydration ",
2009
+ 16 => "Default ",
2010
+ 32 => "TransitionHydration ",
2011
+ 64 => "Transition ",
1989
2012
128 => "Transition",
1990
2013
256 => "Transition",
1991
2014
512 => "Transition",
@@ -2005,48 +2028,48 @@ describe('Timeline profiler', () => {
2005
2028
8388608 => "Retry",
2006
2029
16777216 => "Retry",
2007
2030
33554432 => "Retry",
2008
- 67108864 => "SelectiveHydration ",
2009
- 134217728 => "IdleHydration ",
2010
- 268435456 => "Idle ",
2011
- 536870912 => "Offscreen ",
2012
- 1073741824 => "Deferred ",
2031
+ 67108864 => "Retry ",
2032
+ 134217728 => "SelectiveHydration ",
2033
+ 268435456 => "IdleHydration ",
2034
+ 536870912 => "Idle ",
2035
+ 1073741824 => "Offscreen ",
2013
2036
},
2014
2037
"laneToReactMeasureMap": Map {
2015
- 1 => [],
2016
- 2 => [
2038
+ 1 => [
2017
2039
{
2018
2040
"batchUID": 1,
2019
2041
"depth": 0,
2020
2042
"duration": 0,
2021
- "lanes": "0b0000000000000000000000000000010 ",
2043
+ "lanes": "0b0000000000000000000000000000001 ",
2022
2044
"timestamp": 10,
2023
2045
"type": "render-idle",
2024
2046
},
2025
2047
{
2026
2048
"batchUID": 1,
2027
2049
"depth": 0,
2028
2050
"duration": 0,
2029
- "lanes": "0b0000000000000000000000000000010 ",
2051
+ "lanes": "0b0000000000000000000000000000001 ",
2030
2052
"timestamp": 10,
2031
2053
"type": "render",
2032
2054
},
2033
2055
{
2034
2056
"batchUID": 1,
2035
2057
"depth": 0,
2036
2058
"duration": 0,
2037
- "lanes": "0b0000000000000000000000000000010 ",
2059
+ "lanes": "0b0000000000000000000000000000001 ",
2038
2060
"timestamp": 10,
2039
2061
"type": "commit",
2040
2062
},
2041
2063
{
2042
2064
"batchUID": 1,
2043
2065
"depth": 1,
2044
2066
"duration": 0,
2045
- "lanes": "0b0000000000000000000000000000010 ",
2067
+ "lanes": "0b0000000000000000000000000000001 ",
2046
2068
"timestamp": 10,
2047
2069
"type": "layout-effects",
2048
2070
},
2049
2071
],
2072
+ 2 => [],
2050
2073
4 => [],
2051
2074
8 => [],
2052
2075
16 => [],
@@ -2083,7 +2106,7 @@ describe('Timeline profiler', () => {
2083
2106
"reactVersion": "<filtered-version>",
2084
2107
"schedulingEvents": [
2085
2108
{
2086
- "lanes": "0b0000000000000000000000000000010 ",
2109
+ "lanes": "0b0000000000000000000000000000001 ",
2087
2110
"timestamp": 10,
2088
2111
"type": "schedule-render",
2089
2112
"warning": null,
0 commit comments