Skip to content

Commit 533e32e

Browse files
committed
chore: add pathname to the code coverage log command
1 parent 517b2db commit 533e32e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

support.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Sends collected code coverage object to the backend code
55
* via "cy.task".
66
*/
7-
const sendCoverage = coverage => {
8-
cy.log('Saving code coverage')
7+
const sendCoverage = (coverage, pathname = '/') => {
8+
cy.log(`Saving code coverage **${pathname}**`)
99
// stringify coverage object for speed
1010
cy.task('combineCoverage', JSON.stringify(coverage), {
1111
log: false
@@ -29,6 +29,8 @@ if (Cypress.env('coverage') === false) {
2929
})
3030

3131
beforeEach(() => {
32+
// each object will have the coverage and url pathname
33+
// to let the user know the coverage has been collected
3234
windowCoverageObjects = []
3335

3436
// save reference to coverage for each app window loaded in the test
@@ -37,16 +39,19 @@ if (Cypress.env('coverage') === false) {
3739
const applicationSourceCoverage = win.__coverage__
3840

3941
if (applicationSourceCoverage) {
40-
windowCoverageObjects.push(applicationSourceCoverage)
42+
windowCoverageObjects.push({
43+
coverage: applicationSourceCoverage,
44+
pathname: win.location.pathname
45+
})
4146
}
4247
})
4348
})
4449

4550
afterEach(() => {
4651
// save coverage after the test
4752
// because now the window coverage objects have been updated
48-
windowCoverageObjects.forEach(coverage => {
49-
sendCoverage(coverage)
53+
windowCoverageObjects.forEach(cover => {
54+
sendCoverage(cover.coverage, cover.pathname)
5055
})
5156
})
5257

@@ -76,7 +81,7 @@ if (Cypress.env('coverage') === false) {
7681
// original failed request
7782
return
7883
}
79-
sendCoverage(coverage)
84+
sendCoverage(coverage, 'backend')
8085
})
8186
}
8287

@@ -97,7 +102,7 @@ if (Cypress.env('coverage') === false) {
97102
(fileCoverage, filename) =>
98103
filename.startsWith(specFolder) || filename.startsWith(supportFolder)
99104
)
100-
sendCoverage(coverage)
105+
sendCoverage(coverage, 'unit')
101106
}
102107

103108
// when all tests finish, lets generate the coverage report

0 commit comments

Comments
 (0)