feat(allure): screen diff plugin support by Raytek · Pull Request #134 · codeceptjs/codeceptjs-resemblehelper

@Raytek

@Raytek

@Raytek

@kobenguyent kobenguyent changed the title Allure screen diff plugin support feat(allure): screen diff plugin support

Jan 23, 2024

@kobenguyent

@Raytek

Choose a reason for hiding this comment

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

Pull Request Overview

Adds Allure screen-diff plugin support by changing how screenshots are attached when a visual mismatch exceeds tolerance.

  • Replace three image attachments with a single allure.addScreenDiff call.
  • Switch from Buffer attachments to base64-encoded strings.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +236 to +241

allure.addScreenDiff(
"Screen Diff",
fs.readFileSync(this._getBaseImagePath(baseImage, options), { encoding: "base64" }),
fs.readFileSync(this._getActualImagePath(baseImage), { encoding: "base64" }),
fs.readFileSync(this._getDiffImagePath(baseImage), { encoding: "base64" }),
);

Choose a reason for hiding this comment

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

CodeceptJS's Allure plugin does not expose addScreenDiff in supported versions; calling this will throw at runtime. Use standard attachments with the names expected by the Allure screen-diff plugin (expected, actual, diff), or feature-detect and fall back to addAttachment.

allure.addScreenDiff(
"Screen Diff",
fs.readFileSync(this._getBaseImagePath(baseImage, options), { encoding: "base64" }),
fs.readFileSync(this._getActualImagePath(baseImage), { encoding: "base64" }),
fs.readFileSync(this._getDiffImagePath(baseImage), { encoding: "base64" }),
);
allure.addAttachment(
"expected",
fs.readFileSync(this._getBaseImagePath(baseImage, options)),
"image/png"
);
allure.addAttachment(
"actual",
fs.readFileSync(this._getActualImagePath(baseImage)),
"image/png"
);
allure.addAttachment(
"diff",
fs.readFileSync(this._getDiffImagePath(baseImage)),
"image/png"
);

Copilot uses AI. Check for mistakes.

Comment on lines +238 to +240

fs.readFileSync(this._getBaseImagePath(baseImage, options), { encoding: "base64" }),
fs.readFileSync(this._getActualImagePath(baseImage), { encoding: "base64" }),
fs.readFileSync(this._getDiffImagePath(baseImage), { encoding: "base64" }),

Choose a reason for hiding this comment

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

Reading images as base64 strings increases memory/cpu and bloats attachments by ~33%. Prefer passing Buffers (omit the encoding option) to avoid unnecessary encoding and to keep report size smaller.

fs.readFileSync(this._getBaseImagePath(baseImage, options), { encoding: "base64" }),
fs.readFileSync(this._getActualImagePath(baseImage), { encoding: "base64" }),
fs.readFileSync(this._getDiffImagePath(baseImage), { encoding: "base64" }),
fs.readFileSync(this._getBaseImagePath(baseImage, options)),
fs.readFileSync(this._getActualImagePath(baseImage)),
fs.readFileSync(this._getDiffImagePath(baseImage)),

Copilot uses AI. Check for mistakes.

thomashohn

@Raytek