Skip to content

Commit d09e34d

Browse files
ceccecclaude
andcommitted
fix(test): make jest run under ESM + sync config with tsconfig
pnpm test failed before any test loaded: package.json is "type":"module", so Node loaded jest.config.js as ESM and its require('next/jest') threw. Fixes: - Rename jest.config.js -> jest.config.cjs (CommonJS, as the config file is loaded by Node un-transformed). - jest.setup.js: drop `process.noDeprecation = true`. The test script already passes NODE_OPTIONS=--no-deprecation, and that property is read-only once the flag is set (Node 24), so the assignment threw and failed every suite. - moduleNameMapper: point @uuid at src/utilities/uuidTags.ts (was lib/ capabilities.ts, which doesn't export the helpers) and add the many other tsconfig path aliases that were missing (@utilities, @hooks, @components, …). - Exclude src/__tests__/utils/ (shared helpers, no test cases) from testMatch. pnpm test now executes the full suite: 154 passing of 181. The remaining 27 failures are pre-existing test-level drift, not runner issues — incomplete mocks (stripe payload.findByID; revalidate imports the real payload.config / email-nodemailer ESM instead of mocking getPayload) and assertion drift in the capabilities/storage/images unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 73babcf commit d09e34d

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

jest.config.js renamed to jest.config.cjs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,29 @@ const customJestConfig = {
5555
},
5656
},
5757

58+
// Keep in sync with `compilerOptions.paths` in tsconfig.json so jest resolves the same aliases.
5859
moduleNameMapper: {
5960
'^@/(.*)$': '<rootDir>/src/$1',
61+
'^@blocks/(.*)$': '<rootDir>/src/components/blocks/$1',
62+
'^@cloud/(.*)$': '<rootDir>/src/app/(frontend)/(cloud)/cloud/$1',
63+
'^@components/(.*)$': '<rootDir>/src/components/$1',
64+
'^@data$': '<rootDir>/src/app/_data',
65+
'^@data/(.*)$': '<rootDir>/src/app/_data/$1',
66+
'^@docs/(.*)$': '<rootDir>/src/docs/$1',
67+
'^@forms/(.*)$': '<rootDir>/src/forms/$1',
68+
'^@graphics/(.*)$': '<rootDir>/src/graphics/$1',
69+
'^@hooks/(.*)$': '<rootDir>/src/hooks/$1',
70+
'^@icons/(.*)$': '<rootDir>/src/icons/$1',
71+
'^@payload-config$': '<rootDir>/src/payload.config.ts',
72+
'^@providers$': '<rootDir>/src/providers',
73+
'^@providers/(.*)$': '<rootDir>/src/providers/$1',
6074
'^@root/(.*)$': '<rootDir>/src/$1',
61-
'^@uuid$': '<rootDir>/src/lib/capabilities.ts',
62-
'^@uuid/(.*)$': '<rootDir>/src/lib/$1',
75+
'^@scss/(.*)$': '<rootDir>/src/css/$1',
76+
'^@types$': '<rootDir>/src/payload-types.ts',
77+
'^@utilities$': '<rootDir>/src/utilities',
78+
'^@utilities/(.*)$': '<rootDir>/src/utilities/$1',
79+
// `@uuid` → uuidTags.ts (matches tsconfig; was wrongly pointed at lib/capabilities.ts).
80+
'^@uuid$': '<rootDir>/src/utilities/uuidTags.ts',
6381
},
6482

6583
transform: {
@@ -73,7 +91,9 @@ const customJestConfig = {
7391
'^.+\\.module\\.(css|sass|scss)$',
7492
],
7593

76-
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
94+
// `__tests__/utils/` holds shared helpers (no test cases) — the broad testMatch above would
95+
// otherwise run them as empty suites ("must contain at least one test").
96+
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/', '<rootDir>/src/__tests__/utils/'],
7797
}
7898

7999
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async

jest.setup.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ if (typeof global.fetch === 'undefined') {
6161
global.fetch = jest.fn()
6262
}
6363

64-
// Suppress specific node deprecation warnings
65-
process.noDeprecation = true
64+
// Deprecation warnings are suppressed via NODE_OPTIONS=--no-deprecation in the `test` script.
65+
// Don't reassign process.noDeprecation here: once the flag is set it's a read-only property
66+
// (Node 24) and assigning throws "Cannot assign to read only property 'noDeprecation'".

0 commit comments

Comments
 (0)