"use strict"; const test = require("node:test"); const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); const root = path.join(__dirname, ".."); const views = fs.readdirSync(path.join(root, "views"), { recursive: true }) .filter(file => file.endsWith(".ejs")) .map(file => path.join("views", file)); const browserAssets = [ ...views, "dev-templates/index-real.html", "public/css/bot.css", "public/css/dashboard.css", "public/js/bot.js", "public/js/settings.js", ]; function assertLocalImage(url) { assert.match(url, /^\/images\/[\w.-]+$/); assert.ok(fs.statSync(path.join(root, "public", url), { throwIfNoEntry: false })?.isFile(), url); } test("panel pages and browser assets do not switch to jsDelivr", () => { for (const file of browserAssets) { const source = fs.readFileSync(path.join(root, file), "utf8"); assert.doesNotMatch(source, /cdn-fallback|adp:cdn-down|adp_cdn|cdn\.jsdelivr\.net\/gh\/antonndev\/adcdn/i, file); if (file.endsWith(".ejs") || file.endsWith(".html")) { assert.doesNotMatch(source, /cdn\.jsdelivr\.net/i, file); assert.doesNotMatch(source, /<(?:img|source)\b[^>]*\bsrc=["']https?:\/\//i, file); } for (const [url] of source.matchAll(/\/images\/[\w.-]+\.(?:avif|gif|ico|jpe?g|png|svg|webm|webp)\b/g)) { assertLocalImage(url); } } for (const script of ["cdn-fallback.js", "cdn-fallback.min.js"]) { assert.ok(!fs.existsSync(path.join(root, "public", "js", script)), script); } }); test("bundled template images and version logos point to served local files", () => { for (const { templateImage } of require("../templates.json")) { if (templateImage) assertLocalImage(templateImage); } for (const { logo } of require("../versions.json").providers) { if (logo) assertLocalImage(logo); } }); test("settings preloads the original sidebar toggle SVG before styles and scripts", () => { const settings = fs.readFileSync(path.join(root, "views", "settings.ejs"), "utf8"); const firstScript = settings.indexOf("= 0); assert.match(settings.slice(0, firstScript), //); assert.match(settings, /aria-label="Toggle Sidebar">\s* { const dashboard = fs.readFileSync(path.join(root, "views", "index.ejs"), "utf8"); const status = fs.readFileSync(path.join(root, "views", "status.ejs"), "utf8"); function buttonIcon(source, marker) { const buttons = Array.from(source.matchAll(/]*>[\s\S]*?<\/button>/g), ([button]) => button); const button = buttons.find(markup => markup.slice(0, markup.indexOf(">")).includes(marker)); assert.ok(button, marker); const icon = button.match(/([\s\S]*?)<\/span>/)?.[1].trim(); assert.match(icon, /^<\/i>$/, marker); return icon; } for (const [dashboardButton, statusButton] of [ ['id="openSshTerminalBtn"', 'id="openSshTerminalBtn"'], ['title="Settings"', 'title="Settings"'], ['id="logoutBtn"', 'class="nav-option nav-option--back"'], ]) { assert.equal(buttonIcon(dashboard, dashboardButton), buttonIcon(status, statusButton), dashboardButton); } assert.match(dashboard, /]*href="\/vendor\/fontawesome\/webfonts\/fa-solid-900\.woff2">/); });