test: lock miniapp reference page scope
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { existsSync, readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
const root = resolve(import.meta.dirname, '..')
|
||||
const read = (path) => readFileSync(resolve(root, path), 'utf8')
|
||||
const app = JSON.parse(read('miniapp/app.json'))
|
||||
const corePages = [
|
||||
'index',
|
||||
'discover',
|
||||
'messages',
|
||||
'activity',
|
||||
'mine',
|
||||
'matchmaker',
|
||||
'counseling-intro',
|
||||
'premarital-intro',
|
||||
'content',
|
||||
'anti-fraud',
|
||||
'service-station',
|
||||
]
|
||||
const quickEntryCodes = [
|
||||
'find_object',
|
||||
'matchmaker',
|
||||
'activities',
|
||||
'counseling',
|
||||
'classroom',
|
||||
'premarital',
|
||||
'anti_fraud',
|
||||
'service_station',
|
||||
]
|
||||
|
||||
assert.deepEqual(
|
||||
app.tabBar.list.map((item) => item.text),
|
||||
['首页', '找对象', '消息', '活动', '我的'],
|
||||
'五个 Tab 的顺序发生偏移',
|
||||
)
|
||||
|
||||
for (const page of corePages) {
|
||||
const base = `miniapp/pages/${page}/${page}`
|
||||
for (const extension of ['.json', '.wxml', '.wxss']) {
|
||||
assert.ok(existsSync(resolve(root, base + extension)), `${page}${extension} 不存在`)
|
||||
}
|
||||
const template = read(base + '.wxml')
|
||||
assert.match(template, /reference-page/, `${page} 未接入参考图页面骨架`)
|
||||
assert.doesNotMatch(template, /[\u{1F300}-\u{1FAFF}]/u, `${page} 含 Emoji`)
|
||||
}
|
||||
|
||||
const homeLogic = read('miniapp/pages/index/index.ts')
|
||||
let previousIndex = -1
|
||||
for (const code of quickEntryCodes) {
|
||||
const index = homeLogic.indexOf(code)
|
||||
assert.ok(index >= 0, `首页缺少入口 ${code}`)
|
||||
assert.ok(index > previousIndex, `首页入口 ${code} 顺序错误`)
|
||||
previousIndex = index
|
||||
}
|
||||
|
||||
const theme = read('miniapp/app.wxss')
|
||||
for (const token of [
|
||||
'--mini-night-start',
|
||||
'--mini-night-end',
|
||||
'--mini-accent-pink',
|
||||
'--mini-accent-coral',
|
||||
'--mini-card-bg',
|
||||
'--mini-card-radius',
|
||||
'--mini-shadow',
|
||||
]) {
|
||||
assert.ok(theme.includes(token), `缺少全局 Token ${token}`)
|
||||
}
|
||||
|
||||
console.log('Miniapp reference contracts passed')
|
||||
Reference in New Issue
Block a user