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

Compiler errors extending PuppeteerEnvironment #546

Closed
colinrotherham opened this issue Mar 21, 2023 · 0 comments · Fixed by #547
Closed

Compiler errors extending PuppeteerEnvironment #546

colinrotherham opened this issue Mar 21, 2023 · 0 comments · Fixed by #547

Comments

@colinrotherham
Copy link
Contributor

🐛 Bug Report

The class interface for PuppeteerEnvironment is a named default export:

export { JestPuppeteerConfig, JestPuppeteerGlobal, PuppeteerEnvironment as default };

To Reproduce

But when importing into Node.js (without Babel or a bundler) the source now differs to the types:

class CustomEnvironment extends PuppeteerEnvironment {} // Actual default export, won't compile
class CustomEnvironment extends PuppeteerEnvironment.default {} // But types use named export

Libraries like glob support both by adding default as a property
isaacs/node-glob@c381907

Expected behavior

Compilation should complete without error but the following is shown:

src/custom-environment.js:3:33 - error TS2507: Type 'typeof import("/path/to/project/node_modules/jest-environment-puppeteer/dist/index")' is not a constructor function type.

3 class CustomEnvironment extends PuppeteerEnvironment {
                                  ~~~~~~~~~~~~~~~~~~~~

src/custom-environment.js:8:22 - error TS2339: Property 'global' does not exist on type 'CustomEnvironment'.

8     console.log(this.global)
                       ~~~~~~

src/custom-environment.js:9:22 - error TS2339: Property 'context' does not exist on type 'CustomEnvironment'.

9     console.log(this.context)
                       ~~~~~~~

Link to repl or repo (highly encouraged)

Reproduced in example repo:
https://github.com/colinrotherham/jest-environment-puppeteeer-types

colinrotherham added a commit to alphagov/govuk-frontend that referenced this issue Mar 21, 2023
colinrotherham added a commit to alphagov/govuk-frontend that referenced this issue Mar 22, 2023
colinrotherham added a commit to alphagov/govuk-frontend that referenced this issue Mar 22, 2023
colinrotherham added a commit to alphagov/govuk-frontend that referenced this issue Mar 22, 2023
colinrotherham added a commit to alphagov/govuk-frontend that referenced this issue Mar 23, 2023
colinrotherham added a commit to alphagov/govuk-frontend that referenced this issue Mar 23, 2023
gregberge added a commit that referenced this issue Mar 24, 2023
Fix #545
Fix #546

jest-environment-puppeteer now exports `TestEnvironment`. Since custom environment creation was not public, it is not considered as a breaking change.
gregberge added a commit that referenced this issue Mar 24, 2023
Fix #545
Fix #546

jest-environment-puppeteer now exports `TestEnvironment`. Since custom environment creation was not public, it is not considered as a breaking change.
gregberge added a commit that referenced this issue Mar 24, 2023
Fix #545
Fix #546

jest-environment-puppeteer now exports `TestEnvironment`. Since custom environment creation was not public, it is not considered as a breaking change.
colinrotherham added a commit to alphagov/govuk-frontend that referenced this issue Mar 24, 2023
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

Successfully merging a pull request may close this issue.

1 participant