Skip to content

Commit

Permalink
chore(runtime): simplify createJestObjectFor (#9857)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Apr 22, 2020
1 parent fa4cbbf commit fc5a6ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Expand Up @@ -232,7 +232,7 @@ describe('dependencyExtractor', () => {
"dep2",
);
if (jest.requireActual(\`dep3\`).cond) {}
require
jest
.requireActual('dep4');
// Bad
Expand All @@ -252,7 +252,7 @@ describe('dependencyExtractor', () => {
"dep2",
);
if (jest.requireMock(\`dep3\`).cond) {}
require
jest
.requireMock('dep4');
// Bad
Expand All @@ -272,7 +272,7 @@ describe('dependencyExtractor', () => {
"dep2",
);
if (jest.genMockFromModule(\`dep3\`).cond) {}
require
jest
.requireMock('dep4');
// Bad
Expand Down
14 changes: 4 additions & 10 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -990,10 +990,7 @@ class Runtime {
dirname, // __dirname
filename, // __filename
this._environment.global, // global object
this._createJestObjectFor(
filename,
localModule.require as LocalModuleRequire,
), // jest object
this._createJestObjectFor(filename), // jest object
...this._config.extraGlobals.map(globalVariable => {
if (this._environment.global[globalVariable]) {
return this._environment.global[globalVariable];
Expand Down Expand Up @@ -1311,10 +1308,7 @@ class Runtime {
return moduleRequire;
}

private _createJestObjectFor(
from: Config.Path,
localRequire: LocalModuleRequire,
): Jest {
private _createJestObjectFor(from: Config.Path): Jest {
const disableAutomock = () => {
this._shouldAutoMock = false;
return jestObject;
Expand Down Expand Up @@ -1445,8 +1439,8 @@ class Runtime {
isMockFunction: this._moduleMocker.isMockFunction,
isolateModules,
mock,
requireActual: localRequire.requireActual,
requireMock: localRequire.requireMock,
requireActual: this.requireActual.bind(this, from),
requireMock: this.requireMock.bind(this, from),
resetAllMocks,
resetModuleRegistry: resetModules,
resetModules,
Expand Down

0 comments on commit fc5a6ca

Please sign in to comment.