Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xupea committed Jan 15, 2024
1 parent b5e282a commit 8621a8d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import os from "os";
import { readFileSync } from "jsonfile";

import { StatefulBrowserWindow } from "../src/index";
Expand All @@ -21,6 +22,8 @@ beforeEach(() => {
});

test("tries to read state file from the default location", () => {
const currentPlatform = os.platform();

(readFileSync as any).mockImplementation(() => {
return jest.fn();
});
Expand All @@ -34,12 +37,20 @@ test("tries to read state file from the default location", () => {
});

expect(readFileSync).toHaveBeenCalled();
expect(readFileSync).toHaveBeenCalledWith(
"/path/to/user/data/window-state.json",
);
if (currentPlatform === "win32") {
expect(readFileSync).toHaveBeenCalledWith(
"\\path\\to\\user\\data\\window-state.json",
);
} else {
expect(readFileSync).toHaveBeenCalledWith(
"/path/to/user/data/window-state.json",
);
}
});

test("tries to read state file from the configured source", () => {
const currentPlatform = os.platform();

(readFileSync as any).mockImplementation(() => {
return jest.fn();
});
Expand All @@ -55,7 +66,14 @@ test("tries to read state file from the configured source", () => {
});

expect(readFileSync).toHaveBeenCalled();
expect(readFileSync).toHaveBeenCalledWith("/path/custom/data/state.json");

if (currentPlatform === "win32") {
expect(readFileSync).toHaveBeenCalledWith(
"\\path\\custom\\data\\state.json",
);
} else {
expect(readFileSync).toHaveBeenCalledWith("/path/custom/data/state.json");
}
});

test("considers the state invalid if without bounds", () => {
Expand All @@ -69,8 +87,6 @@ test("considers the state invalid if without bounds", () => {
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
configFilePath: "/path/custom/data",
configFileName: "state.json",
});

expect(win.getBounds().width).not.toBe(100);
Expand Down

0 comments on commit 8621a8d

Please sign in to comment.