Skip to content

Commit d8d6e8d

Browse files
committed
feat(test): use vitest
1 parent f3e8e2c commit d8d6e8d

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

e2e/example.spec.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

e2e/screenshots/example.png

-102 KB
Binary file not shown.

test/e2e.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
}

vitest.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
root: __dirname,
6+
include: ['test/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
7+
testTimeout: 1000 * 29,
8+
},
9+
})

0 commit comments

Comments
 (0)