const assert = require("assert"); const fs = require("fs"); const path = require("path"); const pagesRoot = path.join(__dirname, "..", "pages"); const pageNames = fs.readdirSync(pagesRoot); pageNames.forEach((pageName) => { const pageRoot = path.join(pagesRoot, pageName); const jsPath = path.join(pageRoot, `${pageName}.js`); const wxmlPath = path.join(pageRoot, `${pageName}.wxml`); if (!fs.existsSync(jsPath) || !fs.existsSync(wxmlPath)) return; const js = fs.readFileSync(jsPath, "utf8"); const wxml = fs.readFileSync(wxmlPath, "utf8"); const handlers = [...wxml.matchAll(/(?:bind|catch)[a-z]+="([A-Za-z0-9_]+)"/g)] .map((match) => match[1]); handlers.forEach((handler) => { assert.match( js, new RegExp(`\\n\\s{2}${handler}\\s*\\(`), `${pageName}.wxml references missing handler ${handler}` ); }); }); console.log("page contract tests passed");