Skip to content

Commit

Permalink
Batch coverage sending only if the environment variable 'sendCoverage…
Browse files Browse the repository at this point in the history
…BatchSize' is set and valid
  • Loading branch information
aantes-st committed Sep 26, 2024
1 parent cdeb348 commit 339deb3
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions support.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

const dayjs = require('dayjs')
var duration = require('dayjs/plugin/duration')
const { filterFilesFromCoverage } = require('./support-utils')
const {
filterFilesFromCoverage,
getSendCoverageBatchSize
} = require('./support-utils')

dayjs.extend(duration)

Expand All @@ -16,8 +19,24 @@ const sendCoverage = (coverage, pathname = '/') => {

const totalCoverage = filterFilesFromCoverage(coverage)

const envBatchSize = getSendCoverageBatchSize()
const keys = Object.keys(totalCoverage)

if (envBatchSize && envBatchSize < keys.length) {
sendBatchCoverage(totalCoverage, envBatchSize)
} else {
cy.task('combineCoverage', JSON.stringify(totalCoverage), {
log: false
})
}
}

/**
* Sends collected code coverage object to the backend code
* in batches via "cy.task".
*/
const sendBatchCoverage = (totalCoverage, batchSize) => {
const keys = Object.keys(totalCoverage)
const batchSize = 500

for (let i = 0; i < keys.length; i += batchSize) {
const batchKeys = keys.slice(i, i + batchSize)
Expand Down

0 comments on commit 339deb3

Please sign in to comment.