r/electronjs • • 5h ago

How we end-to-end test an Electron camera app on CI runners that have no camera, including the signed build we actually ship

Thumbnail
gallery
0 Upvotes

We make Electroscope, an open-source (MIT) Electron + TypeScript app for cheap USB electronics microscopes, for Windows 11 x64 and Apple Silicon Macs. The person at the bench gets the live view. Inside the app there's a Streamable HTTP MCP server, so an agent can ask for still frames and draw circles and arrows on the live picture. GitHub's runners don't have a microscope plugged in, so this is how our end-to-end suite works without one, and where it still has gaps. I'd like some input on those gaps.

1. Swap the camera before the app is ready

If ELECTROSCOPE_FAKE_CAMERA=1 is set, the main process appends use-fake-device-for-media-stream and use-fake-ui-for-media-stream (image 3). Chromium then offers its synthetic camera, fake_device_0 at 1920x1080 with a moving pattern, and skips the permission prompt. It needs no macOS camera permission either, so the TCC problems we wrote about here a couple of weeks ago don't apply to it.

2. One script drives the window and the MCP server

scripts/e2e.mjs launches the app with playwright-core's _electron. It can launch the source tree, or a packaged executable if you pass ELECTROSCOPE_EXE. Each run gets a throwaway userData dir and ELECTROSCOPE_PORT=0. The script reads the MCP URL from the text in the title bar, so the test fails if the window shows a wrong address. It then connects with the official MCP TypeScript SDK client and behaves like an agent: 27 steps, from listing tools to saving a full-res PNG.

3. Checking pixels

  • The test adds five marks over MCP. It then takes one plain capture and one with include_annotations: true and reads pixels with sharp. The point on the ring's right edge (0.62, 0.5) must be magenta in the annotated image and must not be magenta in the plain one. The green box edge at (0.12, 0.72) has to be green.
  • The fake pattern moves, so comparing the background of two separate frames was flaky. The zoomed-region test draws the circle with an opaque fill instead. The whole 0.4-0.6 crop then sits inside the circle, so a pixel sampled from it has to be the fill colour.
  • Picture adjustments are checked with mean luma. It went from 102.9 to 175.0 at brightness 1.8 in the run in image 4.
  • For marks the human draws, Playwright drags on the frame. get_status over MCP then has to return those marks within 0.03 of where they were drawn, and Ctrl/Cmd+Z has to remove the last one.

4. The same suite runs on the build we ship

CI on windows-latest runs the suite against the source tree on every push and PR, and uploads the screenshots and captured frames as an artifact. In the release workflow (image 5), the Windows job silently installs the signed NSIS installer, checks the signatures and runs the suite against the installed exe. The macOS job unzips the notarized ZIP, runs codesign --verify --strict --deep, stapler validate and spctl --assess, and then runs the suite against the binary inside the bundle. The publish job needs both of them, so if either fails nothing gets published.

What it doesn't cover

  • Chromium's fake device obeys every control. In image 4 it reports zoom, pan, tilt, focus and exposure, and all of them respond. The app's main trick is hiding sliders that a cheap camera accepts and then ignores, and CI never exercises that. The "shown == working" assertion passes trivially. That path only gets tested in a manual run against a real scope (ELECTROSCOPE_CAMERA='GENERAL - UVC' node scripts/e2e.mjs on the signed Mac app).
  • The macOS permission states (denied / never asked / asking) are tested by sending the IPC message from the main process, not by real TCC.
  • The fake device never stalls, so the "camera opened but never sent a frame" recovery is only covered by unit tests.

About the images: image 1 is a generated illustration, not a screenshot. The rest are real. Image 2 is the window the suite drives. I ran it from source on a Linux box under xvfb-run while writing this. That's why it shows 5 fps, and Linux isn't a release target, it just happened to work. Image 3 is the source, image 4 is that run's output, and image 5 is the release workflow.

Repo: https://github.com/UnlikeOtherAI/Electroscope. Signed installers are on the releases page (Windows installer or portable exe, Mac DMG or ZIP). To run the suite yourself: npm ci, npm run build, node scripts/e2e.mjs --fake.

Questions for anyone who has tested media apps in Electron:

  • Has anyone made a fake camera that misbehaves on purpose, so it ignores controls or stalls? Or does anyone run a virtual UVC device in CI? We haven't tried --use-file-for-fake-video-capture with a recorded microscope clip yet.
  • When the source is moving, do you check exact pixels like this, or use tolerant screenshot diffs?
  • Has anyone else run Playwright's _electron against a hardened-runtime, notarized build, and did you hit any gotchas that haven't hit us yet?