Pustur / whatsapp-chat-parser

A package to parse WhatsApp chats with Node.js or in the browser 💬

Home Page:https://whatsapp-chat-parser.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Pustur opened this issue · comments

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:

const whatsappParser = require('../dist/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: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

@Mintonne Sorry to bother you, but since you have contributed to the package maybe you have suggestions on this?

Hey,

I am not able to run tests on Windows.

'TZ' is not recognized as an internal or external command, operable program or batch file.

Is there a specific global package required?

EDIT: Runs in WSL.

Damn that was necessary to run the tests with a constant timezone but I didn't know that windows would complain about it. I'll look for alternatives.

EDIT: should work now in windows with this fix: 9c11d5f

I tried on my windows machine and besides another issue the fix provided above doesn't work for some reason.
The timezone setting seems to be ignored.

Not sure how to fix it, will investigate further in the next days 😔

Ok timezone issues are fixed by b18f178

Now it works on my windows 10 PC

Hey,

Had a look at this and I am not sure it is possible to test both src and dist without duplicating the test.

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.

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.