next-page-tester
Version:
Enable DOM integration testing on Next.js pages
32 lines (31 loc) • 1.23 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const getPagePaths_1 = __importDefault(require("../getPagePaths"));
const utils_1 = require("../../utils");
const utils_2 = require("./utils");
/**
* Parse tested route against existing page paths.
* @returns path of matching page file and the object of matching params
*/
async function parseMatchingRoute({ options, }) {
const { route } = options;
const { pathname: routePath } = (0, utils_1.parseRoute)({ route }).urlObject;
const pagePaths = await (0, getPagePaths_1.default)({ options });
for (const pagePath of pagePaths) {
const { regex: pagePathRegex, paramTypes } = (0, utils_2.pagePathToRouteRegex)(pagePath);
const result = routePath.match(pagePathRegex);
if (result) {
return {
pagePath,
params: (0, utils_2.makeParamsObject)({
routeRegexCaptureGroups: result.groups,
paramTypes,
}),
};
}
}
}
exports.default = parseMatchingRoute;