新建项目
This commit is contained in:
28
tests/page-contract.test.js
Normal file
28
tests/page-contract.test.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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");
|
||||
Reference in New Issue
Block a user