Skip to content

fix: use happy-dom/jsdom types for envionmentOptions #7795

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

Merged
merged 5 commits into from
Apr 17, 2025

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Apr 4, 2025

Description

Using the same idea as vitejs/vite#18460.

It looks like happy-dom's dts includes invalid types (though largely completion should work), so it's breaking test/dts-config which tests with skipLibCheck: false.

node_modules/.pnpm/happy-dom@17.4.4/node_modules/happy-dom/lib/nodes/node/ICachedQuerySelectorResult.d.ts:4:21 - error TS2344: Type 'Element | null' does not satisfy the constraint 'WeakKey'.
  Type 'null' is not assignable to type 'WeakKey'.

4     result: WeakRef<Element | null> | null;
                      ~~~~~~~~~~~~~~

For now, I add a hack in test/dts-xxx to not pick up this error.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Apr 4, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d687e8c
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67ef38123604750008cb8bf8
😎 Deploy Preview https://deploy-preview-7795--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Apr 4, 2025

@vitest/browser

npm i https://pkg.pr.new/@vitest/browser@7795

@vitest/coverage-istanbul

npm i https://pkg.pr.new/@vitest/coverage-istanbul@7795

@vitest/coverage-v8

npm i https://pkg.pr.new/@vitest/coverage-v8@7795

@vitest/expect

npm i https://pkg.pr.new/@vitest/expect@7795

@vitest/mocker

npm i https://pkg.pr.new/@vitest/mocker@7795

@vitest/pretty-format

npm i https://pkg.pr.new/@vitest/pretty-format@7795

@vitest/runner

npm i https://pkg.pr.new/@vitest/runner@7795

@vitest/snapshot

npm i https://pkg.pr.new/@vitest/snapshot@7795

@vitest/ui

npm i https://pkg.pr.new/@vitest/ui@7795

@vitest/spy

npm i https://pkg.pr.new/@vitest/spy@7795

@vitest/utils

npm i https://pkg.pr.new/@vitest/utils@7795

vite-node

npm i https://pkg.pr.new/vite-node@7795

vitest

npm i https://pkg.pr.new/vitest@7795

@vitest/web-worker

npm i https://pkg.pr.new/@vitest/web-worker@7795

@vitest/ws-client

npm i https://pkg.pr.new/@vitest/ws-client@7795

commit: 98f4d1a

@hi-ogawa hi-ogawa marked this pull request as ready for review April 4, 2025 02:55
@sheremet-va sheremet-va merged commit 6743008 into vitest-dev:main Apr 17, 2025
12 of 14 checks passed
@hi-ogawa hi-ogawa deleted the fix-optional-peer-dep-types branch April 17, 2025 23:48
schogges pushed a commit to kumahq/kuma-gui that referenced this pull request Apr 23, 2025
v3.1.2
   🐞 Bug Fixes
Add global chai variable in vitest/globals (fix: #7474)  -  by @​Jay-Karia in vitest-dev/vitest#7771 and vitest-dev/vitest#7474 (d9297)
Prevent modifying test.exclude when same object passed in coverage.exclude  -  by @​AriPerkkio in vitest-dev/vitest#7774 (c3751)
Fix already hoisted mock  -  by @​hi-ogawa in vitest-dev/vitest#7815 (773b1)
Fix test.scoped inheritance  -  by @​hi-ogawa in vitest-dev/vitest#7814 (db6c3)
Remove pointer-events-none after resizing the left panel  -  by @​alexprudhomme in vitest-dev/vitest#7811 (a7e77)
Default to run mode when stdin is not a TTY  -  by @​kentonv, @​hi-ogawa and @​sheremet-va in vitest-dev/vitest#7673 (6358f)
Use happy-dom/jsdom types for envionmentOptions  -  by @​hi-ogawa in vitest-dev/vitest#7795 (67430)
browser:
Fix transform error before browser server initialization  -  by @​hi-ogawa in vitest-dev/vitest#7783 (5f762)
Fix mocking from outside of root  -  by @​hi-ogawa in vitest-dev/vitest#7789 (03f55)
Scale iframe for non ui case  -  by @​hi-ogawa in vitest-dev/vitest#6512 (c3374)
coverage:
await profiler calls  -  by @​AriPerkkio in vitest-dev/vitest#7763 (795a6)
Expose profiling timers  -  by @​AriPerkkio in vitest-dev/vitest#7820 (5652b)
deps:
Update all non-major dependencies  -  in vitest-dev/vitest#7765 (7c3df)
Update all non-major dependencies  -  in vitest-dev/vitest#7831 (15701)
runner:
Correctly call test hooks and teardown functions  -  by @​sheremet-va in vitest-dev/vitest#7775 (3c00c)
Show stacktrace on test timeout error  -  by @​hi-ogawa in vitest-dev/vitest#7799 (df33b)
ui:
Load panel sizes from storage on initial load  -  by @​userquin in vitest-dev/vitest#7265 (6555d)
vite-node:
Named export should overwrite export all  -  by @​hi-ogawa in vitest-dev/vitest#7846 (5ba0d)
Add ERR_MODULE_NOT_FOUND code error if module cannot be loaded  -  by @​sheremet-va in vitest-dev/vitest#7776 (f9eac)
   🏎 Performance
browser: Improve browser parallelisation  -  by @​sheremet-va in vitest-dev/vitest#7665 (816a5)
@skovhus
Copy link

skovhus commented May 16, 2025

This introduced a regression for us. Now vitest pulls in typescript/lib/lib.dom.d.ts automatically, which can clash when using third party types like @cloudflare/workers-types (which shouldn't be combined with TypeScript's lib.dom).

We can't really upgrade to the latest version of vitest due to this. Not sure if there is any workaround?

@hi-ogawa
Copy link
Contributor Author

This introduced a regression for us. Now vitest pulls in typescript/lib/lib.dom.d.ts automatically, which can clash when using third party types like @cloudflare/workers-types (which shouldn't be combined with TypeScript's lib.dom).

Can you provide a reproduction (what's different before and after this chanege)? I'm not entirely sure how this happens exactly and whether this is a bad behavior. If you use jsdom or happy-dom and you also import vitest somewehre, then such behavior seems somewhat expected (or maybe it's jsdom or happy-dom issues) 🤔

Not sure if there is any workaround?

I think you can use tsconfig paths to avoid loading the real one. Actually this is the trick I used for tests in this PR since the official happy-dom typing was partially broken.

// tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "happy-dom": ["./happy-dom-patch.ts"],
      "jsdom": ["./jsdom-patch.ts"],
    }
  }
}

// happy-dom-patch.ts
export {}

// jsdom-patch.ts
export {}

@skovhus
Copy link

skovhus commented May 16, 2025

I'm not using jsdom or happy dom, it's a cloudflare worker package inside a mono repo. For some reason I see DOM packages being pulled in. tsc --listFiles | grep dom before 3.1.2 doesn't show anything, but with 3.1.2 happy dom and typescript/lib/lib.dom.d.ts shows up.

Not sure if it's related to our mono repo setup.

@hi-ogawa
Copy link
Contributor Author

@skovhus I think the workaround I mentioned above should be fine if you are not using happy-dom at all. If you want us to dig in, please feel free to raise an issue. I cannot tell yet if this is something Vitest should take it into account or a typing issue of happy-dom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants