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.

Allow jest-playwright settings in jest.config.js

See original GitHub issue

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

While not a critical issue, allowing jest-playwright settings to live inside of the standard jest.config.js file would simplify the configuration (fewer config files) and make it easier to understand how Jest is configured by allowing more (hopefully, all) settings to live in one place.

As a real-world example, I am currently working on an open-source project that uses jest-playwright for e2e tests but only Jest for unit and integration tests. You can view the work-in-progress implementation here:

I’m using Jest’s projects option to unify configurations for all test types. Because jest-playwright’s config exists in a separate file that only applies to a single test type (e2e), I’ve moved jest-playwright.config.js into the /tests/e2e/config/ folder, which means my Jest configuration is now split between /jest.config.js and /tests/e2e/config/jest-playwright.config.js. Everything works as expected, but understanding the overall test setup is more difficult for new contributors because configuration files are scattered throughout the project.

Describe the solution you’d like

Allow jest-playwright settings live in jest.config.js using a "jest-playwright" property name:

// jest.config.js
module.exports = {
  'jest-playwright': {
    browsers: [
      'chromium',
      'firefox',
      'webkit',
    ]
  }
};

Jest-playwright settings should also be allowed to live under a camelCase jestPlaywright property name. This format is consistent with Jest’s property name convention:

// jest.config.js
module.exports = {
  jestPlaywright: {
    // ...
  }
};

The configuration should also work for those using Jest’s projects option. Hopefully this will “just work” because of how Jest operates, but I wanted to mention it since Jest projects provide an easy way to isolate jest-playwright to e2e tests.

// jest.config.js
module.exports = {
  projects: [
    // Unit Tests (Jest)
    {
      displayName: 'unit',
      testMatch: ['<rootDir>/tests/unit/*.test.js'],
    },
    // Integration Tests (Jest)
    {
      displayName: 'integration',
      testMatch: ['<rootDir>/tests/integration/*.test.js'],
    },
    // E2E Tests (Jest + Playwright)
    {
      displayName: 'e2e',
      testMatch: ['<rootDir>/tests/e2e/*.test.js'],
      preset: 'jest-playwright-preset',
      jestPlaywright': {
        browsers: [
          'chromium',
          'firefox',
          'webkit',
        ]
      }
    }
  ]
};

(Note above that I personally prefer the camelCase jestPlaywright property name for consistency).

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jhildenbiddlecommented, Jul 21, 2020

@mmarkelov

What about leveraging Jest’s testEnvironmentOptions option? The documentation states the following:

Test environment options that will be passed to the testEnvironment. The relevant options depend on the environment. For example you can override options given to jsdom such as {userAgent: "Agent/007"}.

Perhaps I’m misunderstanding the difference between “environment” and “preset”, but my understanding is that when Jest is configured with preset: jest-playwright-preset, jest-playwright-preset is the environment. If this is the case, then it seems like jest-playwright options could be passed in jest.config.js as follows:

// jest.config.js
module.exports = {
  preset: 'jest-playwright-preset',
  testEnvironmentOptions: {
    // jest-playwright options here...
    browsers: [
      'chromium',
      'firefox',
      'webkit',
    ]
  }
};
1reaction
mmarkelovcommented, Jul 19, 2020

Also I found that ts-jest for example use global property to pass config with jest.config.js:

// jest.config.js:

module.exports = {
 ...,
  globals: {
    'ts-jest': {
      ...,
    },
  },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Jest with Playwright
Create a file called jest-playwright.config.js in the root directory of your project to use the settings which are described in the ...
Read more >
Configuring Jest
Here is how to enable it globally (additional options are not supported):. JavaScript; TypeScript. /** @type {import('jest').Config} */
Read more >
Playwright Jest Cloud Testing - TestingBot
Jest-Playwright allows you to run tests with Jest on browsers controlled ... Next, specify these settings in your Jest configuration file ( jest.config.js...
Read more >
Getting started with Playwright with Jest and TypeScript
npm install --save-dev jest-playwright-preset. Let's add a jest configuration file called jest.config.js that has the following content:.
Read more >
Start UI tests with Playwright + Jest + Typescript
npm install — save-dev jest-playwright-preset. 5. Set up Jest Config & test config with package.json. jest.config.js module.exports = {
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