Skip to content

Commit 3c9720d

Browse files
committed
Add @testdriver.ai/playwright test
1 parent bc87752 commit 3c9720d

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "tauri-app",
33
"private": true,
44
"version": "0.1.0",
5-
"type": "module",
65
"scripts": {
76
"dev": "vite",
87
"build": "tsc && vite build",
@@ -19,6 +18,7 @@
1918
"devDependencies": {
2019
"@playwright/test": "^1.55.1",
2120
"@tauri-apps/cli": "^2",
21+
"@testdriver.ai/playwright": "^1.0.3",
2222
"@types/node": "^24.5.2",
2323
"@types/react": "^19.1.8",
2424
"@types/react-dom": "^19.1.6",

tests/testdriver.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { mockIPC } from "@tauri-apps/api/mocks";
2+
import { expect, test } from "@testdriver.ai/playwright";
3+
4+
// For type-safety of the mockIPC function
5+
declare global {
6+
interface Window {
7+
mockIPC: typeof mockIPC;
8+
}
9+
}
10+
11+
// https://tauri.app/develop/tests/mocking/#mocking-commands-for-invoke
12+
test.beforeEach(async ({ page }) => {
13+
await page.goto("http://localhost:1420");
14+
await page.evaluate(() => {
15+
window.mockIPC((cmd, args) => {
16+
switch (cmd) {
17+
case "greet":
18+
args = args as { name: string };
19+
return `Hello, ${args.name}! You've been greeted from Rust!`;
20+
21+
default:
22+
throw new Error(`Unsupported command: ${cmd}`);
23+
}
24+
});
25+
});
26+
});
27+
28+
test("should have title", async ({ page }) => {
29+
await expect(page).toHaveTitle("Tauri + React + TypeScript");
30+
});
31+
32+
test("should have heading", async ({ page }) => {
33+
await expect(page).toMatchPrompt("Heading says 'Welcome to Tauri + React'");
34+
});
35+
36+
test.describe("should greet with name", () => {
37+
test.agent(`
38+
- Enter the name "Tauri"
39+
- Click the "Greet" button
40+
- You should see the text "Hello, Tauri! You've been greeted from Rust!"
41+
`);
42+
});

0 commit comments

Comments
 (0)