This commit is contained in:
eric sciple 2020-01-24 12:20:47 -05:00
parent a004f0ae58
commit fc725ba36b
7280 changed files with 19 additions and 1796407 deletions

View file

@ -1,29 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/// <reference types="node" />
import { Script, Context } from 'vm';
import { Global, Config } from '@jest/types';
import { ModuleMocker } from 'jest-mock';
import { JestFakeTimers as FakeTimers } from '@jest/fake-timers';
import { JestEnvironment } from '@jest/environment';
declare type Timer = {
id: number;
ref: () => Timer;
unref: () => Timer;
};
declare class NodeEnvironment implements JestEnvironment {
context: Context | null;
fakeTimers: FakeTimers<Timer> | null;
global: Global.Global;
moduleMocker: ModuleMocker | null;
constructor(config: Config.ProjectConfig);
setup(): Promise<void>;
teardown(): Promise<void>;
runScript(script: Script): any;
}
export = NodeEnvironment;
//# sourceMappingURL=index.d.ts.map

View file

@ -1 +0,0 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH,OAAW,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,IAAI,CAAC;AACvC,OAAO,EAAC,MAAM,EAAE,MAAM,EAAC,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAC,cAAc,IAAI,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,aAAK,KAAK,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,KAAK,CAAC;IACjB,KAAK,EAAE,MAAM,KAAK,CAAC;CACpB,CAAC;AAEF,cAAM,eAAgB,YAAW,eAAe;IAC9C,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;IACtB,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;gBAEtB,MAAM,EAAE,MAAM,CAAC,aAAa;IAwDxC,KAAK;IAIL,QAAQ;IAWR,SAAS,CAAC,MAAM,EAAE,MAAM;CAMzB;AAED,SAAS,eAAe,CAAC"}

View file

@ -1,153 +0,0 @@
'use strict';
function _vm() {
const data = _interopRequireDefault(require('vm'));
_vm = function _vm() {
return data;
};
return data;
}
function _jestMock() {
const data = require('jest-mock');
_jestMock = function _jestMock() {
return data;
};
return data;
}
function _jestUtil() {
const data = require('jest-util');
_jestUtil = function _jestUtil() {
return data;
};
return data;
}
function _fakeTimers() {
const data = require('@jest/fake-timers');
_fakeTimers = function _fakeTimers() {
return data;
};
return data;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
class NodeEnvironment {
constructor(config) {
_defineProperty(this, 'context', void 0);
_defineProperty(this, 'fakeTimers', void 0);
_defineProperty(this, 'global', void 0);
_defineProperty(this, 'moduleMocker', void 0);
this.context = _vm().default.createContext();
const global = (this.global = _vm().default.runInContext(
'this',
Object.assign(this.context, config.testEnvironmentOptions)
));
global.global = global;
global.clearInterval = clearInterval;
global.clearTimeout = clearTimeout;
global.setInterval = setInterval;
global.setTimeout = setTimeout;
global.ArrayBuffer = ArrayBuffer; // URL and URLSearchParams are global in Node >= 10
if (typeof URL !== 'undefined' && typeof URLSearchParams !== 'undefined') {
/* global URL, URLSearchParams */
global.URL = URL;
global.URLSearchParams = URLSearchParams;
} // TextDecoder and TextDecoder are global in Node >= 11
if (
typeof TextEncoder !== 'undefined' &&
typeof TextDecoder !== 'undefined'
) {
/* global TextEncoder, TextDecoder */
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
}
(0, _jestUtil().installCommonGlobals)(global, config.globals);
this.moduleMocker = new (_jestMock()).ModuleMocker(global);
const timerIdToRef = id => ({
id,
ref() {
return this;
},
unref() {
return this;
}
});
const timerRefToId = timer => (timer && timer.id) || undefined;
const timerConfig = {
idToRef: timerIdToRef,
refToId: timerRefToId
};
this.fakeTimers = new (_fakeTimers()).JestFakeTimers({
config,
global,
moduleMocker: this.moduleMocker,
timerConfig
});
}
setup() {
return Promise.resolve();
}
teardown() {
if (this.fakeTimers) {
this.fakeTimers.dispose();
}
this.context = null;
this.fakeTimers = null;
return Promise.resolve();
} // TS infers the return type to be `any`, since that's what `runInContext`
// returns.
runScript(script) {
if (this.context) {
return script.runInContext(this.context);
}
return null;
}
}
module.exports = NodeEnvironment;