Skip to content

Commit

Permalink
remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 29, 2022
1 parent 176e16f commit 3895c42
Showing 1 changed file with 1 addition and 64 deletions.
65 changes: 1 addition & 64 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ export default class Runtime {
this.setExport(key, value);
});
},
// should identifier be `node://${moduleName}`?
{context, identifier: moduleName},
);

Expand All @@ -804,69 +803,7 @@ export default class Runtime {
return evaluateSyntheticModule(module);
}

const manualMockOrStub = this._resolver.getMockModule(from, moduleName);

let modulePath =
this._resolver.getMockModule(from, moduleName) ||
this._resolveModule(from, moduleName);

let isManualMock =
manualMockOrStub &&
!this._resolver.resolveStubModuleName(from, moduleName);
if (!isManualMock) {
// If the actual module file has a __mocks__ dir sitting immediately next
// to it, look to see if there is a manual mock for this file.
//
// subDir1/my_module.js
// subDir1/__mocks__/my_module.js
// subDir2/my_module.js
// subDir2/__mocks__/my_module.js
//
// Where some other module does a relative require into each of the
// respective subDir{1,2} directories and expects a manual mock
// corresponding to that particular my_module.js file.

const moduleDir = path.dirname(modulePath);
const moduleFileName = path.basename(modulePath);
const potentialManualMock = path.join(
moduleDir,
'__mocks__',
moduleFileName,
);
if (fs.existsSync(potentialManualMock)) {
isManualMock = true;
modulePath = potentialManualMock;
}
}
if (isManualMock) {
const localModule: InitialModule = {
children: [],
exports: {},
filename: modulePath,
id: modulePath,
loaded: false,
path: modulePath,
};

this._loadModule(
localModule,
from,
moduleName,
modulePath,
undefined,
this._moduleMockRegistry,
);

this._moduleMockRegistry.set(moduleID, localModule.exports);
} else {
// Look for a real module to generate an automock from
this._moduleMockRegistry.set(
moduleID,
this._generateMock(from, moduleName),
);
}

return this._moduleMockRegistry.get(moduleID);
throw new Error('Attempting to import a mock without a factory');
}

private getExportsOfCjs(modulePath: string) {
Expand Down

0 comments on commit 3895c42

Please sign in to comment.