shoutit / shoutit-web

1 stars 0 forks source link

Web app is missing tests #2

Closed gpbl closed 8 years ago

gpbl commented 8 years ago

The goal is that we are safe to merge PRs and deploy them without breaking things. A productivity booster since we would have more time to sleep :smile:

So, we need slowly to test most of our code. It sounds boring but it's actually a fun task, especially if we use a test coverage report :+1:

We can run functional tests, unit tests, and test coverage reports. We could start with some functional tests, just to check the server delivers the pages without JS errors, and slowly add other unit tests on our code.

Which tools? A possible stack could be:

From a first sight, the current codebase is not easy to test. We should refactor a lot of code to make it testable, and also I've never tested the current flux implementation. This makes me think this will be an ongoing issue for long time. However, we can try to write tests for the code we are writing from scratch.

gpbl commented 8 years ago

@shoutit/web FYI i've already setup a small testing environment :tada:

It works well for unit testing both React components and Fluxxor stores and actions, tough Fluxxor stuff requires a bit care to be tested. Examples can be found here

:point_up: Tests must run on node 4, because of jsdom (a reason more to close #14)

npm run test
npm run test:watch
npm run cover
screen shot 2016-01-29 at 15 33 20
gpbl commented 8 years ago

Tests are there! Now we should just remember to add them :P

@p0o dump components are easy to test, see an example here https://github.com/shoutit/shoutit-web/blob/develop/test/components/Button.js Also for single utils: https://github.com/shoutit/shoutit-web/tree/develop/test/utils

If you are new to TDD I can help!

What's quite hard to test are stores :( I blame fluxxor for that. Example of store test: https://github.com/shoutit/shoutit-web/blob/develop/test/stores/ConversationsStore.js

Since i have to stub many things testing stores is 50% useful. Still useful, tough. Idem for actions: https://github.com/shoutit/shoutit-web/blob/develop/test/actions/ConversationsActions.js

Please run npm run test:cover to have a coverage report:

screen shot 2016-02-18 at 13 01 46

The coverage also output an HTML report to the coverage folder:

screen shot 2016-02-18 at 13 02 53

It helps to understand which code has not be tested: for example, replyToShout has not been tested:

screen shot 2016-02-18 at 13 07 05

@mochawich if we have $16,67/month to spend we can add the codeclimate integration. There's a 14 days trial. This cost would be justified if we add tests. We will get the coverage report when we push to the repo.