question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to go about testing both the src/ code and dist/ code

See original GitHub issue

In 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:

https://github.com/Pustur/whatsapp-chat-parser/blob/a3e1d72297448a2b6fccbade1cd6e92ca670b8bd/src/index.test.js#L1

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:coverage is 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:watch is 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.js so 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:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Pusturcommented, Jun 16, 2019

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.

0reactions
Pusturcommented, Jun 16, 2019

export the tests as a function and then call it in 2 different files

This approach worked well, I had to restructure the files a bit but I’m pretty happy with the result.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In CI, should tests be run against src or dist?
Running the tests against the source code right out of the version control system. PE says that we should run the riskiest code...
Read more >
Testing Source & Build Code with Jest - Blog
Testing Build Code. The quick fix would be to change the import from "src" to "dist" (or wherever the built code exists).
Read more >
Dynamic code analysis vs. static analysis source code testing
Managing vulnerabilities involves a wide array of security testing, including both dynamic and static source code analysis.
Read more >
Prepare for testing | IntelliJ IDEA Documentation - JetBrains
In the Project tool window ( Alt+1 ), create a new directory in which you will store your test code. Right-click the new...
Read more >
How setting up unit tests with TypeScript - Medium
In order to set up chai, import the decorators and, doing some other little code setup, you have to copy and paste some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found