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

89 lines
12 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 lodash_1 = require("lodash");
const moment_1 = __importDefault(require("moment"));
const capturer_1 = __importDefault(require("./capturer"));
const path_pattern_1 = __importDefault(require("../utils/path-pattern"));
const get_common_path_1 = __importDefault(require("../utils/get-common-path"));
const default_extension_1 = __importDefault(require("./default-extension"));
const temp_directory_1 = __importDefault(require("../utils/temp-directory"));
const create_safe_listener_1 = __importDefault(require("../utils/create-safe-listener"));
const debug_1 = __importDefault(require("debug"));
const events_1 = require("events");
const DEBUG_LOGGER = (0, debug_1.default)('testcafe:screenshots');
const TEMP_DIR_PREFIX = 'screenshots';
class Screenshots extends events_1.EventEmitter {
constructor({ enabled, path, pathPattern, fullPage, thumbnails, autoTakeOnFails, messageBus }) {
super();
this.enabled = enabled;
this.screenshotsPath = path;
this.screenshotsPattern = pathPattern;
this.fullPage = fullPage;
this.thumbnails = thumbnails;
this.testEntries = [];
this.now = (0, moment_1.default)();
this.tempDirectory = new temp_directory_1.default(TEMP_DIR_PREFIX);
this.autoTakeOnFails = autoTakeOnFails;
this._assignEventHandlers(messageBus);
}
_createSafeListener(listener) {
return (0, create_safe_listener_1.default)(this, listener, DEBUG_LOGGER);
}
_assignEventHandlers(messageBus) {
messageBus.once('start', this._createSafeListener(this._onMessageBusStart));
}
async _onMessageBusStart() {
await this.tempDirectory.init();
}
_addTestEntry(test) {
const testEntry = {
test: test,
testRuns: {},
screenshots: [],
};
this.testEntries.push(testEntry);
return testEntry;
}
_getTestEntry(test) {
return (0, lodash_1.find)(this.testEntries, entry => entry.test === test);
}
_ensureTestEntry(test) {
let testEntry = this._getTestEntry(test);
if (!testEntry)
testEntry = this._addTestEntry(test);
return testEntry;
}
getScreenshotsInfo(test) {
return this._getTestEntry(test).screenshots;
}
hasCapturedFor(test) {
return this.getScreenshotsInfo(test).length > 0;
}
getPathFor(test) {
const testEntry = this._getTestEntry(test);
const screenshotPaths = testEntry.screenshots.map(screenshot => screenshot.screenshotPath);
return (0, get_common_path_1.default)(screenshotPaths);
}
createCapturerFor(test, testIndex, quarantine, connection, warningLog) {
const testEntry = this._ensureTestEntry(test);
const pathPattern = new path_pattern_1.default(this.screenshotsPattern, default_extension_1.default, {
testIndex,
quarantineAttempt: quarantine ? quarantine.getNextAttemptNumber() : null,
now: this.now,
fixture: test.fixture.name,
test: test.name,
parsedUserAgent: connection.browserInfo.parsedUserAgent,
});
return new capturer_1.default(this.screenshotsPath, testEntry, connection, pathPattern, this.fullPage, this.thumbnails, warningLog, this.tempDirectory.path, this.autoTakeOnFails);
}
addTestRun(test, testRun) {
const testEntry = this._getTestEntry(test);
testEntry.testRuns[testRun.browserConnection.id] = testRun;
}
}
exports.default = Screenshots;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2NyZWVuc2hvdHMvaW5kZXguanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxtQ0FBOEI7QUFDOUIsb0RBQTRCO0FBQzVCLDBEQUFrQztBQUNsQyx5RUFBZ0Q7QUFDaEQsK0VBQXFEO0FBQ3JELDRFQUErRDtBQUMvRCw2RUFBb0Q7QUFDcEQseUZBQStEO0FBQy9ELGtEQUEwQjtBQUMxQixtQ0FBc0M7QUFFdEMsTUFBTSxZQUFZLEdBQUcsSUFBQSxlQUFLLEVBQUMsc0JBQXNCLENBQUMsQ0FBQztBQUVuRCxNQUFNLGVBQWUsR0FBRyxhQUFhLENBQUM7QUFFdEMsTUFBcUIsV0FBWSxTQUFRLHFCQUFZO0lBQ2pELFlBQWEsRUFBRSxPQUFPLEVBQUUsSUFBSSxFQ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