Skip to content

Commit c915573

Browse files
committed
Add client test scaffold
1 parent 2aea707 commit c915573

7 files changed

+2697
-89
lines changed

client/jest.config.ts

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/**
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
import nextJest from "next/jest.js";
7+
8+
import type { Config } from "jest";
9+
10+
const createJestConfig = nextJest({
11+
dir: ".",
12+
});
13+
14+
const config: Config = {
15+
setupFilesAfterEnv: ["./jest.setup.ts"],
16+
17+
// All imported modules in your tests should be mocked automatically
18+
// automock: false,
19+
20+
// Stop running tests after `n` failures
21+
// bail: 0,
22+
23+
// The directory where Jest should store its cached dependency information
24+
// cacheDirectory: "/private/var/folders/ts/91_w1yvx1173n9rnxj7vy7mm0000gp/T/jest_dy",
25+
26+
// Automatically clear mock calls, instances, contexts and results before every test
27+
clearMocks: true,
28+
29+
// Indicates whether the coverage information should be collected while executing the test
30+
// collectCoverage: false,
31+
32+
// An array of glob patterns indicating a set of files for which coverage information should be collected
33+
// collectCoverageFrom: undefined,
34+
35+
// The directory where Jest should output its coverage files
36+
// coverageDirectory: undefined,
37+
38+
// An array of regexp pattern strings used to skip coverage collection
39+
// coveragePathIgnorePatterns: [
40+
// "/node_modules/"
41+
// ],
42+
43+
// Indicates which provider should be used to instrument code for coverage
44+
coverageProvider: "v8",
45+
46+
// A list of reporter names that Jest uses when writing coverage reports
47+
// coverageReporters: [
48+
// "json",
49+
// "text",
50+
// "lcov",
51+
// "clover"
52+
// ],
53+
54+
// An object that configures minimum threshold enforcement for coverage results
55+
// coverageThreshold: undefined,
56+
57+
// A path to a custom dependency extractor
58+
// dependencyExtractor: undefined,
59+
60+
// Make calling deprecated APIs throw helpful error messages
61+
// errorOnDeprecated: false,
62+
63+
// The default configuration for fake timers
64+
// fakeTimers: {
65+
// "enableGlobally": false
66+
// },
67+
68+
// Force coverage collection from ignored files using an array of glob patterns
69+
// forceCoverageMatch: [],
70+
71+
// A path to a module which exports an async function that is triggered once before all test suites
72+
// globalSetup: undefined,
73+
74+
// A path to a module which exports an async function that is triggered once after all test suites
75+
// globalTeardown: undefined,
76+
77+
// A set of global variables that need to be available in all test environments
78+
// globals: {},
79+
80+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
81+
// maxWorkers: "50%",
82+
83+
// An array of directory names to be searched recursively up from the requiring module's location
84+
// moduleDirectories: [
85+
// "node_modules"
86+
// ],
87+
88+
// An array of file extensions your modules use
89+
// moduleFileExtensions: [
90+
// "js",
91+
// "mjs",
92+
// "cjs",
93+
// "jsx",
94+
// "ts",
95+
// "tsx",
96+
// "json",
97+
// "node"
98+
// ],
99+
100+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
101+
// moduleNameMapper: {},
102+
103+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
104+
// modulePathIgnorePatterns: [],
105+
106+
// Activates notifications for test results
107+
// notify: false,
108+
109+
// An enum that specifies notification mode. Requires { notify: true }
110+
// notifyMode: "failure-change",
111+
112+
// A preset that is used as a base for Jest's configuration
113+
// preset: undefined,
114+
115+
// Run tests from one or more projects
116+
// projects: undefined,
117+
118+
// Use this configuration option to add custom reporters to Jest
119+
// reporters: undefined,
120+
121+
// Automatically reset mock state before every test
122+
// resetMocks: false,
123+
124+
// Reset the module registry before running each individual test
125+
// resetModules: false,
126+
127+
// A path to a custom resolver
128+
// resolver: undefined,
129+
130+
// Automatically restore mock state and implementation before every test
131+
// restoreMocks: false,
132+
133+
// The root directory that Jest should scan for tests and modules within
134+
// rootDir: undefined,
135+
136+
// A list of paths to directories that Jest should use to search for files in
137+
// roots: [
138+
// "<rootDir>"
139+
// ],
140+
141+
// Allows you to use a custom runner instead of Jest's default test runner
142+
// runner: "jest-runner",
143+
144+
// The paths to modules that run some code to configure or set up the testing environment before each test
145+
// setupFiles: [],
146+
147+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
148+
// setupFilesAfterEnv: [],
149+
150+
// The number of seconds after which a test is considered as slow and reported as such in the results.
151+
// slowTestThreshold: 5,
152+
153+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
154+
// snapshotSerializers: [],
155+
156+
// The test environment that will be used for testing
157+
testEnvironment: "jsdom",
158+
159+
// Options that will be passed to the testEnvironment
160+
// testEnvironmentOptions: {},
161+
162+
// Adds a location field to test results
163+
// testLocationInResults: false,
164+
165+
// The glob patterns Jest uses to detect test files
166+
// testMatch: [
167+
// "**/__tests__/**/*.[jt]s?(x)",
168+
// "**/?(*.)+(spec|test).[tj]s?(x)"
169+
// ],
170+
171+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
172+
// testPathIgnorePatterns: [
173+
// "/node_modules/"
174+
// ],
175+
176+
// The regexp pattern or array of patterns that Jest uses to detect test files
177+
// testRegex: [],
178+
179+
// This option allows the use of a custom results processor
180+
// testResultsProcessor: undefined,
181+
182+
// This option allows use of a custom test runner
183+
// testRunner: "jest-circus/runner",
184+
185+
// A map from regular expressions to paths to transformers
186+
// transform: undefined,
187+
188+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
189+
// transformIgnorePatterns: [
190+
// "/node_modules/",
191+
// "\\.pnp\\.[^\\/]+$"
192+
// ],
193+
194+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
195+
// unmockedModulePathPatterns: undefined,
196+
197+
// Indicates whether each individual test should be reported during the run
198+
// verbose: undefined,
199+
200+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
201+
// watchPathIgnorePatterns: [],
202+
203+
// Whether to use watchman for file crawling
204+
// watchman: true,
205+
};
206+
207+
export default createJestConfig(config);

