/** Smoke: parse release app.js + showView switches */ const fs = require("fs"); const path = require("path"); const vm = require("vm"); const root = path.join(__dirname, "..", "release"); const s = fs.readFileSync(path.join(root, "app.js"), "utf8"); const html = fs.readFileSync(path.join(root, "index.html"), "utf8"); if (!s.includes("PORTAL_DATA")) throw new Error("missing PORTAL_DATA"); if (!s.includes("__nomadroGo")) throw new Error("missing __nomadroGo"); if (!html.includes("onclick=")) throw new Error("missing inline onclick"); const els = {}; function makeEl(id) { const el = { id: id || "", className: id && String(id).indexOf("view-") === 0 ? id === "view-home" ? "view is-active" : "view" : "", style: {}, textContent: "", innerHTML: "", parentNode: { removeChild: function () {} }, _attrs: {}, _listeners: {}, }; el.classList = { add: function (n) { el.className += " " + n; }, remove: function () {}, toggle: function () {}, }; el.getAttribute = function (k) { return el._attrs[k] != null ? el._attrs[k] : null; }; el.setAttribute = function (k, v) { el._attrs[k] = String(v); }; el.addEventListener = function (t, fn) { el._listeners[t] = fn; }; el.querySelectorAll = function () { return []; }; el.getElementsByTagName = function () { return []; }; el.contains = function () { return false; }; return el; } [ "view-home", "view-nav", "view-book", "view-community", "view-vip", "home-brand", "home-cards", "hub-loader", "home-tagline", "home-lead", "home-badge", "home-foot", "home-theme", "home-theme-icon", "brand-current", "content", "drawer", "drawer-nav", "drawer-mask", "drawer-close", "btn-menu", "btn-back-home", "sheet", "sheet-mask", "sheet-icon", "sheet-title", "sheet-sub", "sheet-url-box", "sheet-status", "sheet-select", "sheet-close", "book-list", "book-reader", "community-list", "vip-page", "toast", ].forEach(function (id) { els[id] = makeEl(id); }); els["home-cards"].querySelectorAll = function () { return ["nav", "book", "community", "vip"].map(function (k) { var c = makeEl(); c.className = "hub-portal-card"; c.setAttribute("data-go", k); return c; }); }; const doc = { readyState: "complete", documentElement: { setAttribute: function () {}, style: { setProperty: function () {} } }, body: {}, getElementById: function (id) { return els[id] || null; }, addEventListener: function () {}, }; const w = { document: doc, scrollTo: function () {}, localStorage: { getItem: function () { return null; }, setItem: function () {} }, }; w.window = w; vm.createContext(w); vm.runInContext(s, w); if (typeof w.__nomadroGo !== "function") throw new Error("__nomadroGo not function"); ["nav", "book", "community", "vip", "home"].forEach(function (name) { w.__nomadroGo(name); var el = els["view-" + name]; if (!el || el.style.display !== "block") throw new Error("view " + name + " not shown"); ["home", "nav", "book", "community", "vip"].forEach(function (other) { if (other === name) return; if (els["view-" + other].style.display !== "none") { throw new Error("view " + other + " should be hidden when showing " + name); } }); }); if (!(els["vip-page"].innerHTML || "").length) { w.__nomadroGo("vip"); } if (!(els["content"].innerHTML || "").length && !(els["book-list"].innerHTML || "").length) { // nav/book render may fill these } w.__nomadroGo("nav"); console.log("smoke ok: views switch; content len=", (els.content.innerHTML || "").length); w.__nomadroGo("book"); console.log("book list len=", (els["book-list"].innerHTML || "").length); w.__nomadroGo("community"); console.log("community len=", (els["community-list"].innerHTML || "").length); w.__nomadroGo("vip"); console.log("vip len=", (els["vip-page"].innerHTML || "").length);