mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
[test] Exclude repository root from assertions (#35361)
This commit is contained in:
committed by
GitHub
parent
b061b597f7
commit
ba5b843692
@@ -635,6 +635,7 @@ module.exports = {
|
||||
FocusOptions: 'readonly',
|
||||
OptionalEffectTiming: 'readonly',
|
||||
|
||||
__REACT_ROOT_PATH_TEST__: 'readonly',
|
||||
spyOnDev: 'readonly',
|
||||
spyOnDevAndProd: 'readonly',
|
||||
spyOnProd: 'readonly',
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const repoRoot = path.resolve(__dirname, '../../');
|
||||
|
||||
type DebugInfoConfig = {
|
||||
ignoreProps?: boolean,
|
||||
ignoreRscStreamInfo?: boolean,
|
||||
@@ -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,
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
if (typeof Blob === 'undefined') {
|
||||
global.Blob = require('buffer').Blob;
|
||||
}
|
||||
@@ -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, '**');
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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,
|
||||
@@ -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, {
|
||||
@@ -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(() =>
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user