(name, fn)
| 19 | |
| 20 | // 测试辅助函数(支持同步和异步) |
| 21 | async function test(name, fn) { |
| 22 | testResults.total++; |
| 23 | try { |
| 24 | await fn(); |
| 25 | testResults.passed++; |
| 26 | console.log(`%c✓ ${name}`, "color: green;"); |
| 27 | return true; |
| 28 | } catch (error) { |
| 29 | testResults.failed++; |
| 30 | console.error(`%c✗ ${name}`, "color: red;", error); |
| 31 | return false; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | function testSync(name, fn) { |
| 36 | testResults.total++; |
no test coverage detected