question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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;
    }
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mmarkelovcommented, Oct 23, 2020

@thernstig yeah! That make sense. I put it here

0reactions
thernstigcommented, Oct 22, 2020

That made it, thanks! Maybe there should be a note about this in the README?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest with Vue3 ERROR: Cannot destructure property 'config' of ...
On the project, I used Vue3, Vite, Typescript and testing tool Jest. I found only 1 solution to fix this. I have the...
Read more >
jest-playwright-preset - npm Package Health Analysis - Snyk
For more information about how to use this package see README ... A custom path can be specified to the jest-playwright.config.js file within...
Read more >
jest-playwright-preset: Versions - Openbase
Full version history for jest-playwright-preset including change logs. ... Fix TypeError: Cannot destructure property name of 'undefined' or 'null'.
Read more >
Cannot destructure property 'config' of +'cacheKeyOptions' as ...
Cannot destructure property 'config' of +'cacheKeyOptions' as it is undefined. ... You can check if you're using the latest version with: npm outdated...
Read more >
Using Jest with Playwright
Having a test runner like Jest configured has a lot of benefits instead of writing your tests from scratch. It gives you out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found