Skip to content

Commit ba5b843

Browse files
authored
[test] Exclude repository root from assertions (#35361)
1 parent b061b59 commit ba5b843

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ module.exports = {
635635
FocusOptions: 'readonly',
636636
OptionalEffectTiming: 'readonly',
637637

638+
__REACT_ROOT_PATH_TEST__: 'readonly',
638639
spyOnDev: 'readonly',
639640
spyOnDevAndProd: 'readonly',
640641
spyOnProd: 'readonly',

packages/internal-test-utils/debugInfo.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
'use strict';
22

3-
const path = require('path');
4-
5-
const repoRoot = path.resolve(__dirname, '../../');
6-
73
type DebugInfoConfig = {
84
ignoreProps?: boolean,
95
ignoreRscStreamInfo?: boolean,
@@ -34,7 +30,7 @@ function normalizeStack(stack) {
3430
const [name, file, line, col, enclosingLine, enclosingCol] = stack[i];
3531
copy.push([
3632
name,
37-
file.replace(repoRoot, ''),
33+
file.replace(__REACT_ROOT_PATH_TEST__, ''),
3834
line,
3935
col,
4036
enclosingLine,

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
'use strict';
1212

13-
const path = require('path');
14-
1513
if (typeof Blob === 'undefined') {
1614
global.Blob = require('buffer').Blob;
1715
}
@@ -33,9 +31,8 @@ function normalizeCodeLocInfo(str) {
3331
);
3432
}
3533

36-
const repoRoot = path.resolve(__dirname, '../../../../');
3734
function normalizeReactCodeLocInfo(str) {
38-
const repoRootForRegexp = repoRoot.replace(/\//g, '\\/');
35+
const repoRootForRegexp = __REACT_ROOT_PATH_TEST__.replace(/\//g, '\\/');
3936
const repoFileLocMatch = new RegExp(`${repoRootForRegexp}.+?:\\d+:\\d+`, 'g');
4037
return str && str.replace(repoFileLocMatch, '**');
4138
}

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ function normalizeCodeLocInfo(str) {
3939
);
4040
}
4141

42+
function normalizeSerializedContent(str) {
43+
return str.replaceAll(__REACT_ROOT_PATH_TEST__, '**');
44+
}
45+
4246
describe('ReactFlightDOMEdge', () => {
4347
beforeEach(() => {
4448
// Mock performance.now for timing tests
@@ -481,8 +485,10 @@ describe('ReactFlightDOMEdge', () => {
481485
);
482486
const [stream1, stream2] = passThrough(stream).tee();
483487

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);
486492

487493
const result = await ReactServerDOMClient.createFromReadableStream(
488494
stream2,
@@ -551,9 +557,11 @@ describe('ReactFlightDOMEdge', () => {
551557
);
552558
const [stream1, stream2] = passThrough(stream).tee();
553559

554-
const serializedContent = await readResult(stream1);
560+
const serializedContent = normalizeSerializedContent(
561+
await readResult(stream1),
562+
);
555563

556-
expect(serializedContent.length).toBeLessThan(490);
564+
expect(serializedContent.length).toBeLessThan(465);
557565
expect(timesRendered).toBeLessThan(5);
558566

559567
const model = await ReactServerDOMClient.createFromReadableStream(stream2, {
@@ -623,8 +631,10 @@ describe('ReactFlightDOMEdge', () => {
623631
);
624632
const [stream1, stream2] = passThrough(stream).tee();
625633

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);
628638
expect(timesRendered).toBeLessThan(5);
629639

630640
const model = await serverAct(() =>
@@ -657,8 +667,10 @@ describe('ReactFlightDOMEdge', () => {
657667
<ServerComponent recurse={20} />,
658668
),
659669
);
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;
662674
expect(serializedContent.length).toBeLessThan(150 + expectedDebugInfoSize);
663675
});
664676

scripts/jest/setupTests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
resetAllUnexpectedConsoleCalls,
77
patchConsoleMethods,
88
} = require('internal-test-utils/consoleMock');
9+
const path = require('path');
910

1011
if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
1112
// Inside the class equivalence tester, we have a custom environment, let's
@@ -18,6 +19,9 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
1819
const spyOn = jest.spyOn;
1920
const noop = jest.fn;
2021

22+
// Can be used to normalize paths in stackframes
23+
global.__REACT_ROOT_PATH_TEST__ = path.resolve(__dirname, '../..');
24+
2125
// Spying on console methods in production builds can mask errors.
2226
// This is why we added an explicit spyOnDev() helper.
2327
// It's too easy to accidentally use the more familiar spyOn() helper though,

0 commit comments

Comments
 (0)