Skip to content

Commit

Permalink
feat: Added a --matrix-count parameter to versioned tests (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr authored Aug 19, 2024
1 parent 864f5ad commit 72d8c7d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
36 changes: 35 additions & 1 deletion bin/version-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cmd
.option('--patch', 'Iterate over every patch version of packages.')
.option('--samples <n>', 'Global samples setting to override what is in tests package', int)
.option('--strict', 'Throw an error if there are test files that are not being run')
.option('-m, --matrix-count', 'Compute the test matrix and only output the count of tests to be run')
.action(async (testGlobs) => {
const skip = cmd.skip ? cmd.skip.split(',') : []
const patterns = cmd.pattern ? cmd.pattern.split(',') : []
Expand Down Expand Up @@ -112,16 +113,49 @@ async function run(files, patterns) {
versions: mode,
testPatterns: patterns,
globalSamples: cmd.samples,
strict: !!cmd.strict
strict: !!cmd.strict,
matrixCountOnly: cmd.matrixCount ?? false
})
runner.on('update', viewer.update.bind(viewer))
runner.on('end', viewer.end.bind(viewer))

const matrixTable = {
total: 0,
rows: {}
}
console.log('Finding all versions for a package'.yellow)
runner.on('packageResolved', (pkg, versions) => {
matrixTable.total += versions.length
matrixTable.rows[pkg] = versions.length
console.log(`${pkg}(${versions.length})`)
})

runner.on('matrixCountReady', () => {
const sortedRows = []

const keys = Object.keys(matrixTable.rows).sort()
let width = 0
for (const key of keys) {
if (key.length > width) {
width = key.length
}
sortedRows.push([key, matrixTable.rows[key]])
}


let lastRow
console.log('\n\nModule Test Versions Counts')
for (const row of sortedRows) {
lastRow = `${row[0].padEnd(width)} ${row[1].toLocaleString('en-US')}`
console.log(lastRow)
}
console.log('-'.repeat(lastRow.length))

console.log('total:'.padEnd(width), matrixTable.total.toLocaleString('en-US'))

process.exit(0)
})

// Off to the races!
try {
await runner.start()
Expand Down
10 changes: 9 additions & 1 deletion lib/versioned/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function Suite(testFolders, opts) {
limit: 1,
versions: 'minor',
testPatterns: [],
globalSamples: null
globalSamples: null,
matrixCountOnly: false
},
opts
)
Expand Down Expand Up @@ -56,6 +57,13 @@ Suite.prototype.prepare = function prepare() {
Suite.prototype.start = async function start() {
this.prepare()
const pkgVersions = await this._mapPackagesToVersions()

if (this.opts.matrixCountOnly === true) {
this.emit('matrixCountReady')
this.emit('end')
return
}

await this._runTests(pkgVersions)
this.emit('end')
}
Expand Down

0 comments on commit 72d8c7d

Please sign in to comment.