-
Notifications
You must be signed in to change notification settings - Fork 842
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
Add support for React 18 #7012
Merged
Merged
Add support for React 18 #7012
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
35b3358
feat(DragAndDrop): Switch from react-beautiful-dnd to its fork @hello…
tkajtoch 1c672b1
Add basic React 18 support (#6827)
tkajtoch 160001d
build: Cypress React 18 support and React version switcher (#6933)
tkajtoch d8e93f1
build: adjust enzyme, RTL and jest to run in React 18 runtime (#6940)
tkajtoch 4551c0e
test: React 18 snapshot adjustments (#6944)
tkajtoch e36d4cc
test: React 18 act() adjustments (#6943)
tkajtoch ab7f6cc
feature: EuiDataGrid type improvements to support React 18 (#6958)
tkajtoch f6e1afe
[React 18] Fix remaining TypeScript errors (#6988)
tkajtoch 1b9ed70
[React 18] Fix cross-version compatibility and unit test errors (#7002)
tkajtoch bf42924
[React 18] Fix flaky cypress tests (#7003)
tkajtoch 496d1ae
[React 18] Add full <StrictMode> support (#7007)
tkajtoch 6931692
docs: add changelog
tkajtoch d92103c
feat: add <StrictMode> switcher flag and default to false in docs app
tkajtoch f601d1f
docs: update changelog to remove <StrictMode> note
tkajtoch 48a2563
Fix crashing popover demo
cee-chen 85a71e5
Fix `EuiWrappingPopover` demo to use React 18
cee-chen 9c220c9
Update CodeSandbox to use React 18 APIs
cee-chen 5b30513
:facepalm: fix CodeSandbox
cee-chen 2230fed
refactor: move react version test utilities to src/test/internal
tkajtoch c6b40d4
fix: remove code that's been moved to another file and incorrectly re…
tkajtoch 7e214eb
fix: remove unused TextEncoder jest polyfill
tkajtoch f879d52
Update upcoming_changelogs/7012.md
tkajtoch 2fa936e
[PR feedback] Minor cleanup
cee-chen 95beab1
[EuiInlineEdit] Types cleanup
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { ReactNode } from 'react'; | ||
import { EuiProvider, EuiProviderProps } from '../../../src'; | ||
import type { mount } from '@cypress/react18'; | ||
|
||
// Pick cypress mount function based on which React version is currently being | ||
// tested. It has to be directly compared against process.env.REACT_VERSION | ||
// for tree-shaking to work and not throw an error because of a missing import. | ||
let cypressMount: typeof mount; | ||
if (process.env.REACT_VERSION === '18') { | ||
cypressMount = require('@cypress/react18').mount; | ||
} else { | ||
cypressMount = require('@cypress/react').mount; | ||
} | ||
|
||
export interface MountOptions { | ||
providerProps?: Partial<EuiProviderProps<any>>; | ||
} | ||
|
||
const mountCommand = ( | ||
children: ReactNode, | ||
options: MountOptions = {} | ||
): ReturnType<typeof mount> => { | ||
const { providerProps } = options; | ||
return cypressMount(<EuiProvider {...providerProps}>{children}</EuiProvider>); | ||
}; | ||
|
||
// Export only the type to not confuse code-completion tools | ||
export type mountCommand = typeof mountCommand; | ||
|
||
Cypress.Commands.add('mount', mountCommand); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const getCacheDirectory = | ||
require('jest-config/build/getCacheDirectory').default; | ||
|
||
// Set REACT_VERSION env variable to latest if empty or invalid | ||
if (!['16', '17', '18'].includes(process.env.REACT_VERSION)) { | ||
process.env.REACT_VERSION = '18'; | ||
} | ||
|
||
const reactVersion = process.env.REACT_VERSION; | ||
|
||
console.log(`Running tests on React v${reactVersion}`); | ||
|
||
/** @type {import('jest').Config} */ | ||
const config = { | ||
rootDir: '../../', | ||
roots: [ | ||
'<rootDir>/src/', | ||
'<rootDir>/src-docs/src/components', | ||
'<rootDir>/scripts/babel', | ||
'<rootDir>/scripts/tests', | ||
'<rootDir>/scripts/eslint-plugin', | ||
], | ||
collectCoverageFrom: [ | ||
'src/{components,services,global_styling}/**/*.{ts,tsx,js,jsx}', | ||
'!src/{components,services,global_styling}/**/*.{testenv,spec,a11y,stories}.{ts,tsx,js,jsx}', | ||
'!src/{components,services,global_styling}/index.ts', | ||
'!src/{components,services,global_styling}/**/*/index.ts', | ||
'!src/components/date_picker/react-datepicker/**/*.{js,jsx}', | ||
], | ||
moduleNameMapper: { | ||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': | ||
'<rootDir>/scripts/jest/mocks/file_mock.js', | ||
'\\.(css|less|scss)$': '<rootDir>/scripts/jest/mocks/style_mock.js', | ||
}, | ||
setupFiles: [ | ||
'<rootDir>/scripts/jest/setup/enzyme.js', | ||
'<rootDir>/scripts/jest/setup/throw_on_console_error.js', | ||
'<rootDir>/scripts/jest/setup/mocks.js', | ||
], | ||
setupFilesAfterEnv: [ | ||
'<rootDir>/scripts/jest/setup/polyfills.js', | ||
'<rootDir>/scripts/jest/setup/unmount_enzyme.js', | ||
], | ||
coverageDirectory: '<rootDir>/reports/jest-coverage', | ||
coverageReporters: ['json', 'html'], | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], | ||
testMatch: ['**/*.test.js', '**/*.test.ts', '**/*.test.tsx'], | ||
transform: { | ||
'^.+\\.(js|tsx?)$': 'babel-jest', | ||
}, | ||
snapshotSerializers: [ | ||
'<rootDir>/node_modules/enzyme-to-json/serializer', | ||
'<rootDir>/scripts/jest/setup/emotion', | ||
], | ||
// react version and user permissions aware cache directory | ||
cacheDirectory: `${getCacheDirectory()}_react-${reactVersion}`, | ||
}; | ||
|
||
if (['16', '17'].includes(reactVersion)) { | ||
config.moduleNameMapper[ | ||
'^@testing-library/react((\\\\/.*)?)$' | ||
] = `@testing-library/react-16-17$1`; | ||
config.moduleNameMapper['^react((\\/.*)?)$'] = `react-${reactVersion}$1`; | ||
|
||
config.moduleNameMapper[ | ||
'^react-dom((\\/.*)?)$' | ||
] = `react-dom-${reactVersion}$1`; | ||
} | ||
|
||
module.exports = config; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, it looks like a lot of the
act()
issues that came up during your feature branch were the result of a RTL bug that is going to be shortly fixed in another release: testing-library/react-testing-library#1216Apparently only upgrading to
v13.4.0
also would have resolved the issue 🤷