Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage #1896

Closed
wants to merge 52 commits into from
Closed

Conversation

zhujinxuan
Copy link
Contributor

@zhujinxuan zhujinxuan commented Jun 13, 2018

Is this adding or improving a feature or fixing a bug?

feature

  1. add code coverage
  2. In configuring code coverage, I switch the test tool from mocha to jest. Because we need path alias to make slate-hyperscript use source files instead of lib files
  3. faster test; we do not need to run yarn build for test. We only build when lint code.
  4. faster linting CI. Becuase yarn $LINT_TYPE is run in parallel, I split the yarn lint with yarn lint:code and yarn lint:document then it can be run faster. And it is less confusing when contributors see an error by lint:document than just lint

What's the new behavior?

Sometimes we make careless mistakes just by forgetting to test, or decide to add tests later but forgot. (for example, PR #1864 is an example that a test is missing)

Code analysis can help us eliminate these problems, and suggests us which tests are perhaps missing. And new PR contributors can look at the code coverage difference by code.

How does this change work?

Add codeCov as code coverage service. The following is an example about which files/lines are tested and which are not yet tested. When submitting PR, we can check which newly added lines are not yet tested.

screen shot 2018-06-13 at 6 11 21 pm

screen shot 2018-06-13 at 6 18 28 pm

For example

Have you checked that...?

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn prettier.)
  • The relevant examples still work. (Run examples with yarn watch.)

Does this fix any issues or need any specific reviewers?

Fixes: #1890
Reviewers: @

@zhujinxuan zhujinxuan changed the title Adding coverall.io [On Development] Adding coverall.io Jun 13, 2018
@zhujinxuan zhujinxuan changed the title [On Development] Adding coverall.io Adding coverall.io Jun 13, 2018
@zhujinxuan zhujinxuan changed the title Adding coverall.io Add cover coverage tests Jun 13, 2018
@zhujinxuan
Copy link
Contributor Author

Here is a demo after code coverage is activated zhujinxuan#4.

Here is what we need we do before merging this PR:

  1. Go to https://codecov.io/gh/zhujinxuan/slate and register an account with github
  2. activate ianstormtaylor/slate in
  3. merge this PR; or close and reopen this PR to see how codecov works

@zhujinxuan zhujinxuan closed this Jun 13, 2018
@zhujinxuan zhujinxuan reopened this Jun 13, 2018
@codecov-io
Copy link

codecov-io commented Jun 13, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@9b0e061). Click here to learn what that means.
The diff coverage is 92.3%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1896   +/-   ##
=========================================
  Coverage          ?   65.94%           
=========================================
  Files             ?       79           
  Lines             ?     5436           
  Branches          ?     1354           
=========================================
  Hits              ?     3585           
  Misses            ?     1388           
  Partials          ?      463
Impacted Files Coverage Δ
packages/slate-dev-test-utils/src/index.js 100% <100%> (ø)
packages/slate/src/utils/key-utils.js 64.28% <85.71%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b0e061...4f753e1. Read the comment docs.

@Kornil
Copy link
Contributor

Kornil commented Jun 13, 2018

lots to improve coverage wise :)

@zhujinxuan
Copy link
Contributor Author

Rerun the travis CI by reopen

@zhujinxuan zhujinxuan closed this Jul 19, 2018
@zhujinxuan zhujinxuan reopened this Jul 19, 2018
@zhujinxuan
Copy link
Contributor Author

Fix file conflicts~

@zhujinxuan zhujinxuan changed the title Add cover coverage tests Add test coverage Jul 31, 2018
@zhujinxuan
Copy link
Contributor Author

zhujinxuan commented Aug 3, 2018

Hi, @ianstormtaylor . The conflict of this PR is resolved after #2021. I make a small dev-only change on KeyUtils and dev-fixtures because jest does not support this.skip.

@ianstormtaylor
Copy link
Owner

Hey @zhujinxuan, thank you for all your help here researching how to get code coverage reports. I'm sorry for my poor communication on this pull request. I really like the goal of having code coverage, but I'm just hesitant about switching from Mocha to Jest for lots of small reasons that add up...

Diffs still aren't as good

image

image

There are now extra Object Array prefixes all throughout the diffs when looking at the JSON output of Slate. It's a small thing, but it's just a lot of noise.

Filtering tests isn't as good

image

Whereas Mocha has the --fgrep option, jest has -t but every suite that it doesn't find a match for fails, and then it exists with a 1 error code. This isn't that nice because it's the main way to debug individual tests.

Assertions aren't as good

image

Since Jest doesn't support the default assert module properly, we have to hack around it with the jest-t-assert module, but it doesn't have the exact same API as assert. Again it's a small thing, but just extra confusion.

Configuration isn't as good

image

Jest requires more configuration that's going to be more to maintain over time to figure out why lerna-aliases isn't working, or whatever it ends up being. Mocha by contrast was very simple, just point it at an index.js file.

Bailing early doesn't work

There's a Jest CLI flag called --bail, but it doesn't actually bail out of the tests early like Mocha does... it appears to be broken?

Others feel similarly

I was thinking about this yesterday when I say Tim Oxley tweet about his troubles with Jest, that are some of the same "buildup of small issues" type worries I have.


All that to say, that's why I haven't merged this sooner. I'm just slightly worried about it. That's not to say I won't merge it... I'd just like to be more sure.

Why is it that this is currently not possible with Mocha? Why do we need to switch to Jest? From what I can tell, Coveralls (or others) work with Mocha too?

@zhujinxuan
Copy link
Contributor Author

zhujinxuan commented Aug 3, 2018 via email

@ianstormtaylor
Copy link
Owner

@zhujinxuan thank you, I really appreciate it. I totally understand that feeling of forgetting why in the first place. Thank you for all of your help!

@zhujinxuan
Copy link
Contributor Author

Codecov tests will be moved to PR #2037. Close this PR.

@zhujinxuan zhujinxuan closed this Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code coverage analysis
4 participants