next-page-tester
Version:
Enable DOM integration testing on Next.js pages
29 lines (28 loc) • 1.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const utils_1 = require("../utils");
const normalize_path_1 = __importDefault(require("normalize-path"));
const sorted_routes_1 = require("next/dist/shared/lib/router/utils/sorted-routes");
/**
* Returns available page paths without file extension sorted by matching priority
*/
async function getPagePaths({ options: { pagesDirectory, pageExtensions }, }) {
const files = await (0, utils_1.glob)(path_1.default.join(pagesDirectory, '**', '*'));
const extensionsRegex = new RegExp(`.(${pageExtensions.join('|')})$`);
return (0, sorted_routes_1.getSortedRoutes)(files
// Make page paths relative
.map((filePath) => filePath.replace((0, normalize_path_1.default)(pagesDirectory), ''))
// Filter out files with non-allowed extensions
.filter((filePath) => filePath.match(extensionsRegex))
// Strip file extensions
.map((filePath) => filePath.replace(extensionsRegex, ''))
// Filter out /api folder
.filter((filePath) => !filePath.startsWith('/api/'))
// Filter out /_app and /_document files
.filter((filePath) => filePath !== '/_app' && filePath !== '/_document'));
}
exports.default = getPagePaths;