Skip to content

Build your personal knowledge base with Trilium Notes

e2e(desktop): fix process leak

Elian Doranff917e93c98a
diff --git a/apps/desktop-e2e/playwright.config.ts b/apps/desktop-e2e/playwright.config.ts
index 5c909978eb..d1b7c40f29 100644
--- a/apps/desktop-e2e/playwright.config.ts
+++ b/apps/desktop-e2e/playwright.config.ts
@@ -1,18 +1,14 @@
import { defineConfig, devices } from '@playwright/test';
-import { nxE2EPreset } from '@nx/playwright/preset';
require('dotenv').config({
path: __dirname + "/" + ".env"
});
-// For CI, you may want to set BASE_URL to the deployed application.
-const port = process.env['TRILIUM_PORT'];
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
- ...nxE2EPreset(__filename, { testDir: './src' }),
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
diff --git a/apps/desktop-e2e/src/example.spec.ts b/apps/desktop-e2e/src/example.spec.ts
index 1e3e4181d0..e4f929b26c 100644
--- a/apps/desktop-e2e/src/example.spec.ts
+++ b/apps/desktop-e2e/src/example.spec.ts
@@ -1,13 +1,34 @@
-import { test, expect, _electron as electron } from '@playwright/test';
+import { test, expect, _electron as electron, type ElectronApplication } from '@playwright/test';
import { join } from 'path';
-test('Electron app should display correct title', async () => {
- // Launch Electron app
- const distPath = join(__dirname, '../../desktop/dist/main.cjs');
- const app = await electron.launch({ args: [ distPath ] });
+let app: ElectronApplication;
+
+test.beforeAll(async () => {
+ const distPath = join(__dirname, '../../desktop/dist/main.cjs');
+ app = await electron.launch({ args: [ distPath ] });
+});
+
+test.afterAll(async () => {
+ try {
+ const pid = app.process().pid;
+ await app.close();
+ if (pid) {
+ // Double-check process is dead
+ try {
+ process.kill(pid, 0); // throws if process doesn't exist
+ process.kill(pid, 'SIGKILL'); // force kill if still alive
+ } catch (e) {
+ // Process already dead
+ }
+ }
+ } catch (err) {
+ console.warn('Failed to close Electron app cleanly:', err);
+ }
+});
+
+test('Electron app should display correct title', async () => {
// Get the main window
const window = await app.firstWindow();
await expect(window).toHaveTitle("Setup");
- await app.close();
});