From c9d0d8a2d5d97dd14045489e4b82923589a6c093 Mon Sep 17 00:00:00 2001 From: Javier Guzman <906599+javierguzman@users.noreply.github.com> Date: Wed, 12 Jul 2023 15:58:09 +0200 Subject: [PATCH] build: forge cannot make a build without signing. Also playwright first working test --- e2e_tests/example.spec.ts | 8 ------- e2e_tests/flashing.spec.ts | 37 ++++++++++++++++++++++++++++++ forge.config.ts | 47 +++++++++++++++++++++----------------- package.json | 5 +++- yarn.lock | 9 +++++++- 5 files changed, 75 insertions(+), 31 deletions(-) delete mode 100644 e2e_tests/example.spec.ts create mode 100644 e2e_tests/flashing.spec.ts diff --git a/e2e_tests/example.spec.ts b/e2e_tests/example.spec.ts deleted file mode 100644 index 4b5404c1c..000000000 --- a/e2e_tests/example.spec.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { _electron as electron, test } from "@playwright/test"; - -test("save screenshot", async () => { - const electronApp = await electron.launch({ args: [".webpack/main/index.js"], timeout: 300000 }); - const window = await electronApp.firstWindow(); - await window.screenshot({ path: "landing.png" }); - await electronApp.close(); -}); diff --git a/e2e_tests/flashing.spec.ts b/e2e_tests/flashing.spec.ts new file mode 100644 index 000000000..5e4ff3571 --- /dev/null +++ b/e2e_tests/flashing.spec.ts @@ -0,0 +1,37 @@ +import { _electron as electron, ElectronApplication, test, Page } from "@playwright/test"; +import { findLatestBuild, parseElectronApp, clickMenuItemById } from "electron-playwright-helpers"; + +let electronApp: ElectronApplication; +let page: Page; + +test.beforeAll(async () => { + const latestBuild = findLatestBuild(); + const appInfo = parseElectronApp(latestBuild); + + electronApp = await electron.launch({ + args: [appInfo.main], + executablePath: appInfo.executable, + }); + + electronApp.on("window", async initialPage => { + const filename = initialPage.url()?.split("/").pop(); + console.log(`Window opened: ${filename}`); + + initialPage.on("pageerror", error => { + console.error(error); + }); + + initialPage.on("console", msg => { + console.log(msg.text()); + }); + }); +}); + +test("renders landing page", async () => { + page = await electronApp.firstWindow(); + await page.screenshot({ path: "landing.png" }); +}); + +test.afterAll(async () => { + await electronApp.close(); +}); diff --git a/forge.config.ts b/forge.config.ts index 570315704..4ebbc4e5e 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -1,4 +1,4 @@ -import type { ForgeConfig } from "@electron-forge/shared-types"; +import type { ForgeConfig, ForgePackagerOptions } from "@electron-forge/shared-types"; import { MakerSquirrel } from "@electron-forge/maker-squirrel"; import { WebpackPlugin } from "@electron-forge/plugin-webpack"; import fs from "fs"; @@ -8,27 +8,32 @@ import { spawnSync } from "child_process"; import rendererConfig from "./webpack.renderer.config"; import mainConfig from "./webpack.main.config"; +const packagerConfig: ForgePackagerOptions = { + appBundleId: "com.dygmalab.bazecor", + darwinDarkModeSupport: true, + icon: "./build/logo.png", + name: "Bazecor", + extraResource: ["NEWS.md"], + appCopyright: "Copyright © 2018, 2023 Keyboardio Inc.; Copyright © 2018, 2023 DygmaLab SE; distributed under the GPLv3", +}; + +if (process.env.NODE_ENV !== "development") { + packagerConfig.osxNotarize = { + tool: "notarytool", + appleId: process.env.APPLE_ID || "", + appleIdPassword: process.env.APPLE_ID_PASSWORD || "", + teamId: process.env.APPLE_TEAM_ID || "", + }; + packagerConfig.osxSign = { + optionsForFile: () => ({ + entitlements: "./build/entitlements.plist", + hardenedRuntime: true, + }), + }; +} + const config: ForgeConfig = { - packagerConfig: { - appBundleId: "com.dygmalab.bazecor", - darwinDarkModeSupport: true, - icon: "./build/logo.png", - name: "Bazecor", - extraResource: ["NEWS.md"], - appCopyright: "Copyright © 2018, 2023 Keyboardio Inc.; Copyright © 2018, 2023 DygmaLab SE; distributed under the GPLv3", - osxNotarize: { - tool: "notarytool", - appleId: process.env.APPLE_ID || "", - appleIdPassword: process.env.APPLE_ID_PASSWORD || "", - teamId: process.env.APPLE_TEAM_ID || "", - }, - osxSign: { - optionsForFile: () => ({ - entitlements: "./build/entitlements.plist", - hardenedRuntime: true, - }), - }, - }, + packagerConfig, rebuildConfig: {}, makers: [ new MakerSquirrel({ diff --git a/package.json b/package.json index da0c4ff9a..51598e003 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "main": ".webpack/main", "scripts": { "clean": "rm -rf dist && rm -rf out && rm -rf node_modules", - "start": "electron-forge start", + "start": "NODE_ENV=development electron-forge start", + "make-dev": "NODE_ENV=development electron-forge make", "package": "electron-forge package", "make": "electron-forge make", "make-win": "electron-forge make --platform win32", @@ -21,6 +22,7 @@ "lint": "eslint --ext .ts,.tsx,.js,.jsx .", "prettier": "prettier --write \"./**/*.{js,json,css,scss,md}\"", "test": "vitest run src/renderer/tests src/main/tests", + "e2e": "yarn playwright test", "commit": "cz", "prepare": "husky install" }, @@ -76,6 +78,7 @@ "electron": "^25.2.0", "electron-devtools-installer": "^3.2.0", "electron-forge-maker-appimage": "^24.5.2", + "electron-playwright-helpers": "^1.6.0", "eslint": "^8.0.1", "eslint-config-airbnb": "^19.0.4", "eslint-config-airbnb-typescript": "^17.0.0", diff --git a/yarn.lock b/yarn.lock index cac503d0e..dd65558ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1358,7 +1358,7 @@ xterm-addon-fit "^0.5.0" xterm-addon-search "^0.8.0" -"@electron/asar@^3.2.1": +"@electron/asar@^3.2.1", "@electron/asar@^3.2.4": version "3.2.4" resolved "https://registry.yarnpkg.com/@electron/asar/-/asar-3.2.4.tgz#7e8635a3c4f6d8b3f8ae6efaf5ecb9fbf3bd9864" integrity sha512-lykfY3TJRRWFeTxccEKdf1I6BLl2Plw81H0bbp4Fc5iEc67foDCa5pjJQULVgo0wF+Dli75f3xVcdb/67FFZ/g== @@ -5070,6 +5070,13 @@ electron-packager@^17.1.1: semver "^7.1.3" yargs-parser "^21.1.1" +electron-playwright-helpers@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/electron-playwright-helpers/-/electron-playwright-helpers-1.6.0.tgz#74d17d3e1a4f738afc51e93c0912d2e1e16d496a" + integrity sha512-0csyp77xRAi8m5g1ApcYdTMJ8n0+Geyb4huyMAsIYTInk4wsuUTHmIy2gMfgF3I130ogfpX6ZfEGeffS93FaUA== + dependencies: + "@electron/asar" "^3.2.4" + electron-publish@24.5.0: version "24.5.0" resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-24.5.0.tgz#492a4d7caa232e88ee3c18f5c3b4dc637e5e1b3a"