Unverified 提交 94281146 authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

fix read settings test (#613)

上级 d57c6e24
...@@ -291,16 +291,8 @@ describe("readSettings", () => { ...@@ -291,16 +291,8 @@ describe("readSettings", () => {
throw new Error("File read error"); throw new Error("File read error");
}); });
const consoleSpy = vi
.spyOn(console, "error")
.mockImplementation(() => {});
const result = readSettings(); const result = readSettings();
expect(consoleSpy).toHaveBeenCalledWith(
"Error reading settings:",
expect.any(Error),
);
expect(result).toEqual({ expect(result).toEqual({
selectedModel: { selectedModel: {
name: "auto", name: "auto",
...@@ -318,24 +310,14 @@ describe("readSettings", () => { ...@@ -318,24 +310,14 @@ describe("readSettings", () => {
enableAutoUpdate: true, enableAutoUpdate: true,
releaseChannel: "stable", releaseChannel: "stable",
}); });
consoleSpy.mockRestore();
}); });
it("should return default settings when JSON parsing fails", () => { it("should return default settings when JSON parsing fails", () => {
mockFs.existsSync.mockReturnValue(true); mockFs.existsSync.mockReturnValue(true);
mockFs.readFileSync.mockReturnValue("invalid json"); mockFs.readFileSync.mockReturnValue("invalid json");
const consoleSpy = vi
.spyOn(console, "error")
.mockImplementation(() => {});
const result = readSettings(); const result = readSettings();
expect(consoleSpy).toHaveBeenCalledWith(
"Error reading settings:",
expect.any(Error),
);
expect(result).toMatchObject({ expect(result).toMatchObject({
selectedModel: { selectedModel: {
name: "auto", name: "auto",
...@@ -343,8 +325,6 @@ describe("readSettings", () => { ...@@ -343,8 +325,6 @@ describe("readSettings", () => {
}, },
releaseChannel: "stable", releaseChannel: "stable",
}); });
consoleSpy.mockRestore();
}); });
it("should return default settings when schema validation fails", () => { it("should return default settings when schema validation fails", () => {
...@@ -359,16 +339,8 @@ describe("readSettings", () => { ...@@ -359,16 +339,8 @@ describe("readSettings", () => {
mockFs.existsSync.mockReturnValue(true); mockFs.existsSync.mockReturnValue(true);
mockFs.readFileSync.mockReturnValue(JSON.stringify(mockFileContent)); mockFs.readFileSync.mockReturnValue(JSON.stringify(mockFileContent));
const consoleSpy = vi
.spyOn(console, "error")
.mockImplementation(() => {});
const result = readSettings(); const result = readSettings();
expect(consoleSpy).toHaveBeenCalledWith(
"Error reading settings:",
expect.any(Error),
);
expect(result).toMatchObject({ expect(result).toMatchObject({
selectedModel: { selectedModel: {
name: "auto", name: "auto",
...@@ -376,8 +348,6 @@ describe("readSettings", () => { ...@@ -376,8 +348,6 @@ describe("readSettings", () => {
}, },
releaseChannel: "stable", releaseChannel: "stable",
}); });
consoleSpy.mockRestore();
}); });
it("should handle decryption errors gracefully", () => { it("should handle decryption errors gracefully", () => {
...@@ -394,16 +364,8 @@ describe("readSettings", () => { ...@@ -394,16 +364,8 @@ describe("readSettings", () => {
throw new Error("Decryption failed"); throw new Error("Decryption failed");
}); });
const consoleSpy = vi
.spyOn(console, "error")
.mockImplementation(() => {});
const result = readSettings(); const result = readSettings();
expect(consoleSpy).toHaveBeenCalledWith(
"Error reading settings:",
expect.any(Error),
);
expect(result).toMatchObject({ expect(result).toMatchObject({
selectedModel: { selectedModel: {
name: "auto", name: "auto",
...@@ -411,8 +373,6 @@ describe("readSettings", () => { ...@@ -411,8 +373,6 @@ describe("readSettings", () => {
}, },
releaseChannel: "stable", releaseChannel: "stable",
}); });
consoleSpy.mockRestore();
}); });
}); });
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论