forked from itsyogesh/relaycode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.ts
More file actions
67 lines (60 loc) · 1.98 KB
/
jest.config.ts
File metadata and controls
67 lines (60 loc) · 1.98 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type { Config } from "jest";
import nextJest from "next/jest";
const createJestConfig = nextJest({
dir: "./",
});
// ESM packages that need to be transformed by Jest.
// These packages ship ESM-only builds that Jest can't handle natively.
const esmPackages = [
"@noble/hashes",
"@noble/curves",
"@dedot/utils",
"@dedot/codecs",
"@dedot/types",
"@dedot/shape",
"dedot",
"@scure/base",
"@luno-kit/core",
"@luno-kit/react",
"@luno-kit/ui",
"cuer",
];
const config: Config = {
coverageProvider: "v8",
testEnvironment: "jsdom",
setupFiles: ["<rootDir>/jest.polyfills.ts"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/$1",
},
testPathIgnorePatterns: ["/node_modules/", "__tests__/helpers/"],
collectCoverageFrom: [
"lib/**/*.{ts,tsx}",
"components/**/*.{ts,tsx}",
"hooks/**/*.{ts,tsx}",
"config/**/*.{ts,tsx}",
"context/**/*.{ts,tsx}",
"!**/*.d.ts",
"!**/index.ts",
],
coverageReporters: ["lcov", "text", "text-summary"],
};
// Use async config to modify transformIgnorePatterns after next/jest builds them
// This workaround is needed because next/jest overwrites transformIgnorePatterns
// See: https://github.com/vercel/next.js/issues/35634
export default async (...args: Parameters<ReturnType<typeof createJestConfig>>) => {
const fn = createJestConfig(config);
const resolvedConfig = await fn(...args);
// Create a pattern that allows our ESM packages to be transformed
// Handles both regular node_modules and pnpm's .pnpm directory structure
const esmPackagesPattern = esmPackages
.map((pkg) => pkg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
.join("|");
// Replace the default node_modules pattern with one that excludes our ESM packages
resolvedConfig.transformIgnorePatterns = [
`/node_modules/(?!(${esmPackagesPattern})/)`,
`\\.pnpm/(?!(${esmPackagesPattern.replace(/\//g, "\\+")})@)`,
"^.+\\.module\\.(css|sass|scss)$",
];
return resolvedConfig;
};