Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ module.exports = {
FocusOptions: 'readonly',
OptionalEffectTiming: 'readonly',

__REACT_ROOT_PATH_TEST__: 'readonly',
spyOnDev: 'readonly',
spyOnDevAndProd: 'readonly',
spyOnProd: 'readonly',
Expand Down
6 changes: 1 addition & 5 deletions packages/internal-test-utils/debugInfo.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict';

const path = require('path');

const repoRoot = path.resolve(__dirname, '../../');

type DebugInfoConfig = {
ignoreProps?: boolean,
ignoreRscStreamInfo?: boolean,
Expand Down Expand Up @@ -34,7 +30,7 @@ function normalizeStack(stack) {
const [name, file, line, col, enclosingLine, enclosingCol] = stack[i];
copy.push([
name,
file.replace(repoRoot, ''),
file.replace(__REACT_ROOT_PATH_TEST__, ''),
line,
col,
enclosingLine,
Expand Down
5 changes: 1 addition & 4 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

'use strict';

const path = require('path');

if (typeof Blob === 'undefined') {
global.Blob = require('buffer').Blob;
}
Expand All @@ -33,9 +31,8 @@ function normalizeCodeLocInfo(str) {
);
}

const repoRoot = path.resolve(__dirname, '../../../../');
function normalizeReactCodeLocInfo(str) {
const repoRootForRegexp = repoRoot.replace(/\//g, '\\/');
const repoRootForRegexp = __REACT_ROOT_PATH_TEST__.replace(/\//g, '\\/');
const repoFileLocMatch = new RegExp(`${repoRootForRegexp}.+?:\\d+:\\d+`, 'g');
return str && str.replace(repoFileLocMatch, '**');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function normalizeCodeLocInfo(str) {
);
}

function normalizeSerializedContent(str) {
return str.replaceAll(__REACT_ROOT_PATH_TEST__, '**');
}

describe('ReactFlightDOMEdge', () => {
beforeEach(() => {
// Mock performance.now for timing tests
Expand Down Expand Up @@ -481,8 +485,10 @@ describe('ReactFlightDOMEdge', () => {
);
const [stream1, stream2] = passThrough(stream).tee();

const serializedContent = await readResult(stream1);
expect(serializedContent.length).toBeLessThan(1100);
const serializedContent = normalizeSerializedContent(
await readResult(stream1),
);
expect(serializedContent.length).toBeLessThan(1075);

const result = await ReactServerDOMClient.createFromReadableStream(
stream2,
Expand Down Expand Up @@ -551,9 +557,11 @@ describe('ReactFlightDOMEdge', () => {
);
const [stream1, stream2] = passThrough(stream).tee();

const serializedContent = await readResult(stream1);
const serializedContent = normalizeSerializedContent(
await readResult(stream1),
);

expect(serializedContent.length).toBeLessThan(490);
expect(serializedContent.length).toBeLessThan(465);
expect(timesRendered).toBeLessThan(5);

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

const serializedContent = await readResult(stream1);
expect(serializedContent.length).toBeLessThan(__DEV__ ? 680 : 400);
const serializedContent = normalizeSerializedContent(
await readResult(stream1),
);
expect(serializedContent.length).toBeLessThan(__DEV__ ? 630 : 400);
expect(timesRendered).toBeLessThan(5);

const model = await serverAct(() =>
Expand Down Expand Up @@ -657,8 +667,10 @@ describe('ReactFlightDOMEdge', () => {
<ServerComponent recurse={20} />,
),
);
const serializedContent = await readResult(stream);
const expectedDebugInfoSize = __DEV__ ? 320 * 20 : 0;
const serializedContent = normalizeSerializedContent(
await readResult(stream),
);
const expectedDebugInfoSize = __DEV__ ? 295 * 20 : 0;
expect(serializedContent.length).toBeLessThan(150 + expectedDebugInfoSize);
});

Expand Down
4 changes: 4 additions & 0 deletions scripts/jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
resetAllUnexpectedConsoleCalls,
patchConsoleMethods,
} = require('internal-test-utils/consoleMock');
const path = require('path');

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

// Can be used to normalize paths in stackframes
global.__REACT_ROOT_PATH_TEST__ = path.resolve(__dirname, '../..');

// Spying on console methods in production builds can mask errors.
// This is why we added an explicit spyOnDev() helper.
// It's too easy to accidentally use the more familiar spyOn() helper though,
Expand Down
Loading