-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest.unit.config.ts
More file actions
40 lines (38 loc) · 1.81 KB
/
jest.unit.config.ts
File metadata and controls
40 lines (38 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import type { Config } from 'jest';
const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['<rootDir>/tests/unit/**/*.test.ts'],
setupFilesAfterEnv: ['<rootDir>/tests/setup/unit.setup.ts'],
transform: {
'^.+\\.[jt]sx?$': [
'ts-jest',
{
tsconfig: '<rootDir>/tests/tsconfig.json',
},
],
},
transformIgnorePatterns: ['node_modules/(?!(jose|drizzle-orm|@wxyc/shared)/)'],
moduleNameMapper: {
// Mock workspace packages
'^@wxyc/database$': '<rootDir>/tests/mocks/database.mock.ts',
'^@wxyc/authentication$': '<rootDir>/tests/mocks/authentication.mock.ts',
// Mock database client for any path resolving to shared/database/src/client
'^.*/shared/database/src/client(\\.js)?$': '<rootDir>/tests/mocks/database.mock.ts',
// Mock better-auth modules (ESM-only, can't be transformed by ts-jest)
'^better-auth/plugins/access$': '<rootDir>/tests/mocks/better-auth-access.mock.ts',
'^better-auth/plugins/organization/access$': '<rootDir>/tests/mocks/better-auth-org-access.mock.ts',
'^better-auth/node$': '<rootDir>/tests/mocks/better-auth-node.mock.ts',
// Remove .js extensions from relative imports (ESM compatibility)
'^(\\.{1,2}/.*)\\.(js)$': '$1',
},
// @wxyc/shared is a workspace dep installed under each workspace's node_modules
// rather than hoisted to the root, so root-level tests (tests/**) can't resolve it
// via standard node module resolution. List the workspace node_modules paths so jest's
// resolver finds it.
moduleDirectories: ['node_modules', 'apps/backend/node_modules', 'shared/authentication/node_modules'],
collectCoverageFrom: ['apps/backend/**/*.ts', 'jobs/**/*.ts', '!**/*.d.ts', '!**/dist/**'],
modulePathIgnorePatterns: ['<rootDir>/.claude/worktrees'],
clearMocks: true,
};
export default config;