import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { join } from 'node:path' const root = join(process.cwd(), 'miniapp', 'assets', 'tabbar') const icons = { home: '爱心小屋', discover: '双人缘分', message: '爱心对话', activity: '公益日历', mine: '个人守护', } for (const [name, title] of Object.entries(icons)) { const normal = readFileSync(join(root, 'svg', `${name}.svg`), 'utf8') const active = readFileSync(join(root, 'svg', `${name}-active.svg`), 'utf8') assert.match(normal, new RegExp(`${title}`), `${name} 缺少主题化标题`) assert.match(normal, /#999999/i, `${name} 默认态颜色错误`) assert.match(active, /#E96B6B/i, `${name} 选中态颜色错误`) for (const suffix of ['', '_2x', '_3x']) { const expectedSize = suffix === '' ? 81 : suffix === '_2x' ? 162 : 243 for (const state of ['', '-active']) { const png = readFileSync(join(root, `${name}${state}${suffix}.png`)) assert.equal(png.readUInt32BE(16), expectedSize) assert.equal(png.readUInt32BE(20), expectedSize) assert.equal(png[25], 6, `${name}${state}${suffix} 必须为透明 RGBA PNG`) } } } console.log('Tabbar icon contracts passed')