Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: run test with react v16 v17 and v18 #392

Merged

Conversation

100terres
Copy link
Collaborator

@100terres 100terres commented Aug 20, 2022

@100terres 100terres changed the base branch from main to react-18 August 20, 2022 14:44
Comment on lines 9 to 29
useEffect(() => {
// clean up the registry to avoid any leaks
return function unmount() {
// clean up the registry to avoid any leaks
// doing it after an animation frame so that other things unmounting
// can continue to interact with the registry
requestAnimationFrame(registry.clean);
// FIXME: we do not know if this is still needed, but to make sure we do not
// break any existing existing code using react 16 and 17 we'll
// continue to clean up after an animation frame
//
// The requestAnimationFrame polyfill was added in this commit:
// https://github.com/atlassian/react-beautiful-dnd/pull/1487/commits/8bdffb9d077b0009400620d9cf6575bba7af13dc#diff-b3b2de485fa432e394aebc8abf54be40ad7fac9b39a2ed818fddfd56f1786c53
if (React.version.startsWith('16') || React.version.startsWith('17')) {
// doing it after an animation frame so that other things unmounting
// can continue to interact with the registry
requestAnimationFrame(registry.clean);
} else {
// starting with react v18, we must invoke clean immediately
// we won't be able to access the registry after the unmount
// more details here: https://beta.reactjs.org/learn/synchronizing-with-effects#how-to-handle-the-effect-firing-twice-in-development
registry.clean();
}
};
}, [registry]);
Copy link
Collaborator Author

@100terres 100terres Aug 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Usage without the useEffectOnce as we do in hello-pangea/dnd.

@100terres 100terres self-assigned this Aug 20, 2022
@100terres 100terres force-pushed the 320-run-test-suite-for-react-v16-v17-and-v18-take-2 branch 2 times, most recently from c13f7f7 to c17701b Compare August 20, 2022 17:05
@100terres 100terres force-pushed the 320-run-test-suite-for-react-v16-v17-and-v18-take-2 branch 2 times, most recently from 5768ade to 36e97eb Compare August 20, 2022 20:04
@100terres 100terres linked an issue Aug 21, 2022 that may be closed by this pull request
@100terres 100terres force-pushed the 320-run-test-suite-for-react-v16-v17-and-v18-take-2 branch from e2c13c9 to 36e97eb Compare August 21, 2022 00:22
@100terres 100terres marked this pull request as ready for review August 21, 2022 00:35
@100terres
Copy link
Collaborator Author

@Xhale1 this PR is ready for your review 🙂 I've invited you as a maintainer. I'll be able to assign you as a reviewer once you've accept the invitation.

Comment on lines 193 to +196
- test-unit:
matrix:
parameters:
react-major-version: ['16', '17', '18']
Copy link
Collaborator Author

@100terres 100terres Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This is to run our unit tests three times with a different value in the REACT_MAJOR_VERSION environment variable.

.storybook/main.js Outdated Show resolved Hide resolved
Comment on lines +10 to +14
reactOptions: {
strictMode: true,
},
Copy link
Collaborator Author

@100terres 100terres Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ strict mode enabled in storybook 🎉

Comment on lines +11 to 18
export const decorators: DecoratorFn[] = [
(story, { id }: { id: string }) => {
resetData(id);

return <Story key={id} />;
return story({ key: id });
},
(Story: React.ElementType): React.ReactElement => (
<GlobalStyles>
<Story />
</GlobalStyles>
),
withPerformance,
(story) => <GlobalStyles>{story()}</GlobalStyles>,
];
Copy link
Collaborator Author

@100terres 100terres Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ There was an issue with the strict mode, because of we were using the story as a component.

see: storybookjs/storybook#15223 (comment)

Comment on lines +38 to +58
if (['16', '17'].includes(reactMajorVersion)) {
config.testPathIgnorePatterns = [
...(config.testPathIgnorePatterns || []),
// These test do not requires react and will
// be run in the base run (with react v18)
'test/unit/docs',
'test/unit/health',
];
config.cacheDirectory = `.cache/jest-cache-react-${reactMajorVersion}`;
config.moduleNameMapper = {
'^@testing-library/react((\\/.*)?)$': `@testing-library/react-16-17$1`,
'^react-dom((\\/.*)?)$': `react-dom-${reactMajorVersion}$1`,
'^react((\\/.*)?)$': `react-${reactMajorVersion}$1`,
};
}
Copy link
Collaborator Author

@100terres 100terres Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Important peice of code to be able to test with react 16, 17 and 18.


// override react-virtualized's types, because the current version
// uses react 17 types
declare module 'react-virtualized' {
Copy link
Collaborator Author

@100terres 100terres Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ react-virtualized does not support react 18

100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
… set (#392)

also reactor how we manipulate environment variables in our test
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
… set (#392)

also reactor how we manipulate environment variables in our test
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
100terres added a commit that referenced this pull request Aug 21, 2022
… set (#392)

also reactor how we manipulate environment variables in our test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run test suite for react v16, v17 and v18 Support strict mode with react v18
2 participants