Skip to content

Commit

Permalink
test: Restructure testing setup.
Browse files Browse the repository at this point in the history
Mostly following https://github.com/vercel/next.js/tree/6a32d854fcbb8bb513371db0584375c17c219815/examples/with-jest

Preparation for testing of react components and hooks
  • Loading branch information
oBusk committed Oct 4, 2021
1 parent 35b5214 commit d921d97
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.next
.vscode/.chrome
coverage/
1 change: 1 addition & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "test-file-stub";
3 changes: 3 additions & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Mock CSS files.

module.exports = {};
26 changes: 17 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
module.exports = {
collectCoverageFrom: ["src/**/*.{js,ts,jsx,tsx}", "!**/*.d.ts"],
moduleDirectories: ["node_modules", "src"],
collectCoverageFrom: [
"**/*.{js,jsx,ts,tsx}",
"!**/*.d.ts",
"!**/node_modules/**",
],
coverageDirectory: "coverage",
testPathIgnorePatterns: ["/node_modules/", "/.next/"],
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
moduleNameMapper: {
// Handle CSS imports (with CSS modules)
// https://jestjs.io/docs/webpack#mocking-css-modules
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",

// Handle CSS imports (without CSS modules)
"^.+\\.(css|sass|scss)$": "<rootDir>/__mocks__/styleMock.js",

// Handle image imports
// https://jestjs.io/docs/webpack#handling-static-assets
"^.+\\.(jpg|jpeg|png|gif|webp|svg)$": "<rootDir>/__mocks__/fileMock.js",
},
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/.next/"],
transformIgnorePatterns: [
"/node_modules/",
"^.+\\.module\\.(css|sass|scss)$",
],
};
Loading

0 comments on commit d921d97

Please sign in to comment.