-
Notifications
You must be signed in to change notification settings - Fork 142
chore: add testing documentation and coverage checks #1147
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1147 +/- ##
==========================================
+ Coverage 82.80% 83.16% +0.35%
==========================================
Files 66 66
Lines 2786 2786
Branches 334 334
==========================================
+ Hits 2307 2317 +10
+ Misses 432 424 -8
+ Partials 47 45 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Juan Escalada <97265671+jescalada@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good in general, I just added a small nitpick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of good stuff here! I'd like to see resetting stubs emphasized as I lost a couple of hours to debugging confusing issues caused by stubs that were not reset.
|
||
## Testing | ||
|
||
As of v1.19.2, GitProxy uses [Mocha](https://mochajs.org/) (`ts-mocha`) as the test runner, and [Chai](https://www.chaijs.com/) for unit test assertions. End-to-end (E2E) tests are written in [Cypress](https://docs.cypress.io), and some fuzz testing is done with [`fast-check`](https://fast-check.dev/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the Cypress tests E2E? They're not handling the proxy but the rather just the admin UI and hence only part of application.
As of v1.19.2, GitProxy uses [Mocha](https://mochajs.org/) (`ts-mocha`) as the test runner, and [Chai](https://www.chaijs.com/) for unit test assertions. End-to-end (E2E) tests are written in [Cypress](https://docs.cypress.io), and some fuzz testing is done with [`fast-check`](https://fast-check.dev/). | |
As of v1.19.2, GitProxy uses [Mocha](https://mochajs.org/) (`ts-mocha`) as the test runner, and [Chai](https://www.chaijs.com/) for unit test assertions. User interface tests are written in [Cypress](https://docs.cypress.io), and some fuzz testing is done with [`fast-check`](https://fast-check.dev/). |
|
||
If test coverage is still insufficient after writing your tests, check out the [CodeCov report](https://app.codecov.io/gh/finos/git-proxy) after making the PR and take a look at which lines are missing coverage. | ||
|
||
### E2E testing with Cypress |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E2E or UI? See previous comment
|
||
Core concepts to keep in mind when unit testing JS/TS modules with Chai: | ||
|
||
#### Stub internal methods to make tests predictable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to emphasize resetting sinon and a the proxyquire cache after the tests - in #1164 I spent a ton of time trying to debug a weird issue that turned out to be stubs from other tests leaking into subsequent ones (there may be more cases than I fixed).
before(async function () { | ||
app = await service.start(); | ||
|
||
await db.deleteRepo('test-repo'); | ||
await db.deleteUser('u1'); | ||
await db.deleteUser('u2'); | ||
await db.createUser('u1', 'abc', 'test@test.com', 'test', true); | ||
await db.createUser('u2', 'abc', 'test2@test.com', 'test', true); | ||
}); | ||
|
||
// Tests go here | ||
|
||
after(async function () { | ||
await service.httpServer.close(); | ||
|
||
await db.deleteRepo('test-repo'); | ||
await db.deleteUser('u1'); | ||
await db.deleteUser('u2'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth including a small sinon example and subsequent reset in after - see earlier comment about emphasizing the reset.
Implements the coverage checks mentioned in #1019, although it doesn't add any auto-merge on coverage attained (we still want maintainers to take a look at larger PRs and decide the right time to merge).
I've also added some documentation on how to implement unit, E2E and fuzz tests for new PRs.