const addContext = (report, screenshots, videoUrl) => { const getTests = t => t.tests const getSuites = t => t.suites const addSuiteContext = (suite, previousTitles = []) => { const titles = suite.title ? previousTitles.concat(suite.title) : previousTitles getTests(suite).forEach(test => { test.timedOut = false // for some reason this is dropped const context = [ { title: 'Video', value: videoUrl, }, ] const testFileName = titles .concat(test.title) .join(' -- ') .replace(/,/g, '') const testScreenshots = screenshots.filter(s => s.includes(testFileName)) testScreenshots.forEach(screenshot => { // There could be multiple screenshots for various reasons. `${testFileName}.png` is the failure one. Others are postfixed with a name if (screenshot.includes(`${testFileName}.png`)) { context.splice(0, 0, { title: 'Failure Screenshot', value: screenshot, }) } else { context.splice(0, 0, { title: screenshot.match(`${testFileName}(.+).png`)[1].replace(' -- ', ''), value: screenshot, }) } }) test.context = JSON.stringify(context) }) getSuites(suite).forEach(s => { addSuiteContext(s, titles) }) } addSuiteContext(report.suites) return report } module.exports = addContext