# codeceptjs/codeceptjs-resemblehelper architecture

> Architecture diagram of the GitHub repository codeceptjs/codeceptjs-resemblehelper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codeceptjs/codeceptjs-resemblehelper
- Repository: https://github.com/codeceptjs/codeceptjs-resemblehelper

## Overview

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: [`src/index.ts`](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/src/index.ts) (Helper entry), [`__test__/screenshots`](https://github.com/codeceptjs/codeceptjs-resemblehelper/tree/master/__test__/screenshots) (Local images), [`__test__/steps_file.ts`](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/__test__/steps_file.ts) (Step defs), [`__test__/visual_test.ts`](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/__test__/visual_test.ts) (Codecept tests)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_test["Test Harness"]
  node_n_codecept_tests["Codecept tests<br/>specs<br/>[visual_test.ts]"]
  node_n_codecept_conf["Codecept config<br/>runtime config<br/>[codecept.conf.ts]"]
  node_n_steps["Step defs<br/>test glue<br/>[steps_file.ts]"]
end

subgraph group_g_helper["Helper Core"]
  node_n_helper_entry["Helper entry<br/>CodeceptJS helper<br/>[index.ts]"]
  node_n_helper_api["Visual API<br/>helper methods"]
  node_n_full_compare["Full compare<br/>image diff path"]
  node_n_element_compare["Element compare<br/>element diff path"]
  node_n_screenshot_write["Screenshot write<br/>output path"]
end

subgraph group_g_storage["Storage"]
  node_n_baseline_resolver[("Baseline lookup<br/>file resolution")]
  node_n_local_files[("Local images<br/>filesystem")]
  node_n_s3_store[("S3 store<br/>object storage")]
end

subgraph group_g_external["External Boundaries"]
  node_n_diff_engine{{"resemble.js<br/>diff engine"}}
  node_n_browser(("Browser runtime<br/>automation context"))
  node_n_allure["Allure<br/>reporting"]
  node_n_test_workflow["Test workflow<br/>CI workflow<br/>[test.yml]"]
  node_n_publish_workflow["Publish workflow<br/>CI workflow<br/>[npm-publish.yml]"]
end

node_n_codecept_tests -->|"uses"| node_n_steps
node_n_steps -->|"drives"| node_n_helper_entry
node_n_codecept_conf -->|"loads"| node_n_helper_entry
node_n_helper_entry -->|"exposes"| node_n_helper_api
node_n_helper_api -->|"seeVisualDiff"| node_n_full_compare
node_n_helper_api -->|"seeVisualDiffForElement"| node_n_element_compare
node_n_helper_api -->|"screenshotElement"| node_n_screenshot_write
node_n_full_compare -->|"captures"| node_n_browser
node_n_element_compare -->|"reads coords"| node_n_browser
node_n_screenshot_write -->|"captures"| node_n_browser
node_n_full_compare -->|"loads baseline"| node_n_baseline_resolver
node_n_element_compare -->|"loads baseline"| node_n_baseline_resolver
node_n_baseline_resolver -->|"reads"| node_n_local_files
node_n_full_compare -->|"diffs"| node_n_diff_engine
node_n_element_compare -->|"diffs"| node_n_diff_engine
node_n_diff_engine -->|"attaches"| node_n_allure
node_n_full_compare -->|"writes diff"| node_n_local_files
node_n_screenshot_write -->|"writes output"| node_n_local_files
node_n_helper_entry -.->|"optional remote"| node_n_s3_store
node_n_s3_store -->|"provides baselines"| node_n_baseline_resolver
node_n_full_compare -.->|"validated by"| node_n_test_workflow
node_n_helper_entry -.->|"released by"| node_n_publish_workflow

click node_n_codecept_tests "https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/__test__/visual_test.ts"
click node_n_codecept_conf "https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/__test__/codecept.conf.ts"
click node_n_steps "https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/__test__/steps_file.ts"
click node_n_helper_entry "https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/src/index.ts"
click node_n_local_files "https://github.com/codeceptjs/codeceptjs-resemblehelper/tree/master/__test__/screenshots"
click node_n_test_workflow "https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/.github/workflows/test.yml"
click node_n_publish_workflow "https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/.github/workflows/npm-publish.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_codecept_tests,node_n_codecept_conf,node_n_steps toneBlue
class node_n_helper_entry,node_n_helper_api,node_n_full_compare,node_n_element_compare,node_n_screenshot_write toneAmber
class node_n_baseline_resolver,node_n_local_files,node_n_s3_store toneMint
class node_n_diff_engine,node_n_browser,node_n_allure,node_n_test_workflow,node_n_publish_workflow toneRose
```

## Components

### Test Harness

CodeceptJS-based validation and visual specs

- [Codecept tests](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/__test__/visual_test.ts): specs · Top-level visual test entrypoints that drive the helper · `__test__/visual_test.ts`
- [Codecept config](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/__test__/codecept.conf.ts): runtime config · Loads the helper into the test runner · `__test__/codecept.conf.ts`
- [Step defs](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/__test__/steps_file.ts): test glue · Typed step definitions used by the test harness · `__test__/steps_file.ts`

### Helper Core

The exported CodeceptJS helper and its comparison pipeline

- [Helper entry](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/src/index.ts): CodeceptJS helper · Single exported helper consumed by CodeceptJS · `src/index.ts`
- **Visual API**: helper methods · Public methods for screenshot capture and visual comparison
- **Full compare**: image diff path · Compares a captured screenshot against a baseline
- **Element compare**: element diff path · Compares only the active element region on the page
- **Screenshot write**: output path · Writes an element screenshot to the configured output directory

### Storage

Local screenshots, baselines, diffs, and optional S3-backed storage

- **Baseline lookup**: file resolution · Finds the matching baseline image from the configured base folder
- [Local images](https://github.com/codeceptjs/codeceptjs-resemblehelper/tree/master/__test__/screenshots): filesystem · Base, diff, and output image folders on disk · `__test__/screenshots`
- **S3 store**: object storage · Optional remote bucket for baselines, outputs, and diffs

### External Boundaries

Browser automation, diff engine, reporting, and release workflow

- **resemble.js**: diff engine · Computes mismatch percentage and diff artifacts
- **Browser runtime**: automation context · Provides screenshots and element coordinates
- **Allure**: reporting · Receives attachments for mismatches above tolerance
- [Test workflow](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/.github/workflows/test.yml): CI workflow · GitHub Actions job that validates the package · `.github/workflows/test.yml`
- [Publish workflow](https://github.com/codeceptjs/codeceptjs-resemblehelper/blob/master/.github/workflows/npm-publish.yml): CI workflow · GitHub Actions job that publishes the package to npm · `.github/workflows/npm-publish.yml`

## Connections

- 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
