Open simlu opened 5 years ago
Why not just use babel
to transpile while running tests?
I'm not sure if you're using Jest, but if you are it has support for testing with babel, webpack and TypeScript.
Reference
@jaydp17 I'm not sure I understand. Can you use @zeit/ncc
as a babel plugin? How would that work with nyc? We went with the outlined solution (running ncc separately) and it works reasonably well and allows us to catch the problems that come up.
What I meant is @zeit/ncc
is just (babel || typescript) + webpack.
And given that it's a local test environment we don't need to webpack files, thus if we just run babel before running the tests it should work.
The solution you went with (i.e. running ncc
) before running tests is also a good solution.
I don't know the system, so I might be missing a few details, but if there's no need to bundle assets, that time could be saved.
Regarding nyc
, I've never had 100% success with it, so I can't really comment on it. I used to use nyc
long time ago then Jest came along, and I just moved over to Jest, which generates coverage by just adding the flag --coverage
I'm not sure if you've already done this, but if you don't want to explicitly run ncc
before npm test
, you can create a pretest
npm script, and execute ncc in that. By doing this, npm/yarn will automatically run ncc
when you run npm test
.
Let me know if you need more details on the pretest
npm script, or if you've already done that.
We're currently thinking about how to use this plugin and ensure that the compiled handlers still pass our tests. We could use the
sls package
command, however we have the problem that this requires cloudformation references via${cf:...}
which are only available on ci. So tests couldn't be run locally without having access to or creating the needed aws environment. But we would love to run these tests locally as well.One solution would be to run ncc separately and then run the tests against those compile targets. However when options are defined in the sls configuration, those would need to be used for the separate ncc run as well.
I'm just wondering if you have a suggestion on how to solve for our use case? How do you ensure that ncc doesn't screw up your test cases?
Thank you very much, L~