From 6103f290c27ec7885e1a0bea5b43530151ff4a88 Mon Sep 17 00:00:00 2001 From: GeekRicardo Date: Tue, 18 Aug 2026 21:46:49 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E7=BA=AF=E5=87=BD=E6=95=B0=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=88node:test=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 导出 toNum/round2/isDeepSeekModel/isDeepSeekProvider/codexWindowName 供测试 - 覆盖字符串数字兼容、双路由判断、Codex 窗口秒数映射 --- lib/index.js | 2 +- package.json | 3 +++ test/parse.test.mjs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/parse.test.mjs diff --git a/lib/index.js b/lib/index.js index e12ee22..bc853f3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1084,4 +1084,4 @@ function apply(ctx) { ); } -export { apply, inject }; +export { apply, inject, toNum, round2, isDeepSeekModel, isDeepSeekProvider, codexWindowName }; diff --git a/package.json b/package.json index be972d1..6b7171e 100644 --- a/package.json +++ b/package.json @@ -45,5 +45,8 @@ "react": { "optional": true } + }, + "scripts": { + "test": "node --test test/" } } diff --git a/test/parse.test.mjs b/test/parse.test.mjs new file mode 100644 index 0000000..61d14b1 --- /dev/null +++ b/test/parse.test.mjs @@ -0,0 +1,33 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { toNum, round2, isDeepSeekModel, isDeepSeekProvider, codexWindowName } from "../lib/index.js"; + +test("toNum 兼容字符串与数字", () => { + assert.equal(toNum("69"), 69); + assert.equal(toNum(3.14), 3.14); + assert.equal(toNum("abc"), null); + assert.equal(toNum(null), null); +}); + +test("round2 保留两位小数", () => { + assert.equal(round2(1.234), 1.23); + assert.equal(round2(0.005), 0.01); +}); + +test("isDeepSeekModel 前缀匹配", () => { + assert.equal(isDeepSeekModel("deepseek-v4-flash"), true); + assert.equal(isDeepSeekModel("kimi-k3"), false); +}); + +test("isDeepSeekProvider 兼容两条官方路由", () => { + assert.equal(isDeepSeekProvider("deepseek"), true); + assert.equal(isDeepSeekProvider("deepseek-official"), true); + assert.equal(isDeepSeekProvider("kimi-coding"), false); +}); + +test("codexWindowName 窗口秒数映射", () => { + assert.deepEqual(codexWindowName(18000), { label: "5小时", key: "5h" }); + assert.deepEqual(codexWindowName(604800), { label: "7天", key: "7d" }); + assert.deepEqual(codexWindowName(2592000), { label: "30天", key: "30d" }); + assert.deepEqual(codexWindowName(3600), { label: "1小时", key: "1h" }); +});