Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is @types/jest-environment-puppeteer still required? #568

Open
pyoor opened this issue Oct 25, 2023 · 3 comments
Open

Is @types/jest-environment-puppeteer still required? #568

pyoor opened this issue Oct 25, 2023 · 3 comments

Comments

@pyoor
Copy link
Contributor

pyoor commented Oct 25, 2023

After updating jest-environment-puppeteer to 9.0.1, I get the following typescript compiler error:
error TS2304: Cannot find name 'page'.

The README notes that typescript definitions are now provided for jest-puppeteer versions > v8.0.0. However, the only way I'm able to resolve the issue is by installing the @types/jest-environment-puppeteer. Is this something wrong with my configuration?

Relevant dependencies:

    "@jest/globals": "^29.7.0",
    "jest": "^29.7.0",
    "jest-environment-puppeteer": "^9.0.1",
    "puppeteer-core": "^21.4.1",
    "ts-jest": "^29.1.1",
    "typescript": "^5.2.2"

tsconfig.json:

{
  "compilerOptions": {
    "noEmit": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "resolveJsonModule": true,
    "target": "ES2022",
    "lib": [
      "ES2022",
      "DOM"
    ],
    "strict": false,
  }
}

jest.config.ts

export default {
  preset: "ts-jest",
  globalSetup: "jest-environment-puppeteer/setup",
  globalTeardown: "jest-environment-puppeteer/teardown",
  testEnvironment: "jest-environment-puppeteer",
  testTimeout: 30000,
}
@erik-stodola
Copy link

@pyoor Thank you kind sir for this wisdom I was experiencing a similar issue and adding the latest @types/jest-environment-puppeteer to my devDependencies in my package.json helped me resolve my problem.

In my case version 5.0.6 worked just fine of @types/jest-environment-puppeteer - https://www.npmjs.com/package/@types/jest-environment-puppeteer

@jason-ha
Copy link

jason-ha commented Feb 8, 2024

I am unable to use @types/jest-environment-puppeteer to work around this while also using [email protected]. Installing @types/jest-environment-puppeteer devDependency then results in:

node_modules/.pnpm/[email protected]/node_modules/expect-puppeteer/dist/index.d.ts:1:38 - error TS2305: Module '"puppeteer"' has no exported member 'FrameWaitForFunctionOptions'.

1 import { Page, Frame, ElementHandle, FrameWaitForFunctionOptions, ClickOptions, Dialog } from 'puppeteer';

I see from lock file that using @types/[email protected] results in the addition of several older and duplicate packages like [email protected] where without already had dependency on jest-environment-node/29.7.0.

Directly @types/jest-environment-puppeteer/5.0.6 has dependencies:

      '@jest/types': 26.6.2
      '@types/puppeteer': 5.4.7  <-- does not have FrameWaitForFunctionOptions
      jest-environment-node: 27.5.1

@jason-ha
Copy link

jason-ha commented Feb 8, 2024

The difference I see in the @types versus package is that the global additions are not declared. @types has:

declare global {
    const browser: Browser;
    const context: BrowserContext;
    const page: Page;
    const jestPuppeteer: JestPuppeteer;
}

Per the difficulties I ran into, I built a local @types/jest-environment-puppeteer that re-exports jest-environment-puppeteer with the addition of global declaration:

declare global {
	const browser: JestPuppeteerGlobal["browser"];
	const context: JestPuppeteerGlobal["context"];
	const page: JestPuppeteerGlobal["page"];
	const jestPuppeteer: JestPuppeteerGlobal["jestPuppeteer"];
}

DLehenbauer added a commit to microsoft/FluidFramework that referenced this issue Feb 8, 2024
Upgrades puppeteer and related dependencies to the latest version.

- Fix some logic for a few typings that now come through properly.
- Handle puppeteer breaking change of toMatch -> toMatchTextContext.
- Use headless "shell" mode until use of new mode can be investigated.

jest-environment-puppeteer is not providing typing for its globals, but
old (stale types) @types/jest-environment-puppeteer will - see
argos-ci/jest-puppeteer#568. expect-puppeteer
however needs more recent puppeteer types that
@types/jest-environment-puppeteer interferes with. So, force any
lingering @types/puppeteer to just puppeteer

Future: get jest-environment-puppeteer fixed or replace @types with our
own to reduce garbage dependencies.

---------

Co-authored-by: Tyler Butler <[email protected]>
Co-authored-by: Daniel Lehenbauer <[email protected]>
kian-thompson pushed a commit to kian-thompson/FluidFramework that referenced this issue Feb 13, 2024
…9548)

Upgrades puppeteer and related dependencies to the latest version.

- Fix some logic for a few typings that now come through properly.
- Handle puppeteer breaking change of toMatch -> toMatchTextContext.
- Use headless "shell" mode until use of new mode can be investigated.

jest-environment-puppeteer is not providing typing for its globals, but
old (stale types) @types/jest-environment-puppeteer will - see
argos-ci/jest-puppeteer#568. expect-puppeteer
however needs more recent puppeteer types that
@types/jest-environment-puppeteer interferes with. So, force any
lingering @types/puppeteer to just puppeteer

Future: get jest-environment-puppeteer fixed or replace @types with our
own to reduce garbage dependencies.

---------

Co-authored-by: Tyler Butler <[email protected]>
Co-authored-by: Daniel Lehenbauer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants