How to go about testing both the src/ code and dist/ code
See original GitHub issueIn index.test.js we are not currently testing index.js but instead we are requiring the built and minified file whatsapp-chat-parser.min.js:
The reason behind this is that I want to make sure that even after going through rollup the file that is shipped to the users still works properly.
But there are a few problems with this approach:
- The coverage generated by
npm run test:coverageis not accurate and thus becomes useless. In the future I’d like to have a badge with the coverage report so we need it to work properly - Running
npm run test:watchis not reliable because it doesn’t rebuild the files after every save - Testing the
dist/file is more of an integration test than a unit test
So I think the correct thing to do is test index.js directly inside index.test.js (as we used to) and then add an integration test that tests the distribution file whatsapp-chat-parser.min.js.
This however has another little problem:
- The contents of the integration test would be the same as
index.test.jsso it would be a repetition. Edits made to one file should be mirrored to the other and it’s easy to forget it.
Also I think that this kind of test should only run before publishing to npm (prepublishOnly) and on circleci, not after every commit since building the files is a bit slow.
How can we solve these problems elegantly?
I’d like to hear some ideas
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (8 by maintainers)

Top Related StackOverflow Question
I had a brief discussion with a friend today and he suggested to export the tests as a function and then call it in 2 different files. I think that could work but I still have to think about how to organize it.
I’ll let you know when I have something to show, thanks.
This approach worked well, I had to restructure the files a bit but I’m pretty happy with the result.