-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(platform) instanceof bug between execution contexts of RegExp object #1048
Conversation
First encountered at jest-playwright repo: playwright-community/jest-playwright#38 Solution based on: https://stackoverflow.com/questions/4339288/typeof-for-regexp#comment4724685_4339350
Use single quotes.
Not sure how to resolve typescript lint error |
This is because jest overwrites all of the globals right? Would |
typescript does't narrow the type to a regex now that the check is not simple. Cast the variable to a regex before using it. |
I modified the logic and refactored it to helper.ts Where do I add unit tests? I tried searching unit tests for isNumber and isString but can't find them. |
Where exactly do we pass regex object between contexts? Is this related to the workaround @aslushnikov added before WebKit started accepting multiple collients over the WebSocket? |
No it’s because jest overrides all globals by default via the vm package. |
We always test from the public api. You can use the vm package to get a regex from another context, and verify that you can pass it in as the url match. |
Btw, if I understood you correctly, I tried: const ctx = vm.createContext();
const regexp = vm.runInContext('new RegExp(/digits\\/\\d\\.png/)', ctx);
console.log(regexp instanceof RegExp, regexp.constructor instanceof RegExp) but the output was |
For the record: this already happened to us here - #808 (comment)
Which is exactly what we test against here! @aesyondu, @JoelEinbinder Is this in a good shape for landing, or am I missing something? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks for the patch!
Co-Authored-By: Joel Einbinder <[email protected]>
First encountered at jest-playwright repo:
playwright-community/jest-playwright#38
Solution based on:
https://stackoverflow.com/questions/4339288/typeof-for-regexp#comment4724685_4339350