-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added tests for createWindow and unpack, moved jest.setup.ts to…
… the root, installed jest-mock-extended (#51) ## Changes * Added tests for `unpack` and `create-window` * Added `jest-mock-extended` to improve type safety * Added missing `archive.mjs` that was lost in one other PR and is needed for the future build
- Loading branch information
1 parent
382b8ce
commit 760f3ee
Showing
9 changed files
with
118 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import fsp from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
import Seven from "node-7z"; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const my7z = path.join(__dirname, "..", "resources", "7zip", "win", "7za.exe"); | ||
|
||
const sourceFolder = path.join(__dirname, "..", "resources", "python-embedded"); | ||
const outputArchive = path.join(__dirname, "..", "resources", "python-embedded.7z"); | ||
|
||
const files = await fsp.readdir(sourceFolder); | ||
|
||
const archive = Seven.add( | ||
outputArchive, | ||
files.map(file => path.join(sourceFolder, file)), | ||
{ | ||
$bin: my7z, | ||
recursive: true, | ||
} | ||
); | ||
|
||
archive.on("end", () => { | ||
console.log("Compression finished"); | ||
}); | ||
|
||
archive.on("error", error => { | ||
console.error("Compression error:", error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { BrowserWindow } from "electron"; | ||
import Store from "electron-store"; | ||
import type { DeepMockProxy } from "jest-mock-extended"; | ||
import { mockDeep } from "jest-mock-extended"; | ||
|
||
import { createWindow } from "@/utils/create-window"; | ||
|
||
jest.mock("electron", () => ({ | ||
BrowserWindow: jest.fn().mockImplementation(() => ({ | ||
webContents: { | ||
setWindowOpenHandler: jest.fn(), | ||
}, | ||
on: jest.fn(), | ||
isMinimized: jest.fn(), | ||
isMaximized: jest.fn(), | ||
})), | ||
shell: { | ||
openExternal: jest.fn(), | ||
}, | ||
screen: { | ||
getAllDisplays: jest.fn().mockReturnValue([ | ||
{ | ||
bounds: { x: 0, y: 0, width: 1024, height: 768 }, | ||
}, | ||
]), | ||
getPrimaryDisplay: jest.fn().mockReturnValue({ | ||
bounds: { x: 0, y: 0, width: 1920, height: 1080 }, | ||
workArea: { x: 0, y: 0, width: 1920, height: 1040 }, | ||
}), | ||
}, | ||
})); | ||
|
||
jest.mock("electron-store", () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})); | ||
|
||
describe("createWindow", () => { | ||
const defaultState = { x: 100, y: 100, width: 1024, height: 768 }; | ||
let storeMock: DeepMockProxy<Store>; | ||
|
||
beforeEach(() => { | ||
storeMock = mockDeep<Store>(); | ||
(Store as unknown as jest.Mock).mockImplementation(() => storeMock); | ||
storeMock.get.mockReturnValue(defaultState); | ||
}); | ||
|
||
it("should create a BrowserWindow with default size when no state is saved", async () => { | ||
await createWindow("testWindow", {}); | ||
|
||
expect(BrowserWindow).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
webPreferences: expect.objectContaining({ | ||
contextIsolation: true, | ||
nodeIntegration: false, | ||
}), | ||
}) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.