Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,37 @@ jobs:
- run: npm run test:browser:install
- run: npm run test:browser

build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npx vite build
- run: npm ci
- run: npx vite build

electron-e2e:
name: Electron E2E
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build-vite
- run: npx playwright install --with-deps
- run: xvfb-run -a npm run test:e2e
- name: Upload Playwright artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: electron-e2e-artifacts
path: |
test-results/
playwright-report/
if-no-files-found: ignore
18 changes: 9 additions & 9 deletions src/hooks/useScreenRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
}
});

const safeHideCountdownOverlay = useCallback(async (runId: number) => {
try {
await window.electronAPI.hideCountdownOverlay(runId);
} catch (error) {
console.warn("Failed to hide countdown overlay:", error);
}
}, []);

useEffect(() => {
let cleanup: (() => void) | undefined;

Expand Down Expand Up @@ -450,7 +458,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
webcamRecorder.current = null;
teardownMedia();
};
}, [teardownMedia]);
}, [teardownMedia, safeHideCountdownOverlay]);

const safeShowCountdownOverlay = async (value: number, runId: number) => {
try {
Expand All @@ -477,14 +485,6 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
}
};

const safeHideCountdownOverlay = async (runId: number) => {
try {
await window.electronAPI.hideCountdownOverlay(runId);
} catch (error) {
console.warn("Failed to hide countdown overlay:", error);
}
};

const isCountdownRunActive = (runId?: number) =>
runId === undefined || countdownRunId.current === runId;

Expand Down
50 changes: 48 additions & 2 deletions tests/e2e/gif-export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,59 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { _electron as electron, expect, test } from "@playwright/test";
import { type ElectronApplication, _electron as electron, expect, test } from "@playwright/test";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.join(__dirname, "../..");
const MAIN_JS = path.join(ROOT, "dist-electron/main.js");
const TEST_VIDEO = path.join(__dirname, "../fixtures/sample.webm");

async function waitForProcessExit(
child: ReturnType<ElectronApplication["process"]>,
timeoutMs: number,
) {
if (child.exitCode !== null) return true;

return new Promise<boolean>((resolve) => {
let timer: ReturnType<typeof setTimeout>;
const cleanup = () => {
clearTimeout(timer);
child.removeListener("exit", onExit);
};
const finish = (exited: boolean) => {
cleanup();
resolve(exited);
};
const onExit = () => finish(true);
const onTimeout = () => finish(false);

timer = setTimeout(onTimeout, timeoutMs);
child.once("exit", onExit);
if (child.exitCode !== null) finish(true);
});
}

async function closeElectronApp(app: ElectronApplication) {
const child = app.process();
await app
.evaluate(({ app: electronApp }) => {
electronApp.exit(0);
})
.catch(() => {
// App may already be closing.
});
const exited = await waitForProcessExit(child, 2_000);
if (child.exitCode === null) {
child.kill("SIGKILL");
const killed = await waitForProcessExit(child, 2_000);
if (!killed) {
throw new Error("Electron process did not exit after SIGKILL");
}
} else if (!exited) {
throw new Error("Electron process exit timed out");
}
}

test("exports a GIF from a loaded video", async () => {
const outputPath = path.join(os.tmpdir(), `test-gif-export-${Date.now()}.gif`);
let testVideoInRecordings = "";
Expand Down Expand Up @@ -126,7 +172,7 @@ test("exports a GIF from a loaded video", async () => {
const stats = fs.statSync(outputPath);
expect(stats.size).toBeGreaterThan(1024); // at least 1 KB
} finally {
await app.close();
await closeElectronApp(app);
if (fs.existsSync(outputPath)) {
fs.unlinkSync(outputPath);
}
Expand Down
Loading