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

Update CONTRIBUTING.md to give some context about adding tests #7069

Merged
merged 4 commits into from
Sep 30, 2018

Conversation

natealcedo
Copy link
Contributor

@natealcedo natealcedo commented Sep 29, 2018

Summary

New contributors to jest are self aware that the code that they write needs to be tested. More often than not though, they are confused on how to test the functionality they have just written and where to put the test that they want to write. This pull request adds a small section in the contributing.md to guide them as to how tests are done in this repository.

Test plan

No testing required since it's just a document update. Unless you consider proofreading testing? :)

Edit: Typo

@codecov-io
Copy link

codecov-io commented Sep 29, 2018

Codecov Report

Merging #7069 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7069   +/-   ##
=======================================
  Coverage   66.89%   66.89%           
=======================================
  Files         251      251           
  Lines       10488    10488           
  Branches        4        3    -1     
=======================================
  Hits         7016     7016           
  Misses       3471     3471           
  Partials        1        1

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 e2dac2b...63cd7ab. Read the comment docs.

CONTRIBUTING.md Outdated

##### Integration tests

There will be situations however where the work you have done cannot be tested alone using unit tests. In situations like this, you should write an integration test for your code. The integration tests reside within the `e2e` directory. Within this directory, there is a `__tests__` directory. This is where you will write the integration test itself. The tests within this directory execute jest itself using `runJest.js` and assertions are usually made on one if not all the output of the following `status`, `stdout` and `stderr`. The other sub directories within the `e2e` directory are where you will write the test files that jest will run for your integration tests. Feel free to take a look at any of the tests in the `__tests__` directory within `e2e` to have a better sense of how it is currently being done.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add that you can run the integration test to inspect that it behaves like you want by running ../../jest while inside it. Useful when debugging a failing one as well.

E.g.

$ cd e2e/clear-cache
$ ../../jest
 PASS  __tests__/clear_cache.test.js
  ✓ stub (4ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.225s
Ran all test suites.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea. Do you mind if I steal that code snippet? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go for it!

CONTRIBUTING.md Outdated

##### Integration tests

There will be situations however where the work you have done cannot be tested alone using unit tests. In situations like this, you should write an integration test for your code. The integration tests reside within the `e2e` directory. Within this directory, there is a `__tests__` directory. This is where you will write the integration test itself. The tests within this directory execute jest itself using `runJest.js` and assertions are usually made on one if not all the output of the following `status`, `stdout` and `stderr`. The other sub directories within the `e2e` directory are where you will write the test files that jest will run for your integration tests. Feel free to take a look at any of the tests in the `__tests__` directory within `e2e` to have a better sense of how it is currently being done.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other sub directories within the e2e directory are where you will write the test files that jest will run for your integration tests

I think the phrase "test files" may be confusing, how about saying they're just "files"?

Copy link
Contributor Author

@natealcedo natealcedo Sep 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to be more explicit in that regard. However, the more I think about it, the more I agree with your point of view. Whatever jest runs, in this context, are test files by default. :P Let me make the necessary changes.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you so much for tackling this!

I'd like some more eyes on it (especially native speakers), but it LGTM

CONTRIBUTING.md Outdated

```bash
$ cd e2e/clear-cache
$ ../../packages/jest-cli/bin/jest.js
Copy link
Contributor Author

@natealcedo natealcedo Sep 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB I couldn't achieve your behavior by running ../../jest within the folder. Possibly an error on my machine? Anyways doesn't ../../jest just invoke ../../packages/jest-cli/bin/jest.js?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that's fine. Maybe do node ../../packages/jest-cli/bin/jest.js so it's easier for people to understand they can do node --inspect or use ndb

@SimenB
Copy link
Member

SimenB commented Sep 30, 2018

Thanks!

@SimenB SimenB merged commit f0f2ee3 into jestjs:master Sep 30, 2018
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants