/ jest.config.cjs
jest.config.cjs
 1  const path = require("path");
 2  
 3  /** @type {import('ts-jest').JestConfigWithTsJest} */
 4  module.exports = {
 5    preset: "ts-jest",
 6    testEnvironment: "node",
 7    extensionsToTreatAsEsm: [".ts"],
 8    moduleNameMapper: {
 9      "^(\\.{1,2}/.*)\\.js$": "$1",
10      // IMPORTANT: Use path.resolve() instead of <rootDir> for mock paths
11      // This ensures tests work regardless of:
12      // - Package name changes (filesystem-of-a-down → vulcan-file-ops)
13      // - Directory name changes (users can clone repo anywhere with any name)
14      // - Where users install the project
15      // Using __dirname makes paths relative to THIS config file location
16      "^pdf-parse$": path.resolve(__dirname, "src/tests/__mocks__/pdf-parse.ts"),
17      "^pdfmake/build/pdfmake\\.js$": path.resolve(
18        __dirname,
19        "src/tests/__mocks__/pdfmake/build/pdfmake.js.ts"
20      ),
21      "^pdfmake/build/vfs_fonts\\.js$": path.resolve(
22        __dirname,
23        "src/tests/__mocks__/pdfmake/build/vfs_fonts.js.ts"
24      ),
25      "^html-to-pdfmake$": path.resolve(
26        __dirname,
27        "src/tests/__mocks__/html-to-pdfmake.ts"
28      ),
29      "^jsdom$": path.resolve(__dirname, "src/tests/__mocks__/jsdom.ts"),
30    },
31    transform: {
32      "^.+\\.tsx?$": [
33        "ts-jest",
34        {
35          useESM: true,
36          diagnostics: {
37            ignoreCodes: [151002],
38            warnOnly: true,
39          },
40        },
41      ],
42    },
43    coveragePathIgnorePatterns: [
44      "/node_modules/",
45      "/dist/",
46      "/src/tests/__mocks__/",
47      "\\.d\\.ts$",
48    ],
49    testMatch: ["**/tests/**/*.test.ts", "**/__tests__/**/*.test.ts"],
50    testPathIgnorePatterns: ["/node_modules/", "/dist/"],
51    collectCoverageFrom: ["src/**/*.ts", "!src/tests/**", "!src/__tests__/**"],
52  };