37 lines
5.4 KiB
JavaScript
37 lines
5.4 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 debug_1 = __importDefault(require("debug"));
|
||
|
const log_1 = __importDefault(require("./log"));
|
||
|
const information_message_1 = require("../notifications/information-message");
|
||
|
const constants_1 = __importDefault(require("../configuration/constants"));
|
||
|
const timer_1 = __importDefault(require("../utils/timer"));
|
||
|
const get_any_key_1 = __importDefault(require("../utils/get-any-key"));
|
||
|
const { MAX_AUTHENTICATION_DELAY } = constants_1.default.CLI.AUTHENTICATION_HELPER;
|
||
|
const debugLog = (0, debug_1.default)('testcafe:cli:authentication-helper');
|
||
|
async function checkAuthentication(action, errorClass) {
|
||
|
try {
|
||
|
return { result: await action() };
|
||
|
}
|
||
|
catch (error) {
|
||
|
if (!(error instanceof errorClass))
|
||
|
throw error;
|
||
|
return { error };
|
||
|
}
|
||
|
}
|
||
|
async function authenticationHelper(action, errorClass, { interactive = true } = {}) {
|
||
|
let { result, error } = await checkAuthentication(action, errorClass);
|
||
|
const timer = new timer_1.default(MAX_AUTHENTICATION_DELAY);
|
||
|
while (error && !timer.expired && interactive) {
|
||
|
debugLog(error);
|
||
|
log_1.default.write(information_message_1.SCREEN_RECORDING_PERMISSION_REQUEST);
|
||
|
await Promise.race([timer.promise, (0, get_any_key_1.default)()]);
|
||
|
({ result, error } = await checkAuthentication(action, errorClass));
|
||
|
}
|
||
|
return { result, error };
|
||
|
}
|
||
|
exports.default = authenticationHelper;
|
||
|
module.exports = exports.default;
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0aGVudGljYXRpb24taGVscGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NsaS9hdXRoZW50aWNhdGlvbi1oZWx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