jest-repl
Version:
390 lines (360 loc) • 12.2 kB
JavaScript
/*!
* /**
* * Copyright (c) Meta Platforms, Inc. and affiliates.
* *
* * This source code is licensed under the MIT license found in the
* * LICENSE file in the root directory of this source tree.
* * /
*/
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./package.json":
/***/ ((module) => {
module.exports = /*#__PURE__*/JSON.parse('{"version":"30.0.0-rc.1"}');
/***/ }),
/***/ "./src/cli/args.ts":
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.usage = exports.options = void 0;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const usage = exports.usage = 'Usage: $0 [--config=<pathToConfigFile>]';
const runtimeCLIOptions = {
cache: {
default: true,
description: 'Whether to use the preprocessor cache. Disable ' + 'the cache using --no-cache.',
type: 'boolean'
},
config: {
alias: 'c',
description: 'The path to a Jest config file.',
type: 'string'
},
debug: {
description: 'Print debugging info about your jest config.',
type: 'boolean'
},
watchman: {
default: true,
description: 'Whether to use watchman for file crawling. Disable using ' + '--no-watchman.',
type: 'boolean'
}
};
const options = exports.options = {
...runtimeCLIOptions,
replname: {
alias: 'r',
description: 'The "name" of the file given to transformers to be ' + 'transformed. For example, "repl.ts" if using a TypeScript transformer.',
type: 'string'
}
};
/***/ }),
/***/ "./src/cli/index.ts":
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
//#!/usr/bin/env node
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.run = run;
function _yargs() {
const data = _interopRequireDefault(require("yargs"));
_yargs = function () {
return data;
};
return data;
}
function _jestConfig() {
const data = require("jest-config");
_jestConfig = function () {
return data;
};
return data;
}
function _jestValidate() {
const data = require("jest-validate");
_jestValidate = function () {
return data;
};
return data;
}
var args = _interopRequireWildcard(__webpack_require__("./src/cli/args.ts"));
var _runtimeCli = __webpack_require__("./src/cli/runtime-cli.ts");
var _version = __webpack_require__("./src/cli/version.ts");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const REPL_SCRIPT = require.resolve('./repl');
async function run() {
const argv = await (0, _yargs().default)(process.argv.slice(2)).usage(args.usage).options(args.options).argv;
(0, _jestValidate().validateCLIOptions)(argv, {
...args.options,
deprecationEntries: _jestConfig().deprecationEntries
});
argv._ = [REPL_SCRIPT];
return (0, _runtimeCli.run)(argv, [`Jest REPL v${_version.VERSION}`]);
}
/***/ }),
/***/ "./src/cli/runtime-cli.ts":
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
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 util() {
const data = _interopRequireWildcard(require("util"));
util = 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 _transform() {
const data = require("@jest/transform");
_transform = function () {
return data;
};
return data;
}
function _jestConfig() {
const data = require("jest-config");
_jestConfig = function () {
return data;
};
return data;
}
function _jestRuntime() {
const data = _interopRequireDefault(require("jest-runtime"));
_jestRuntime = 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;
}
var args = _interopRequireWildcard(__webpack_require__("./src/cli/args.ts"));
var _version = __webpack_require__("./src/cli/version.ts");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* 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 = await (0, _yargs().default)(process.argv.slice(2)).usage(args.usage).help(false).version(false).options(args.options).argv;
(0, _jestValidate().validateCLIOptions)(argv, {
...args.options,
deprecationEntries: _jestConfig().deprecationEntries
});
}
if (argv.help === true) {
(0, _yargs().default)().showHelp();
process.on('exit', () => process.exitCode = 1);
return;
}
if (argv.version === true) {
console.log(`v${_version.VERSION}\n`);
return;
}
if (argv._.length === 0) {
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].toString());
if (argv.debug === true) {
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 projectConfig = {
...options.projectConfig,
automock: false
};
try {
const numCpus = (0, _os().availableParallelism)();
const hasteMap = await _jestRuntime().default.createContext(projectConfig, {
maxWorkers: Math.max(numCpus - 1, 1),
watchman: globalConfig.watchman
});
const transformer = await (0, _transform().createScriptTransformer)(projectConfig);
const Environment = await transformer.requireAndTranspileModule(projectConfig.testEnvironment);
const customConsole = new (_console().CustomConsole)(process.stdout, process.stderr);
const environment = new Environment({
globalConfig,
projectConfig
}, {
console: customConsole,
docblockPragmas: {},
testPath: filePath
});
(0, _jestUtil().setGlobal)(environment.global, 'console', customConsole, 'retain');
(0, _jestUtil().setGlobal)(environment.global, 'jestProjectConfig', projectConfig, 'retain');
(0, _jestUtil().setGlobal)(environment.global, 'jestGlobalConfig', globalConfig, 'retain');
const runtime = new (_jestRuntime().default)(projectConfig, environment, hasteMap.resolver, transformer, new Map(), {
changedFiles: undefined,
collectCoverage: false,
collectCoverageFrom: [],
coverageProvider: 'v8',
sourcesRelatedToTestsInChangedFiles: undefined
}, filePath, globalConfig);
for (const path of projectConfig.setupFiles) {
const esm = runtime.unstable_shouldLoadAsEsm(path);
if (esm) {
await runtime.unstable_importModule(path);
} else {
const setupFile = runtime.requireModule(path);
if (typeof setupFile === 'function') {
await setupFile();
}
}
}
const esm = runtime.unstable_shouldLoadAsEsm(filePath);
if (esm) {
await runtime.unstable_importModule(filePath);
} else {
runtime.requireModule(filePath);
}
} catch (error) {
console.error(_chalk().default.red(util().types.isNativeError(error) ? error.stack : error));
process.on('exit', () => {
process.exitCode = 1;
});
}
}
/***/ }),
/***/ "./src/cli/version.ts":
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({
value: true
}));
exports.VERSION = void 0;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// For some reason, doing `require`ing here works, while inside `cli` fails
const VERSION = exports.VERSION = __webpack_require__("./package.json").version;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry needs to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
(() => {
var exports = __webpack_exports__;
Object.defineProperty(exports, "__esModule", ({
value: true
}));
Object.defineProperty(exports, "repl", ({
enumerable: true,
get: function () {
return _cli.run;
}
}));
Object.defineProperty(exports, "runtime", ({
enumerable: true,
get: function () {
return _runtimeCli.run;
}
}));
var _cli = __webpack_require__("./src/cli/index.ts");
var _runtimeCli = __webpack_require__("./src/cli/runtime-cli.ts");
})();
module.exports = __webpack_exports__;
/******/ })()
;