Skip to content

Commit 0b92a80

Browse files
committed
Maintenance: Fixed testing issues after NPM dep version changes
1 parent d73e03c commit 0b92a80

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

jest.config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55

66
import type {Config} from 'jest';
77
import {pathsToModuleNameMapper} from "ts-jest";
8-
import { compilerOptions } from './tsconfig.json';
8+
import { createRequire } from 'module';
9+
const { compilerOptions } = createRequire(import.meta.url)('./tsconfig.json');
10+
11+
const compilerPaths = compilerOptions.paths as Record<string, string[]>;
12+
const cleanedPaths: Record<string, string[]> = {};
13+
Object.keys(compilerPaths).forEach((key) => {
14+
const paths = compilerPaths[key];
15+
cleanedPaths[key] = paths.map(p => p.replace('./', ''));
16+
});
917

1018
const config: Config = {
1119
// All imported modules in your tests should be mocked automatically
@@ -98,7 +106,7 @@ const config: Config = {
98106
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
99107
moduleNameMapper: {
100108
'lexical/shared/invariant': 'resources/js/wysiwyg/lexical/core/shared/__mocks__/invariant',
101-
...pathsToModuleNameMapper(compilerOptions.paths),
109+
...pathsToModuleNameMapper(cleanedPaths),
102110
},
103111

104112
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"module": "esnext",
77
"moduleResolution": "bundler",
88
"rootDir": "./resources/js/",
9-
"types": ["jest"],
9+
"types": ["jest", "node"],
1010
"paths": {
1111
"@icons/*": ["./resources/icons/*"],
1212
"lexical": ["./resources/js/wysiwyg/lexical/core/index.ts"],

0 commit comments

Comments
 (0)