Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(runtime): simplify createJestObjectFor #9857

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('dependencyExtractor', () => {
"dep2",
);
if (jest.requireActual(\`dep3\`).cond) {}
require
jest
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a copy paste error in #7385 I presume

.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
Original file line number Diff line number Diff line change
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