[test] Exclude repository root from assertions (#35361)
Sebastian "Sebbie" Silbermann committed
Dec 15, 2025 at 11:45 UTC
ba5b843692519a226347aecfb789d90fcb24b4bc
5 files changed
+27
-17
.eslintrc.js
+1
@@ -635,6 +635,7 @@ module.exports = {
635
FocusOptions: 'readonly',
636
OptionalEffectTiming: 'readonly',
637
638
+ __REACT_ROOT_PATH_TEST__: 'readonly',
639
spyOnDev: 'readonly',
640
spyOnDevAndProd: 'readonly',
641
spyOnProd: 'readonly',
packages/internal-test-utils/debugInfo.js
+1
-5
@@ -1,9 +1,5 @@
1
'use strict';
2
3
-const path = require('path');
4
-
5
-const repoRoot = path.resolve(__dirname, '../../');
6
-
3
type DebugInfoConfig = {
4
ignoreProps?: boolean,
5
ignoreRscStreamInfo?: boolean,
@@ -34,7 +30,7 @@ function normalizeStack(stack) {
30
const [name, file, line, col, enclosingLine, enclosingCol] = stack[i];
31
copy.push([
32
name,
37
- file.replace(repoRoot, ''),
33
+ file.replace(__REACT_ROOT_PATH_TEST__, ''),
34
line,
35
col,
36
enclosingLine,
packages/react-client/src/__tests__/ReactFlight-test.js
+1
-4
@@ -10,8 +10,6 @@
10
11
'use strict';
12
13
-const path = require('path');
14
-
13
if (typeof Blob === 'undefined') {
14
global.Blob = require('buffer').Blob;
15
}
@@ -33,9 +31,8 @@ function normalizeCodeLocInfo(str) {
31
);
32
}
33
36
-const repoRoot = path.resolve(__dirname, '../../../../');
34
function normalizeReactCodeLocInfo(str) {
38
- const repoRootForRegexp = repoRoot.replace(/\//g, '\\/');
35
+ const repoRootForRegexp = __REACT_ROOT_PATH_TEST__.replace(/\//g, '\\/');
36
const repoFileLocMatch = new RegExp(`${repoRootForRegexp}.+?:\\d+:\\d+`, 'g');
37
return str && str.replace(repoFileLocMatch, '**');
38
}
packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js
+20
-8
@@ -39,6 +39,10 @@ function normalizeCodeLocInfo(str) {
39
);
40
}
41
42
+function normalizeSerializedContent(str) {
43
+ return str.replaceAll(__REACT_ROOT_PATH_TEST__, '**');
44
+}
45
+
46
describe('ReactFlightDOMEdge', () => {
47
beforeEach(() => {
48
// Mock performance.now for timing tests
@@ -481,8 +485,10 @@ describe('ReactFlightDOMEdge', () => {
485
);
486
const [stream1, stream2] = passThrough(stream).tee();
487
484
- const serializedContent = await readResult(stream1);
485
- expect(serializedContent.length).toBeLessThan(1100);
488
+ const serializedContent = normalizeSerializedContent(
489
+ await readResult(stream1),
490
+ );
491
+ expect(serializedContent.length).toBeLessThan(1075);
492
493
const result = await ReactServerDOMClient.createFromReadableStream(
494
stream2,
@@ -551,9 +557,11 @@ describe('ReactFlightDOMEdge', () => {
557
);
558
const [stream1, stream2] = passThrough(stream).tee();
559
554
- const serializedContent = await readResult(stream1);
560
+ const serializedContent = normalizeSerializedContent(
561
+ await readResult(stream1),
562
+ );
563
556
- expect(serializedContent.length).toBeLessThan(490);
564
+ expect(serializedContent.length).toBeLessThan(465);
565
expect(timesRendered).toBeLessThan(5);
566
567
const model = await ReactServerDOMClient.createFromReadableStream(stream2, {
@@ -623,8 +631,10 @@ describe('ReactFlightDOMEdge', () => {
631
);
632
const [stream1, stream2] = passThrough(stream).tee();
633
626
- const serializedContent = await readResult(stream1);
627
- expect(serializedContent.length).toBeLessThan(__DEV__ ? 680 : 400);
634
+ const serializedContent = normalizeSerializedContent(
635
+ await readResult(stream1),
636
+ );
637
+ expect(serializedContent.length).toBeLessThan(__DEV__ ? 630 : 400);
638
expect(timesRendered).toBeLessThan(5);
639
640
const model = await serverAct(() =>
@@ -657,8 +667,10 @@ describe('ReactFlightDOMEdge', () => {
667
<ServerComponent recurse={20} />,
668
),
669
);
660
- const serializedContent = await readResult(stream);
661
- const expectedDebugInfoSize = __DEV__ ? 320 * 20 : 0;
670
+ const serializedContent = normalizeSerializedContent(
671
+ await readResult(stream),
672
+ );
673
+ const expectedDebugInfoSize = __DEV__ ? 295 * 20 : 0;
674
expect(serializedContent.length).toBeLessThan(150 + expectedDebugInfoSize);
675
});
676
scripts/jest/setupTests.js
+4
@@ -6,6 +6,7 @@ const {
6
resetAllUnexpectedConsoleCalls,
7
patchConsoleMethods,
8
} = require('internal-test-utils/consoleMock');
9
+const path = require('path');
10
11
if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
12
// Inside the class equivalence tester, we have a custom environment, let's
@@ -18,6 +19,9 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
19
const spyOn = jest.spyOn;
20
const noop = jest.fn;
21
22
+ // Can be used to normalize paths in stackframes
23
+ global.__REACT_ROOT_PATH_TEST__ = path.resolve(__dirname, '../..');
24
+
25
// Spying on console methods in production builds can mask errors.
26
// This is why we added an explicit spyOnDev() helper.
27
// It's too easy to accidentally use the more familiar spyOn() helper though,