find-test-names
Version:
Given a Mocha / Cypress spec file, returns the list of suite and test names
36 lines (29 loc) • 847 B
JavaScript
const { stripIndent } = require('common-tags')
const START = '<!-- cypress-test-counts -->'
const END = '<!-- cypress-test-counts-end -->'
function getCountTable(totals) {
return stripIndent`
Test status | Count
---|---
Total | ${totals.passed}
Pending | ${totals.pending}
`
}
function updateText(text, totals) {
const startIndex = text.indexOf(START)
if (startIndex === -1) {
throw new Error('Could not find cypress-test-counts comment')
}
const endIndex = text.indexOf(END)
if (endIndex === -1) {
throw new Error('Could not find cypress-test-counts-end comment')
}
const start = text.slice(0, startIndex)
const end = text.slice(endIndex)
const updatedTable = getCountTable(totals)
return start + START + '\n' + updatedTable + '\n' + end
}
module.exports = {
updateText,
getCountTable,
}