Skip to content

feat(test): add captureScreenshot helper to test/screenshots.ts - #78

Merged
nicomiguelino merged 5 commits into
mainfrom
feat/capture-screenshot-helper
Sep 1, 2026
Merged

feat(test): add captureScreenshot helper to test/screenshots.ts#78
nicomiguelino merged 5 commits into
mainfrom
feat/capture-screenshot-helper

Conversation

@nicomiguelino

@nicomiguelino nicomiguelino commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds captureScreenshot(browser, options) to src/test/screenshots.ts, where options: CaptureScreenshotOptions is { 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's simple-table-app, etc.).
    • Uses an options object rather than the positional-args signature originally proposed in feat: add runScreenshotTests helper to test/screenshots.ts #27, to avoid transposing adjacent same-typed string args (filenamePrefix, screenlyJsContent) at call sites — cheap to change pre-release, before any consumer depends on the exact shape.
    • setupMocks is 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.
  • Updates the scripts/create-template/e2e/screenshots.spec.ts scaffold (used by create-scaffold.js to bootstrap new Edge Apps in this repo) to use the new helper.
  • Documents captureScreenshot in README.md under a new "Screenshot Testing" subsection.
  • Bumps the package version to 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

- 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
- Adopt Calendar Versioning (YY.M.PATCH) per #76; first release under
  the new scheme for August 2026
- NOTE: depends on #76 (docs: switch CONTRIBUTING.md to CalVer) being
  merged first
Copilot AI lite review requested due to automatic review settings September 1, 2026 03:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 captureScreenshot helper to src/test/screenshots.ts for consistent screenshot test setup and capture.
  • Update the scripts/create-template e2e screenshot spec scaffold to call the new helper.
  • Bump package version to 26.8.0 (Calendar Versioning) and sync package-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.

Comment thread src/test/screenshots.ts
- Wrap the page setup/navigation/screenshot logic in try/finally so
  context.close() always runs, even if a step throws
Copilot AI review requested due to automatic review settings September 1, 2026 03:39
@nicomiguelino

Copy link
Copy Markdown
Contributor Author

Good catch — fixed in e0aa483 by wrapping the body in try/finally so context.close() always runs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.route forces route handlers to return Promise<void>, but Playwright allows synchronous handlers too. This makes common page.route(..., route => { ... }) patterns fail type-checking for consumers of captureScreenshot.
  route(
    url: string,
    handler: (route: PlaywrightRoute) => Promise<void>,
  ): Promise<void>

src/test/screenshots.ts:248

  • setupMocks is typed as (page: PlaywrightPage) => Promise<void>. With strict: true, callers cannot annotate the callback parameter as Playwright’s real Page type (it becomes too specific under strictFunctionTypes), which makes it hard to use the full Page API without casts. Consider making this callback bivariant so callers can type it as Page when 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
Copilot AI review requested due to automatic review settings September 1, 2026 04:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • captureScreenshot call sites with no app-specific mocks currently have to pass a no-op setupMocks. If setupMocks is made optional, default it in the destructuring to keep the implementation simple and avoid extra checks.
    filenamePrefix,
    screenlyJsContent,
    setupMocks,
  }: CaptureScreenshotOptions,
): Promise<void> {

Comment thread src/test/screenshots.ts Outdated
Comment thread src/test/screenshots.ts
- 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
Copilot AI review requested due to automatic review settings September 1, 2026 04:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {

@nicomiguelino
nicomiguelino merged commit 2fb1cb6 into main Sep 1, 2026
5 checks passed
@nicomiguelino
nicomiguelino deleted the feat/capture-screenshot-helper branch September 1, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add runScreenshotTests helper to test/screenshots.ts

3 participants