-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
working mock test #39240
working mock test #39240
Conversation
Looks interesting. Two questions:
|
Per the HTTPS loader PR the actual behavior of
I actually think the problem here is in part my using a MessagePort which wants to asynchronously dispatch events. I generally think we need to move loaders off thread and have faced pushback in the past due to startup penalty of doing so; however, I wrote this with off-thread in mind. Using globals is easier! However, this avoids leaking globals and allows communication to be done in a way that cannot be tampered with or prevented by user code between Loader <-> Preload Code <-> Module Instances. Definitely want to make the API work better so might have to use a different communications API than MessagePort for now. Currently the functions are never passed to the loader via a 1st class reference, they are only passed as a list of exports and the global preload code is managing the first class references. All communication with the loader is done via message ports. |
Yes, but it has enough information to just use
🙏
Of course you're right. And to think I wrote something like this... (well, it was a while ago 😊). So, OK, removing my objection on thread-separated loaders. |
now that consolidation PR is landed, rebasing, looks like we need a slight alteration to handle multiple nesting importMetaCallbacks |
6948c7c
to
8eb74ef
Compare
removing draft status since there aren't any pending design comments and hoping to land early next week |
e82f771
to
f584efb
Compare
f584efb
to
13ab19e
Compare
Reading through CI reliability and the failed CI runs, I think the cause for the failures isn't this PR. |
Co-authored-by: Geoffrey Booth <[email protected]>
Co-authored-by: Geoffrey Booth <[email protected]>
PR-URL: #39240 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]>
Landed in 1998e83 |
PR-URL: #39240 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]>
PR-URL: #39240 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]>
PR-URL: #39240 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]>
This PR adds a communications channel for loaders to utilize across global preload code and hooks. It allows communication from the loader directly to references. Currently it is somewhat awkward to use since MessagePort does async events but does solve the global usage in https://dev.to/giltayar/mock-all-you-want-supporting-es-modules-in-the-testdouble-js-mocking-library-3gh1 .
The important bit of this PR is that we add a test for mocking via a reflective API on the main thread.
It does alter the API signature of
getGlobalPreloadCode
and adds a new implicit parameter to change theimport.meta
initialization, this can be used to fix the problem with HTTPS imports being done via a loader by allowing a rewrite of theimport.meta
to the proper value instead of the cache key in the module map.Likely we should iterate on this API since this is more the bare minimum to make things work and not a pleasant API currently.
CC: @nodejs/loaders @giltayar