mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
e2e(desktop): fix process leak
This commit is contained in:
parent
a7091779b7
commit
ff917e93c9
@ -1,18 +1,14 @@
|
|||||||
import { defineConfig, devices } from '@playwright/test';
|
import { defineConfig, devices } from '@playwright/test';
|
||||||
import { nxE2EPreset } from '@nx/playwright/preset';
|
|
||||||
|
|
||||||
require('dotenv').config({
|
require('dotenv').config({
|
||||||
path: __dirname + "/" + ".env"
|
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.
|
* See https://playwright.dev/docs/test-configuration.
|
||||||
*/
|
*/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
...nxE2EPreset(__filename, { testDir: './src' }),
|
|
||||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||||
use: {
|
use: {
|
||||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||||
|
@ -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';
|
import { join } from 'path';
|
||||||
|
|
||||||
test('Electron app should display correct title', async () => {
|
let app: ElectronApplication;
|
||||||
// Launch Electron app
|
|
||||||
const distPath = join(__dirname, '../../desktop/dist/main.cjs');
|
|
||||||
const app = await electron.launch({ args: [ distPath ] });
|
|
||||||
|
|
||||||
|
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
|
// Get the main window
|
||||||
const window = await app.firstWindow();
|
const window = await app.firstWindow();
|
||||||
await expect(window).toHaveTitle("Setup");
|
await expect(window).toHaveTitle("Setup");
|
||||||
await app.close();
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user