Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed May 23, 2024
1 parent ca08d8c commit f497a1e
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 57 deletions.
16 changes: 8 additions & 8 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,10 +1123,11 @@ describe('ReactFlight', () => {
}

function App() {
return (
<Indirection>
<ClientComponent />
</Indirection>
// We use the ReactServer runtime here to get the Server owner.
return ReactServer.createElement(
Indirection,
null,
ReactServer.createElement(ClientComponent),
);
}

Expand All @@ -1143,11 +1144,10 @@ describe('ReactFlight', () => {
'\n' +
'Check the render method of `Component`. See https://react.dev/link/warning-keys for more information.\n' +
' in span (at **)\n' +
// TODO: Because this validates after the div has been mounted, it is part of
// the parent stack but since owner stacks will switch to owners this goes away again.
(gate(flags => flags.enableOwnerStacks) ? ' in div (at **)\n' : '') +
' in Component (at **)\n' +
' in Indirection (at **)\n' +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in Indirection (at **)\n') +
' in App (at **)',
);
});
Expand Down
8 changes: 6 additions & 2 deletions packages/react-dom/src/__tests__/ReactChildReconciler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ describe('ReactChildReconciler', () => {
'could change in a future version.\n' +
' in div (at **)\n' +
' in Component (at **)\n' +
' in Parent (at **)\n' +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in Parent (at **)\n') +
' in GrandParent (at **)',
);
});
Expand Down Expand Up @@ -189,7 +191,9 @@ describe('ReactChildReconciler', () => {
'could change in a future version.\n' +
' in div (at **)\n' +
' in Component (at **)\n' +
' in Parent (at **)\n' +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in Parent (at **)\n') +
' in GrandParent (at **)',
);
});
Expand Down
8 changes: 6 additions & 2 deletions packages/react-dom/src/__tests__/ReactComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@ describe('ReactComponent', () => {
'Or maybe you meant to call this function rather than return it.\n' +
' <span>{Foo}</span>\n' +
' in span (at **)\n' +
' in div (at **)\n' +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in div (at **)\n') +
' in Foo (at **)',
);
});
Expand Down Expand Up @@ -820,7 +822,9 @@ describe('ReactComponent', () => {
'Or maybe you meant to call this function rather than return it.\n' +
' <span>{Foo}</span>\n' +
' in span (at **)\n' +
' in div (at **)\n' +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in div (at **)\n') +
' in Foo (at **)',
]);
await act(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ describe('ReactDOM', () => {
// ReactDOM(App > div > span)
'Invalid ARIA attribute `ariaTypo`. ARIA attributes follow the pattern aria-* and must be lowercase.\n' +
' in span (at **)\n' +
' in div (at **)\n' +
(gate(flags => flags.enableOwnerStacks) ? '' : ' in div (at **)\n') +
' in App (at **)',
// ReactDOM(App > div > ServerEntry) >>> ReactDOMServer(Child) >>> ReactDOMServer(App2) >>> ReactDOMServer(blink)
'Invalid ARIA attribute `ariaTypo2`. ARIA attributes follow the pattern aria-* and must be lowercase.\n' +
Expand All @@ -569,7 +569,7 @@ describe('ReactDOM', () => {
// ReactDOM(App > div > font)
'Invalid ARIA attribute `ariaTypo5`. ARIA attributes follow the pattern aria-* and must be lowercase.\n' +
' in font (at **)\n' +
' in div (at **)\n' +
(gate(flags => flags.enableOwnerStacks) ? '' : ' in div (at **)\n') +
' in App (at **)',
]);
});
Expand Down
8 changes: 6 additions & 2 deletions packages/react-dom/src/__tests__/ReactMultiChild-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ describe('ReactMultiChild', () => {
'could change in a future version.\n' +
' in div (at **)\n' +
' in WrapperComponent (at **)\n' +
' in div (at **)\n' +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in div (at **)\n') +
' in Parent (at **)',
);
});
Expand Down Expand Up @@ -292,7 +294,9 @@ describe('ReactMultiChild', () => {
'could change in a future version.\n' +
' in div (at **)\n' +
' in WrapperComponent (at **)\n' +
' in div (at **)\n' +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in div (at **)\n') +
' in Parent (at **)',
);
});
Expand Down
13 changes: 11 additions & 2 deletions packages/react-dom/src/__tests__/ReactUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ describe('ReactUpdates', () => {
it('warns about a deferred infinite update loop with useEffect', async () => {
function NonTerminating() {
const [step, setStep] = React.useState(0);
React.useEffect(() => {
React.useEffect(function myEffect() {
setStep(x => x + 1);
});
return step;
Expand All @@ -1860,10 +1860,12 @@ describe('ReactUpdates', () => {

let error = null;
let stack = null;
let nativeStack = null;
const originalConsoleError = console.error;
console.error = (e, s) => {
error = e;
stack = s;
nativeStack = new Error().stack;
Scheduler.log('stop');
};
try {
Expand All @@ -1876,7 +1878,14 @@ describe('ReactUpdates', () => {
}

expect(error).toContain('Maximum update depth exceeded');
expect(stack).toContain('at NonTerminating');
// The currently executing effect should be on the native stack
expect(nativeStack).toContain('at myEffect');
if (!gate(flags => flags.enableOwnerStacks)) {
// The currently running component's name is not in the owner
// stack because it's just its JSX callsite.
expect(stack).toContain('at NonTerminating');
}
expect(stack).toContain('at App');
});

it('can have nested updates if they do not cross the limit', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ describe('ReactHooks', () => {
useImperativeHandle(ref, () => {}, props.deps);
return null;
});
App.displayName = 'App';

await expect(async () => {
await act(() => {
Expand Down Expand Up @@ -846,6 +847,7 @@ describe('ReactHooks', () => {
});
return null;
});
App.displayName = 'App';

await expect(async () => {
await act(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ describe('ReactIncrementalErrorLogging', () => {
),
expect.stringMatching(
new RegExp(
'\\s+(in|at) ErrorThrowingComponent (.*)\n' +
'\\s+(in|at) span(.*)\n' +
'\\s+(in|at) div(.*)',
gate(flags => flags.enableOwnerStacks)
? '\\s+(in|at) ErrorThrowingComponent'
: '\\s+(in|at) ErrorThrowingComponent (.*)\n' +
'\\s+(in|at) span(.*)\n' +
'\\s+(in|at) div(.*)',
),
),
);
Expand Down Expand Up @@ -139,9 +141,11 @@ describe('ReactIncrementalErrorLogging', () => {
),
expect.stringMatching(
new RegExp(
'\\s+(in|at) ErrorThrowingComponent (.*)\n' +
'\\s+(in|at) span(.*)\n' +
'\\s+(in|at) div(.*)',
gate(flags => flags.enableOwnerStacks)
? '\\s+(in|at) ErrorThrowingComponent'
: '\\s+(in|at) ErrorThrowingComponent (.*)\n' +
'\\s+(in|at) span(.*)\n' +
'\\s+(in|at) div(.*)',
),
),
);
Expand Down Expand Up @@ -197,10 +201,12 @@ describe('ReactIncrementalErrorLogging', () => {
),
expect.stringMatching(
new RegExp(
'\\s+(in|at) ErrorThrowingComponent (.*)\n' +
'\\s+(in|at) span(.*)\n' +
'\\s+(in|at) ErrorBoundary(.*)\n' +
'\\s+(in|at) div(.*)',
gate(flags => flags.enableOwnerStacks)
? '\\s+(in|at) ErrorThrowingComponent'
: '\\s+(in|at) ErrorThrowingComponent (.*)\n' +
'\\s+(in|at) span(.*)\n' +
'\\s+(in|at) ErrorBoundary(.*)\n' +
'\\s+(in|at) div(.*)',
),
),
);
Expand Down Expand Up @@ -278,9 +284,7 @@ describe('ReactIncrementalErrorLogging', () => {
),
expect.stringMatching(
gate(flag => flag.enableOwnerStacks)
? // With owner stacks the return path is cut off but in this case
// this is also what the owner stack looks like.
new RegExp('\\s+(in|at) Foo (.*)')
? new RegExp('\\s+(in|at) Foo')
: new RegExp(
'\\s+(in|at) Foo (.*)\n' + '\\s+(in|at) ErrorBoundary(.*)',
),
Expand Down
21 changes: 13 additions & 8 deletions packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,18 @@ describe('ReactLazy', () => {

expect(error.message).toMatch('Element type is invalid');
assertLog(['Loading...']);
assertConsoleErrorDev([
'Expected the result of a dynamic import() call',
'Expected the result of a dynamic import() call',
]);
assertConsoleErrorDev(
[
'Expected the result of a dynamic import() call',
'Expected the result of a dynamic import() call',
],
gate(flags => flags.enableOwnerStacks)
? {
// There's no owner
withoutStack: true,
}
: undefined,
);
expect(root).not.toMatchRenderedOutput('Hi');
});

Expand Down Expand Up @@ -996,10 +1004,7 @@ describe('ReactLazy', () => {
await act(() => resolveFakeImport(Foo));
assertLog(['A', 'B']);
}).toErrorDev(
' in Text (at **)\n' +
// TODO: Because this validates after the div has been mounted, it is part of
// the parent stack but since owner stacks will switch to owners this goes away again.
(gate(flags => flags.enableOwnerStacks) ? ' in div (at **)\n' : '') +
(gate(flags => flags.enableOwnerStacks) ? '' : ' in Text (at **)\n') +
' in Foo (at **)',
);
expect(root).toMatchRenderedOutput(<div>AB</div>);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/__tests__/ReactMemo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ describe('memo', () => {
'\n\nCheck the top-level render call using <Inner>. It was passed a child from Inner. ' +
'See https://react.dev/link/warning-keys for more information.\n' +
' in span (at **)\n' +
' in Inner (at **)\n' +
' in p (at **)',
' in Inner (at **)' +
(gate(flags => flags.enableOwnerStacks) ? '' : '\n in p (at **)'),
);
});

Expand Down
12 changes: 8 additions & 4 deletions packages/react/src/__tests__/ReactCreateRef-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ describe('ReactCreateRef', () => {
).toErrorDev(
'Unexpected ref object provided for div. ' +
'Use either a ref-setter function or React.createRef().\n' +
' in div (at **)\n' +
' in Wrapper (at **)',
' in div (at **)' +
(gate(flags => flags.enableOwnerStacks)
? ''
: '\n in Wrapper (at **)'),
);

expect(() =>
Expand All @@ -60,8 +62,10 @@ describe('ReactCreateRef', () => {
).toErrorDev(
'Unexpected ref object provided for ExampleComponent. ' +
'Use either a ref-setter function or React.createRef().\n' +
' in ExampleComponent (at **)\n' +
' in Wrapper (at **)',
' in ExampleComponent (at **)' +
(gate(flags => flags.enableOwnerStacks)
? ''
: '\n in Wrapper (at **)'),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,10 @@ describe('ReactElementValidator', () => {
'"key" prop.\n\nCheck the render method of `Component`. See ' +
'https://react.dev/link/warning-keys for more information.\n' +
' in div (at **)\n' +
// TODO: Because this validates after the div has been mounted, it is part of
// the parent stack but since owner stacks will switch to owners this goes away again.
(gate(flags => flags.enableOwnerStacks) ? ' in div (at **)\n' : '') +
' in Component (at **)\n' +
' in Parent (at **)\n' +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in Parent (at **)\n') +
' in GrandParent (at **)',
);
});
Expand Down Expand Up @@ -262,8 +261,6 @@ describe('ReactElementValidator', () => {
'Each child in a list should have a unique "key" prop.' +
'\n\nCheck the render method of `ParentComp`. It was passed a child from MyComp. ' +
'See https://react.dev/link/warning-keys for more information.\n' +
// TODO: Because this validates after the div has been mounted, it is part of
// the parent stack but since owner stacks will switch to owners this goes away again.
' in div (at **)\n' +
' in MyComp (at **)\n' +
' in ParentComp (at **)',
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/__tests__/ReactJSXElementValidator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ describe('ReactJSXElementValidator', () => {
'Each child in a list should have a unique "key" prop.' +
'\n\nCheck the render method of `ParentComp`. It was passed a child from MyComp. ' +
'See https://react.dev/link/warning-keys for more information.\n' +
// TODO: Because this validates after the div has been mounted, it is part of
// the parent stack but since owner stacks will switch to owners this goes away again.
' in div (at **)\n' +
' in MyComp (at **)\n' +
' in ParentComp (at **)',
Expand Down
7 changes: 3 additions & 4 deletions packages/react/src/__tests__/ReactJSXRuntime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ describe('ReactJSXRuntime', () => {
}).toErrorDev(
'Warning: Each child in a list should have a unique "key" prop.\n\n' +
'Check the render method of `Parent`. See https://react.dev/link/warning-keys for more information.\n' +
' in Child (at **)\n' +
// TODO: Because this validates after the div has been mounted, it is part of
// the parent stack but since owner stacks will switch to owners this goes away again.
(gate(flags => flags.enableOwnerStacks) ? ' in div (at **)\n' : '') +
(gate(flags => flags.enableOwnerStacks)
? ''
: ' in Child (at **)\n') +
' in Parent (at **)',
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ describe('create-react-class-integration', () => {
return null;
},
});
Component.displayName = 'Component';

await expect(async () => {
await expect(async () => {
Expand Down Expand Up @@ -643,6 +644,7 @@ describe('create-react-class-integration', () => {
return null;
},
});
Component.displayName = 'Component';

await expect(async () => {
await expect(async () => {
Expand Down

0 comments on commit f497a1e

Please sign in to comment.