perfrunner
Version:
Command-line-interface for the perfrunner - automated UI performance test tool
26 lines (25 loc) • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOutputPathFromUrl = exports.getOutputPathFromtestName = void 0;
const path_1 = require("path");
const generateFriendlyNameFromUrl = (url) => {
const friendlyHost = url.host.replace(/[\.:]/g, '_'); // remove . and : from host
const pathName = url.pathname;
const normalizedPath = pathName.endsWith('/') ? pathName.substring(0, pathName.length - 1) : pathName;
const friendlyPath = normalizedPath.replace(/[\\\/]/g, '__').replace(/\./g, '__');
const friendlyProtocol = url.protocol.replace(':', '__');
return `${friendlyProtocol}${friendlyHost}${friendlyPath}`;
};
const santizePath = (path) => path; // TODO: implement sanitaze
function getOutputPathFromtestName(outputFolder, testName) {
const safePathToSubfolder = santizePath(testName);
return (0, path_1.resolve)(process.cwd(), outputFolder, safePathToSubfolder);
}
exports.getOutputPathFromtestName = getOutputPathFromtestName;
function getOutputPathFromUrl(outputFolder, url) {
const subfolder = generateFriendlyNameFromUrl(new URL(url));
const safePathToSubfolder = santizePath(subfolder);
const result = (0, path_1.resolve)(process.cwd(), outputFolder, safePathToSubfolder);
return result;
}
exports.getOutputPathFromUrl = getOutputPathFromUrl;