Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Using a custom environment per the docs give: "TypeError: Cannot destructure property 'collectCoverage' of 'this._jestPlaywrightConfig' as it is undefined." #413

@thernstig

Description

@thernstig

Describe the bug
Using a custom environment per the docs give: TypeError: Cannot destructure property 'collectCoverage' of 'this._jestPlaywrightConfig' as it is undefined. The custom environment has been configured according to https://github.com/playwright-community/jest-playwright#usage-with-jest-circus

To Reproduce
Add a custom environment according to https://github.com/playwright-community/jest-playwright#usage-with-jest-circus

Expected behavior
It should work.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Ubuntu 18.04
  • Playwright version: 1.5.1
  • jest-playwright version: 1.3.1

Jest configuration (Either in the package.json > jest or in the jest.config.js):

module.exports = {
 // Test sequencers cannot exist in projects, only in global config
 testSequencer: './tests/e2e/util/jestSequencer.js',
 projects: [
   {
     displayName: 'E2E',
     rootDir: 'tests/e2e',
     testEnvironment: '<rootDir>/util/CustomEnvironment.js',
     testRunner: 'jest-circus/runner',
     runner: '<rootDir>/util/serialJestRunner.js',
     preset: 'jest-playwright-preset',
     globals: {
       TEST_URL: testUrl,
     },
     setupFilesAfterEnv: ['<rootDir>/jest.setup.js', 'expect-playwright'],
     globalSetup: '<rootDir>/util/globalSetup.js',
     globalTeardown: '<rootDir>/util/globalTeardown.js',
   },
 ],
};

Additional context
This is the custom environment:

class CustomEnvironment extends PlaywrightEnvironment {
  constructor(config) {
    super(config);
    this.config = config;
  }

  async setup() {
    await super.setup();
    this.allure = new Allure();
    this.allure.setOptions({
      targetDir: `${this.config.rootDir}/allure_results`,
    });
  }

  async handleTestEvent(event) {
    switch (event.name) {
      case 'start_describe_definition':
        this.allure.startSuite(event.blockName);
        break;

      case 'test_start':
        this.allure.startCase(event.test.name);
        break;

      case 'test_done': {
        if (event.test.errors.length > 0) {
          const screenshot = await this.global.page.screenshot();
          this.allure.addAttachment('screenshot', screenshot, 'image/png');
          this.allure.endCase('failed', event.error);
        } else this.allure.endCase('passed');
        break;
      }

      case 'run_finish': {
        this.allure.endSuite();
        break;
      }

      default:
        break;
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions