Skip to content

Commit

Permalink
954 - Add tests coverage (#977)
Browse files Browse the repository at this point in the history
* chore(pkg): add coverage

* e2e(coverage): integreate

* chore(ignore): ignore coverage

* chore(pkg): script for coverage

* chore(webpack): update coverage reporter

* fix(e2e): order of instantiation

* e2e(api): use `dealService` due to changes in #942

Reason: order of code executions

* docs(cypress): add cov part
  • Loading branch information
hiaux0 authored May 10, 2022
1 parent c405efd commit e57a70a
Show file tree
Hide file tree
Showing 9 changed files with 5,562 additions and 214 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ node_modules
# Cypress
cypress/videos
cypress/screenshots

# Coverage
coverage
.nyc_output
6 changes: 6 additions & 0 deletions cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,9 @@ https://docs.cypress.io/guides/references/configuration#cypress-json
[app_action]: (https://www.cypress.io/blog/2019/01/03/stop-using-page-objects-and-start-using-app-actions/)

*[[Back to top] 🔝](#concepts)*

### Coverage
Have to run a separate command to instrument the code (instrument = add helper code, that tracks when code was executed)
`npm run start-dev:cov`

Then can run other e2e commands
18 changes: 15 additions & 3 deletions cypress/integration/common/deal-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class E2eDealsApi {
return Cypress.firestoreService;
}

private static getDealService() {
// @ts-ignore - Hack to access dealService inside Cypress
return Cypress.dealService;
}

private static getDataSourceDeals(): FirestoreDealsService<
IDealTokenSwapDocument,
IDealRegistrationTokenSwap
Expand Down Expand Up @@ -179,9 +184,16 @@ export class E2eDealsApi {
* 2. Interact with Firestore
*/
return cy.then(async () => {
const firestoreService = E2eDealsApi.getFirestoreService();

const createdDeal = await firestoreService.createDealTokenSwap(registrationData);
const dealService = E2eDealsApi.getDealService();

/**
* Have to use `@ts-ignore`, because we cannot import `DealService` in cypress.
* Cannot import, because of bundling issues (bundling does not support importing Aurelia code)
*/
// @ts-ignore
await dealService.ensureInitialized();
// @ts-ignore
const createdDeal = await dealService.createDeal(registrationData) as IDealTokenSwapDocument;

E2eDeals.setDeal(createdDeal);

Expand Down
3 changes: 3 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ module.exports = (on, config) => {
]
}
}));

require('@cypress/code-coverage/task')(on, config)
return config
};
2 changes: 2 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// Import commands.js using ES2015 syntax:
import './commands';

import '@cypress/code-coverage/support'

// Alternatively you can use CommonJS syntax:
// require('./commands');

Expand Down
Loading

0 comments on commit e57a70a

Please sign in to comment.