-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Cee Chen <[email protected]> Co-authored-by: Cee Chen <[email protected]>
- Loading branch information
1 parent
90909b6
commit d3e8e0b
Showing
176 changed files
with
5,099 additions
and
2,437 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
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.