-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
🪟 🔧 Use jest directly as test runner #21174
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
env: { | ||
test: { | ||
// Define presets used to compile code when running jest tests | ||
presets: [ | ||
["@babel/preset-env", { targets: { node: "current" } }], | ||
["@babel/preset-react", { runtime: "automatic" }], | ||
"@babel/preset-typescript", | ||
], | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// eslint-disable-next-line jest/no-jest-import | ||
import type { Config } from "jest"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ Actual jest config, compiled from our previous |
||
|
||
const jestConfig: Config = { | ||
verbose: true, | ||
// Required to overwrite the default which would ignore node_modules from transformation, | ||
// but several node_modules are not transpiled so they would fail without babel transformation running | ||
transformIgnorePatterns: [], | ||
snapshotSerializers: ["./src/test-utils/classname-serializer.js"], | ||
coveragePathIgnorePatterns: ["\\.stories\\.tsx$"], | ||
modulePathIgnorePatterns: ["src/.*/__mocks__"], | ||
testEnvironment: "jsdom", | ||
moduleDirectories: ["node_modules", "src"], | ||
moduleNameMapper: { | ||
"\\.module\\.scss$": "test-utils/mock-data/mockIdentity.js", | ||
"\\.(css|png|svg|scss)$": "test-utils/mock-data/mockEmpty.js", | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ Make sure we mock asset imports in a way that jest test run properly. |
||
}, | ||
setupFilesAfterEnv: ["./src/test-utils/setup-tests.ts"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ Moved this file (and the |
||
}; | ||
|
||
export default jestConfig; |
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// An empty object exported that jest can use for png, css, or svg asset imports | ||
module.exports = {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// A mock that will return the name of the property called on it. | ||
// Useful for mocking out (S)CSS modules. | ||
|
||
module.exports = new Proxy( | ||
{}, | ||
{ | ||
get: (target, key) => { | ||
if (key === "__esModule") { | ||
return false; | ||
} | ||
return key; | ||
}, | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// jest-dom adds custom jest matchers for asserting on DOM nodes. | ||
// allows you to do things like: | ||
// expect(element).toHaveTextContent(/react/i) | ||
// learn more: https://github.com/testing-library/jest-dom | ||
import "@testing-library/jest-dom/extend-expect"; | ||
import "@testing-library/jest-dom"; | ||
import "../globals"; | ||
|
||
// jsdom doesn't mock `matchMedia`, which is required by react-slick | ||
Object.defineProperty(window, "matchMedia", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ Rewrote this mock slightly from what we had beforehand here, to align with what |
||
writable: true, | ||
value: jest.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // deprecated | ||
removeListener: jest.fn(), // deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn(), | ||
})), | ||
}); |
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.
ℹ️ Add the require babel configuration (that
babel-jest
will read) that is required to transform our code. We only add this when running in thetest
environment, to not potentially collide with any configuration of Create React App, while we're still using it to build the rest of the app.