JSPM

  • Created
  • Published
  • Downloads 1365609
  • Score
    100M100P100Q203988F
  • License MIT

Running tests using Jest & Playwright.

Package Exports

  • jest-playwright-preset
  • jest-playwright-preset/lib/PlaywrightEnvironment

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jest-playwright-preset) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Jest Playwright

Running your tests using Jest & Playwright

npm install jest-playwright-preset playwright

Usage

Update your Jest configuration:

"jest": {
    "preset": "jest-playwright-preset"
  }

Configuration

You can specify a jest-playwright.config.js at the root of the project or define a custom path using JEST_PLAYWRIGHT_CONFIG environment variable. It should export a config object.

  • launchBrowserApp <[object]> All Playwright launch options can be specified in config. Since it is JavaScript, you can use all stuff you need, including environment.
  • context <[object]> All Playwright context options can be specified in config.
  • browser <[string]>. Define a browser to run tests into.
    • chromium Each test runs Chromium.
    • firefox Each test runs Firefox.
    • webkit Each test runs Webkit.
  • device <[string]>. Define a device to run tests into. Actual list of devices can be found here
  • exitOnPageError <[boolean]> Exits page on any global error message thrown. Defaults to true.

Browser type

You can specify browser in multiple ways:

  • With BROWSER environment variable
  • With your jest-playwright.config.js

If you don't pass any value it will be use chromium as default

Use Playwright in your tests:

"test": "BROWSER=chromium jest"
describe('Google', () => {
  beforeAll(async () => {
    await page.goto('https://whatismybrowser.com/')
  })

  it('should display "google" text on page', async () => {
    const browser = await page.$eval('.string-major a', el => el.text)
    expect(browser).toContain('Chrome')
  })
})

Inspiration

Thanks to Smooth Code for great jest-puppeteer.

License

MIT