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

152 lines
20 KiB
JavaScript
Raw Normal View History

"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NsaS9jbGkuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxrREFBMEI7QUFDMUIsK0NBQTJEO0FBQzNELDJDQUFpRDtBQUNqRCx3RUFBa0Q7QUFDbEQsZ0ZBQXVEO0FBQ3ZELGdEQUF3QjtBQUN4QixzRUFBNkM7QUFDN0Msa0dBQXVFO0FBQ3ZFLDRDQUFpQztBQUNqQyxrREFBMEI7QUFDMUIsbUVBQTBDO0FBQzFDLDZEQUFnRDtBQUVoRCxNQUFNLE1BQU0sR0FBRyxJQUFBLGVBQUssRUFBQyxjQUFjLENBQUMsQ0FBQztBQUVyQyw2REFBNkQ7QUFDN0QsTUFBTSxXQUFXLEdBQVcsT0FBTyxDQUFDLGFBQWEsQ0FBQyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0FBQzVELE1BQU0sbUJBQW1CLEdBQUcsV0FBVyxDQUFDLDBCQUEwQixDQUFDLENBQUM7QUFFcEUsSUFBSSxpQkFBaUIsR0FBRyxJQUFJLENBQUM7QUFDN0IsSUFBSSxnQkFBZ0IsR0FBSSxLQUFLLENBQUM7QUFDOUIsSUFBS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