Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronous step or logStep methods #1201

Open
egorvas opened this issue Dec 1, 2024 · 3 comments
Open

Synchronous step or logStep methods #1201

egorvas opened this issue Dec 1, 2024 · 3 comments

Comments

@egorvas
Copy link

egorvas commented Dec 1, 2024

Hi guys. If I am not mistaken, in the current implementation of allure-js, it's not possible to create a step from a sync context as I was able to before with the startStep/endStep functions, is it?

Is your feature request related to a problem? Please describe.

I'm integrating Allure reporting into my testing framework, and I need to create Allure steps synchronously without using await. Currently, when I call allure.step or allure.logStep synchronously, the steps do not display correctly in the Allure report.

From what I understand, it's currently not possible to invoke step or logStep synchronously, as they are designed to be asynchronous and require await. This limitation poses a challenge when working with synchronous code, particularly with assertion libraries like Chai's assert, which operates synchronously.

Describe the solution you'd like

I would like to have the ability to create Allure steps synchronously, without the need to use await. Specifically, having a synchronous version of logStep would be highly beneficial. This would allow seamless integration of Allure steps within synchronous code blocks and assertion libraries, without requiring the entire codebase to be refactored to support asynchronous operations.

I am looking for something like this:


const chaiAllurePlugin = function (_chai: any, utils: any) {
  const Assertion = _chai.Assertion
  const originalAssert = Assertion.prototype.assert

  Assertion.prototype.assert = function (...args: any[]) {
    const assertionMessage = utils.flag(this, "message") || "Chai assertion"
    allure.stepSync(assertionMessage, {
          originalAssert.apply(this, args)
    })
  }
}

export default chaiAllurePlugin
@baev
Copy link
Member

baev commented Dec 5, 2024

We'll be unable to provide the sync versions of Allure API due to limitations in some testing frameworks.

The new API is framework-agnostic (it can be used the same way in different frameworks). This allows us to provide integrations with additional testing tools (e.g., Axios to automatically request/response logging or Chai for automatic asserts logging).

Underneath, the new Allure API relies on the TestRuntime abstraction, which is used as a message hub between the test worker and reporter (since test frameworks may execute the reporter and test code in different workers).

Since some of the message hubs (e.g., in CucumberJS or Playwright) are async, we will not be able to ensure the proper delivery of test events when using synchronous runtime API calls (sync logStep can't be implemented in Playwright).

We don't like the idea of some parts of the API being unsupported by some frameworks, so we decided not to implement Allure Runtime API's sync versions.

However, in your case, since you're implementing a new integration with your custom test framework (I assume), you can implement the TestRuntime in a synchronous way (do all the logic synchronously and return resolved promise). This way, you'll not need to use the await keyword on the Allure Runtime API methods. You can even reexport synchronous versions of all Allure Runtime API methods to avoid IDE/linter warnings.

@egorvas
Copy link
Author

egorvas commented Dec 5, 2024

@baev thankyou for your replay. What I'm trying to add automatic logging of assertions in the chai framework. And I just can't do it correctly because of the asynchronicity. Judging by your message, there is already implemented support for allures in the chai and axios frameworks, where can I read about it?

@baev
Copy link
Member

baev commented Dec 5, 2024

@egorvas, it's only planned; there is no ETA yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants