116 lines
18 KiB
JavaScript
116 lines
18 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 correct_file_path_1 = __importDefault(require("../utils/correct-file-path"));
|
|
const escape_user_agent_1 = __importDefault(require("../utils/escape-user-agent"));
|
|
const events_1 = __importDefault(require("events"));
|
|
const DATE_FORMAT = 'YYYY-MM-DD';
|
|
const TIME_FORMAT = 'HH-mm-ss';
|
|
const ERRORS_FOLDER = 'errors';
|
|
const PROBLEMATIC_PLACEHOLDER_VALUE = '';
|
|
const PLACEHOLDERS = {
|
|
DATE: '${DATE}',
|
|
TIME: '${TIME}',
|
|
TEST_INDEX: '${TEST_INDEX}',
|
|
FILE_INDEX: '${FILE_INDEX}',
|
|
QUARANTINE_ATTEMPT: '${QUARANTINE_ATTEMPT}',
|
|
FIXTURE: '${FIXTURE}',
|
|
TEST: '${TEST}',
|
|
USERAGENT: '${USERAGENT}',
|
|
BROWSER: '${BROWSER}',
|
|
BROWSER_VERSION: '${BROWSER_VERSION}',
|
|
OS: '${OS}',
|
|
OS_VERSION: '${OS_VERSION}',
|
|
TEST_ID: '${TEST_ID}',
|
|
RUN_ID: '${RUN_ID}',
|
|
};
|
|
const DEFAULT_PATH_PATTERN_FOR_REPORT = `${PLACEHOLDERS.DATE}_${PLACEHOLDERS.TIME}\\${PLACEHOLDERS.TEST_ID}\\` +
|
|
`${PLACEHOLDERS.RUN_ID}\\${PLACEHOLDERS.USERAGENT}\\${PLACEHOLDERS.FILE_INDEX}`;
|
|
const TEST_ID_TEMPLATE = data => data.testIndex ? `test-${data.testIndex}` : '';
|
|
const RUN_ID_TEMPLATE = data => data.quarantineAttempt ? `run-${data.quarantineAttempt}` : '';
|
|
class PathPattern extends events_1.default {
|
|
constructor(pattern, fileExtension, data) {
|
|
super();
|
|
this.pattern = this._ensurePattern(pattern);
|
|
this.data = this._addDefaultFields(data);
|
|
this.placeholderToDataMap = this._createPlaceholderToDataMap();
|
|
this.fileExtension = fileExtension;
|
|
}
|
|
_ensurePattern(pattern) {
|
|
if (pattern)
|
|
return pattern;
|
|
return DEFAULT_PATH_PATTERN_FOR_REPORT;
|
|
}
|
|
_addDefaultFields(data) {
|
|
const defaultFields = {
|
|
testId: TEST_ID_TEMPLATE(data),
|
|
runId: RUN_ID_TEMPLATE(data),
|
|
formattedDate: data.now.format(DATE_FORMAT),
|
|
formattedTime: data.now.format(TIME_FORMAT),
|
|
fileIndex: 1,
|
|
errorFileIndex: 1,
|
|
};
|
|
return Object.assign({}, defaultFields, data);
|
|
}
|
|
_createPlaceholderToDataMap() {
|
|
return {
|
|
[PLACEHOLDERS.TEST_ID]: this.data.testId,
|
|
[PLACEHOLDERS.RUN_ID]: this.data.runId,
|
|
[PLACEHOLDERS.DATE]: this.data.formattedDate,
|
|
[PLACEHOLDERS.TIME]: this.data.formattedTime,
|
|
[PLACEHOLDERS.TEST_INDEX]: this.data.testIndex,
|
|
[PLACEHOLDERS.QUARANTINE_ATTEMPT]: this.data.quarantineAttempt || 1,
|
|
[PLACEHOLDERS.FIXTURE]: this.data.fixture,
|
|
[PLACEHOLDERS.TEST]: this.data.test,
|
|
[PLACEHOLDERS.FILE_INDEX]: forError => forError ? this.data.errorFileIndex : this.data.fileIndex,
|
|
[PLACEHOLDERS.USERAGENT]: this.data.parsedUserAgent.prettyUserAgent,
|
|
[PLACEHOLDERS.BROWSER]: this.data.parsedUserAgent.name,
|
|
[PLACEHOLDERS.BROWSER_VERSION]: this.data.parsedUserAgent.version,
|
|
[PLACEHOLDERS.OS]: this.data.parsedUserAgent.os.name,
|
|
[PLACEHOLDERS.OS_VERSION]: this.data.parsedUserAgent.os.version,
|
|
};
|
|
}
|
|
_buildPath(pattern, placeholderToDataMap, forError) {
|
|
let resultFilePath = pattern;
|
|
const problematicPlaceholders = [];
|
|
for (const placeholder in placeholderToDataMap) {
|
|
const findPlaceholderRegExp = new RegExp((0, lodash_1.escapeRegExp)(placeholder), 'g');
|
|
resultFilePath = resultFilePath.replace(findPlaceholderRegExp, () => {
|
|
if (placeholder === PLACEHOLDERS.FILE_INDEX) {
|
|
const getFileIndexFn = placeholderToDataMap[placeholder];
|
|
let result = getFileIndexFn(forError);
|
|
if (forError)
|
|
result = `${ERRORS_FOLDER}\\${result}`;
|
|
return result;
|
|
}
|
|
else if (placeholder === PLACEHOLDERS.USERAGENT) {
|
|
const userAgent = placeholderToDataMap[placeholder];
|
|
return (0, escape_user_agent_1.default)(userAgent);
|
|
}
|
|
let calculatedValue = placeholderToDataMap[placeholder];
|
|
if (calculatedValue === null || calculatedValue === void 0) {
|
|
problematicPlaceholders.push(placeholder);
|
|
calculatedValue = PROBLEMATIC_PLACEHOLDER_VALUE;
|
|
}
|
|
return calculatedValue;
|
|
});
|
|
}
|
|
if (problematicPlaceholders.length)
|
|
this.emit('problematic-placeholders-found', { placeholders: problematicPlaceholders });
|
|
return resultFilePath;
|
|
}
|
|
getPath(forError) {
|
|
const path = this._buildPath(this.pattern, this.placeholderToDataMap, forError);
|
|
return (0, correct_file_path_1.default)(path, this.fileExtension);
|
|
}
|
|
// For testing purposes
|
|
static get PLACEHOLDERS() {
|
|
return PLACEHOLDERS;
|
|
}
|
|
}
|
|
exports.default = PathPattern;
|
|
module.exports = exports.default;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGF0aC1wYXR0ZXJuLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL3BhdGgtcGF0dGVybi5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG1DQUFrRDtBQUNsRCxtRkFBeUQ7QUFDekQsbUZBQXlEO0FBQ3pELG9EQUFrQztBQUVsQyxNQUFNLFdBQVcsR0FBRyxZQUFZLENBQUM7QUFDakMsT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GREZWZhdWx0RmllbGRzKGRhdGEpO1xuICAgICAgICB0aGlzLnBsYWNlaG9sZGVyVG9EYXRhTWFwID0gdGhpcy5fY3JlYXRlUGxhY2Vob2xkZXJUb0RhdGFNYXAoKTtcbiAgICAgICAgdGhpcy5maWxlRXh0ZW5zaW9uICAgICAgICA9IGZpbGVFeHRlbnNpb247XG4gICAgfVxuXG4gICAgX2Vuc3VyZVBhdHRlcm4gKHBhdHRlcm4pIHtcbiAgICAgICAgaWYgKHBhdHRlcm4pXG4gICAgICAgICAgICByZXR1cm4gcGF0dGVybjtcblxuICAgICAgICByZXR1cm4gREVGQVVMVF9QQVRIX1BBVFRFUk5fRk9SX1JFUE9SVDtcbiAgICB9XG5cbiAgICBfYWRkRGVmYXVsdEZpZWxkcyAoZGF0YSkge1xuICAgICAgICBjb25zdCBkZWZhdWx0RmllbGRzID0ge1xuICAgICAgICAgICAgdGVzdElkOiAgICAgICAgIFRFU1RfSURfVEVNUExBVEUoZGF0YSksXG4gICAgICAgICAgICBydW5JZDogICAgICAgICAgUlVOX0lEX1RFTVBMQVRFKGRhdGEpLFxuICAgICAgICAgICAgZm9ybWF0dGVkRGF0ZTogIGRhdGEubm93LmZvcm1hdChEQVRFX0ZPUk1BVCksXG4gICAgICAgICAgICBmb3JtYXR0ZWRUaW1lOiAgZGF0YS5ub3cuZm9ybWF0KFRJTUVfRk9STUFUKSxcbiAgICAgICAgICAgIGZpbGVJbmRleDogICAgICAxLFxuICAgICAgICAgICAgZXJyb3JGaWxlSW5kZXg6IDEsXG4gICAgICAgIH07XG5cbiAgICAgICAgcmV0dXJuIE9iamVjdC5hc3NpZ24oe30sIGRlZmF1bHRGaWVsZHMsIGRhdGEpO1xuICAgIH1cblxuICAgIF9jcmVhdGVQbGFjZWhvbGRlclRvRGF0YU1hcCAoKSB7XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICBbUExBQ0VIT0xERVJTLlRFU1RfSURdOiAgICAgICAgICAgIHRoaXMuZGF0YS50ZXN0SWQsXG4gICAgICAgICAgICBbUExBQ0VIT0xERVJTLlJVTl9JRF06ICAgICAgICAgICAgIHRoaXMuZGF0YS5ydW5JZCxcbiAgICAgICAgICAgIFtQTEFDRUhPTERFUlMuREFURV06ICAgICAgICAgICAgICAgdGhpcy5kYXRhLmZvcm1hdHRlZERhdGUsXG4gICAgICAgICAgICBbUExBQ0VIT0xERVJTLlRJTUVdOiAgICAgICAgICAgICAgIHRoaXMuZGF0YS5mb3JtYXR0ZWRUaW1lLFxuICAgICAgICAgICAgW1BMQUNFSE9MREVSUy5URVNUX0lOREVYXTogICAgICAgICB0aGlzLmRhdGEudGVzdEluZGV4LFxuICAgICAgICAgICAgW1BMQUNFSE9MREVSUy5RVUFSQU5USU5FX0FUVEVNUFRdOiB0aGlzLmRhdGEucXVhcmFudGluZUF0dGVtcHQgfHwgMSxcbiAgICAgICAgICAgIFtQTEFDRUhPTERFUlMuRklYVFVSRV06ICAgICAgICAgICAgdGhpcy5kYXRhLmZpeHR1cmUsXG4gICAgICAgICAgICBbUExBQ0VIT0xERVJTLlRFU1RdOiAgICAgICAgICAgICAgIHRoaXMuZGF0YS50ZXN0LFxuICAgICAgICAgICAgW1BMQUNFSE9MREVSUy5GSUxFX0lOREVYXTogICAgICAgICBmb3JFcnJvciA9PiBmb3JFcnJvciA/IHRoaXMuZGF0YS5lcnJvckZpbGVJbmRleCA6IHRoaXMuZGF0YS5maWxlSW5kZXgsXG4gICAgICAgICAgICBbUExBQ0VIT0xERVJTLlVTRVJBR0VOVF06ICAgICAgICAgIHRoaXMuZGF0YS5wYXJzZWRVc2VyQWdlbnQucHJldHR5VXNlckFnZW50LFxuICAgICAgICAgICAgW1BMQUNFSE9MREVSUy5CUk9XU0VSXTogICAgICAgICAgICB0aGlzLmRhdGEucGFyc2VkVXNlckFnZW50Lm5hbWUsXG4gICAgICAgICAgICBbUExBQ0VIT0xERVJTLkJST1dTRVJfVkVSU0lPTl06ICAgIHRoaXMuZGF0YS5wYXJzZW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nJvcilcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9IGAke0VSUk9SU19GT0xERVJ9XFxcXCR7cmVzdWx0fWA7XG5cbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBlbHNlIGlmIChwbGFjZWhvbGRlciA9PT0gUExBQ0VIT0xERVJTLlVTRVJBR0VOVCkge1xuICAgICAgICAgICAgICAgICAgICBjb25zdCB1c2VyQWdlbnQgPSBwbGFjZWhvbGRlclRvRGF0YU1hcFtwbGFjZWhvbGRlcl07XG5cbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGVzY2FwZVVzZXJBZ2VudCh1c2VyQWdlbnQpO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIGxldCBjYWxjdWxhdGVkVmFsdWUgPSBwbGFjZWhvbGRlclRvRGF0YU1hcFtwbGFjZWhvbGRlcl07XG5cbiAgICAgICAgICAgICAgICBpZiAoY2FsY3VsYXRlZFZhbHVlID09PSBudWxsIHx8IGNhbGN1bGF0ZWRWYWx1ZSA9PT0gdm9pZCAwKSB7XG4gICAgICAgICAgICAgICAgICAgIHByb2JsZW1hdGljUGxhY2Vob2xkZXJzLnB1c2gocGxhY2Vob2xkZXIpO1xuXG4gICAgICAgICAgICAgICAgICAgIGNhbGN1bGF0ZWRWYWx1ZSA9IFBST0JMRU1BVElDX1BMQUNFSE9MREVSX1ZBTFVFO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHJldHVybiBjYWxjdWxhdGVkVmFsdWU7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChwcm9ibGVtYXRpY1BsYWNlaG9sZGVycy5sZW5ndGgpXG4gICAgICAgICAgICB0aGlzLmVtaXQoJ3Byb2JsZW1hdGljLXBsYWNlaG9sZGVycy1mb3VuZCcsIHsgcGxhY2Vob2xkZX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