attach e2e screenshots to slack alerts
This commit is contained in:
@@ -101,6 +101,20 @@ function readPhase(root) {
|
||||
return phaseFile ? fs.readFileSync(phaseFile, 'utf8').trim() : ''
|
||||
}
|
||||
|
||||
function maestroScreenshot(file) {
|
||||
const match = path
|
||||
.basename(file)
|
||||
.match(/^screenshot-.*?-(\d+)-\((.+)\)\.(jpe?g|png)$/i)
|
||||
return match
|
||||
? {
|
||||
file,
|
||||
timestamp: Number(match[1]),
|
||||
flow: match[2],
|
||||
extension: match[3].toLowerCase(),
|
||||
}
|
||||
: null
|
||||
}
|
||||
|
||||
function platformResult({name, status, root, artifactUrl}) {
|
||||
const files = walk(root)
|
||||
const reports = files.filter(file => /(?:report|junit).*\.xml$/i.test(file))
|
||||
@@ -116,6 +130,24 @@ function platformResult({name, status, root, artifactUrl}) {
|
||||
// A cancelled or timed-out Maestro run may never flush JUnit. Its CLI log is
|
||||
// streamed continuously, so use those failure lines when JUnit has no detail.
|
||||
const failures = junitFailures.length > 0 ? junitFailures : cliFailures
|
||||
const screenshots = files
|
||||
.map(maestroScreenshot)
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => b.timestamp - a.timestamp)
|
||||
const failureScreenshots = failures
|
||||
.flatMap(failure => {
|
||||
const screenshot = screenshots.find(item => item.flow === failure.name)
|
||||
return screenshot
|
||||
? [
|
||||
{
|
||||
flow: failure.name,
|
||||
file: screenshot.file,
|
||||
extension: screenshot.extension,
|
||||
},
|
||||
]
|
||||
: []
|
||||
})
|
||||
.slice(0, 5)
|
||||
// A skipped platform (e.g. iOS while temporarily disabled) is not a failure
|
||||
// as long as it produced no flow failures.
|
||||
const failed =
|
||||
@@ -125,6 +157,7 @@ function platformResult({name, status, root, artifactUrl}) {
|
||||
status,
|
||||
failed,
|
||||
failures,
|
||||
screenshots: failureScreenshots,
|
||||
phase: readPhase(root),
|
||||
hasJUnit: reports.length > 0,
|
||||
artifactUrl,
|
||||
@@ -308,6 +341,14 @@ export function buildSummary({
|
||||
...(index < platforms.length - 1 ? [{type: 'divider'}] : []),
|
||||
]),
|
||||
]
|
||||
const screenshotUploads = platforms.flatMap(platform =>
|
||||
platform.screenshots.map(screenshot => ({
|
||||
file: path.relative(process.cwd(), screenshot.file),
|
||||
filename: `${platform.name.toLowerCase()}-${screenshot.flow}.${screenshot.extension}`,
|
||||
title: `${platform.name} — ${screenshot.flow}`,
|
||||
alt_text: `${platform.name} failure screenshot for ${screenshot.flow}`,
|
||||
})),
|
||||
)
|
||||
return {
|
||||
notify,
|
||||
platforms,
|
||||
@@ -319,6 +360,7 @@ export function buildSummary({
|
||||
commitUrl,
|
||||
}),
|
||||
payload: {text, blocks},
|
||||
screenshotUploads,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import os from 'node:os'
|
||||
import path from 'node:path'
|
||||
import test from 'node:test'
|
||||
|
||||
import {buildSummary} from './summarize-maestro.mjs'
|
||||
|
||||
test('includes up to five matching failure screenshots and prefers the latest', t => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'maestro-summary-'))
|
||||
t.after(() => fs.rmSync(root, {recursive: true}))
|
||||
|
||||
const failures = Array.from({length: 7}, (_, index) => `flow-${index + 1}`)
|
||||
fs.writeFileSync(
|
||||
path.join(root, 'report.xml'),
|
||||
`<testsuite>${failures
|
||||
.map(
|
||||
name =>
|
||||
`<testcase name="${name}"><failure>Failed ${name}</failure></testcase>`,
|
||||
)
|
||||
.join('')}</testsuite>`,
|
||||
)
|
||||
for (const [index, name] of failures.entries()) {
|
||||
if (name === 'flow-2') continue
|
||||
fs.writeFileSync(
|
||||
path.join(root, `screenshot-❌-${index + 1}-(${name}).png`),
|
||||
'',
|
||||
)
|
||||
}
|
||||
fs.writeFileSync(path.join(root, 'screenshot-❌-7-(unrelated).png'), '')
|
||||
fs.writeFileSync(path.join(root, 'screenshot-❌-8-(flow-1).png'), '')
|
||||
|
||||
const summary = buildSummary({
|
||||
iosStatus: 'failure',
|
||||
androidStatus: 'skipped',
|
||||
iosRoot: root,
|
||||
sha: '0123456789abcdef',
|
||||
runUrl: 'https://example.com/run',
|
||||
commitUrl: 'https://example.com/commit',
|
||||
})
|
||||
|
||||
assert.deepEqual(
|
||||
summary.screenshotUploads.map(upload => upload.filename),
|
||||
['flow-1', 'flow-3', 'flow-4', 'flow-5', 'flow-6'].map(
|
||||
name => `ios-${name}.png`,
|
||||
),
|
||||
)
|
||||
assert.equal(
|
||||
summary.screenshotUploads[0].file,
|
||||
path.relative(
|
||||
process.cwd(),
|
||||
path.join(root, 'screenshot-❌-8-(flow-1).png'),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
test('does not create screenshot uploads for setup failures', () => {
|
||||
const summary = buildSummary({
|
||||
iosStatus: 'failure',
|
||||
androidStatus: 'skipped',
|
||||
sha: '0123456789abcdef',
|
||||
runUrl: 'https://example.com/run',
|
||||
commitUrl: 'https://example.com/commit',
|
||||
})
|
||||
|
||||
assert.deepEqual(summary.screenshotUploads, [])
|
||||
})
|
||||
Reference in New Issue
Block a user