From 39dc75a7475f9ded462217a5dab3156f53dc8ffd Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Thu, 14 Nov 2019 15:49:34 -0500 Subject: [PATCH] fix: stringify coverage object to improve performance (#98) --- support.js | 6 +++--- task.js | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/support.js b/support.js index f1ccdac4..55b1e297 100644 --- a/support.js +++ b/support.js @@ -23,7 +23,7 @@ if (Cypress.env('coverage') === false) { const applicationSourceCoverage = win.__coverage__ if (applicationSourceCoverage) { - cy.task('combineCoverage', applicationSourceCoverage) + cy.task('combineCoverage', JSON.stringify(applicationSourceCoverage)) } }) }) @@ -54,7 +54,7 @@ if (Cypress.env('coverage') === false) { // original failed request return } - cy.task('combineCoverage', coverage) + cy.task('combineCoverage', JSON.stringify(coverage)) }) } @@ -75,7 +75,7 @@ if (Cypress.env('coverage') === false) { (fileCoverage, filename) => filename.startsWith(specFolder) || filename.startsWith(supportFolder) ) - cy.task('combineCoverage', coverage) + cy.task('combineCoverage', JSON.stringify(coverage)) } // when all tests finish, lets generate the coverage report diff --git a/task.js b/task.js index 666991ee..c6675fb2 100644 --- a/task.js +++ b/task.js @@ -61,8 +61,14 @@ module.exports = { /** * Combines coverage information from single test * with previously collected coverage. + * + * @param {string} sentCoverage Stringified coverage object sent by the test runner + * @returns {null} Nothing is returned from this task */ - combineCoverage(coverage) { + combineCoverage(sentCoverage) { + const coverage = JSON.parse(sentCoverage) + debug('parsed sent coverage') + fixSourcePathes(coverage) const previous = existsSync(nycFilename) ? JSON.parse(readFileSync(nycFilename))