This commit is contained in:
eric sciple 2020-01-24 12:20:19 -05:00
parent beb1329f9f
commit 2b95e76931
7736 changed files with 1874747 additions and 51184 deletions

View file

@ -0,0 +1,13 @@
/**
* 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.
*/
import { Config } from '@jest/types';
import { JestEnvironment } from '@jest/environment';
import { TestResult } from '@jest/test-result';
import Runtime from 'jest-runtime';
declare const jestAdapter: (globalConfig: Config.GlobalConfig, config: Config.ProjectConfig, environment: JestEnvironment, runtime: Runtime, testPath: string) => Promise<TestResult>;
export = jestAdapter;
//# sourceMappingURL=jestAdapter.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"jestAdapter.d.ts","sourceRoot":"","sources":["../../src/legacy-code-todo-rewrite/jestAdapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAE7C,OAAO,OAAO,MAAM,cAAc,CAAC;AAKnC,QAAA,MAAM,WAAW,4JAsEhB,CAAC;AAgCF,SAAS,WAAW,CAAC"}

View file

@ -0,0 +1,159 @@
'use strict';
var _path = _interopRequireDefault(require('path'));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
var Promise = global[Symbol.for('jest-native-promise')] || global.Promise;
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function() {
var self = this,
args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err);
}
_next(undefined);
});
};
}
const FRAMEWORK_INITIALIZER = require.resolve('./jestAdapterInit');
const jestAdapter =
/*#__PURE__*/
(function() {
var _ref = _asyncToGenerator(function*(
globalConfig,
config,
environment,
runtime,
testPath
) {
const _runtime$requireInter = runtime.requireInternalModule(
FRAMEWORK_INITIALIZER
),
initialize = _runtime$requireInter.initialize,
runAndTransformResultsToJestFormat =
_runtime$requireInter.runAndTransformResultsToJestFormat;
runtime
.requireInternalModule(
_path.default.resolve(__dirname, './jestExpect.js')
)
.default({
expand: globalConfig.expand
});
const getPrettier = () =>
config.prettierPath ? require(config.prettierPath) : null;
const getBabelTraverse = () => require('@babel/traverse').default;
const _initialize = initialize({
config,
environment,
getBabelTraverse,
getPrettier,
globalConfig,
localRequire: runtime.requireModule.bind(runtime),
parentProcess: process,
testPath
}),
globals = _initialize.globals,
snapshotState = _initialize.snapshotState;
if (config.timers === 'fake') {
// during setup, this cannot be null (and it's fine to explode if it is)
environment.fakeTimers.useFakeTimers();
}
globals.beforeEach(() => {
if (config.resetModules) {
runtime.resetModules();
}
if (config.clearMocks) {
runtime.clearAllMocks();
}
if (config.resetMocks) {
runtime.resetAllMocks();
if (config.timers === 'fake') {
// during setup, this cannot be null (and it's fine to explode if it is)
environment.fakeTimers.useFakeTimers();
}
}
if (config.restoreMocks) {
runtime.restoreAllMocks();
}
});
config.setupFilesAfterEnv.forEach(path => runtime.requireModule(path));
runtime.requireModule(testPath);
const results = yield runAndTransformResultsToJestFormat({
config,
globalConfig,
testPath
});
return _addSnapshotData(results, snapshotState);
});
return function jestAdapter(_x, _x2, _x3, _x4, _x5) {
return _ref.apply(this, arguments);
};
})();
const _addSnapshotData = (results, snapshotState) => {
results.testResults.forEach(({fullName, status}) => {
if (status === 'pending' || status === 'failed') {
// if test is skipped or failed, we don't want to mark
// its snapshots as obsolete.
snapshotState.markSnapshotsAsCheckedForTest(fullName);
}
});
const uncheckedCount = snapshotState.getUncheckedCount();
const uncheckedKeys = snapshotState.getUncheckedKeys();
if (uncheckedCount) {
snapshotState.removeUncheckedKeys();
}
const status = snapshotState.save();
results.snapshot.fileDeleted = status.deleted;
results.snapshot.added = snapshotState.added;
results.snapshot.matched = snapshotState.matched;
results.snapshot.unmatched = snapshotState.unmatched;
results.snapshot.updated = snapshotState.updated;
results.snapshot.unchecked = !status.deleted ? uncheckedCount : 0; // Copy the array to prevent memory leaks
results.snapshot.uncheckedKeys = Array.from(uncheckedKeys);
return results;
};
module.exports = jestAdapter;

View file

