mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
test: 修正 mock 的滥用情况
This commit is contained in:
@@ -1,22 +1,12 @@
|
||||
import { mock, describe, expect, test, beforeEach } from "bun:test";
|
||||
|
||||
// Mock heavy deps before importing memoize
|
||||
// Mock log.ts to cut the bootstrap/state dependency chain
|
||||
mock.module("src/utils/log.ts", () => ({
|
||||
logError: () => {},
|
||||
logToFile: () => {},
|
||||
getLogDisplayTitle: () => "",
|
||||
logEvent: () => {},
|
||||
}));
|
||||
mock.module("src/utils/slowOperations.ts", () => ({
|
||||
jsonStringify: JSON.stringify,
|
||||
jsonParse: JSON.parse,
|
||||
slowLogging: { enabled: false },
|
||||
clone: (v: any) => structuredClone(v),
|
||||
cloneDeep: (v: any) => structuredClone(v),
|
||||
callerFrame: () => "",
|
||||
SLOW_OPERATION_THRESHOLD_MS: 100,
|
||||
writeFileSync_DEPRECATED: () => {},
|
||||
}));
|
||||
|
||||
const { memoizeWithTTL, memoizeWithTTLAsync, memoizeWithLRU } = await import(
|
||||
"../memoize"
|
||||
|
||||
@@ -1,27 +1,4 @@
|
||||
import { mock, describe, expect, test } from "bun:test";
|
||||
|
||||
// Mock ink/stringWidth to avoid heavy Ink import chain
|
||||
mock.module("src/ink/stringWidth.js", () => ({
|
||||
stringWidth: (str: string) => {
|
||||
// Simplified width calculation for test purposes
|
||||
let width = 0;
|
||||
for (const char of str) {
|
||||
const code = char.codePointAt(0)!;
|
||||
// CJK Unified Ideographs and common full-width ranges
|
||||
if (
|
||||
(code >= 0x4e00 && code <= 0x9fff) || // CJK
|
||||
(code >= 0x3000 && code <= 0x303f) || // CJK Symbols
|
||||
(code >= 0xff01 && code <= 0xff60) || // Fullwidth Forms
|
||||
(code >= 0xf900 && code <= 0xfaff) // CJK Compatibility
|
||||
) {
|
||||
width += 2;
|
||||
} else if (code > 0) {
|
||||
width += 1;
|
||||
}
|
||||
}
|
||||
return width;
|
||||
},
|
||||
}));
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
const sliceAnsi = (await import("../sliceAnsi")).default;
|
||||
|
||||
|
||||
@@ -30,18 +30,6 @@ mock.module("src/services/tokenEstimation.ts", () => ({
|
||||
countTokensViaHaikuFallback: async () => 0,
|
||||
}));
|
||||
|
||||
// Mock slowOperations to avoid bun:bundle import
|
||||
mock.module("src/utils/slowOperations.ts", () => ({
|
||||
jsonStringify: JSON.stringify,
|
||||
jsonParse: JSON.parse,
|
||||
slowLogging: { enabled: false },
|
||||
clone: (v: any) => structuredClone(v),
|
||||
cloneDeep: (v: any) => structuredClone(v),
|
||||
callerFrame: () => "",
|
||||
SLOW_OPERATION_THRESHOLD_MS: 100,
|
||||
writeFileSync_DEPRECATED: () => {},
|
||||
}));
|
||||
|
||||
const {
|
||||
getTokenCountFromUsage,
|
||||
getTokenUsage,
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
import { mock, describe, expect, test } from "bun:test";
|
||||
|
||||
mock.module("figures", () => ({
|
||||
default: {
|
||||
lineUpDownRight: "├",
|
||||
lineUpRight: "└",
|
||||
lineVertical: "│",
|
||||
},
|
||||
}));
|
||||
|
||||
mock.module("src/ink.js", () => ({
|
||||
color: (colorKey: string, themeName: string) => (text: string) => text,
|
||||
}));
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
const { treeify } = await import("../treeify");
|
||||
|
||||
|
||||
@@ -1,26 +1,5 @@
|
||||
import { describe, expect, mock, test } from "bun:test";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
mock.module("src/ink/stringWidth.js", () => ({
|
||||
stringWidth: (str: string) => {
|
||||
let width = 0;
|
||||
for (const char of str) {
|
||||
const code = char.codePointAt(0)!;
|
||||
if (
|
||||
(code >= 0x4e00 && code <= 0x9fff) ||
|
||||
(code >= 0x3000 && code <= 0x303f) ||
|
||||
(code >= 0xff01 && code <= 0xff60) ||
|
||||
(code >= 0xf900 && code <= 0xfaff)
|
||||
) {
|
||||
width += 2;
|
||||
} else if (code >= 0x1f300 && code <= 0x1faff) {
|
||||
width += 2;
|
||||
} else if (code > 0) {
|
||||
width += 1;
|
||||
}
|
||||
}
|
||||
return width;
|
||||
},
|
||||
}));
|
||||
import {
|
||||
truncatePathMiddle,
|
||||
truncateToWidth,
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
import { mock, describe, expect, test, beforeEach, afterEach } from "bun:test";
|
||||
|
||||
// Mock slowOperations to cut bootstrap/state dependency chain
|
||||
// (figures.js → env.js → fsOperations.js → slowOperations.js → bootstrap/state.js)
|
||||
mock.module("src/utils/slowOperations.ts", () => ({
|
||||
jsonStringify: JSON.stringify,
|
||||
jsonParse: JSON.parse,
|
||||
slowLogging: { enabled: false },
|
||||
clone: (v: any) => structuredClone(v),
|
||||
cloneDeep: (v: any) => structuredClone(v),
|
||||
callerFrame: () => "",
|
||||
SLOW_OPERATION_THRESHOLD_MS: 100,
|
||||
writeFileSync_DEPRECATED: () => {},
|
||||
}));
|
||||
mock.module("src/utils/log.ts", () => ({
|
||||
logError: () => {},
|
||||
logToFile: () => {},
|
||||
|
||||
@@ -18,18 +18,6 @@ mock.module("src/utils/log.ts", () => ({
|
||||
_resetErrorLogForTesting: () => {},
|
||||
}));
|
||||
|
||||
// Mock slowOperations to avoid bun:bundle
|
||||
mock.module("src/utils/slowOperations.ts", () => ({
|
||||
jsonStringify: JSON.stringify,
|
||||
jsonParse: JSON.parse,
|
||||
slowLogging: { enabled: false },
|
||||
clone: (v: any) => structuredClone(v),
|
||||
cloneDeep: (v: any) => structuredClone(v),
|
||||
callerFrame: () => "",
|
||||
SLOW_OPERATION_THRESHOLD_MS: 100,
|
||||
writeFileSync_DEPRECATED: () => {},
|
||||
}));
|
||||
|
||||
const {
|
||||
getDenyRuleForTool,
|
||||
getAskRuleForTool,
|
||||
|
||||
Reference in New Issue
Block a user