You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**All new lines of code introduced in a PR, must have over 80% coverage** (patch coverage). This is enforced by our CI, and generally a PR will not be merged unless this coverage requirement is met. Please make sure to write thorough unit tests to increase GitProxy's code quality!
185
185
186
186
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.
187
+
188
+
### E2E testing with Cypress
189
+
190
+
Although coverage is currently low, we have introduced Cypress testing to make sure that end-to-end flows are working as expected with every added feature.
191
+
192
+
This is a sample test from `cypress/e2e/repo.cy.js`:
193
+
194
+
```js
195
+
describe('Repo', () => {
196
+
beforeEach(() => {
197
+
// Custom login command
198
+
cy.login('admin', 'admin');
199
+
200
+
cy.visit('/dashboard/repo');
201
+
202
+
// prevent failures on 404 request and uncaught promises
203
+
cy.on('uncaught:exception', () =>false);
204
+
});
205
+
206
+
describe('Code button for repo row', () => {
207
+
it('Opens tooltip with correct content and can copy', () => {
// find the nearby span containing Code we can click to open the tooltip
222
+
.find('span')
223
+
.contains('Code')
224
+
.should('exist')
225
+
.click();
226
+
227
+
cy
228
+
// find the newly opened tooltip
229
+
.get(tooltipQuery)
230
+
.should('exist')
231
+
.find('span')
232
+
// check it contains the url we expect
233
+
.contains(cloneURL)
234
+
.should('exist')
235
+
.parent()
236
+
// find the adjacent span that contains the svg
237
+
.find('span')
238
+
.next()
239
+
// check it has the copy icon first and click it
240
+
.get('svg.octicon-copy')
241
+
.should('exist')
242
+
.click()
243
+
// check the icon has changed to the check icon
244
+
.get('svg.octicon-copy')
245
+
.should('not.exist')
246
+
.get('svg.octicon-check')
247
+
.should('exist');
248
+
249
+
// failed to successfully check the clipboard
250
+
});
251
+
});
252
+
});
253
+
```
254
+
255
+
Here, we use a similar syntax to Mocha to **describe the behaviour that we expect**. The difference, is that Cypress expects us to write actual commands for executing actions in the app. Some commands used very often include `visit` (navigates to a certain page), `get` (gets a certain page element to check its properties), `contains` (checks if an element has a certain string value in it), `should` (similar to `expect` in unit tests).
256
+
257
+
#### Custom commands
258
+
259
+
Cypress allows defining **custom commands** to reuse and simplify code.
260
+
261
+
In the above example, `cy.login('admin', 'admin')` is actually a custom command defined in `/cypress/support/commands.js`. It allows logging a user into the app, which is a requirement for many E2E flows:
0 commit comments