89 lines
12 KiB
JavaScript
89 lines
12 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 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2NyZWVuc2hvdHMvaW5kZXguanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxtQ0FBOEI7QUFDOUIsb0RBQTRCO0FBQzV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