Skip to content

Commit

Permalink
Minor cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Nov 16, 2015
1 parent e1faf1b commit 620ea9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
11 changes: 5 additions & 6 deletions src/HasteModuleLoader/HasteModuleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@ class Loader {
const filename = moduleObj.__filename;
let moduleContent = transform(filename, this._config);
let collectorStore;

// Every module receives a mock parent so they don't assume they are run
// standalone.
moduleObj.parent = mockParentModule;
moduleObj.require = this.constructBoundRequire(filename);

const onlyCollectFrom = this._config.collectCoverageOnlyFrom;
const shouldCollectCoverage =
(this._config.collectCoverage === true && !onlyCollectFrom) ||
Expand All @@ -203,6 +197,11 @@ class Loader {
const origCurrExecutingManualMock = this._isCurrentlyExecutingManualMock;
this._isCurrentlyExecutingManualMock = filename;

// Every module receives a mock parent so they don't assume they are run
// standalone.
moduleObj.parent = mockParentModule;
moduleObj.require = this.constructBoundRequire(filename);

// Use this name for the module wrapper for consistency with node.
const evalResultVariable = 'Object.<anonymous>';
const wrapper = 'this["' + evalResultVariable + '"] = function(module, exports, require, __dirname, __filename, global, jest, ____JEST_COVERAGE_DATA____) {' + moduleContent + '\n};';
Expand Down
14 changes: 5 additions & 9 deletions src/environments/JSDOMEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,24 @@ class JSDOMEnvironment {
this.global.Error.stackTraceLimit = 100;
installCommonGlobals(this.global, config.globals);
this.fakeTimers = new FakeTimers(this.global);
this._disposed = false;
}

dispose() {
this.global.close();
this.global = null;
this.document = null;
this.fakeTimers = null;
this._disposed = true;
}

runSourceText(sourceText, filename) {
if (!this._disposed) {
vm.runInContext(sourceText, this.document._ownerDocument._global, {
filename,
displayErrors: false,
});
}
vm.runInContext(sourceText, this.document._ownerDocument._global, {
filename,
displayErrors: false,
});
}

runWithRealTimers(cb) {
if (!this._disposed) {
if (this.global) {
this.fakeTimers.runWithRealTimers(cb);
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/environments/NodeEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class NodeEnvironment {
this.global.JSON = JSON;
installCommonGlobals(this.global, config.globals);
this.fakeTimers = new FakeTimers(this.global);
this._disposed = false;
}

dispose() {
Expand All @@ -33,16 +32,14 @@ class NodeEnvironment {
}

runSourceText(sourceText, filename) {
if (!this._disposed) {
vm.runInContext(sourceText, this.global, {
filename,
displayErrors: false,
});
}
vm.runInContext(sourceText, this.global, {
filename,
displayErrors: false,
});
}

runWithRealTimers(callback) {
if (!this._disposed) {
if (this.global) {
this.fakeTimers.runWithRealTimers(callback);
}
}
Expand Down

0 comments on commit 620ea9e

Please sign in to comment.