playwright-community / jest-playwright

Running tests using Jest & Playwright
MIT License
532 stars 75 forks source link

Not Able to Use jest-playwright-preset in Playwright Docker Container #793

Closed lifan0127 closed 2 years ago

lifan0127 commented 2 years ago

Describe the bug The jest-playwright-preset package, when used in a playwright docker container, leads to TypeError: Class extends value #<Object> is not a constructor or null. It started to happen to me yesterday as all my CI tests are failing due to this error. I am not sure whether jest-playwright-preset or the playwright Docker image is contributing to this behavior.

To Reproduce Use this minimal Docker file:

FROM mcr.microsoft.com/playwright:v1.21.0-focal

WORKDIR /app

RUN npm install jest-playwright-preset

CMD node -e "const { globalSetup: playwrightGlobalSetup } = require('jest-playwright-preset')"

Build the image and run it: docker build -t app . && docker run --rm app

Expected behavior The following error message appeared:

/app/node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:59
    return class PlaywrightEnvironment extends RootEnv {
                                               ^

TypeError: Class extends value #<Object> is not a constructor or null
    at Object.getPlaywrightEnv (/app/node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:59:48)
    at Object.<anonymous> (/app/node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:242:27)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/app/node_modules/jest-playwright-preset/index.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)

Desktop (please complete the following information):

yannbf commented 2 years ago

We're experiencing the same issue:

TypeError: Jest: Got error running globalSetup - /tmp/storybook-e2e-testing/angular_modern_inline_rendering/node_modules/@storybook/test-runner/playwright/global-setup.js, 
reason: Class extends value #<Object> is not a constructor or null
    at Object.getPlaywrightEnv (/tmp/storybook-e2e-testing/angular_modern_inline_rendering/node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:59:5)
    at Object.<anonymous> (/tmp/storybook-e2e-testing/angular_modern_inline_rendering/node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:242:27)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Object.newLoader (/tmp/storybook-e2e-testing/angular_modern_inline_rendering/node_modules/pirates/lib/index.js:141:7)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/tmp/storybook-e2e-testing/angular_modern_inline_rendering/node_modules/jest-playwright-preset/index.js:1:18)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Object.newLoader (/tmp/storybook-e2e-testing/angular_modern_inline_rendering/node_modules/pirates/lib/index.js:141:7)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)

I wonder if this is related to the release of Jest 28?

lifan0127 commented 2 years ago

Hi @yannbf, thanks for your reply! I am at least temporarily back in business by specifying v27 for jest, jest-runner, and jest-environment-node.

    "jest": "^27.5.1",
    "jest-runner": "^27.5.1",
    "jest-environment-node": "27.5.1"
IanVS commented 2 years ago

It seems like the peerDependencies range should be locked down to < 28 for now until an update is made to support 28. https://github.com/playwright-community/jest-playwright/blob/c536b17fc391c272d9493f7e57bf19bfd223c264/package.json#L55-L58

IanVS commented 2 years ago

@mmarkelov @mxschmitt it seems that the jest-playwright runner is broken right now due to Jest 28 being released. Do either of you have a little time to look into this? This package is used by @storybook/test-runner, which cannot move over to the playwright runner directly. Any help or guidance would be much appreciated!

mxschmitt commented 2 years ago

Should be fixed in https://github.com/playwright-community/jest-playwright/pull/799 and a bugfix release gets released shortly.