Skip to content

Commit 28e8d8b

Browse files
committed
feat: add playwright and example test
1 parent dfa51dd commit 28e8d8b

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ release
2828
package-lock.json
2929
pnpm-lock.yaml
3030
yarn.lock
31+
/test-results/
32+
/playwright-report/
33+
/playwright/.cache/

e2e/example.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test, expect, _electron as electron } from "@playwright/test";
2+
3+
test("homepage has title and links to intro page", async () => {
4+
const app = await electron.launch({ args: [".", "--no-sandbox"] });
5+
const page = await app.firstWindow();
6+
expect(await page.title()).toBe("Electron + Vite + React");
7+
await page.screenshot({ path: "e2e/screenshots/example.png" });
8+
});

e2e/screenshots/example.png

97.1 KB
Loading

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"scripts": {
1515
"dev": "vite",
1616
"build": "tsc && vite build && electron-builder",
17-
"preview": "vite preview"
17+
"preview": "vite preview",
18+
"e2e": "npx playwright test"
1819
},
1920
"devDependencies": {
21+
"@playwright/test": "^1.29.1",
2022
"@types/react": "^18.0.26",
2123
"@types/react-dom": "^18.0.10",
2224
"@vitejs/plugin-react": "^3.0.0",

playwright.config.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import type { PlaywrightTestConfig } from "@playwright/test";
2+
3+
/**
4+
* Read environment variables from file.
5+
* https://github.com/motdotla/dotenv
6+
*/
7+
// require('dotenv').config();
8+
9+
/**
10+
* See https://playwright.dev/docs/test-configuration.
11+
*/
12+
const config: PlaywrightTestConfig = {
13+
testDir: "./e2e",
14+
/* Maximum time one test can run for. */
15+
timeout: 30 * 1000,
16+
expect: {
17+
/**
18+
* Maximum time expect() should wait for the condition to be met.
19+
* For example in `await expect(locator).toHaveText();`
20+
*/
21+
timeout: 5000,
22+
},
23+
/* Run tests in files in parallel */
24+
fullyParallel: true,
25+
/* Fail the build on CI if you accidentally left test.only in the source code. */
26+
forbidOnly: !!process.env.CI,
27+
/* Retry on CI only */
28+
retries: process.env.CI ? 2 : 0,
29+
/* Opt out of parallel tests on CI. */
30+
workers: process.env.CI ? 1 : undefined,
31+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
32+
reporter: "html",
33+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
34+
use: {
35+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
36+
actionTimeout: 0,
37+
/* Base URL to use in actions like `await page.goto('/')`. */
38+
// baseURL: 'http://localhost:3000',
39+
40+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
41+
trace: "on-first-retry",
42+
},
43+
44+
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
45+
// outputDir: 'test-results/',
46+
47+
/* Run your local dev server before starting the tests */
48+
// webServer: {
49+
// command: 'npm run start',
50+
// port: 3000,
51+
// },
52+
};
53+
54+
export default config;

0 commit comments

Comments
 (0)