feat(test): use vitest

This commit is contained in:
Leo Wang(草鞋没号) committed 2024-11-17 19:31:52 +08:00
1 parent f3e8e2cf68
commit d8d6e8dcb1
4 files changed
+73 -8

No files matched your search

-8
View File
@@ -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" });
});
Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

+64
View File
@@ -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<BrowserWindow> = 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')
})
})
}
+9
View File
@@ -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,
},
})