electron-vite / electron-vite-react

:electron: Electron + Vite + React + Sass boilerplate.
https://electron-vite.github.io
MIT License
1.92k stars 234 forks source link

Bug: running multiple playwright tests #139

Open IhsenBouallegue opened 1 year ago

IhsenBouallegue commented 1 year ago

I used the template and ran one test. It passes no problems, but running multiple ones fails with this error Error: electron.launch: Process failed to launch!. I prepared a simple repo which has the same test duplicated. Here is a test snippet:

import { test, expect, _electron as electron } from "@playwright/test";

test("homepage has title and links to intro page", async () => {
  const app = await electron.launch({ args: [".", "--no-sandbox"] });
  const page = await app.firstWindow();
  expect(await page.title()).toBe("Electron + Vite + React");
  await page.screenshot({ path: "e2e/screenshots/example.png" });
  await app.close();
});

Link to the GitHub repository with the repro https://github.com/IhsenBouallegue/electron-pw

Steps

Expected

All tests run and pass

Actual

A test is failing because of electron.launch()

IhsenBouallegue commented 1 year ago

Hey @lifeiscontent, I see you have added playwright support. Maybe you have some insight on how to fix this basic issue.

lifeiscontent commented 1 year ago

@IhsenBouallegue I wanted this to work differently, but the way it was merged you have to first build the project to run in order for the tests to work, which in my opinion seems like an unnecessary step because it should be using vite under the hood you should be able to run both the production version and the development version e2e but currently I'm not sure how to do that, this is what I was trying to explain to @caoxiemeihao but I don't think he understood the explanation and just merged the PR.

IhsenBouallegue commented 1 year ago

Hey @lifeiscontent after a lot of investigation and confusion. I found out that it is because of these 3 lines in the main process of Electron:

if (!app.requestSingleInstanceLock()) {
  app.quit()
  process.exit(0)
}

They prevent another instance from launching and as the E2E tests are parallel, it throws an error. I discovered this a bit too late. I completely migrated to Electron Forge and had to change the whole config, which led to me discovering this. I find it weird how no one tried to start more than one E2E test.

Possible solutions:

I will leave it up to you if you want to solve this or close the issue.

adnanlah commented 9 months ago

@IhsenBouallegue I wanted this to work differently, but the way it was merged you have to first build the project to run in order for the tests to work, which in my opinion seems like an unnecessary step because it should be using vite under the hood you should be able to run both the production version and the development version e2e but currently I'm not sure how to do that, this is what I was trying to explain to @caoxiemeihao but I don't think he understood the explanation and just merged the PR.

Did this problem get resolved or not yet?

lifeiscontent commented 9 months ago

@adnanlah not yet