@@ -46,6 +46,7 @@ exports.with_server = function with_server({paths}, body) {
4646} ;
4747
4848let results ;
49+ const seen_results = new Set ( ) ;
4950
5051const new_results = { } ;
5152
@@ -179,10 +180,7 @@ function mkdirSyncRec(targetDir) {
179180describe . page = ( url , body , { reload_page = true , name, root} = { } ) => {
180181 let _url = url ? url : page_url ;
181182 test_root = root ? root : test_root ;
182- const dir_name = path . join ( test_root , "screenshots" , RESULTS_TAGNAME , _url . replace ( ".html" , "" ) ) ;
183- if ( ! fs . existsSync ( dir_name ) ) {
184- mkdirSyncRec ( dir_name ) ;
185- }
183+
186184 describe ( name ? name : _url , ( ) => {
187185 let old = page_url ;
188186 let old_reload = page_reload ;
@@ -243,7 +241,7 @@ expect.extend({
243241test . capture = function capture ( name , body , { timeout = 60000 , viewport = null , wait_for_update = true , fail_on_errors = true } = { } ) {
244242 const _url = page_url ;
245243 const _reload_page = page_reload ;
246- test (
244+ const spec = test (
247245 name ,
248246 async ( ) => {
249247 errors = [ ] ;
@@ -256,6 +254,15 @@ test.capture = function capture(name, body, {timeout = 60000, viewport = null, w
256254
257255 const iterations = process . env . PSP_SATURATE ? 10 : 1 ;
258256
257+ const test_name = `${ name . replace ( / [ \. ' ] / g, "_" ) } ` ;
258+ const path_name = `${ spec . result . fullName . replace ( ".html" , "" ) . replace ( / [ \. ' ] / g, "_" ) } ` ;
259+ let dir_name = path . join ( test_root , "screenshots" , RESULTS_TAGNAME , path_name ) ;
260+ dir_name = dir_name . slice ( 0 , dir_name . length - test_name . length - 1 ) ;
261+ const filename = path . join ( dir_name , test_name ) ;
262+ if ( ! fs . existsSync ( dir_name ) ) {
263+ mkdirSyncRec ( dir_name ) ;
264+ }
265+
259266 for ( let x = 0 ; x < iterations ; x ++ ) {
260267 if ( _reload_page ) {
261268 await page . close ( ) ;
@@ -313,9 +320,7 @@ test.capture = function capture(name, body, {timeout = 60000, viewport = null, w
313320 . update ( screenshot )
314321 . digest ( "hex" ) ;
315322
316- const filename = path . join ( test_root , "screenshots" , RESULTS_TAGNAME , `${ _url . replace ( ".html" , "" ) } ` , `${ name . replace ( / / g, "_" ) . replace ( / [ \. ' ] / g, "" ) } ` ) ;
317-
318- if ( hash === results [ _url + "/" + name ] ) {
323+ if ( hash === results [ path_name ] ) {
319324 fs . writeFileSync ( filename + ".png" , screenshot ) ;
320325 } else {
321326 fs . writeFileSync ( filename + ".failed.png" , screenshot ) ;
@@ -329,20 +334,22 @@ test.capture = function capture(name, body, {timeout = 60000, viewport = null, w
329334 }
330335
331336 if ( process . env . WRITE_TESTS ) {
332- new_results [ _url + "/" + name ] = hash ;
337+ new_results [ path_name ] = hash ;
333338 }
334339
335340 if ( process . env . PSP_PAUSE_ON_FAILURE ) {
336- if ( ! process . env . WRITE_TESTS && ( hash !== results [ _url + "/" + name ] || errors . length > 0 ) ) {
341+ if ( ! process . env . WRITE_TESTS && ( hash !== results [ path_name ] || errors . length > 0 ) ) {
337342 private_console . error ( `Failed ${ name } , pausing` ) ;
338343 await prompt ( `Failed ${ name } , pausing. Press enter to continue ..` ) ;
339344 }
340345 }
341346 if ( fail_on_errors ) {
342347 expect ( errors ) . toNotError ( ) ;
343348 }
344- expect ( hash ) . toBe ( results [ _url + "/" + name ] ) ;
349+ expect ( hash ) . toBe ( results [ path_name ] ) ;
350+ expect ( seen_results . has ( path_name ) ) . toBeFalsy ( ) ;
345351 }
352+ seen_results . add ( path_name ) ;
346353 } ,
347354 timeout
348355 ) ;
0 commit comments