jest-puppeteer icon indicating copy to clipboard operation
jest-puppeteer copied to clipboard

runScript is not defined

Open RachitSharmaHS opened this issue 3 years ago • 2 comments

💥 Regression Report

Tests don't run in an environment set up with runScript function when using jest version 24.9.0 and jest-environment-puppeteer 5.0.4.

Last working version

Worked up to version: 5.0.3

Stopped working in version: 5.0.4

To Reproduce

Run tests in an environment set up with the runScript function with jest version less than 27.0.0, and jest-environment-puppeteer 5.0.4.

Expected behavior

Tests fail with "runScript is not defined" error.

Explanation

This method was deprecated in jest 27.0.0 (and by extension in jest-environment-node) for test environment.

RachitSharmaHS avatar Jul 26 '21 06:07 RachitSharmaHS

Looks like we would just need to add a runScript method like https://github.com/facebook/jest/blob/2f6931e91d5ab126de70caf150c68709752e7f6c/packages/jest-environment-node/src/index.ts#L109-L114

And add a test or two.

If you want to create a PR I would be happy to review it :+1:

UziTech avatar Jul 26 '21 22:07 UziTech

Yes, I have the same issue when running on[email protected]and [email protected]. I am a bit restricted to the jest version since, it is the version from create-react-app@3.

I get this error:

 FAIL  test/unit/__tests__/dummy.test.js
  ● Test suite failed to run

    TypeError: this._environment.runScript is not a function

      at Runtime._execModule (node_modules/jest-runtime/build/index.js:856:41)

I can fix the testEnvironment variable in the jest config to node and it will work, but page and browser are not in the globals. But at least it runs. I am not using the react-scripts test commands but the jest commands directly.

I also added the runScript to the jest-environment-puppeteer, which solved the problem, but then the page and browser globals are still not available.

with:

import 'expect-puppeteer'
cross-env DEBUG=test  \
JEST_PUPPETEER_CONFIG=./test/visual/jest-puppeteer.config.js \
jest --runInBand --detectOpenHandles --config=./test/visual/jest.config.js

ngmiduc avatar May 26 '22 09:05 ngmiduc

Please upgrade to v8 and reopen submit a new issue if you experience this problem.

gregberge avatar Mar 07 '23 08:03 gregberge