Innovenergy_trunk/frontend/node_modules/testcafe/lib/cli/cli.js

152 lines
20 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const runtime_1 = require("../errors/runtime");
const types_1 = require("../errors/types");
const argument_parser_1 = __importDefault(require("./argument-parser"));
const termination_handler_1 = __importDefault(require("./termination-handler"));
const log_1 = __importDefault(require("./log"));
const remotes_wizard_1 = __importDefault(require("./remotes-wizard"));
const correct_browsers_and_sources_1 = __importDefault(require("./correct-browsers-and-sources"));
const __1 = __importDefault(require("../"));
const debug_1 = __importDefault(require("debug"));
const log_entry_1 = __importDefault(require("../utils/log-entry"));
const dashboard_1 = __importDefault(require("../dashboard"));
const LOGGER = (0, debug_1.default)('testcafe:cli');
// NOTE: Load the provider pool lazily to reduce startup time
const lazyRequire = require('import-lazy')(require);
const browserProviderPool = lazyRequire('../browser/provider/pool');
let showMessageOnExit = true;
let exitMessageShown = false;
let exiting = false;
function exitHandler(terminationLevel) {
if (showMessageOnExit && !exitMessageShown) {
exitMessageShown = true;
log_1.default.write('Stopping TestCafe...');
process.on('exit', () => log_1.default.hideSpinner(true));
}
if (exiting || terminationLevel < 2)
return;
exiting = true;
exit(0);
}
function exit(code) {
log_1.default.hideSpinner(true);
// NOTE: give a process time to flush the output.
// It's necessary in some environments.
setTimeout(() => process.exit(code), 0);
}
function error(err) {
log_1.default.hideSpinner();
let message = null;
if (err instanceof runtime_1.GeneralError)
message = err.message;
else if (err instanceof runtime_1.APIError)
message = err.coloredStack;
else
message = err.stack;
log_1.default.write(chalk_1.default.red('ERROR ') + message + '\n');
log_1.default.write(chalk_1.default.gray('Type "testcafe -h" for help.'));
exit(1);
}
async function runTests(argParser) {
const opts = argParser.opts;
const port1 = opts.ports && opts.ports[0];
const port2 = opts.ports && opts.ports[1];
const proxy = opts.proxy;
const proxyBypass = opts.proxyBypass;
const configFile = opts.configFile;
log_1.default.showSpinner();
const { hostname, ssl, dev, experimentalDebug, retryTestPages, cache, disableHttp2, v8Flags, experimentalProxyless, disableCrossDomain, experimentalEsm, } = opts;
const testCafe = await (0, __1.default)({
developmentMode: dev,
isCli: true,
hostname,
port1,
port2,
ssl,
experimentalDebug,
retryTestPages,
cache,
configFile,
disableHttp2,
v8Flags,
experimentalProxyless,
disableCrossDomain,
experimentalEsm,
});
const correctedBrowsersAndSources = await (0, correct_browsers_and_sources_1.default)(argParser, testCafe.configuration);
const automatedBrowsers = correctedBrowsersAndSources.browsers;
const remoteBrowsers = await (0, remotes_wizard_1.default)(testCafe, argParser.remoteCount, opts.qrCode);
const browsers = automatedBrowsers.concat(remoteBrowsers);
const sources = correctedBrowsersAndSources.sources;
const runner = opts.live ? testCafe.createLiveModeRunner() : testCafe.createRunner();
let failed = 0;
runner
.useProxy(proxy, proxyBypass)
.src(sources)
.tsConfigPath(argParser.opts.tsConfigPath)
.browsers(browsers)
.reporter(argParser.opts.reporter)
.concurrency(argParser.opts.concurrency)
.filter(argParser.opts.filter)
.video(opts.video, opts.videoOptions, opts.videoEncodingOptions)
.screenshots(opts.screenshots)
.startApp(opts.app, opts.appInitDelay)
.clientScripts(argParser.opts.clientScripts)
.compilerOptions(argParser.opts.compilerOptions);
runner.once('done-bootstrapping', () => log_1.default.hideSpinner());
try {
const runOpts = argParser.getRunOptions();
failed = await runner.run(runOpts);
}
finally {
showMessageOnExit = false;
await testCafe.close();
}
exit(failed);
}
async function runDashboardIntegration(state) {
await (0, dashboard_1.default)(state);
exit(0);
}
async function listBrowsers(providerName) {
const provider = await browserProviderPool.getProvider(providerName);
if (!provider)
throw new runtime_1.GeneralError(types_1.RUNTIME_ERRORS.browserProviderNotFound, providerName);
if (provider.isMultiBrowser) {
const browserNames = await provider.getBrowserList();
await browserProviderPool.dispose();
if (providerName === 'locally-installed')
console.log(browserNames.join('\n'));
else
console.log(browserNames.map(browserName => `"${providerName}:${browserName}"`).join('\n'));
}
else
console.log(`"${providerName}"`);
exit(0);
}
(async function cli() {
const terminationHandler = new termination_handler_1.default();
terminationHandler.on(termination_handler_1.default.TERMINATION_LEVEL_INCREASED_EVENT, exitHandler);
try {
const argParser = new argument_parser_1.default();
(0, log_entry_1.default)(LOGGER, process.argv);
await argParser.parse(process.argv);
(0, log_entry_1.default)(LOGGER, argParser.opts);
if (argParser.isDashboardCommand)
await runDashboardIntegration(argParser.sendReportState);
else if (argParser.opts.listBrowsers)
await listBrowsers(argParser.opts.providerName);
else
await runTests(argParser);
}
catch (err) {
showMessageOnExit = false;
error(err);
}
})();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NsaS9jbGkuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxrREFBMEI7QUFDMUIsK0NBQTJEO0FBQzNELDJDQUFpRDtBQUNqRCx3RUFBa0Q7QUFDbEQsZ0ZBQXVEO0FBQ3ZELGdEQUF3QjtBQUN4QixzRUFBNkM7QUFDN0Msa0dBQXVFO0FBQ3ZFLDRDQUFpQztBQUNqQyxrREFBMEI7QUFDMUIsbUVBQTBDO0FBQzFDLDZEQUFnRDtBQUVoRCxNQUFNLE1BQU0sR0FBRyxJQUFBLGVBQUssRUFBQyxjQUFjLENBQUMsQ0FBQztBQUVyQyw2REFBNkQ7QUFDN0QsTUFBTSxXQUFXLEdBQVcsT0FBTyxDQUFDLGFBQWEsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0FBQzVELE1BQU0sbUJBQW1CLEdBQUcsV0FBVyxDQUFDLDBCQUEwQixDQUFDLENBQUM7QUFFcEUsSUFBSSxpQkFBaUIsR0FBRyxJQUFJLENBQUM7QUFDN0IsSUFBSSxnQkFBZ0IsR0FBSSxLQUFLLENBQUM7QUFDOUIsSUFBSSxPQUFPLE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