Files
zszq-trs/YLErpWeb/fe-tests/_shim_run.js
T
hjhan 7f64d48699 test(fe): 接入 SwapCalc 纯计算模块 + 前端精度回归测试
- incomeSwapTrade.js / swapTradeEdit.js 改为调用 SwapCalc.*(缩放/取整/全价推导)

- 新增 fe-tests 守卫:4 个历史 bug 回归 + 8 场景对齐 C# FrontendCalcReference 金标准 + otcformat.js 精度配置守卫

- 新增 .git/hooks/pre-commit 自动运行前端守卫(失败阻断提交)
2026-07-07 12:30:19 +08:00

51 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* _shim_run.js — 不依赖 jest 的轻量测试运行器(仅用于在沙箱内验证测试文件逻辑)。
* 本机请用 jestcd YLErpWeb/fe-tests && npm i && npm test
*/
let passed = 0;
let failed = 0;
const failures = [];
function fmt(v) {
return typeof v === 'object' ? JSON.stringify(v) : String(v);
}
function makeExpect(actual) {
return {
toBe(expected) {
if (Object.is(actual, expected)) { passed++; }
else { failed++; failures.push('toBe: expected ' + fmt(expected) + ' got ' + fmt(actual)); }
},
toBeDefined() {
if (actual !== undefined && actual !== null) { passed++; }
else { failed++; failures.push('toBeDefined: got ' + fmt(actual)); }
},
toBeLessThanOrEqual(n) {
if (actual <= n) { passed++; }
else { failed++; failures.push('toBeLessThanOrEqual: ' + fmt(actual) + ' <= ' + n + ' failed'); }
},
toBeGreaterThanOrEqual(n) {
if (actual >= n) { passed++; }
else { failed++; failures.push('toBeGreaterThanOrEqual: ' + fmt(actual) + ' >= ' + n + ' failed'); }
},
};
}
global.expect = (actual) => makeExpect(actual);
global.describe = (name, fn) => { fn(); };
global.test = (name, fn) => {
try { fn(); }
catch (e) { failed++; failures.push(name + ': ' + e.message); }
};
global.it = global.test;
require('./swapCalc.test.js');
require('./otcformat.test.js');
require('./parity.test.js');
console.log('\n==== RUNNER (jest-shim) ====');
console.log('PASS=' + passed + ' FAIL=' + failed);
failures.forEach((f) => console.log(' ✗ ' + f));
console.log(failures.length ? 'RESULT: RED' : 'RESULT: GREEN');
process.exit(failed > 0 ? 1 : 0);