wix-incubator / jest-allure2-reporter

🦉📊 Idiomatic Jest reporter for Allure Framework
https://wix-incubator.github.io/jest-allure2-reporter/
MIT License
9 stars 0 forks source link

Screenshots when a test failed? #5

Open damasofc opened 1 year ago

damasofc commented 1 year ago

This feature is really important please so we can get screenshots on the report when a test fails

I had this with detox:

const Allure = require('allure-js-commons'); // version "1.3.2",
const fs = require('fs');
const stripAnsi = require('strip-ansi');

class AllureReporterCircus {

  constructor({ detox }) {
    this.allure = new Allure();
    this.detox = detox;
  }

  run_describe_start(event) {
    if (event.describeBlock.parent !== undefined) {
      this.allure.startSuite(event.describeBlock.name);
    }
  }

  run_describe_finish(event) {
    if (event.describeBlock.parent !== undefined) {
      this.allure.endSuite();
    }
  }

  test_start(event) {
    const { test } = event;
    this.allure.startCase(test.name)
  }

  async test_done(event) {
    if (event.test.errors.length > 0) {
      const { test } = event;
      const screenshotPath = await this.detox.device.takeScreenshot(`${test.startedAt}-failed`);
      const buffer = fs.readFileSync(`${screenshotPath}`);
      this.allure.addAttachment('Screenshot test failue', Buffer.from(buffer, 'base64'), 'image/png');

      const err = test.errors[0][0];
      err.message = stripAnsi(err.message);
      err.stack = stripAnsi(err.stack);

      this.allure.endCase('failed', err);
    }
    else {
      this.allure.endCase('passed')
    }
  }

  test_skip(event) {
    const { test } = event;
    this.allure.startCase(test.name);
    this.allure.pendingCase(test.name);
  }
}

module.exports = AllureReporterCircus;

Is there a way I could have this with jest-allure2-reporter?

noomorph commented 1 year ago

Sure, I realize the importance of this feature. This is blocked currenly by #4, and I plan to renew works on it very soon.

This is exactly the reason why https://github.com/wix/Detox/issues/2337 is still open.

I'll leave your issue open for other people looking for the screenshots functionality so they don't create duplicates.

Thanks for checking out this repo. I hope it brings you joy soon.

noomorph commented 11 months ago

I think that ETA for Detox+Allure is likely to be around December 2023.

Today I released the alpha v2 of jest-allure2-reporter, but it will take some time to rewrite the artifacts subsystem in Detox so it can be easily integrated with it.

The rewrite is mostly about simplification of the source code of Detox, but since there's a huge piece of it (around 10k lines of code, AFAIR), it is not that trivial. 🫠

professorkolik commented 1 month ago

@noomorph any new ETA on this? thank you