Skip to content

Commit 70151db

Browse files
committed
feat: add Playwright testing support and enhance project structure
- Introduced Playwright for end-to-end testing, including new test scripts and configurations. - Updated .gitignore to exclude Playwright reports and test results. - Enhanced ESLint configuration to ignore Playwright-related files. - Added new scripts in package.json for running Playwright tests. - Created a new Playwright configuration file and integrated it into the TypeScript setup. - Updated GitHub workflows to include Playwright browser installation and testing steps. - Refactored wokwi-cli to improve modularity and maintainability with new transport mechanisms.
1 parent 22806db commit 70151db

File tree

17 files changed

+238
-9
lines changed

17 files changed

+238
-9
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Tests
22

33
on:
44
push:
5-
branches: [main]
65
pull_request:
76
branches: [main]
7+
workflow_dispatch:
88

99
jobs:
1010
test:
@@ -20,5 +20,11 @@ jobs:
2020
cache: 'pnpm'
2121
- name: Install dependencies
2222
run: pnpm install --frozen-lockfile
23+
- name: Build packages
24+
run: pnpm run build
25+
- name: Install Playwright browsers
26+
run: pnpm exec playwright install --with-deps
2327
- name: Run tests
2428
run: pnpm test
29+
- name: Test wokwi-embed with Playwright
30+
run: pnpm test:embed:playwright

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ wokwi.toml
44
*.bin
55
diagram.json
66
screenshot.png
7+
playwright-report/
8+
test-results/

eslint.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export default defineConfig(
1818
'**/.git/**',
1919
'**/coverage/**',
2020
'**/*.min.js',
21+
'**/playwright-report/**',
22+
'**/test-results/**',
2123
],
2224
},
2325

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"lint": "eslint .",
1111
"lint:fix": "eslint . --fix",
1212
"test": "pnpm run lint && vitest --run",
13+
"test:embed:playwright": "playwright test test/wokwi-embed",
14+
"test:embed:playwright:ui": "playwright test test/wokwi-embed --ui",
1315
"cli": "tsx packages/wokwi-cli/src/main.ts",
1416
"prepare": "husky install"
1517
},
@@ -21,6 +23,7 @@
2123
},
2224
"devDependencies": {
2325
"@eslint/js": "^9.39.1",
26+
"@playwright/test": "^1.48.0",
2427
"esbuild": "^0.25.2",
2528
"eslint": "^9.39.1",
2629
"eslint-config-prettier": "^10.1.8",

packages/wokwi-cli/src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import chalkTemplate from 'chalk-template';
33
import { createWriteStream, existsSync, readFileSync, writeFileSync } from 'fs';
44
import path, { join } from 'path';
55
import YAML from 'yaml';
6-
import { APIClient, WebSocketTransport, type APIEvent, type ChipsLogPayload, type SerialMonitorDataPayload } from 'wokwi-client-js';
6+
import { APIClient, type APIEvent, type ChipsLogPayload, type SerialMonitorDataPayload } from 'wokwi-client-js';
7+
import { WebSocketTransport } from './transport/WebSocketTransport.js';
78
import { DEFAULT_SERVER } from './constants.js';
89
import { ExpectEngine } from './ExpectEngine.js';
910
import { SimulationTimeoutError } from './SimulationTimeoutError.js';
@@ -361,7 +362,7 @@ async function main() {
361362
});
362363

363364
if (interactive) {
364-
process.stdin.pipe(client.serialMonitorWritable());
365+
process.stdin.pipe(await client.serialMonitorWritable());
365366
}
366367

367368
if (scenario != null) {

packages/wokwi-cli/src/mcp/SimulationManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { existsSync, readFileSync } from 'fs';
22
import path from 'path';
3-
import { APIClient, WebSocketTransport, type APIEvent } from 'wokwi-client-js';
3+
import { APIClient, type APIEvent } from 'wokwi-client-js';
4+
import { WebSocketTransport } from '../transport/WebSocketTransport.js';
45
import { DEFAULT_SERVER } from '../constants.js';
56
import { parseConfig } from '../config.js';
67
import { loadChips } from '../loadChips.js';

packages/wokwi-client-js/src/transport/WebSocketTransport.ts renamed to packages/wokwi-cli/src/transport/WebSocketTransport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { type ITransport } from 'wokwi-client-js';
12
import { WebSocket } from 'ws';
2-
import { ITransport } from './ITransport.js';
33

44
const retryDelays = [1000, 2000, 5000, 10000, 20000];
55

packages/wokwi-client-js/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
".": {
1010
"types": "./dist/index.d.ts",
1111
"import": "./dist/index.js"
12+
},
13+
"./transport/MessagePortTransport.js": {
14+
"types": "./dist/transport/MessagePortTransport.d.ts",
15+
"import": "./dist/transport/MessagePortTransport.js"
16+
},
17+
"./APIClient.js": {
18+
"types": "./dist/APIClient.d.ts",
19+
"import": "./dist/APIClient.js"
1220
}
1321
},
1422
"files": [

packages/wokwi-client-js/src/APIClient.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Writable } from 'stream';
21
import type {
32
APICommand,
43
APIError,
@@ -107,9 +106,12 @@ export class APIClient {
107106
});
108107
}
109108

110-
serialMonitorWritable() {
109+
async serialMonitorWritable() {
110+
// Dynamic import for Node.js-only API
111+
const { Writable } = await import('stream');
112+
const { Buffer } = await import('buffer');
111113
return new Writable({
112-
write: (chunk, encoding, callback) => {
114+
write: (chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void) => {
113115
if (typeof chunk === 'string') {
114116
chunk = Buffer.from(chunk, encoding);
115117
}

packages/wokwi-client-js/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export { APIClient } from './APIClient.js';
44
// Transport interfaces and implementations
55
export { ITransport } from './transport/ITransport.js';
66
export { MessagePortTransport } from './transport/MessagePortTransport.js';
7-
export { WebSocketTransport } from './transport/WebSocketTransport.js';
87

98
// Pause Point
109
export { PausePoint } from './PausePoint.js';

0 commit comments

Comments
 (0)