Skip to content

Commit

Permalink
fix(e2e): remove devtools (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsagetlethias committed Apr 26, 2022
1 parent 9ccb99e commit 127a9ca
Show file tree
Hide file tree
Showing 8 changed files with 787 additions and 575 deletions.
8 changes: 3 additions & 5 deletions .releaserc.js
Expand Up @@ -21,14 +21,12 @@ const branches = [
];
const isPreRealse = process.env.GITHUB_REF
? branches.some(
(branche) =>
branche.prerelease &&
`refs/heads/${branche.name}` === process.env.GITHUB_REF
(branch) =>
branch.prerelease &&
`refs/heads/${branch.name}` === process.env.GITHUB_REF
)
: true;

console.log({ isPreRealse });

/** @type {import("semantic-release").Options["plugins"]} */
const plugins = [
"@semantic-release/commit-analyzer",
Expand Down
7 changes: 5 additions & 2 deletions TODO.md
Expand Up @@ -21,6 +21,9 @@
- [ ] send bug
- [ ] check for update
- [ ] Isomorphic electron mock ?
- [ ] Use preload + sandbox
- [ ] move common electron + Archifiltre code to 3rd party package
- [ ] migrate from jotai to zustand 4

## Doc
- [ ] Tech doc tool (docusaurus? next? jekyll?) + github pages
Expand All @@ -30,8 +33,8 @@

## Recette
- [x] Issue template
- [ ] beta branch usage
- [ ] ownership
- [x] beta branch usage
- [x] ownership

## Infra / Archi
- [ ] change build system to vite-electron-builder (https://github.com/cawa-93/vite-electron-builder)
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -17,7 +17,7 @@
"dist:linux": "electron-builder --linux AppImage",
"start": "electron dist/main/main.js",
"start:mac": "open -n 'electron/dist/mac/mac/Mails par Archifiltre.app'",
"lint": "eslint src/",
"lint": "eslint src/ && stylelint src/",
"lint:fix": "eslint --fix src/ && stylelint --fix src/",
"lint:test": "eslint -c tests/.eslintrc.json 'tests/**/*.ts*'",
"lint:fix-test": "eslint --fix -c tests/.eslintrc.json 'tests/**/*.ts*'",
Expand Down Expand Up @@ -154,7 +154,7 @@
"axios": "^0.26.1",
"cross-env": "^7.0.3",
"dotenv": "^16.0.0",
"electron": "^17.0.0",
"electron": "^18.1.0",
"electron-builder": "^22.14.5",
"electron-notarize": "^1.1.1",
"electron-webpack": "^2.8.2",
Expand All @@ -163,7 +163,7 @@
"eslint-plugin-playwright": "^0.6.0",
"eslint-plugin-typescript-sort-keys": "^2.1.0",
"eslint-plugin-unused-imports": "^1",
"glob": "^7.2.0",
"glob": "^8.0.1",
"husky": "^7.0.4",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.4.7",
Expand Down Expand Up @@ -212,4 +212,4 @@
"xlsx": "^0.18.0",
"zustand": "^3.7.0"
}
}
}
2 changes: 0 additions & 2 deletions scripts/electron_chromiumVersion.js
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
const { app, BrowserView } = require("electron");

app.whenReady()
Expand Down
5 changes: 4 additions & 1 deletion src/main/index.ts
Expand Up @@ -26,6 +26,9 @@ module.hot?.accept();
const setupSentryIntegrations = setupSentry();

Menu.setApplicationMenu(null);
if (!IS_PACKAGED()) {
app.commandLine.appendSwitch("disable-features", "OutOfBlinkCors");
}

/**
* Stub index.html url for main window. As E2E is not packaged, it needs a direct access to generated file. In dev mode, calling localhost let the dev server handling the file.
Expand Down Expand Up @@ -62,7 +65,7 @@ const createMainWindow = async () => {
},
});

if (!IS_PACKAGED()) mainWindow.webContents.openDevTools();
if (!IS_PACKAGED() && !IS_E2E) mainWindow.webContents.openDevTools();

await mainWindow.loadURL(INDEX_URL);
};
Expand Down
42 changes: 5 additions & 37 deletions tests/e2e/app.spec.ts
@@ -1,48 +1,16 @@
import type { ElectronApplication, Page } from "@playwright/test";
import { _electron as electron, expect, test } from "@playwright/test";
import path from "path";
import { expect, test } from "@playwright/test";

import { closeApp, startApp } from "./utils/test";

test.describe("App e2e", () => {
let electronApp: ElectronApplication, win: Page;
test.beforeEach(async () => {
const main = path.resolve(
__dirname,
"..",
"..",
"dist",
"main",
"main.js"
);
electronApp = await electron.launch({
args: [
// "--disable_splash_screen",
// "--disable-extensions",
// "--disable-dev-shm-usage",
// "--no-sandbox",
// "--disable-gpu",
// "--headless",
// "--disable-software-rasterizer",
// "--disable-setuid-sandbox",
main,
],
env: {
DISPLAY: ":0", //TODO: input as env var
E2E: "true",
NODE_ENV: "test-e2e",
},
timeout: 120000,
});
await electronApp.evaluate(({ app }) => {
return app.getAppPath();
});

win = await electronApp.firstWindow();
win.on("console", console.log);
await win.waitForLoadState();
[electronApp, win] = await startApp();
});

test.afterEach(async () => {
await electronApp.close();
await closeApp(electronApp);
});

test("should render the application", async () => {
Expand Down
75 changes: 75 additions & 0 deletions tests/e2e/utils/test.ts
@@ -0,0 +1,75 @@
import type { ElectronApplication, Locator, Page } from "@playwright/test";
import { _electron as electron } from "@playwright/test";
import path from "path";

let electronApp: ElectronApplication, win: Page;
/**
* Starts the electron application
*/
export const startApp = async (): Promise<
[app: ElectronApplication, win: Page]
> => {
const main = path.resolve(
__dirname,
"..",
"..",
"..",
"dist",
"main",
"main.js"
);
electronApp = await electron.launch({
args: [main],
env: {
DISPLAY: ":0",
E2E: "true",
NODE_ENV: "test-e2e",
},
timeout: 120000,
});
await electronApp.evaluate(({ app }) => {
return app.getAppPath();
});

win = await electronApp.firstWindow();
// eslint-disable-next-line no-console
win.on("console", console.log);
await win.waitForLoadState();

return [electronApp, win];
};

export const closeApp = async (app = electronApp): Promise<void> => {
await app.close();
};

/**
* Wait for the given time. (like sleep)
*/
export const wait = async (time: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, time));

/**
* Types the text as keyboard input. Handles unicode characters for non text keys.
*/
export const typeText = async (text: string, w = win): Promise<void> => {
const letters = text.split("");
for (const letter of letters) {
await w.keyboard.type(letter);
}
};

/**
* Clicks over the element locator
*/
export const clickOverElement = async (
locator: Locator,
w = win
): Promise<void> => {
const box = await locator.boundingBox();
if (!box) {
return;
}
const { x, y } = box;
await w.mouse.click(x, y);
};

0 comments on commit 127a9ca

Please sign in to comment.