Skip to content

Commit c6a63d4

Browse files
authored
Fix aiTrace plugin (#5478)
* add fix * fix
1 parent c61c2e5 commit c6a63d4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

lib/plugin/aiTrace.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default function (config) {
127127
firstFailedStepSaved = false
128128
})
129129

130-
event.dispatcher.on(event.step.after, async step => {
130+
event.dispatcher.on(event.step.after, step => {
131131
if (!currentTest) return
132132
if (step.status === 'failed') {
133133
testFailed = true
@@ -140,13 +140,10 @@ export default function (config) {
140140
output.debug(`aiTrace: Skipping failed step "${step.toString()}" - already handled by step.failed event`)
141141
return
142142
}
143-
recorder.add(`save artifacts for step ${step.toString()}`, async () => {
144-
try {
145-
await persistStep(step)
146-
} catch (err) {
147-
output.debug(`aiTrace: Error saving step: ${err.message}`)
148-
}
149-
}, true)
143+
const stepPersistPromise = persistStep(step).catch(err => {
144+
output.debug(`aiTrace: Error saving step: ${err.message}`)
145+
})
146+
recorder.add(`wait aiTrace step persistence: ${step.toString()}`, () => stepPersistPromise, true)
150147
})
151148

152149
event.dispatcher.on(event.step.failed, async step => {
@@ -284,7 +281,22 @@ export default function (config) {
284281
output.debug(`aiTrace: Browser unavailable, partial artifact capture: ${err.message}`)
285282
}
286283

287-
if (!step.artifacts?.screenshot) {
284+
if (step.artifacts?.screenshot) {
285+
const screenshotPath = path.isAbsolute(step.artifacts.screenshot)
286+
? step.artifacts.screenshot
287+
: path.resolve(dir, step.artifacts.screenshot)
288+
const screenshotFile = path.basename(screenshotPath)
289+
stepData.artifacts.screenshot = screenshotFile
290+
step.artifacts.screenshot = screenshotPath
291+
292+
if (!fs.existsSync(screenshotPath)) {
293+
try {
294+
await helper.saveScreenshot(screenshotPath, config.fullPageScreenshots)
295+
} catch (err) {
296+
output.debug(`aiTrace: Could not save screenshot: ${err.message}`)
297+
}
298+
}
299+
} else {
288300
try {
289301
const screenshotFile = `${stepPrefix}_screenshot.png`
290302
const screenshotPath = path.join(dir, screenshotFile)

0 commit comments

Comments
 (0)