Need to use unibabel in node for test #2

開啟中
coolaj862019-04-17 14:27:44 +00:00建立 · 3 comment
管理員

Hello @coolaj86,

I need to test a function using unibabel with jest so in node environment. Which is actually not possible.
This is for a property based testing, so mocking would defeat the purpose.
Please allow to use unibabel in node when node_env is test at least.

> Hello @coolaj86, > I need to test a function using unibabel with jest so in node environment. Which is actually not possible. > This is for a property based testing, so mocking would defeat the purpose. > Please allow to use unibabel in node when node_env is test at least.

Unibabel endup in my node stack because I use jest and jest run in node. In fact most js unit testing library run in node, not the browser. Only exception I know of is karma.
Let's forget the incompatibility with node for a moment.
Jest allows to mock any dependencies at the import level. But since an error is thrown as soon as unibabel is imported, it's impossible to mock unibabel with jest.
Only thing I could do was to use require inside the function that uses it.

Also, jest use jsdom to emulate the browser api. So I maybe wrong, but I think unibabel would work with jest.

Unibabel endup in my node stack because I use jest and jest run in node. In fact most js unit testing library run in node, not the browser. Only exception I know of is karma. Let's forget the incompatibility with node for a moment. Jest allows to mock any dependencies at the import level. But since an error is thrown as soon as unibabel is imported, it's impossible to mock unibabel with jest. Only thing I could do was to use require inside the function that uses it. Also, jest use jsdom to emulate the browser api. So I maybe wrong, but I think unibabel would work with jest.
Author
管理員

Hey @ThieryMichel,

Sorry for the long wait. I've published unibabel@v3.0.0 (tagged as next rather than latest on npm) and it now supports node.

Would you mind giving it a try and letting me know if it works for you?

Hey @ThieryMichel, Sorry for the long wait. I've published unibabel@v3.0.0 (tagged as _next_ rather than _latest_ on npm) and it now supports node. Would you mind giving it a try and letting me know if it works for you?

Hey @coolaj86,

It works great, thanks.

Hey @coolaj86, It works great, thanks.
登入 才能加入這對話。
未選擇標籤
未選擇里程碑
No Assignees
2 參與者
訊息
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: coolaj86/unibabel.js#2
No description provided.