Innovenergy_trunk/frontend/node_modules/testcafe/lib/dashboard/index.js

145 lines
19 KiB
JavaScript
Raw Permalink 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 prompts_1 = __importDefault(require("prompts"));
const chalk_1 = __importDefault(require("chalk"));
const connector_1 = __importDefault(require("./connector"));
const email_validator_1 = __importDefault(require("email-validator"));
const messages_1 = __importDefault(require("./messages"));
const get_default_project_link_1 = __importDefault(require("./get-default-project-link"));
const config_storage_1 = __importDefault(require("../dashboard/config-storage"));
const formatting_1 = require("./formatting");
const documentation_url_1 = __importDefault(require("./documentation-url"));
const dashboardConnector = new connector_1.default();
const dashboardConfigStorage = new config_storage_1.default();
async function registerInDashboard() {
(0, formatting_1.info)(messages_1.default.REGISTRATION_ENTER_EMAIL_INVITATION);
const { email } = await (0, prompts_1.default)({
type: 'text',
name: 'email',
message: messages_1.default.PROMPT_EMAIL_CAPTION,
validate: (input) => {
if (!email_validator_1.default.validate(input))
return messages_1.default.PROMPT_INVALID_EMAIL;
return true;
},
});
if (!email) {
(0, formatting_1.error)(messages_1.default.REGISTRATION_CANCELLED);
return;
}
const sendEmailResult = await dashboardConnector.sendEmail(email);
if (!sendEmailResult.success) {
const sendEmailErrorMessage = sendEmailResult.isDashboardError
? sendEmailResult.errorMessage
: messages_1.default.REGISTRATION_EMAIL_SENDING_NETWORK_ERROR;
(0, formatting_1.error)(sendEmailErrorMessage);
return;
}
(0, formatting_1.info)(messages_1.default.REGISTRATION_EMAIL_SENT);
const { token } = await (0, prompts_1.default)({
type: 'text',
name: 'token',
message: messages_1.default.PROMPT_TOKEN_CAPTION,
});
if (!token) {
(0, formatting_1.error)(messages_1.default.REGISTRATION_CANCELLED);
return;
}
const validationResult = await dashboardConnector.validateToken(token);
if (!validationResult.success) {
const validationResultErrorMessage = validationResult.isDashboardError
? validationResult.errorMessage
: messages_1.default.TOKEN_VALIDATION_NETWORK_ERROR;
(0, formatting_1.error)(validationResultErrorMessage);
return;
}
dashboardConfigStorage.options.sendReport = true;
await saveNewToken(token);
(0, formatting_1.success)(messages_1.default.REGISTRATION_FINISHED);
(0, formatting_1.info)('View test results at:\n' +
`${chalk_1.default.underline.blueBright((0, get_default_project_link_1.default)(token))}`);
(0, formatting_1.info)(`Run ${chalk_1.default.black.bgWhiteBright('testcafe dashboard off')} to disable this behavior.` +
`Learn more at:\n${chalk_1.default.underline.blueBright(documentation_url_1.default)}`);
}
async function saveNewToken(token) {
dashboardConfigStorage.options.token = token;
await dashboardConfigStorage.save();
}
async function updateDefaultToken() {
if (!dashboardConfigStorage.options.sendReport)
(0, formatting_1.warning)(messages_1.default.TOKEN_UPDATING_NOT_SEND_REPORT);
// NOTE: for the formatting reason
(0, formatting_1.info)('');
const { doYouWantToUpdateDefaultToken } = await (0, prompts_1.default)({
type: 'confirm',
name: 'doYouWantToUpdateDefaultToken',
message: 'Your setup includes a default Dashboard token. Do you want to change it?:',
});
if (!doYouWantToUpdateDefaultToken) {
(0, formatting_1.error)(messages_1.default.TOKEN_UPDATE_CANCELLED);
return;
}
// NOTE: for the formatting reason
(0, formatting_1.info)('');
const { newToken } = await (0, prompts_1.default)({
type: 'text',
name: 'newToken',
message: 'Enter the new default token value:',
});
if (!newToken) {
(0, formatting_1.error)(messages_1.default.TOKEN_UPDATE_CANCELLED);
return;
}
const validationResult = await dashboardConnector.validateToken(newToken);
if (!validationResult.success) {
const validationResultErrorMessage = validationResult.isDashboardError
? validationResult.errorMessage
: messages_1.default.TOKEN_VALIDATION_NETWORK_ERROR;
(0, formatting_1.error)(validationResultErrorMessage);
return;
}
await saveNewToken(newToken);
(0, formatting_1.success)(messages_1.default.TOKEN_UPDATED);
}
async function setSendReportState(state) {
const sendReportAsBoolean = state === 'on';
dashboardConfigStorage.options.sendReport = sendReportAsBoolean;
await dashboardConfigStorage.save();
const resultMessage = sendReportAsBoolean ? messages_1.default.SEND_REPORT_STATE_ON : messages_1.default.SEND_REPORT_STATE_OFF;
(0, formatting_1.success)(resultMessage);
}
async function tryToRegisterInDashboard() {
(0, formatting_1.info)(messages_1.default.TOKEN_NO_DEFAULT_FOUND);
const { launchConfigurationWizard } = await (0, prompts_1.default)({
type: 'confirm',
name: 'launchConfigurationWizard',
message: 'Do you want to launch the configuration wizard?',
initial: true,
});
if (!launchConfigurationWizard) {
(0, formatting_1.error)(messages_1.default.REGISTRATION_CANCELLED);
return;
}
await registerInDashboard();
}
async function default_1(sendReportState) {
const storageExists = await dashboardConfigStorage.load();
if (sendReportState !== void 0) {
if (storageExists)
await setSendReportState(sendReportState);
else
await tryToRegisterInDashboard();
return;
}
const thereIsDefaultToken = !!dashboardConfigStorage.options.token;
if (thereIsDefaultToken)
await updateDefaultToken();
else
await registerInDashboard();
}
exports.default = default_1;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZGFzaGJvYXJkL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsc0RBQThCO0FBQzlCLGtEQUEwQjtBQUMxQiw0REFBNkM7QUFDN0Msc0VBQTZDO0FBQzdDLDBEQUFrQztBQUNsQywwRkFBK0Q7QUFDL0QsaUZBQWlFO0FBR2pFLDZDQUtzQjtBQUV0Qiw0RUFBOEQ7QUFFOUQsTUFBTSxrQkFBa0IsR0FBTyxJQUFJLG1CQUFrQixFQUFFLENBQUM7QUFDeEQsTUFBTSxzQkFBc0IsR0FBRyxJQUFJLHdCQUFzQixFQUFFLENBQUM7QUFFNUQsS0FBSyxVQUFVLG1CQUFtQjtJQUM5QixJQUFBLGlCQUFJLEVBQUMsa0JBQVEsQ0FBQyxtQ0FBbUMsQ0FBQyxDQUFDO0lBRW5ELE1BQU0sRUFBRSxLQUFLLEVBQUUsR0FBRyxNQ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