@@ -8,7 +8,7 @@ import Container from '../container.js'
88import recorder from '../recorder.js'
99import event from '../event.js'
1010import output from '../output.js'
11- import { deleteDir } from '../utils.js'
11+ import { deleteDir , clearString } from '../utils.js'
1212import colors from 'chalk'
1313
1414const supportedHelpers = Container . STANDARD_ACTING_HELPERS
@@ -97,11 +97,13 @@ export default function (config) {
9797 } )
9898
9999 event . dispatcher . on ( event . test . before , test => {
100- const sha256hash = crypto
100+ const testTitle = clearString ( test . fullTitle ( ) ) . slice ( 0 , 200 )
101+ const uniqueHash = crypto
101102 . createHash ( 'sha256' )
102103 . update ( test . file + test . title )
103104 . digest ( 'hex' )
104- dir = path . join ( reportDir , `trace_${ sha256hash } ` )
105+ . slice ( 0 , 8 )
106+ dir = path . join ( reportDir , `trace_${ testTitle } _${ uniqueHash } ` )
105107 mkdirp . sync ( dir )
106108 stepNum = 0
107109 error = null
@@ -162,6 +164,16 @@ export default function (config) {
162164 prefix : stepPrefix ,
163165 artifacts : { } ,
164166 meta : { } ,
167+ debugOutput : [ ] ,
168+ }
169+
170+ if ( step . startTime && step . endTime ) {
171+ stepData . meta . duration = ( ( step . endTime - step . startTime ) / 1000 ) . toFixed ( 2 ) + 's'
172+ }
173+
174+ if ( config . captureDebugOutput && debugOutput . length > 0 ) {
175+ stepData . debugOutput = [ ...debugOutput ]
176+ debugOutput = [ ]
165177 }
166178
167179 try {
@@ -176,19 +188,27 @@ export default function (config) {
176188 }
177189
178190 // Save screenshot
179- const screenshotFile = `${ stepPrefix } _screenshot.png`
180- await helper . saveScreenshot ( path . join ( dir , screenshotFile ) , config . fullPageScreenshots )
181- stepData . artifacts . screenshot = screenshotFile
191+ if ( ! step . artifacts ?. screenshot ) {
192+ const screenshotFile = `${ stepPrefix } _screenshot.png`
193+ await helper . saveScreenshot ( path . join ( dir , screenshotFile ) , config . fullPageScreenshots )
194+ stepData . artifacts . screenshot = screenshotFile
195+ } else {
196+ stepData . artifacts . screenshot = step . artifacts . screenshot
197+ }
182198
183199 // Save HTML
184200 if ( config . captureHTML && helper . grabSource ) {
185- try {
186- const html = await helper . grabSource ( )
187- const htmlFile = `${ stepPrefix } _page.html`
188- fs . writeFileSync ( path . join ( dir , htmlFile ) , html )
189- stepData . artifacts . html = htmlFile
190- } catch ( err ) {
191- output . debug ( `aiTrace: Could not capture HTML: ${ err . message } ` )
201+ if ( ! step . artifacts ?. html ) {
202+ try {
203+ const html = await helper . grabSource ( )
204+ const htmlFile = `${ stepPrefix } _page.html`
205+ fs . writeFileSync ( path . join ( dir , htmlFile ) , html )
206+ stepData . artifacts . html = htmlFile
207+ } catch ( err ) {
208+ output . debug ( `aiTrace: Could not capture HTML: ${ err . message } ` )
209+ }
210+ } else {
211+ stepData . artifacts . html = step . artifacts . html
192212 }
193213 }
194214
@@ -257,10 +277,20 @@ export default function (config) {
257277 steps . forEach ( ( stepData , index ) => {
258278 markdown += `${ stepData . step } \n`
259279
280+ if ( stepData . meta . duration ) {
281+ markdown += ` > duration: ${ stepData . meta . duration } \n`
282+ }
283+
260284 if ( stepData . meta . url ) {
261285 markdown += ` > navigated to ${ stepData . meta . url } \n`
262286 }
263287
288+ if ( config . captureDebugOutput && stepData . debugOutput && stepData . debugOutput . length > 0 ) {
289+ stepData . debugOutput . forEach ( line => {
290+ markdown += ` > ${ line } \n`
291+ } )
292+ }
293+
264294 if ( stepData . artifacts . html ) {
265295 markdown += ` > [HTML](./${ stepData . artifacts . html } )\n`
266296 }
0 commit comments