client/jest.setup.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Globally import jest on test runs
2+
3+
import "@testing-library/jest-dom";

client/package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"preinstall": "npx only-allow pnpm"
10+
"preinstall": "npx only-allow pnpm",
11+
"test": "jest"
1112
},
1213
"dependencies": {
1314
"clsx": "2.1.1",
@@ -18,6 +19,9 @@
1819
"tailwind-merge": "2.3.0"
1920
},
2021
"devDependencies": {
22+
"@testing-library/jest-dom": "^5.4.5",
23+
"@testing-library/react": "^15.0.7",
24+
"@types/jest": "^29.5.12",
2125
"@types/node": "^20",
2226
"@types/react": "^18",
2327
"@types/react-dom": "^18",
@@ -28,9 +32,12 @@
2832
"eslint-config-prettier": "^9.1.0",
2933
"eslint-plugin-import": "^2.29.1",
3034
"eslint-plugin-prettier": "^5.1.3",
35+
"jest": "^29.7.0",
36+
"jest-environment-jsdom": "^29.7.0",
3137
"postcss": "^8",
3238
"prettier": "^3.2.5",
3339
"tailwindcss": "^3.4.1",
40+
"ts-node": "^10.9.2",
3441
"typescript": "^5"
3542
},
3643
"packageManager": "[email protected]+sha256.22e36fba7f4880ecf749a5ca128b8435da085ecd49575e7fb9e64d6bf4fad394"

0 commit comments

Comments
 (0)