-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): setup jest test to run against the last three major vers…
…ion of react (#392)
- Loading branch information
Showing
10 changed files
with
117 additions
and
46 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 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,64 @@ | ||
// eslint-disable-next-line import/no-import-module-exports | ||
import type { Config } from 'jest'; | ||
|
||
declare global { | ||
interface ProcessEnv { | ||
REACT_MAJOR_VERSION: string; | ||
CI?: boolean; | ||
} | ||
} | ||
|
||
const reactMajorVersion = process.env.REACT_MAJOR_VERSION; | ||
|
||
const config: Config = { | ||
clearMocks: true, | ||
modulePathIgnorePatterns: ['/dist/'], | ||
resetMocks: true, | ||
resetModules: true, | ||
restoreMocks: true, | ||
|
||
// We need a `snapshotResolver` because we run our tests | ||
// for different react versions. Each version render components | ||
// differently thus returning a different snapshot. We'll store | ||
// each snapshot in different folders: | ||
// __react_16_snapshots__, __react_17_snapshots__, etc. | ||
snapshotResolver: '<rootDir>/test/setup/snapshot-resolver.ts', | ||
setupFiles: ['./test/setup/env-setup.ts'], | ||
setupFilesAfterEnv: ['./test/setup/test-setup.ts'], | ||
testEnvironment: './test/setup/environment.ts', | ||
// node_modules is default. | ||
testPathIgnorePatterns: ['/node_modules/', '/cypress/'], | ||
transform: { | ||
'\\.[jt]sx?$': 'babel-jest', | ||
}, | ||
verbose: true, | ||
watchPlugins: [ | ||
'jest-watch-typeahead/filename', | ||
'jest-watch-typeahead/testname', | ||
], | ||
}; | ||
|
||
// eslint-disable-next-line no-console | ||
console.log('Testing with React version:', `${reactMajorVersion || '18'}.x.x`); | ||
|
||
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`, | ||
}; | ||
} | ||
|
||
if (process.env.CI) { | ||
config.maxWorkers = 2; | ||
} | ||
|
||
module.exports = config; |
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,28 @@ | ||
import path from 'path'; | ||
|
||
// resolve snapshot folder with the react version | ||
// __react_16_snapshots__, __react_17_snapshots__, etc. | ||
export default { | ||
// resolves from test to snapshot path | ||
resolveSnapshotPath: (testPath: string, snapshotExtension: string) => { | ||
const breadcrumb = testPath.split(path.sep); | ||
const filename = breadcrumb.pop(); | ||
|
||
return ( | ||
[ | ||
...breadcrumb, | ||
`__react_${process.env.REACT_MAJOR_VERSION}_snapshots__`, | ||
filename, | ||
].join(path.sep) + snapshotExtension | ||
); | ||
}, | ||
|
||
// resolves from snapshot to test path | ||
resolveTestPath: (snapshotFilePath: string, snapshotExtension: string) => | ||
snapshotFilePath | ||
.replace(/__react_[0-9]+_snapshots__[\\/]/, '') | ||
.slice(0, -snapshotExtension.length), | ||
|
||
// Example test path, used for preflight consistency check of the implementation above | ||
testPathForConsistencyCheck: 'some/example.test.ts', | ||
}; |
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
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
...t/integration/server-side-rendering/__react_17_snapshots__/server-rendering.spec.tsx.snap
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should support rendering to a string 1`] = `"<main data-reactroot=\\"\\"><div data-rfd-droppable-id=\\"droppable\\" data-rfd-droppable-context-id=\\"0\\"><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"0\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"0\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"0\\">item: <!-- -->0</div><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"1\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"1\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"1\\">item: <!-- -->1</div><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"2\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"2\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"2\\">item: <!-- -->2</div></div></main>"`; | ||
|
||
exports[`should support rendering to static markup 1`] = `"<main><div data-rfd-droppable-id=\\"droppable\\" data-rfd-droppable-context-id=\\"0\\"><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"0\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"0\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"0\\">item: 0</div><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"1\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"1\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"1\\">item: 1</div><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"2\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"2\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"2\\">item: 2</div></div></main>"`; |
5 changes: 5 additions & 0 deletions
5
...t/integration/server-side-rendering/__react_18_snapshots__/server-rendering.spec.tsx.snap
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should support rendering to a string 1`] = `"<main><div data-rfd-droppable-id=\\"droppable\\" data-rfd-droppable-context-id=\\"0\\"><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"0\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"0\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"0\\">item: <!-- -->0</div><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"1\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"1\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"1\\">item: <!-- -->1</div><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"2\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"2\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"2\\">item: <!-- -->2</div></div></main>"`; | ||
|
||
exports[`should support rendering to static markup 1`] = `"<main><div data-rfd-droppable-id=\\"droppable\\" data-rfd-droppable-context-id=\\"0\\"><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"0\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"0\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"0\\">item: 0</div><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"1\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"1\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"1\\">item: 1</div><div data-rfd-draggable-context-id=\\"0\\" data-rfd-draggable-id=\\"2\\" tabindex=\\"0\\" role=\\"button\\" aria-describedby=\\"rfd-hidden-text-0-hidden-text-0\\" data-rfd-drag-handle-draggable-id=\\"2\\" data-rfd-drag-handle-context-id=\\"0\\" draggable=\\"false\\" data-is-dragging=\\"false\\" data-is-drop-animating=\\"false\\" data-is-combining=\\"false\\" data-is-combine-target=\\"false\\" data-is-clone=\\"false\\" data-testid=\\"2\\">item: 2</div></div></main>"`; |