Open asm0dey opened 4 years ago
Hi, thanks for raising this. Judging by the stack trace, you’re using Node with ES6 module support, which is great to see but unfortunately, Node doesn’t yet have a complete mechanism for hooking into the import
statement.
You have some options:
Turn off ES6 module loading for your tests, and use Babel to transpile your tests. If you’re using Rollup you’ll need a separate config file to do that. There's an example of this approach in this repo. It’s not straightforward but I can help answer any questions.
You can try using the new import.meta.resolve
function, which is new in the latest version of Node, but I haven’t tried this myself and don’t feel too confident that it will work.
If you’re feeling adventurous, you could try reimplementing this script using the experimental loader hooks. I’ve attempted this before and didn’t have any success, but it looks like the API has made some progress since then. There’s an example of a CoffeeScript loader here. This task is on my radar but I’d need to schedule this in, and again there’s no guarantee of success with the current state of the loader API.
For option 1, one way to turn off ES6 modules is to name your test file with a .cjs
extension, but it depends on how you’ve set up your package.
Let me know if that helps!
Thank you for your answer! I'm aware of option 1, but it eliminates speed bonuses of jasmine and should make is as slow as jest is. Other two options look really creepy to me :)
Let’s keep this issue open until we have a satisfactory solution for test files that use Node’s ES6 module support.
Maybe a silly lead (I have similar concerns) :
Use mocha --require @babel/register
to launch the tests, and in your test file, use import 'svelte/register';
?
On my side, I still struggle to make the aliases inside my svelte component work, but the component in itself is well imported.
Seems not so silly : if I don't use aliases in my modules, it works ! Now, let's take a look at https://github.com/tleunen/babel-plugin-module-resolver for aliases handling.
Nice idea, I guess the downside is that you’d need to include that in every test file?
Keep us posted on the alias issue :)
I'm trying to use mocha as it's written in readme and getting following error: