123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- exports.run = run;
- function _os() {
- const data = _interopRequireDefault(require('os'));
- _os = function _os() {
- return data;
- };
- return data;
- }
- function _path() {
- const data = _interopRequireDefault(require('path'));
- _path = function _path() {
- return data;
- };
- return data;
- }
- function _chalk() {
- const data = _interopRequireDefault(require('chalk'));
- _chalk = function _chalk() {
- return data;
- };
- return data;
- }
- function _realpathNative() {
- const data = require('realpath-native');
- _realpathNative = function _realpathNative() {
- return data;
- };
- return data;
- }
- function _yargs() {
- const data = _interopRequireDefault(require('yargs'));
- _yargs = function _yargs() {
- return data;
- };
- return data;
- }
- function _console() {
- const data = require('@jest/console');
- _console = function _console() {
- return data;
- };
- return data;
- }
- function _jestUtil() {
- const data = require('jest-util');
- _jestUtil = function _jestUtil() {
- return data;
- };
- return data;
- }
- function _jestValidate() {
- const data = require('jest-validate');
- _jestValidate = function _jestValidate() {
- return data;
- };
- return data;
- }
- function _jestConfig() {
- const data = require('jest-config');
- _jestConfig = function _jestConfig() {
- return data;
- };
- return data;
- }
- var _version = require('../version');
- var args = _interopRequireWildcard(require('./args'));
- function _interopRequireWildcard(obj) {
- if (obj && obj.__esModule) {
- return obj;
- } else {
- var newObj = {};
- if (obj != null) {
- for (var key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- var desc =
- Object.defineProperty && Object.getOwnPropertyDescriptor
- ? Object.getOwnPropertyDescriptor(obj, key)
- : {};
- if (desc.get || desc.set) {
- Object.defineProperty(newObj, key, desc);
- } else {
- newObj[key] = obj[key];
- }
- }
- }
- }
- newObj.default = obj;
- return newObj;
- }
- }
- function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : {default: obj};
- }
- function _objectSpread(target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = arguments[i] != null ? arguments[i] : {};
- var ownKeys = Object.keys(source);
- if (typeof Object.getOwnPropertySymbols === 'function') {
- ownKeys = ownKeys.concat(
- Object.getOwnPropertySymbols(source).filter(function(sym) {
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
- })
- );
- }
- ownKeys.forEach(function(key) {
- _defineProperty(target, key, source[key]);
- });
- }
- return target;
- }
- 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;
- }
- function run(cliArgv, cliInfo) {
- const realFs = require('fs');
- const fs = require('graceful-fs');
- fs.gracefulify(realFs);
- let argv;
- if (cliArgv) {
- argv = cliArgv;
- } else {
- argv = _yargs()
- .default.usage(args.usage)
- .help(false)
- .version(false)
- .options(args.options).argv; // @ts-ignore: fix this at some point
- (0, _jestValidate().validateCLIOptions)(
- argv,
- _objectSpread({}, 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, _realpathNative().sync)(process.cwd());
- const filePath = _path().default.resolve(root, argv._[0]);
- if (argv.debug) {
- const info = cliInfo ? ', ' + cliInfo.join(', ') : '';
- console.log(`Using Jest Runtime v${_version.VERSION}${info}`);
- } // TODO: Figure this out
- // @ts-ignore: this might not have the correct arguments
- const options = (0, _jestConfig().readConfig)(argv, root);
- const globalConfig = options.globalConfig; // Always disable automocking in scripts.
- const config = _objectSpread({}, options.projectConfig, {
- automock: false,
- unmockedModulePathPatterns: null
- }); // Break circular dependency
- const Runtime = require('..');
- Runtime.createContext(config, {
- maxWorkers: Math.max(_os().default.cpus().length - 1, 1),
- watchman: globalConfig.watchman
- })
- .then(hasteMap => {
- 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);
- runtime.requireModule(filePath);
- })
- .catch(e => {
- console.error(_chalk().default.red(e.stack || e));
- process.on('exit', () => (process.exitCode = 1));
- });
- }
|