How codeceptjs/codeceptjs-resemblehelper works
1. This repository is a small Node.js/TypeScript package that extends CodeceptJS with visual regression support. Its core purpose is to compare screenshots against baselines and fail tests when the mismatch exceeds a tolerance.
2. The main product boundary is a single helper exported from src/index.ts. That helper is what CodeceptJS loads via "require": "codeceptjs-resemblehelper" in a test configuration. In other words, the repo is not an app itself; it is a test-infrastructure plugin.
3. The central data flow is: test code triggers a helper method → the helper captures or receives a screenshot → the helper loads the matching baseline image from baseFolder → resemble.js computes a diff and mismatch percentage → the helper either passes, fails, or stores diff output depending on options.
4. The helper supports two primary comparison paths:
- full-image comparison through seeVisualDiff
- element-only comparison through seeVisualDiffForElement
The latter depends on the browser/runtime being able to resolve element coordinates on the active page, so it is tied to the underlying browser automation context.
5. There is also a screenshot-writing path via screenshotElement, which saves an element screenshot into the configured output directory. The README notes this method is Puppeteer-specific, so the package has at least one automation-tool-specific branch in its runtime behavior.
6. File handling is a major architectural concern. The repo uses separate folders for:
- baseline images (baseFolder)
- diff artifacts (diffFolder)
- output screenshots
The comparison logic assumes consistent image dimensions unless the user explicitly handles that constraint via options.
7. The comparison engine is resemble.js, which is responsible for image diffing and output customization. The helper passes through options such as tolerance, ignored boxes, and resemble output settings, so the helper acts as a façade over the image-diff library rather than reimplementing pixel comparison itself.
8. There is an optional remote-storage subsystem for AWS S3 and S3-compatible providers. When configured, the helper downloads baselines from a bucket, uploads generated output images, and stores diff images in structured folders such as base, output, and diff. This changes the data boundary from local filesystem only to filesystem plus object storage.
9. The helper also integrates with reporting tooling. The README mentions Allure attachments for mismatches above tolerance, which means the helper can emit artifacts into the test report pipeline in addition to writing files to disk or S3.
10. The repository includes a dedicated test harness under __test__, with CodeceptJS configuration, step definitions, and visual test specs. That test suite likely exercises both comparison behavior and screenshot generation end-to-end, using sample baseline/diff fixtures in the screenshots tree.
11. CI/CD is handled through GitHub Actions workflows in .github/workflows. One workflow runs tests, and another publishes to npm, so the repository’s delivery pipeline is split between validation and package release.
12. From an architecture diagram perspective, the important nodes are: CodeceptJS test code at the top, this helper as the integration layer in the middle, and three downstream services/boundaries beneath it: the browser automation runtime for screenshots/element coordinates, the local filesystem or S3 for image storage, and resemble.js for diff calculation.
Main entry points: index.ts Helper entry · screenshots Local images · steps_file.ts Step defs · visual_test.ts Codecept tests
Components 16
Test Harness
CodeceptJS-based validation and visual specs
- Codecept tests · Top-level visual test entrypoints that drive the helper
__test__/visual_test.ts - Codecept config · Loads the helper into the test runner
__test__/codecept.conf.ts - Step defs · Typed step definitions used by the test harness
__test__/steps_file.ts
Helper Core
The exported CodeceptJS helper and its comparison pipeline
- Helper entry · Single exported helper consumed by CodeceptJS
src/index.ts - Visual API · Public methods for screenshot capture and visual comparison
- Full compare · Compares a captured screenshot against a baseline
- Element compare · Compares only the active element region on the page
- Screenshot write · Writes an element screenshot to the configured output directory
Storage
Local screenshots, baselines, diffs, and optional S3-backed storage
- Baseline lookup · Finds the matching baseline image from the configured base folder
- Local images · Base, diff, and output image folders on disk
__test__/screenshots - S3 store · Optional remote bucket for baselines, outputs, and diffs
External Boundaries
Browser automation, diff engine, reporting, and release workflow
- resemble.js · Computes mismatch percentage and diff artifacts
- Browser runtime · Provides screenshots and element coordinates
- Allure · Receives attachments for mismatches above tolerance
- Test workflow · GitHub Actions job that validates the package
.github/workflows/test.yml - Publish workflow · GitHub Actions job that publishes the package to npm
.github/workflows/npm-publish.yml
Connections 22
- Codecept tests → Step defs: uses · Tests call typed step helpers
- Step defs → Helper entry: drives · Step definitions invoke the helper through CodeceptJS
- Codecept config → Helper entry: loads · Configuration registers the helper for the runner
- Helper entry → Visual API: exposes · The exported helper provides the visual methods
- Visual API → Full compare: seeVisualDiff · Full-image comparison path
- Visual API → Element compare: seeVisualDiffForElement · Element-only comparison path
- Visual API → Screenshot write: screenshotElement · Writes an element screenshot to disk
- Full compare → Browser runtime: captures · Obtains the screenshot from the automation runtime
- Element compare → Browser runtime: reads coords · Depends on browser/page element location support
- Screenshot write → Browser runtime: captures · Uses the runtime to generate an element screenshot
- Full compare → Baseline lookup: loads baseline · Resolves the expected image for comparison
- Element compare → Baseline lookup: loads baseline · Resolves the expected element baseline
- Baseline lookup → Local images: reads · Default baseline source is the local screenshots tree
- Full compare → resemble.js: diffs · Delegates pixel comparison and mismatch calculation
- Element compare → resemble.js: diffs · Delegates region comparison and mismatch calculation
- resemble.js → Allure: attaches · Mismatch results can be sent to the report pipeline
- Full compare → Local images: writes diff · Stores generated diff/output artifacts locally
- Screenshot write → Local images: writes output · Persists generated screenshots to the output folder
- Helper entry → S3 store: optional remote · Can switch storage boundaries to S3-compatible object storage
- S3 store → Baseline lookup: provides baselines · Remote baselines may be downloaded before comparison
- Full compare → Test workflow: validated by · CI executes the test suite against the helper
- Helper entry → Publish workflow: released by · Package publishing is handled separately in GitHub Actions