Skip to content

createJestEnvironment doesn't support #handleTestEvent #1289

@ma-nk

Description

@ma-nk

Describe the bug
I am using jest-puppeteer's PuppeteerEnvrironment together with allure-jest reporter. Everything seems to work well, except of #handleTestEvent function from custom env:

To Reproduce
custom-environment.ts:

import { createJestEnvironment } from "allure-jest/factory";
import PuppeteerEnvironment from "jest-environment-puppeteer";

class CustomEnvironment extends PuppeteerEnvironment {
  async handleTestEvent(event) {
    console.error(
      `handleTestEvent: ${event.name}, errors: ${event.test?.errors?.length}`,
    );
    if (event.name === "test_fn_failure") {
         this.global.page.screenshot(...);
      }
    }
  }
}

module.exports = createJestEnvironment(CustomEnvironment);

Expected behavior
function is invoked

Additional context
This is needed to ensure screenshots on failure are created consistently, i.e. when expect.getState() assertions pass, but test throws unrelated error in runtime (i.e. originating from internal component):

const hasCurrentTestFailed = () => {
  const { assertionCalls, numPassingAsserts } = expect.getState();
  return assertionCalls === 0 || assertionCalls > numPassingAsserts;
};

afterEach(async () => {
  try {
    if (hasCurrentTestFailed()) {
   // unreachable code ...
     page.screenshot()

Metadata

Metadata

Assignees

Labels

theme:jestJest related issuetype:bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions