Skip to content

Commit 41e6a52

Browse files
authored
Update restart.test.js
1 parent 83e5ef4 commit 41e6a52

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

tests/e2e/restart.test.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
const { _electron: electron } = require('playwright');
22
const { test, expect } = require('@playwright/test');
33
const { execSync } = require('child_process');
4+
const os = require('os');
45

56
function isElectronRunning() {
67
try {
7-
// Check if Electron process is running on Windows
8-
const output = execSync('tasklist').toString();
9-
return output.includes('electron.exe');
8+
const platform = os.platform();
9+
10+
// Check if Electron process is running based on the operating system
11+
if (platform === 'win32') {
12+
const output = execSync('tasklist').toString();
13+
return output.includes('electron.exe');
14+
} else if (platform === 'darwin') {
15+
const output = execSync('ps -A').toString();
16+
return output.includes('Electron');
17+
} else if (platform === 'linux') {
18+
const output = execSync('pgrep electron').toString();
19+
return output.trim() !== '';
20+
}
1021
} catch (error) {
1122
console.error('Error checking for Electron process:', error);
1223
return false;
@@ -15,7 +26,13 @@ function isElectronRunning() {
1526

1627
function forceKillElectron() {
1728
try {
18-
execSync('taskkill /F /IM electron.exe');
29+
const platform = os.platform();
30+
31+
if (platform === 'win32') {
32+
execSync('taskkill /F /IM electron.exe');
33+
} else if (platform === 'darwin' || platform === 'linux') {
34+
execSync('pkill -f Electron');
35+
}
1936
console.log('Electron process forcefully terminated.');
2037
} catch (error) {
2138
console.error('Error forcefully terminating Electron process:', error);
@@ -36,7 +53,7 @@ test('Launch and close Electron app 10 times', async () => {
3653
// Wait for a moment to allow for process termination
3754
await new Promise((resolve) => setTimeout(resolve, 2000));
3855

39-
// Check if the Electron app is still running in the task manager
56+
// Check if the Electron app is still running
4057
let running = isElectronRunning();
4158
if (running) {
4259
console.warn(`Iteration ${i + 1}: Electron app is still running. Attempting to force kill.`);

0 commit comments

Comments
 (0)