allure-framework / allure-js

Allure integrations for JavaScript test frameworks
https://allurereport.org/
Apache License 2.0
230 stars 124 forks source link

Support before and after hooks #48

Closed just-boris closed 7 months ago

just-boris commented 5 years ago

I'm submitting a ...

What is the current behavior?

Currently, all steps and attachments in before and after sections are getting ignored. We should provide an ability to record them to the report.

What is the expected behavior?

this code should work, attachment added to the report.

before(() => {
   allure.attachment('from before', 'hello!', ContentType.TEXT);
})

Please tell us about your environment:

Allure version 2.7.0
Test framework jest@latest
Allure adaptor allure-mocha@latest
Generate report using allure-jenkins@latest

Other information

[//]: # ( . e.g. detailed explanation, stacktraces, related issues, suggestions . how to fix, links for us to have more context, eg. Stackoverflow, Gitter etc )

guitartsword commented 4 years ago

I want to add a file with the current test on an afterEach

afterEach(function () {
  allure.attachment('File att', 'File Data', ContentType.TEXT);
  allure.testAttachment('File tatt', 'File Data', ContentType.TEXT);
  allure.createAttachment('File catt', 'File Data', ContentType.TEXT);
});

Opening the allure-results folder I can see the attachment was created, but the test doesn't have the files. I guess the problem is that the afterEach hook is treated as another test case and this test case is not generated causing the attachment that created not to be link to a test case.

What we want is something like the following:

describe('Suite Name', function () {
  before(function () {
    allure.tag('first');
    allure.tag('before');
  });
  after(function () {
    allure.tag('last');
    allure.tag('after');
  });
  beforeEach(function () {
    allure.tag('beforeEach');
  });
  afterEach(function () {
    allure.tag('afterEach');
  });
  it('Test One', function () {
    allure.issue('1', 'https://www.example.com?issue=1');
  });
  it('Test Two', function () {
    allure.issue('2', 'https://www.example.com?issue=2');
  });
  it('Test Three', function () {
    allure.issue('3', 'https://www.example.com?issue=3');
  });
});

Notes:

sskorol commented 4 years ago

after hook should work as soon as #138 is merged and a new version is released. In terms of before hook, there's an issue in Mocha (https://github.com/mochajs/mocha/issues/4266) which adds a confusion to the current codebase. So at least we should wait until it's fixed.