@ -0,0 +1,48 @@
/**
* 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 { Circus, Config } from '@jest/types';
import { JestEnvironment } from '@jest/environment';
import { TestResult } from '@jest/test-result';
export declare const initialize: ({ config, environment, getPrettier, getBabelTraverse, globalConfig, localRequire, parentProcess, testPath, }: {
config: Config.ProjectConfig;
environment: JestEnvironment;
getPrettier: () => any;
getBabelTraverse: () => Function;
globalConfig: Config.GlobalConfig;
localRequire: (path: string) => any;
testPath: string;
parentProcess: NodeJS.Process;
}) => {
globals: {
afterAll: (fn: Circus.HookFn, timeout?: number | undefined) => void;
afterEach: (fn: Circus.HookFn, timeout?: number | undefined) => void;
beforeAll: (fn: Circus.HookFn, timeout?: number | undefined) => void;
beforeEach: (fn: Circus.HookFn, timeout?: number | undefined) => void;
describe: {
(blockName: string, blockFn: import("@jest/types/build/Global").BlockFn): void;
each: (table: import("@jest/types/build/Global").EachTable, ...taggedTemplateData: unknown[]) => (title: string, test: import("@jest/types/build/Global").EachTestFn, timeout?: number | undefined) => void;
only: {
(blockName: string, blockFn: import("@jest/types/build/Global").BlockFn): void;
each: (table: import("@jest/types/build/Global").EachTable, ...taggedTemplateData: unknown[]) => (title: string, test: import("@jest/types/build/Global").EachTestFn, timeout?: number | undefined) => void;
};
skip: {
(blockName: string, blockFn: import("@jest/types/build/Global").BlockFn): void;
each: (table: import("@jest/types/build/Global").EachTable, ...taggedTemplateData: unknown[]) => (title: string, test: import("@jest/types/build/Global").EachTestFn, timeout?: number | undefined) => void;
};
};
it: import("@jest/types/build/Global").It;
test: import("@jest/types/build/Global").It;
};
snapshotState: import("../../../jest-snapshot/build/State").default;
};
export declare const runAndTransformResultsToJestFormat: ({ config, globalConfig, testPath, }: {
config: Config.ProjectConfig;
globalConfig: Config.GlobalConfig;
testPath: string;
}) => Promise<TestResult>;
//# sourceMappingURL=jestAdapterInit.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"jestAdapterInit.d.ts","sourceRoot":"","sources":["../../src/legacy-code-todo-rewrite/jestAdapterInit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAEH,OAAO,EAAC,MAAM,EAAE,MAAM,EAAC,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAA0B,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAgBtE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoGtB,CAAC;AAEF,eAAO,MAAM,kCAAkC;;;;yBA0G9C,CAAC"}

View file

@ -0,0 +1,300 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.runAndTransformResultsToJestFormat = exports.initialize = void 0;
var _expect = require('expect');
var _jestMessageUtil = require('jest-message-util');
var _jestSnapshot = require('jest-snapshot');
var _throat = _interopRequireDefault(require('throat'));
var _state = require('../state');
var _utils = require('../utils');
var _run = _interopRequireDefault(require('../run'));
var _ = _interopRequireDefault(require('..'));
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;
var Promise = global[Symbol.for('jest-native-promise')] || global.Promise;
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function() {
var self = this,
args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err);
}
_next(undefined);
});
};
}
const initialize = ({
config,
environment,
getPrettier,
getBabelTraverse,
globalConfig,
localRequire,
parentProcess,
testPath
}) => {
const mutex = (0, _throat.default)(globalConfig.maxConcurrency);
Object.assign(global, _.default);
global.xit = global.it.skip;
global.xtest = global.it.skip;
global.xdescribe = global.describe.skip;
global.fit = global.it.only;
global.fdescribe = global.describe.only;
global.test.concurrent = (test => {
const concurrent = (testName, testFn, timeout) => {
// For concurrent tests we first run the function that returns promise, and then register a
// nomral test that will be waiting on the returned promise (when we start the test, the promise
// will already be in the process of execution).
// Unfortunately at this stage there's no way to know if there are any `.only` tests in the suite
// that will result in this test to be skipped, so we'll be executing the promise function anyway,
// even if it ends up being skipped.
const promise = mutex(() => testFn());
global.test(testName, () => promise, timeout);
};
concurrent.only = (testName, testFn, timeout) => {
const promise = mutex(() => testFn()); // eslint-disable-next-line jest/no-focused-tests
test.only(testName, () => promise, timeout);
};
concurrent.skip = test.skip;
return concurrent;
})(global.test);
(0, _state.addEventHandler)(eventHandler);
if (environment.handleTestEvent) {
(0, _state.addEventHandler)(environment.handleTestEvent.bind(environment));
}
(0, _state.dispatch)({
name: 'setup',
parentProcess,
testNamePattern: globalConfig.testNamePattern
});
if (config.testLocationInResults) {
(0, _state.dispatch)({
name: 'include_test_location_in_result'
});
} // Jest tests snapshotSerializers in order preceding built-in serializers.
// Therefore, add in reverse because the last added is the first tested.
config.snapshotSerializers
.concat()
.reverse()
.forEach(path => {
(0, _jestSnapshot.addSerializer)(localRequire(path));
});
const expand = globalConfig.expand,
updateSnapshot = globalConfig.updateSnapshot;
const snapshotResolver = (0, _jestSnapshot.buildSnapshotResolver)(config);
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new _jestSnapshot.SnapshotState(snapshotPath, {
expand,
getBabelTraverse,
getPrettier,
updateSnapshot
});
(0, _expect.setState)({
snapshotState,
testPath
}); // Return it back to the outer scope (test runner outside the VM).
return {
globals: _.default,
snapshotState
};
};
exports.initialize = initialize;
const runAndTransformResultsToJestFormat =
/*#__PURE__*/
(function() {
var _ref = _asyncToGenerator(function*({config, globalConfig, testPath}) {
const runResult = yield (0, _run.default)();
let numFailingTests = 0;
let numPassingTests = 0;
let numPendingTests = 0;
let numTodoTests = 0;
const assertionResults = runResult.testResults.map(testResult => {
let status;
if (testResult.status === 'skip') {
status = 'pending';
numPendingTests += 1;
} else if (testResult.status === 'todo') {
status = 'todo';
numTodoTests += 1;
} else if (testResult.errors.length) {
status = 'failed';
numFailingTests += 1;
} else {
status = 'passed';
numPassingTests += 1;
}
const ancestorTitles = testResult.testPath.filter(
name => name !== _state.ROOT_DESCRIBE_BLOCK_NAME
);
const title = ancestorTitles.pop();
return {
ancestorTitles,
duration: testResult.duration,
failureMessages: testResult.errors,
fullName: title
? ancestorTitles.concat(title).join(' ')
: ancestorTitles.join(' '),
invocations: testResult.invocations,
location: testResult.location,
numPassingAsserts: 0,
status,
title: testResult.testPath[testResult.testPath.length - 1]
};
});
let failureMessage = (0, _jestMessageUtil.formatResultsErrors)(
assertionResults,
config,
globalConfig,
testPath
);
let testExecError;
if (runResult.unhandledErrors.length) {
testExecError = {
message: '',
stack: runResult.unhandledErrors.join('\n')
};
failureMessage =
(failureMessage || '') +
'\n\n' +
runResult.unhandledErrors
.map(err =>
(0, _jestMessageUtil.formatExecError)(err, config, globalConfig)
)
.join('\n');
}
(0, _state.dispatch)({
name: 'teardown'
});
return {
console: undefined,
displayName: config.displayName,
failureMessage,
leaks: false,
// That's legacy code, just adding it so Flow is happy.
numFailingTests,
numPassingTests,
numPendingTests,
numTodoTests,
openHandles: [],
perfStats: {
// populated outside
end: 0,
start: 0
},
skipped: false,
snapshot: {
added: 0,
fileDeleted: false,
matched: 0,
unchecked: 0,
uncheckedKeys: [],
unmatched: 0,
updated: 0
},
sourceMaps: {},
testExecError,
testFilePath: testPath,
testResults: assertionResults
};
});
return function runAndTransformResultsToJestFormat(_x) {
return _ref.apply(this, arguments);
};
})();
exports.runAndTransformResultsToJestFormat = runAndTransformResultsToJestFormat;
const eventHandler = event => {
switch (event.name) {
case 'test_start': {
(0, _expect.setState)({
currentTestName: (0, _utils.getTestID)(event.test)
});
break;
}
case 'test_done': {
_addSuppressedErrors(event.test);
_addExpectedAssertionErrors(event.test);
break;
}
}
};
const _addExpectedAssertionErrors = test => {
const failures = (0, _expect.extractExpectedAssertionsErrors)();
const errors = failures.map(failure => failure.error);
test.errors = test.errors.concat(errors);
}; // Get suppressed errors from ``jest-matchers`` that weren't throw during
// test execution and add them to the test result, potentially failing
// a passing test.
const _addSuppressedErrors = test => {
const _getState = (0, _expect.getState)(),
suppressedErrors = _getState.suppressedErrors;
(0, _expect.setState)({
suppressedErrors: []
});
if (suppressedErrors.length) {
test.errors = test.errors.concat(suppressedErrors);
}
};

View file

@ -0,0 +1,11 @@
/**
* 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.
*/
declare const _default: (config: {
expand: boolean;
}) => void;
export default _default;
//# sourceMappingURL=jestExpect.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"jestExpect.d.ts","sourceRoot":"","sources":["../../src/legacy-code-todo-rewrite/jestExpect.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;;;AAYH,wBAaE"}

View file

@ -0,0 +1,40 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.default = void 0;
var _expect = _interopRequireDefault(require('expect'));
var _jestSnapshot = require('jest-snapshot');
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {default: obj};
}
/**
* 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.
*/
var _default = config => {
global.expect = _expect.default;
_expect.default.setState({
expand: config.expand
});
_expect.default.extend({
toMatchInlineSnapshot: _jestSnapshot.toMatchInlineSnapshot,
toMatchSnapshot: _jestSnapshot.toMatchSnapshot,
toThrowErrorMatchingInlineSnapshot:
_jestSnapshot.toThrowErrorMatchingInlineSnapshot,
toThrowErrorMatchingSnapshot: _jestSnapshot.toThrowErrorMatchingSnapshot
});
_expect.default.addSnapshotSerializer = _jestSnapshot.addSerializer;
};
exports.default = _default;