diff --git a/e2e/example.spec.ts b/e2e/example.spec.ts deleted file mode 100644 index 59ff80f..0000000 --- a/e2e/example.spec.ts +++ /dev/null @@ -1,8 +0,0 @@ -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" }); -}); diff --git a/e2e/screenshots/example.png b/e2e/screenshots/example.png deleted file mode 100644 index dad308e..0000000 Binary files a/e2e/screenshots/example.png and /dev/null differ diff --git a/test/e2e.spec.ts b/test/e2e.spec.ts new file mode 100644 index 0000000..b820059 --- /dev/null +++ b/test/e2e.spec.ts @@ -0,0 +1,64 @@ +import path from 'node:path' +import { + type ElectronApplication, + type Page, + type JSHandle, + _electron as electron, +} from 'playwright' +import type { BrowserWindow } from 'electron' +import { + beforeAll, + afterAll, + describe, + expect, + test, +} from 'vitest' + +const root = path.join(__dirname, '..') +let electronApp: ElectronApplication +let page: Page + +if (process.platform === 'linux') { + // pass ubuntu + test(() => expect(true).true) +} else { + beforeAll(async () => { + electronApp = await electron.launch({ + args: ['.', '--no-sandbox'], + cwd: root, + env: { ...process.env, NODE_ENV: 'development' }, + }) + page = await electronApp.firstWindow() + + const mainWin: JSHandle = await electronApp.browserWindow(page) + await mainWin.evaluate(async (win) => { + win.webContents.executeJavaScript('console.log("Execute JavaScript with e2e testing.")') + }) + }) + + afterAll(async () => { + await page.screenshot({ path: 'test/screenshots/e2e.png' }) + await page.close() + await electronApp.close() + }) + + describe('[electron-vite-react] e2e tests', async () => { + test('startup', async () => { + const title = await page.title() + expect(title).eq('Electron + Vite + React') + }) + + test('should be home page is load correctly', async () => { + const h1 = await page.$('h1') + const title = await h1?.textContent() + expect(title).eq('Electron + Vite + React') + }) + + test('should be count button can click', async () => { + const countButton = await page.$('button') + await countButton?.click() + const countValue = await countButton?.textContent() + expect(countValue).eq('count is 1') + }) + }) +} diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..068f6fd --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + root: __dirname, + include: ['test/**/*.{test,spec}.?(c|m)[jt]s?(x)'], + testTimeout: 1000 * 29, + }, +})