Skip to content

Main entry should not load global expect typing#1496

Merged
christian-bromann merged 1 commit intowebdriverio:mainfrom
naruaway:entrypoint-typing
Mar 22, 2024
Merged

Main entry should not load global expect typing#1496
christian-bromann merged 1 commit intowebdriverio:mainfrom
naruaway:entrypoint-typing

Conversation

@naruaway
Copy link
Copy Markdown
Contributor

@naruaway naruaway commented Mar 17, 2024

Fixes #1492

Loading jest-global.d.ts in the TypeScript compilation makes expect global symbol available in type level.

Currently, just importing "expect-webdriverio" loads jest-global.d.ts. However, importing "expect-webdriverio" does not actually load expect in the runtime global scope.

Because of this mismatch, when using "expect-webdriverio" as standalone npm package like import {expect as myExpect} from "expect-webdriverio", TypeScript cannot emit error for the following broken script:

import {expect as myExpect} from 'expect-webdriverio';

expect(true).toBe(true);

Note that I initially tried removing ExpectWebdriverIO namespace completely by simply relying on TypeScript modules (tsconfig.json with declaration:true) but I just realized that will be unacceptable breaking change so I kept the diff minimum.

Verification

I built 1a7f734 locally (npm pack) and tested with small project and confirmed that now global expect symbol properly causes type error while other typing are kept:

verification

@naruaway
Copy link
Copy Markdown
Contributor Author

Note that we need to merge webdriverio/webdriverio#12499 first

@naruaway
Copy link
Copy Markdown
Contributor Author

Note that this is technically a breaking change since some dependents might be relying on this type. However, I would consider this is more like bug fix since this does not align with the runtime behavior. Also, it should be easy to notice and fix in dependents just by adding global expect type in their side so I personally think it's fine to release this change as a patch or a minor release

@naruaway
Copy link
Copy Markdown
Contributor Author

For the compatibility with the main webdriverio packages, It would be nice if we can make sure that webdriverio package older before webdriverio/webdriverio#12502 will never use the new version of expect-webdriverio.

However, this means we should bump the major version of expect-webdriverio, which is too much for this small change IMHO

@erwinheitzman
Copy link
Copy Markdown
Member

Last time we did this, things broke when running the Jasmine framework. I think this needs some testing with both Mocha and Jasmine to verify both work as expected

@naruaway
Copy link
Copy Markdown
Contributor Author

naruaway commented Mar 18, 2024

@erwinheitzman I think they broke probably because we did not have webdriverio/webdriverio#12499

We can merge and publish webdriverio/webdriverio#12499 and webdriverio/webdriverio#12502 first

@naruaway naruaway force-pushed the entrypoint-typing branch from 1a7f734 to e87dba7 Compare March 18, 2024 13:54
@naruaway naruaway force-pushed the entrypoint-typing branch from e87dba7 to e451bc9 Compare March 18, 2024 13:55
@naruaway
Copy link
Copy Markdown
Contributor Author

I just confirmed that both Jasmine tests and Mocha tests do not break with the change in this PR and webdriverio/webdriverio#12499 using https://github.com/naruaway-sandbox/webdriverio-test-repros

While testing, I realized that we should also update the top-level types field as well so I updated this PR

@christian-bromann
Copy link
Copy Markdown
Member

We can merge and publish webdriverio/webdriverio#12499 and webdriverio/webdriverio#12502 first

Merged them.

I will release v8 as soon as possible. I don't think we would expect any breaking changes from that.

@naruaway can you think of any potential issues that might come up for people that update their packages?

@naruaway
Copy link
Copy Markdown
Contributor Author

@christian-bromann Thanks!

can you think of any potential issues that might come up for people that update their packages?

I believe there is no potential issue for people using webdriverio@8 after releasing v8 from webdriverio/webdriverio#12502

My reasoning is based on webdriverio/webdriverio#12499 (comment). In short, it just adds additional global declaration which will conflict with the current version of expect-webdriverio but the types are the same and that conflict is suppressed by skipLibCheck: true of tsconfig.json. Technically it will cause issues for people who are using skipLibCheck: false. However, webdriverio and its related packages already have type errors so we do not need to care such users IMHO. Also, skipLibCheck: true is very common in the whole ecosystem (e.g. Next.js)

Copy link
Copy Markdown
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@christian-bromann
Copy link
Copy Markdown
Member

I will cut a release today of v8 and this package as minor updates.

@christian-bromann christian-bromann merged commit e107019 into webdriverio:main Mar 22, 2024
@naruaway
Copy link
Copy Markdown
Contributor Author

Hi @christian-bromann, if you are going to bump version for packages, probably it's better to bump minor @wdio/globals v8 first so that consumers can get the update (this is "bug fix") for @wdio/globals first. If they receive the update for expect-webdriverio first before updating @wdio/globals , they will encounter type error (only type error though). In that case, they need to update @wdio/globals later but it might be hard to realize that this is the way

@christian-bromann
Copy link
Copy Markdown
Member

christian-bromann commented Apr 12, 2024

Released in expect-webdriverio v4.13.0 and webdriverio v8.36.0.

@naruaway
Copy link
Copy Markdown
Contributor Author

Thanks! I just verified the newly released combination for sure.
The fix works perfectly! 🎉 Thanks for the review and help 👍

Before the fix

There is no type error but in this case it will cause runtime error since there is no expect global variable loaded
Screenshot 2024-04-13 at 2 59 01

After the fix

✅ There is type error, which is expected since it aligns with the reality in runtime
Screenshot 2024-04-13 at 2 57 42

@christian-bromann
Copy link
Copy Markdown
Member

Thanks for confirming!

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 this pull request may close these issues.

Importing "expect-webdriverio" should not introduce expect symbol in the global scope in type level

3 participants