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

Method exec

packages/jest-runtime/src/internals/ModuleExecutor.ts:90–177  ·  view source on GitHub ↗
(
    localModule: InitialModule,
    options: TransformOptions | undefined,
    moduleRegistry: ModuleRegistry,
    from: string | null,
    moduleName: string | undefined,
  )

Source from the content-addressed store, hash-verified

88 }
89
90 exec(
91 localModule: InitialModule,
92 options: TransformOptions | undefined,
93 moduleRegistry: ModuleRegistry,
94 from: string | null,
95 moduleName: string | undefined,
96 ): ExecResult {
97 if (!this.environment.global) {
98 return 'env-disposed';
99 }
100
101 const module = localModule as Module;
102
103 const filename = module.filename;
104 const origCurrExecutingManualMock = this.currentlyExecutingManualMock;
105 this.currentlyExecutingManualMock = filename;
106
107 try {
108 module.children = [];
109
110 Object.defineProperty(module, 'parent', {
111 enumerable: true,
112 get() {
113 const key = from || '';
114 return moduleRegistry.get(key) || null;
115 },
116 });
117 const modulePaths = this.resolution.getModulePaths(module.path);
118 const globalPaths = this.resolution.getGlobalPaths(moduleName);
119 module.paths = [...modulePaths, ...globalPaths];
120
121 Object.defineProperty(module, 'require', {
122 value: this.requireBuilder.for(localModule, options),
123 });
124
125 const transformedCode = this.transformCache.transform(filename, options);
126
127 const compiledFunction = this.compile(transformedCode, filename);
128 if (compiledFunction === null) {
129 return 'env-disposed';
130 }
131
132 const jestObject = this.jestGlobals.jestObjectFor(filename);
133
134 const lastArgs: [Jest | undefined, ...Array<Global.Global>] = [
135 this.config.injectGlobals ? jestObject : undefined,
136 ...this.config.sandboxInjectedGlobals.map<Global.Global>(
137 globalVariable => {
138 if (this.environment.global[globalVariable]) {
139 return this.environment.global[globalVariable];
140 }
141
142 throw new Error(
143 `You have requested '${globalVariable}' as a global variable, but it was not present. Please check your config or your global environment.`,
144 );
145 },
146 ),
147 ];

Callers 11

validateSnapshotHeaderFunction · 0.80
loadModuleMethod · 0.80
parseWithCommentsFunction · 0.80
toMatchFunction · 0.80
formatReceivedFunction · 0.80
wrapAnsiStringFunction · 0.80
_toMatchSnapshotFunction · 0.80
getIndentationLengthFunction · 0.80
extractSummariesFunction · 0.80

Calls 8

compileMethod · 0.95
handleExecutionErrorMethod · 0.95
definePropertyMethod · 0.80
forMethod · 0.80
jestObjectForMethod · 0.80
getModulePathsMethod · 0.45
getGlobalPathsMethod · 0.45
transformMethod · 0.45

Tested by

no test coverage detected