(test, status)
| 355 | } |
| 356 | |
| 357 | function persist(test, status) { |
| 358 | if (!steps.length) { |
| 359 | output.debug('aiTrace: No steps to save in trace') |
| 360 | return |
| 361 | } |
| 362 | |
| 363 | // on=test: only render the last step in markdown; artifacts of earlier steps |
| 364 | // remain on disk unreferenced. |
| 365 | if (trigger.on === 'test') { |
| 366 | steps = steps.slice(-1) |
| 367 | } |
| 368 | |
| 369 | const testDuration = ((Date.now() - testStartTime) / 1000).toFixed(2) |
| 370 | |
| 371 | let markdown = `file: ${test.file || 'unknown'}\n` |
| 372 | markdown += `name: ${test.title}\n` |
| 373 | markdown += `time: ${testDuration}s\n` |
| 374 | markdown += `---\n\n` |
| 375 | |
| 376 | if (status === 'failed') { |
| 377 | if (test.art && test.art.message) { |
| 378 | markdown += `Error: ${test.art.message}\n\n` |
| 379 | } |
| 380 | if (test.art && test.art.stack) { |
| 381 | markdown += `${test.art.stack}\n\n` |
| 382 | } |
| 383 | markdown += `---\n\n` |
| 384 | } |
| 385 | |
| 386 | if (config.captureDebugOutput && debugOutput.length > 0) { |
| 387 | markdown += `CodeceptJS Debug Output:\n\n` |
| 388 | debugOutput.forEach(line => { |
| 389 | markdown += `> ${line}\n` |
| 390 | }) |
| 391 | markdown += `\n---\n\n` |
| 392 | } |
| 393 | |
| 394 | steps.forEach((stepData, index) => { |
| 395 | const stepAnchor = clearString(stepData.step).replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 50) |
| 396 | markdown += `### Step ${index + 1}: ${stepData.step}\n` |
| 397 | markdown += `<a id="${stepAnchor}"></a>\n` |
| 398 | |
| 399 | if (stepData.meta.duration) { |
| 400 | markdown += ` > duration: ${stepData.meta.duration}\n` |
| 401 | } |
| 402 | |
| 403 | if (stepData.meta.url) { |
| 404 | markdown += ` > navigated to ${stepData.meta.url}\n` |
| 405 | } |
| 406 | |
| 407 | if (config.captureDebugOutput && stepData.debugOutput && stepData.debugOutput.length > 0) { |
| 408 | stepData.debugOutput.forEach(line => { |
| 409 | markdown += ` > ${line}\n` |
| 410 | }) |
| 411 | } |
| 412 | |
| 413 | const links = artifactLinks(stepData.artifacts, { consoleCount: stepData.meta.consoleCount }) |
| 414 | if (links) markdown += links + '\n' |
no test coverage detected