react-scripts
Version:
Configuration and scripts for Create React App.
60 lines (44 loc) • 1.34 kB
JavaScript
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
;
const FakeTimers = require('jest-util').FakeTimers;
const installCommonGlobals = require('jest-util').installCommonGlobals;
const vm = require('vm');
const isNaN = global.isNaN;
class NodeEnvironment {
constructor(config) {
const global = this.global = {};
vm.createContext(this.global);
global.global = global;
global.clearInterval = clearInterval;
global.clearTimeout = clearTimeout;
global.setInterval = setInterval;
global.setTimeout = setTimeout;
global.isNaN = isNaN;
global.ArrayBuffer = ArrayBuffer;
global.JSON = JSON;
global.Promise = Promise;
installCommonGlobals(global, config.globals);
this.fakeTimers = new FakeTimers(global, config);
}
dispose() {
if (this.fakeTimers) {
this.fakeTimers.dispose();
}
this.global = null;
this.fakeTimers = null;
}
runScript(script) {
if (this.global) {
return script.runInContext(this.global);
}
return null;
}}
module.exports = NodeEnvironment;