Skip to content

Commit 69bb335

Browse files
feat: jest configuration
1 parent ef22e3d commit 69bb335

3 files changed

Lines changed: 328 additions & 26 deletions

File tree

jest.config.ts

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
const nextJest = require("next/jest");
2+
3+
const createJestConfig = nextJest({
4+
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
5+
dir: "./",
6+
});
7+
18
/*
29
* For a detailed explanation regarding each configuration property and type check, visit:
310
* https://jestjs.io/docs/configuration
@@ -32,10 +39,10 @@ const jestConfig = {
3239
// coverageDirectory: undefined,
3340

3441
// An array of regexp pattern strings used to skip coverage collection
35-
coveragePathIgnorePatterns: ["/node_modules/"],
42+
// coveragePathIgnorePatterns: ["/node_modules/"],
3643

3744
// Indicates which provider should be used to instrument code for coverage
38-
coverageProvider: "v8",
45+
// coverageProvider: "babel",
3946

4047
// A list of reporter names that Jest uses when writing coverage reports
4148
// coverageReporters: [
@@ -75,7 +82,7 @@ const jestConfig = {
7582
// maxWorkers: "50%",
7683

7784
// An array of directory names to be searched recursively up from the requiring module's location
78-
moduleDirectories: ["node_modules"],
85+
// moduleDirectories: ["node_modules", "."],
7986

8087
// An array of file extensions your modules use
8188
// moduleFileExtensions: [
@@ -90,31 +97,37 @@ const jestConfig = {
9097
// ],
9198

9299
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
93-
moduleNameMapper: {
94-
/* Handle CSS imports (with CSS modules)
95-
https://jestjs.io/docs/webpack#mocking-css-modules */
96-
"^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
97-
98-
// Handle CSS imports (without CSS modules)
99-
"^.+\\.(css|sass|scss)$": "<rootDir>/__mocks__/styleMock.js",
100+
// moduleNameMapper: {
101+
// /* Handle CSS imports (with CSS modules)
102+
// https://jestjs.io/docs/webpack#mocking-css-modules */
103+
// "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
104+
105+
// // Handle CSS imports (without CSS modules)
106+
// "^.+\\.(css|sass|scss)$": "<rootDir>/__mocks__/styleMock.js",
107+
108+
// /* Handle image imports
109+
// https://jestjs.io/docs/webpack#handling-static-assets */
110+
// "^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$":
111+
// "<rootDir>/__mocks__/fileMock.js",
112+
// },
100113

101-
/* Handle image imports
102-
https://jestjs.io/docs/webpack#handling-static-assets */
103-
"^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$":
104-
"<rootDir>/__mocks__/fileMock.js",
114+
moduleNameMapper: {
115+
"^@(components)/(.*)$": "<rootDir>/$1/$2",
105116
},
106117

107118
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
108119
// modulePathIgnorePatterns: [],
109120

121+
modulePaths: ["<rootDir>"],
122+
110123
// Activates notifications for test results
111124
// notify: false,
112125

113126
// An enum that specifies notification mode. Requires { notify: true }
114127
// notifyMode: "failure-change",
115128

116129
// A preset that is used as a base for Jest's configuration
117-
// preset: undefined,
130+
// preset: "ts-jest",
118131

119132
// Run tests from one or more projects
120133
// projects: undefined,
@@ -138,9 +151,7 @@ const jestConfig = {
138151
// rootDir: undefined,
139152

140153
// A list of paths to directories that Jest should use to search for files in
141-
// roots: [
142-
// "<rootDir>"
143-
// ],
154+
roots: ["<rootDir>"],
144155

145156
// Allows you to use a custom runner instead of Jest's default test runner
146157
// runner: "jest-runner",
@@ -158,7 +169,7 @@ const jestConfig = {
158169
// snapshotSerializers: [],
159170

160171
// The test environment that will be used for testing
161-
testEnvironment: "jsdom",
172+
testEnvironment: "jest-environment-jsdom",
162173

163174
// Options that will be passed to the testEnvironment
164175
// testEnvironmentOptions: {},
@@ -170,7 +181,7 @@ const jestConfig = {
170181
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)"],
171182

172183
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
173-
testPathIgnorePatterns: ["/node_modules/"],
184+
// testPathIgnorePatterns: ["/node_modules/"],
174185

175186
// The regexp pattern or array of patterns that Jest uses to detect test files
176187
// testRegex: [],
@@ -182,13 +193,17 @@ const jestConfig = {
182193
// testRunner: "jest-circus/runner",
183194

184195
// A map from regular expressions to paths to transformers
185-
// transform: undefined,
196+
// transform: {
197+
// /* Use babel-jest to transpile tests with the next/babel preset
198+
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object */
199+
// "^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }],
200+
// },
186201

187202
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
188-
transformIgnorePatterns: [
189-
"/node_modules/",
190-
"^.+\\.module\\.(css|sass|scss)$",
191-
],
203+
// transformIgnorePatterns: [
204+
// "/node_modules/",
205+
// "^.+\\.module\\.(css|sass|scss)$",
206+
// ],
192207

193208
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
194209
// unmockedModulePathPatterns: undefined,
@@ -203,4 +218,4 @@ const jestConfig = {
203218
// watchman: true,
204219
};
205220

206-
export default jestConfig;
221+
export default createJestConfig(jestConfig);

0 commit comments

Comments
 (0)