DEV Community

Discussion on: How to write simple babel macro

Collapse
 
moranf profile image
Moran Fine

Hi, how do you unit test this Babel macro?

Collapse
 
stereobooster profile image
stereobooster

With AVA and snapshots. See here

Collapse
 
moranf profile image
Moran Fine • Edited

When I try to run the tests in IDEA, using Jest, I get "Empty tests suite", and it says that the tests passed: 0 of 2 tests, and it's also not producing any snapshots. Is there any other way to run them?

Thread Thread
 
stereobooster profile image
stereobooster

Oh wait a second you right it is Jest. Why I thought it was AVA? Anyway, you should be able to run npm test in console.

Thread Thread
 
moranf profile image
Moran Fine

Do you know maybe how can I import several custom babel-macros from one place in my project (For example index.js)?

Thread Thread
 
stereobooster profile image
stereobooster

As far as I know this is not possible, this kind of contradicts the idea of macro. You need explicitly declare in each file which macro you want to use. If you want something to be applied everywhere you need to use babel-plugin for this.

I can be wrong here. You can open issue in babel-macro repository with this question.

Thread Thread
 
moranf profile image
Moran Fine

Thank you for your answers!
Is that possible to at least to import the macro from an absolute path instead of the relative one?

Thread Thread
 
stereobooster profile image
stereobooster

Yes, should be possible. I don't see why not