MCPcopy
hub / github.com/jestjs/jest / makeLoader

Function makeLoader

packages/jest-runtime/src/internals/__tests__/EsmLoader.test.ts:40–104  ·  view source on GitHub ↗
(overrides: Partial<Stubs> = {})

Source from the content-addressed store, hash-verified

38};
39
40function makeLoader(overrides: Partial<Stubs> = {}) {
41 const context = createContext({});
42 const esmRegistry = new Map<string, unknown>();
43 const logFormattedReferenceError = jest.fn();
44 const stubs: Stubs = {
45 cjsExportsCache: {
46 getExportsOf: jest.fn(() => []),
47 } as unknown as jest.Mocked<CjsExportsCache>,
48 coreModule: {
49 require: jest.fn(),
50 } as unknown as jest.Mocked<CoreModuleProvider>,
51 environment: {
52 getVmContext: () => context,
53 } as unknown as JestEnvironment,
54 fileCache: {
55 readFileBuffer: jest.fn(),
56 } as unknown as jest.Mocked<FileCache>,
57 jestGlobals: {
58 esmGlobalsModule: jest.fn(),
59 jestObjectFor: jest.fn(),
60 } as unknown as jest.Mocked<JestGlobals>,
61 logFormattedReferenceError,
62 mockState: {
63 getEsmFactory: jest.fn(() => undefined),
64 getEsmModuleId: jest.fn((from, name) => `${from}\0${name}`),
65 shouldMockEsmSync: jest.fn((_from, name) => ({
66 moduleID: name,
67 shouldMock: false,
68 })),
69 } as unknown as jest.Mocked<MockState>,
70 registries: {
71 getActiveEsmRegistry: jest.fn(() => esmRegistry),
72 getModuleMock: jest.fn(),
73 setModuleMock: jest.fn(),
74 } as unknown as jest.Mocked<ModuleRegistries>,
75 requireModuleOrMock: jest.fn() as any,
76 resolution: {
77 isCoreModule: jest.fn(() => false),
78 resolveEsm: jest.fn((_from, name) => name),
79 } as unknown as jest.Mocked<Resolution>,
80 shouldLoadAsEsm: jest.fn(() => true),
81 testState: new TestState(logFormattedReferenceError),
82 transformCache: {
83 canTransformSync: jest.fn(() => true),
84 hasMutex: jest.fn(() => false),
85 transform: jest.fn(),
86 } as unknown as jest.Mocked<TransformCache>,
87 ...overrides,
88 };
89 const loader = new EsmLoader({
90 cjsExportsCache: stubs.cjsExportsCache,
91 coreModule: stubs.coreModule,
92 environment: stubs.environment,
93 fileCache: stubs.fileCache,
94 jestGlobals: stubs.jestGlobals,
95 mockState: stubs.mockState,
96 registries: stubs.registries,
97 requireModuleOrMock: stubs.requireModuleOrMock,

Callers 1

EsmLoader.test.tsFile · 0.70

Calls 2

createContextFunction · 0.85
fnMethod · 0.80

Tested by

no test coverage detected