-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Cypress React 18 support and React version switcher (#6933)
* refactor: convert Cypress mount and realMount commands to TypeScript * build: Conditionally use @cypress/react or @cypress/react18 depending on REACT_VERSION environment variable * build: add Cypress React version switcher * docs: update cypress-testing.md * build: move react version console.log
- Loading branch information
Showing
9 changed files
with
129 additions
and
101 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +0,0 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { mount as cypressMount } from 'cypress/react'; | ||
import { EuiProvider } from '../../../src'; | ||
|
||
Cypress.Commands.add('mount', (children, options = {}) => { | ||
const { providerProps } = options; | ||
return cypressMount(<EuiProvider {...providerProps}>{children}</EuiProvider>); | ||
}); | ||
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,30 @@ | ||
/* | ||
* 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 } 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; | ||
} | ||
|
||
const mountCommand = (children: ReactNode): ReturnType<typeof mount> => { | ||
return cypressMount(<EuiProvider>{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
Oops, something went wrong.