From f50659bf121e1ae5c11beaa3cd1465e13006c679 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 21 Apr 2020 23:50:12 +0200 Subject: [PATCH] chore(runtime): simplify `createJestObjectFor` --- .../src/lib/__tests__/dependencyExtractor.test.js | 6 +++--- packages/jest-runtime/src/index.ts | 14 ++++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js b/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js index 516b5741b598..6ce7e444fae9 100644 --- a/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js +++ b/packages/jest-haste-map/src/lib/__tests__/dependencyExtractor.test.js @@ -232,7 +232,7 @@ describe('dependencyExtractor', () => { "dep2", ); if (jest.requireActual(\`dep3\`).cond) {} - require + jest .requireActual('dep4'); // Bad @@ -252,7 +252,7 @@ describe('dependencyExtractor', () => { "dep2", ); if (jest.requireMock(\`dep3\`).cond) {} - require + jest .requireMock('dep4'); // Bad @@ -272,7 +272,7 @@ describe('dependencyExtractor', () => { "dep2", ); if (jest.genMockFromModule(\`dep3\`).cond) {} - require + jest .requireMock('dep4'); // Bad diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 001de2f98ec9..92a46b78b914 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -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]; @@ -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; @@ -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,