123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- exports.run = run;
- function _os() {
- const data = require('os');
- _os = function () {
- return data;
- };
- return data;
- }
- function path() {
- const data = _interopRequireWildcard(require('path'));
- path = function () {
- return data;
- };
- return data;
- }
- function _chalk() {
- const data = _interopRequireDefault(require('chalk'));
- _chalk = function () {
- return data;
- };
- return data;
- }
- function _yargs() {
- const data = _interopRequireDefault(require('yargs'));
- _yargs = function () {
- return data;
- };
- return data;
- }
- function _console() {
- const data = require('@jest/console');
- _console = function () {
- return data;
- };
- return data;
- }
- function _jestConfig() {
- const data = require('jest-config');
- _jestConfig = function () {
- return data;
- };
- return data;
- }
- function _jestUtil() {
- const data = require('jest-util');
- _jestUtil = function () {
- return data;
- };
- return data;
- }
- function _jestValidate() {
- const data = require('jest-validate');
- _jestValidate = function () {
- return data;
- };
- return data;
- }
- function _version() {
- const data = require('../version');
- _version = function () {
- return data;
- };
- return data;
- }
- var args = _interopRequireWildcard(require('./args'));
- function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : {default: obj};
- }
- function _getRequireWildcardCache() {
- if (typeof WeakMap !== 'function') return null;
- var cache = new WeakMap();
- _getRequireWildcardCache = function () {
- return cache;
- };
- return cache;
- }
- function _interopRequireWildcard(obj) {
- if (obj && obj.__esModule) {
- return obj;
- }
- if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
- return {default: obj};
- }
- var cache = _getRequireWildcardCache();
- if (cache && cache.has(obj)) {
- return cache.get(obj);
- }
- var newObj = {};
- var hasPropertyDescriptor =
- Object.defineProperty && Object.getOwnPropertyDescriptor;
- for (var key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- var desc = hasPropertyDescriptor
- ? Object.getOwnPropertyDescriptor(obj, key)
- : null;
- if (desc && (desc.get || desc.set)) {
- Object.defineProperty(newObj, key, desc);
- } else {
- newObj[key] = obj[key];
- }
- }
- }
- newObj.default = obj;
- if (cache) {
- cache.set(obj, newObj);
- }
- return newObj;
- }
- /**
- * 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.
- */
- async function run(cliArgv, cliInfo) {
- let argv;
- if (cliArgv) {
- argv = cliArgv;
- } else {
- argv = _yargs()
- .default.usage(args.usage)
- .help(false)
- .version(false)
- .options(args.options).argv;
- (0, _jestValidate().validateCLIOptions)(argv, {
- ...args.options,
- deprecationEntries: _jestConfig().deprecationEntries
- });
- }
- if (argv.help) {
- _yargs().default.showHelp();
- process.on('exit', () => (process.exitCode = 1));
- return;
- }
- if (argv.version) {
- console.log(`v${_version().VERSION}\n`);
- return;
- }
- if (!argv._.length) {
- console.log('Please provide a path to a script. (See --help for details)');
- process.on('exit', () => (process.exitCode = 1));
- return;
- }
- const root = (0, _jestUtil().tryRealpath)(process.cwd());
- const filePath = path().resolve(root, argv._[0]);
- if (argv.debug) {
- const info = cliInfo ? ', ' + cliInfo.join(', ') : '';
- console.log(`Using Jest Runtime v${_version().VERSION}${info}`);
- }
- const options = await (0, _jestConfig().readConfig)(argv, root);
- const globalConfig = options.globalConfig; // Always disable automocking in scripts.
- const config = {...options.projectConfig, automock: false};
- const Runtime = require('..');
- try {
- var _runtime$unstable_sho2;
- const hasteMap = await Runtime.createContext(config, {
- maxWorkers: Math.max((0, _os().cpus)().length - 1, 1),
- watchman: globalConfig.watchman
- });
- const Environment = require(config.testEnvironment);
- const environment = new Environment(config);
- (0, _jestUtil().setGlobal)(
- environment.global,
- 'console',
- new (_console().CustomConsole)(process.stdout, process.stderr)
- );
- (0, _jestUtil().setGlobal)(environment.global, 'jestProjectConfig', config);
- (0, _jestUtil().setGlobal)(
- environment.global,
- 'jestGlobalConfig',
- globalConfig
- );
- const runtime = new Runtime(
- config,
- environment,
- hasteMap.resolver,
- undefined,
- undefined,
- filePath
- );
- for (const path of config.setupFiles) {
- var _runtime$unstable_sho;
- // TODO: remove ? in Jest 26
- const esm =
- (_runtime$unstable_sho = runtime.unstable_shouldLoadAsEsm) === null ||
- _runtime$unstable_sho === void 0
- ? void 0
- : _runtime$unstable_sho.call(runtime, path);
- if (esm) {
- await runtime.unstable_importModule(path);
- } else {
- runtime.requireModule(path);
- }
- } // TODO: remove ? in Jest 26
- const esm =
- (_runtime$unstable_sho2 = runtime.unstable_shouldLoadAsEsm) === null ||
- _runtime$unstable_sho2 === void 0
- ? void 0
- : _runtime$unstable_sho2.call(runtime, filePath);
- if (esm) {
- await runtime.unstable_importModule(filePath);
- } else {
- runtime.requireModule(filePath);
- }
- } catch (e) {
- console.error(_chalk().default.red(e.stack || e));
- process.on('exit', () => (process.exitCode = 1));
- }
- }
|