UNPKG

e2ed

Version:

E2E testing framework over Playwright

36 lines (35 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getUrlTemplate = void 0; const node_path_1 = require("node:path"); const node_url_1 = require("node:url"); const asserts_1 = require("../asserts"); const isIdentifier_1 = require("./isIdentifier"); const maxExtensionLength = 4; const minExtensionLength = 2; /** * Get url template from url (for API statistics). * `query` part is cut off, and all identifiers in the `pathname` are replaced with asterisks. * @internal */ const getUrlTemplate = (url) => { const { origin, pathname } = new node_url_1.URL(url); const parts = pathname.split('/'); const extension = (0, node_path_1.extname)(pathname).slice(1); if ((extension.length >= minExtensionLength && extension.length <= maxExtensionLength && /^[a-z]+$/.test(extension)) || extension === 'woff2') { return { hasExtension: true, urlTemplate: `${origin}${pathname}` }; } for (let index = 0; index < parts.length; index += 1) { const part = parts[index]; (0, asserts_1.assertValueIsDefined)(part, 'part is defined', { url }); if ((0, isIdentifier_1.isIdentifier)(part)) { parts[index] = '*'; } } const newPathname = parts.join('/'); return { hasExtension: false, urlTemplate: `${origin}${newPathname}` }; }; exports.getUrlTemplate = getUrlTemplate;