返回 AiToEarn
e2e.spec.ts
根目录 / project / aitoearn-electron / test / e2e.spec.ts
1 import path from 'node:path'
2 import {
3 type ElectronApplication,
4 type Page,
5 type JSHandle,
6 _electron as electron,
7 } from 'playwright'
8 import type { BrowserWindow } from 'electron'
9 import {
10 beforeAll,
11 afterAll,
12 describe,
13 expect,
14 test,
15 } from 'vitest'
16
17 const root = path.join(__dirname, '..')
18 let electronApp: ElectronApplication
19 let page: Page
20
21 if (process.platform === 'linux') {
22 // pass ubuntu
23 test(() => expect(true).true)
24 } else {
25 beforeAll(async () => {
26 electronApp = await electron.launch({
27 args: ['.', '--no-sandbox'],
28 cwd: root,
29 env: { ...process.env, NODE_ENV: 'development' },
30 })
31 page = await electronApp.firstWindow()
32
33 const mainWin: JSHandle<BrowserWindow> = await electronApp.browserWindow(page)
34 await mainWin.evaluate(async (win) => {
35 win.webContents.executeJavaScript('console.log("Execute JavaScript with e2e testing.")')
36 })
37 })
38
39 afterAll(async () => {
40 await page.screenshot({ path: 'test/screenshots/e2e.png' })
41 await page.close()
42 await electronApp.close()
43 })
44
45 describe('[electron-vite-react] e2e tests', async () => {
46 test('startup', async () => {
47 const title = await page.title()
48 expect(title).eq('Electron + Vite + React')
49 })
50
51 test('should be home page is load correctly', async () => {
52 const h1 = await page.$('h1')
53 const title = await h1?.textContent()
54 expect(title).eq('Electron + Vite + React')
55 })
56
57 test('should be count button can click', async () => {
58 const countButton = await page.$('button')
59 await countButton?.click()
60 const countValue = await countButton?.textContent()
61 expect(countValue).eq('count is 1')
62 })
63 })
64 }
65
65 lines TYPESCRIPT