文件
fenleixinxi/uniapp/tests/harness.mjs
linda 376a7ed793 feat(uniapp): 小程序端(用户端 uni-app)源码入库到 uniapp/ 目录
需求:小程序端代码要同时同步到服务器与 git 远程仓库,此前前端仅存在于本地目录(无 remote,从未推送),
服务器与 gitcode 上只有后端。现并入本仓库,复用现有「push 即部署」链路,一次推送双端落地。

- 新增 uniapp/:小程序端源码全量快照(150 文件 / 1.2M)
  pages(13 页面) · components(fc-navbar/fc-tabbar/fc-post-card/fc-empty) ·
  common(api·utils·mock·assets·store·config) · static(74 图标 + 3 轮播插画 + LOGO) ·
  docs(01-04 交付文档) · tests(零依赖全链路用例) · tools(图标/主题/轮播配图生成脚本)
- 明确排除:AGENTS.md(含后台密码、服务器 root 密码、小程序 AppSecret,切勿入库)、
  unpackage/(构建产物,由 uniapp/.gitignore 忽略)、node_modules、.DS_Store、*.log
- .gitignore 新增 /uniapp/AGENTS.md 兜底(与根 /AGENTS.md、/fluniapp/ 同一约定)
- README.md 增补「本项目结构 + 部署链路」章节,说明 uniapp/ 为源码快照、
  小程序真正上线仍需微信开发者工具 cli upload

说明:本次为源码快照,未携带前端本地仓库历史——其历史提交中含 AGENTS.md 凭据,
若做 subtree 合并会把密码永久写入本仓库历史,故采用快照方式。
2026-10-17 14:19:03 +08:00

126 行
3.4 KiB
JavaScript

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

/**
* 极简测试框架(零依赖,兼容 Node 18+)
* 提供 describe / it / expect 与断言方法,并汇总测试报告。
*/
let suites = []
let current = null
export function describe(name, fn) {
current = { name, cases: [] }
suites.push(current)
fn()
current = null
}
export function it(name, fn) {
if (!current) throw new Error('it() 必须写在 describe() 内')
current.cases.push({ name, fn })
}
export function expect(actual) {
return {
toBe(expected) {
assert(Object.is(actual, expected), `期望 ${fmt(expected)},实际 ${fmt(actual)}`)
},
toEqual(expected) {
const a = JSON.stringify(actual)
const b = JSON.stringify(expected)
assert(a === b, `期望 ${b},实际 ${a}`)
},
toBeTruthy() {
assert(!!actual, `期望为真值,实际 ${fmt(actual)}`)
},
toBeFalsy() {
assert(!actual, `期望为假值,实际 ${fmt(actual)}`)
},
toBeDefined() {
assert(actual !== undefined && actual !== null, `期望有值,实际 ${fmt(actual)}`)
},
toBeGreaterThan(n) {
assert(typeof actual === 'number' && actual > n, `期望 > ${n},实际 ${fmt(actual)}`)
},
toBeLessThanOrEqual(n) {
assert(typeof actual === 'number' && actual <= n, `期望 <= ${n},实际 ${fmt(actual)}`)
},
toContain(s) {
assert(String(actual).includes(s), `期望包含 "${s}",实际 ${fmt(actual)}`)
},
toHaveLength(n) {
assert(actual && actual.length === n, `期望长度 ${n},实际 ${actual && actual.length}`)
},
toBeArray() {
assert(Array.isArray(actual), `期望为数组,实际 ${fmt(actual)}`)
},
toMatch(re) {
assert(re.test(String(actual)), `期望匹配 ${re},实际 ${fmt(actual)}`)
},
}
}
/** 断言异步调用必须抛错(用于校验业务规则拦截) */
export async function expectReject(fn, msgPart) {
try {
await fn()
} catch (e) {
if (msgPart) {
assert(String(e.message).includes(msgPart), `期望错误信息包含 "${msgPart}",实际 "${e.message}"`)
}
return e
}
throw new Error('期望抛出异常,但调用成功返回')
}
function assert(cond, message) {
if (!cond) throw new Error(message)
}
function fmt(v) {
if (typeof v === 'string') return `"${v}"`
try {
return typeof v === 'object' ? JSON.stringify(v) : String(v)
} catch (e) {
return String(v)
}
}
/** 执行全部用例并输出报告 */
export async function run() {
let passed = 0
let failed = 0
const failures = []
console.log('\n=========== 全链路接口测试报告 ===========\n')
for (const suite of suites) {
console.log(`📦 ${suite.name}`)
for (const c of suite.cases) {
try {
await c.fn()
passed++
console.log(` ✅ ${c.name}`)
} catch (e) {
failed++
failures.push({ suite: suite.name, name: c.name, error: e.message })
console.log(` ❌ ${c.name}\n → ${e.message}`)
}
}
console.log('')
}
console.log('------------------------------------------')
console.log(`用例总数: ${passed + failed} 通过: ${passed} 失败: ${failed}`)
console.log('------------------------------------------\n')
if (failures.length) {
console.log('失败明细:')
failures.forEach((f, i) => console.log(` ${i + 1}. [${f.suite}] ${f.name} → ${f.error}`))
console.log('')
process.exitCode = 1
} else {
console.log('🎉 全部用例通过,前后端接口契约与业务规则校验一致。\n')
}
// 重置,便于同一进程重复运行
suites = []
return { passed, failed }
}