Skip to content

Commit

Permalink
remember relative to absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 12, 2023
1 parent 9b5d040 commit 852139e
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ function cypressSplit(on, config) {

// collect the test results to generate a better report
const specResults = {}
// map from absolute to relative spec names as reported by Cypress
const specAbsoluteToRelative = {}

on('after:spec', (spec, results) => {
// console.log(results, results)
debug('after:spec for %s %o', spec.relative, results.stats)
Expand All @@ -56,6 +59,7 @@ function cypressSplit(on, config) {
}

specResults[spec.absolute] = results
specAbsoluteToRelative[spec.absolute] = spec.relative
})

let SPLIT = process.env.SPLIT || config.env.split || config.env.SPLIT
Expand Down Expand Up @@ -119,23 +123,32 @@ function cypressSplit(on, config) {
console.log('%s chunk %d of %d', label, splitIndex + 1, splitN)

debug('get chunk %o', { specs, splitN, splitIndex })
/** @type {string[]} absolute spec filenames */
const splitSpecs = getChunk(specs, splitN, splitIndex)

const specRows = splitSpecs.map((specName, k) => {
const specRow = [String(k + 1), specName]
return specRow
const cwd = process.cwd()
console.log('spec from the current directory %s', cwd)
const nameRows = splitSpecs.map((specName, k) => {
const row = [String(k + 1), path.relative(cwd, specName)]
return row
})
console.log(cTable.getTable(['k', 'spec'], specRows))
console.log(cTable.getTable(['k', 'spec'], nameRows))

const cwd = process.cwd()
const addSpecResults = () => {
// at this point, the specAbsoluteToRelative object should be filled
const specRows = splitSpecs.map((absoluteSpecPath, k) => {
const relativeName = specAbsoluteToRelative[absoluteSpecPath]
const specRow = [String(k + 1), relativeName]
return specRow
})

specRows.forEach((specRow) => {
const specAbsolutePath = specRow[1]
const specResult = specResults[specAbsolutePath]
if (specResult) {
// shorted to relative filename
const specName = path.relative(cwd, specAbsolutePath)
debug('spec results for %s', specName)
const relativeName = specAbsoluteToRelative[specAbsolutePath]
debug('spec results for %s', relativeName)
debug(specResult.stats)
// have to convert numbers to strings
specRow.push(String(specResult.stats.passes))
Expand Down

0 comments on commit 852139e

Please sign in to comment.