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
Using td.replaceEsm() in a TypeScript project #480
Comments
I need to lean on @giltayar's help to understand this one |
Just chiming in here since I've dealt with this issue as well. From what I gather, there is currently a limitation in Node.js to support more than one loader with ESM in the way that you're describing. It's impossible to use this project in conjunction with My personal recommendation is to write tests in JavaScript with |
Thanks @quinnturner for clarifying! I saw the discussion about the loaders but thought maybe someone has found a way 😅 Do you have any examples on how you've dealt with this? @searls This issue can be closed, if you want to :) |
Ok, we'll all just have to hope for better loader support in Node proper 🤞 |
I have a solution. But today is a hectic day, so I'll write it down tomorrow. Keep your hopes up high, because at my company we're using both Testdouble and TypeScript. |
OK, here goes. You need three loaders! One for TypeScript, one for TestDouble (this one!), and one for supporting multiple loaders because Node.js doesn't support multiple loaders(yet. work is ongoing to fix this). TypeScript: use https://github.com/giltayar/babel-register-esm to implement TypeScript support. You will need a Testdouble: use the Multiple loaders: use https://github.com/giltayar/esm-multi-loader. See instructions on how to use this to load both the Hope this helps.. |
Description
I'm currently trying to use TestDouble to mock dependencies in my TypeScript + ESM project. However, I'm not sure if what I'm trying to accomplish is even possible.
Issue
Using the
testdouble
loader throws an error when running my tests. Currently bothts-node/esm
andtestdouble
loader are used in.mocharc.json
but it also doesn't work with just thetestdouble
loader (see error below) or just thets-node/esm
loader (obviously mocking doesn't work). Have I reached the limits of what's possible and need to try and remove the ESM dependencies? Or would I need to ditch TypeScript to make this work?Environment
node -v
output: v16.13.1npm -v
output: 8.1.2npm ls testdouble
version: 3.16.4Example Repo
You can clone this repo and run
npm t
to see the error.The text was updated successfully, but these errors were encountered: