Skip to content

Commit f0d3623

Browse files
committed
Add a proper smoke test for all platforms
1 parent 9b624dd commit f0d3623

File tree

6 files changed

+174
-4
lines changed

6 files changed

+174
-4
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ jobs:
8181
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8282
USE_SYSTEM_FPM: ${{ matrix.platform == 'linux' && matrix.arch == 'arm64' }}
8383

84+
- name: Run smoke tests
85+
run: |
86+
# We manually start ADB, so the tests don't (because if they do, they fail
87+
# to exit, due to the hanging process)
88+
"$ANDROID_HOME/platform-tools/adb" start-server 2>/dev/null || true
89+
90+
if [ "$RUNNER_OS" == "Linux" ]; then
91+
xvfb-run --auto-servernum npm test
92+
else
93+
npm test
94+
fi
95+
shell: bash
96+
8497
- uses: actions/upload-artifact@v4
8598
with:
8699
name: ${{ matrix.platform }}-${{ matrix.arch }}-distributables

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ build/
44
dist/
55
httptoolkit-server/
66
appveyor-tools/
7+
.playwright/

package-lock.json

Lines changed: 101 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"build:dir-only": "npm run server:setup && electron-builder --dir",
1818
"start": "npm run server:setup && npm run start:app",
1919
"start:dev": "tsx ./skip-server.ts && cross-env HTK_DEV=true APP_URL='http://localhost:8080' npm run start:app",
20-
"start:app": "tsc-watch --onSuccess \"electron .\""
20+
"start:app": "tsc-watch --onSuccess \"electron .\"",
21+
"test": "npm run server:setup && npm run build:src && playwright test"
2122
},
2223
"keywords": [],
2324
"author": "Tim Perry",
@@ -141,6 +142,7 @@
141142
"yargs": "^15.1.0"
142143
},
143144
"devDependencies": {
145+
"@playwright/test": "^1.56.1",
144146
"@types/lodash": "^4.14.149",
145147
"@types/node-fetch": "^2.1.4",
146148
"@types/semver": "^7.3.4",

playwright.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from '@playwright/test';
2+
3+
export default defineConfig({
4+
testDir: './test',
5+
timeout: 20000,
6+
workers: 1,
7+
retries: 0,
8+
reporter: 'list',
9+
outputDir: '.playwright'
10+
});

test/smoke.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { test, expect, _electron as electron } from '@playwright/test';
2+
import * as path from 'path';
3+
4+
async function launchApp() {
5+
const app = await electron.launch({
6+
cwd: path.join(import.meta.dirname, '..'),
7+
args: [
8+
'.',
9+
// On Linux ARM64 CI, sandboxing doesn't work, so we have to skip it:
10+
...(process.env.CI && process.platform === 'linux' && process.arch === 'arm64' ?
11+
[
12+
'--no-sandbox',
13+
'--disable-setuid-sandbox'
14+
] : []
15+
)
16+
],
17+
timeout: 10000,
18+
env: {
19+
...process.env,
20+
// Disable auto-update during tests
21+
'HTTPTOOLKIT_SERVER_DISABLE_AUTOUPDATE': '1'
22+
}
23+
});
24+
25+
app.process().stdout?.on('data', (data) => {
26+
console.log('[stdout]', data.toString().trim());
27+
});
28+
app.process().stderr?.on('data', (data) => {
29+
console.error('[stderr]', data.toString().trim());
30+
});
31+
32+
return app;
33+
}
34+
35+
test('app launches and loads UI from server', async () => {
36+
const electronApp = await launchApp();
37+
const window = await electronApp.firstWindow();
38+
39+
// Has the UI loaded & initialized (connected to the server) successfully?
40+
await expect(window.locator('h1:has-text("Intercept HTTP")')).toBeVisible({ timeout: 15000 });
41+
42+
// Has the preload injected the desktop APIs successfully?
43+
await expect(window.evaluate(() => typeof (window as any).desktopApi !== 'undefined')).resolves.toBe(true);
44+
45+
await electronApp.close();
46+
});

0 commit comments

Comments
 (0)