-
Notifications
You must be signed in to change notification settings - Fork 142
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
Add docs for using testdouble
when we have to use another loader (ie ts-node/esm
)
#514
Comments
cc/ @giltayar, our resident ESM czar. I know Node 20 causes problems if you happen to be on it |
Try I'm not sure when multiple loaders started getting supported, so maybe 16 does not support multiple, so if that doesn't work, try v18. And as @searls DON'T use v20, as there are serious bugs there around loaders. |
@giltayar node documentation for v16 shows clearly support for multiple loaders. However - the docs are for The order of loaders is important and the loader passed last gets invoked first, thus I believe the order should be Unsure why mocks do not work with the solution in my repo. |
Thanks for the excellent reproduction! It really helped me figure things out. First, how to make it work, and then why.
Now for the why:
There is a LOT of confusion around |
Thanks for a great explanation @giltayar . |
I can confirm that adding ava config to
and running tests like |
On the linked issue, I have posted a brief explanation of why ts-node does not always short-circuit despite appearing like it does, and why its resolver needs to come last in the chain. (first in the args, last in the chain) |
by the way, for node 20 you have to switch
|
Description
I am already running my tests with
--loader=ts-node/esm
to handle TypeScript to ESM compilation and writing my tests in TypeScript.How can I now plug in
Testdouble
to be able to callreplaceEsm
in my tests? An example of this would be very useful.From what I can see we can specify multiple loaders, but I have failed to find the right way to do it:
https://nodejs.org/docs/latest-v16.x/api/esm.html#loaders
(I am, in particular, using Ava)
Issue
It is not clear how to use
testdouble
with--loader=ts-node/esm
Environment
node -v
output: v16.13.2npm -v
(oryarn --version
) output:npm ls testdouble
(oryarn list testdouble
) version: 3.17.2Failing Test
Example Repo
npm it
and observe the issueRunkit Notebook
var td = require('testdouble')
at the topCode-fenced Examples
The text was updated successfully, but these errors were encountered: