feat(test): add captureScreenshot helper to test/screenshots.ts - #78
Conversation
- Add captureScreenshot to src/test/screenshots.ts to consolidate the duplicated browser/page setup, clock and screenly.js mocking, and screenshot capture boilerplate found across Edge App e2e specs - setupMocks callback keeps the helper generic for app-specific route mocks - test() calls remain in spec files for correct Playwright source reporting - Update the create-template e2e scaffold to use the new helper Closes #27
There was a problem hiding this comment.
Pull request overview
Introduces a reusable captureScreenshot(...) helper in the test utilities to centralize the common Playwright setup/mocking/navigation/screenshot steps used by Edge App screenshot specs, updates the e2e template scaffold to use it, and bumps the package version to the first Calendar Versioning release.
Changes:
- Add
captureScreenshothelper tosrc/test/screenshots.tsfor consistent screenshot test setup and capture. - Update the
scripts/create-templatee2e screenshot spec scaffold to call the new helper. - Bump package version to
26.8.0(Calendar Versioning) and syncpackage-lock.json.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/test/screenshots.ts | Adds Playwright-shaped interfaces and the new captureScreenshot helper. |
| scripts/create-template/e2e/screenshots.spec.ts | Replaces duplicated boilerplate with captureScreenshot(...) usage in the scaffold. |
| package.json | Updates version to 26.8.0. |
| package-lock.json | Updates lockfile package versions to 26.8.0. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Wrap the page setup/navigation/screenshot logic in try/finally so context.close() always runs, even if a step throws
|
Good catch — fixed in e0aa483 by wrapping the body in |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
src/test/screenshots.ts:38
PlaywrightPage.routeforces route handlers to returnPromise<void>, but Playwright allows synchronous handlers too. This makes commonpage.route(..., route => { ... })patterns fail type-checking for consumers ofcaptureScreenshot.
route(
url: string,
handler: (route: PlaywrightRoute) => Promise<void>,
): Promise<void>
src/test/screenshots.ts:248
setupMocksis typed as(page: PlaywrightPage) => Promise<void>. Withstrict: true, callers cannot annotate the callback parameter as Playwright’s realPagetype (it becomes too specific understrictFunctionTypes), which makes it hard to use the full Page API without casts. Consider making this callback bivariant so callers can type it asPagewhen they have Playwright types available.
setupMocks: (page: PlaywrightPage) => Promise<void>,
- Replace positional args with a CaptureScreenshotOptions object to avoid transposing adjacent same-typed strings (filenamePrefix, screenlyJsContent) at call sites, since this is cheap to change pre-release - Update the create-template e2e scaffold to match - Document captureScreenshot in README.md under a new "Screenshot Testing" subsection
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
src/test/screenshots.ts:263
captureScreenshotcall sites with no app-specific mocks currently have to pass a no-opsetupMocks. IfsetupMocksis made optional, default it in the destructuring to keep the implementation simple and avoid extra checks.
filenamePrefix,
screenlyJsContent,
setupMocks,
}: CaptureScreenshotOptions,
): Promise<void> {
- PlaywrightPage.route now accepts url: string | RegExp and passes a request param to the handler, which may also return void for sync handlers, matching real Playwright's route() signature more closely - Extract the duplicated inline route-page type from setupOpenWeatherMocks/setupScreenlyJsMock into a shared PlaywrightRoutable interface - Make setupMocks optional on CaptureScreenshotOptions, defaulting to a no-op, so callers with nothing app-specific to mock don't need to pass one - Simplify the create-template scaffold accordingly and update the README's Screenshot Testing section Addresses Copilot review feedback on #78
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/test/screenshots.ts:263
- The PR description (and linked issue) describe
captureScreenshot(browser, width, height, filenamePrefix, screenlyJsContent, setupMocks)as a positional-args API, but the implementation here uses an options object. Please align the public API story by either updating the PR description/docs to reflect the options shape, or adding a positional-args overload/wrapper for the described signature (so consumers can follow the docs verbatim).
export async function captureScreenshot(
browser: PlaywrightBrowser,
{
width,
height,
filenamePrefix,
screenlyJsContent,
setupMocks = async () => {},
}: CaptureScreenshotOptions,
): Promise<void> {
Summary
captureScreenshot(browser, options)tosrc/test/screenshots.ts, whereoptions: CaptureScreenshotOptionsis{ width, height, filenamePrefix, screenlyJsContent, setupMocks? }. Consolidates the browser/page setup, clock + screenly.js mocking, navigation, and screenshot capture boilerplate that's currently duplicated across Edge App e2e specs (rss-reader-app,Playground'ssimple-table-app, etc.).filenamePrefix,screenlyJsContent) at call sites — cheap to change pre-release, before any consumer depends on the exact shape.setupMocksis optional (defaults to a no-op) for callers with nothing app-specific to mock.test()calls stay in the spec files (not wrapped by the helper) so Playwright still reports the correct source location.scripts/create-template/e2e/screenshots.spec.tsscaffold (used bycreate-scaffold.jsto bootstrap new Edge Apps in this repo) to use the new helper.captureScreenshotinREADME.mdunder a new "Screenshot Testing" subsection.26.8.0, adopting Calendar Versioning (YY.M.PATCH) per docs(contributing): switch to Calendar Versioning #76 — this is the first release under the new scheme for August 2026.DEPENDS ON #76 being merged first, since that PR documents the versioning scheme this release follows.
NOTE: existing Edge App repos (
rss-reader-app,Playground, etc.) still contain the duplicated boilerplate this helper replaces. Those will be migrated manually in follow-up PRs, not as part of this change.Closes #27