@@ -23,6 +23,7 @@ import * as plots from "./plots/index.js";
23
23
svg . setAttributeNS ( "http://www.w3.org/2000/xmlns/" , "xmlns:xlink" , "http://www.w3.org/1999/xlink" ) ;
24
24
const actual = beautify . html ( root . outerHTML , { indent_size : 2 } ) ;
25
25
const outfile = path . resolve ( "./test/output" , path . basename ( name , ".js" ) + "." + ext ) ;
26
+ const diffile = path . resolve ( "./test/output" , path . basename ( name , ".js" ) + "-changed." + ext ) ;
26
27
let expected ;
27
28
28
29
try {
@@ -37,11 +38,22 @@ import * as plots from "./plots/index.js";
37
38
}
38
39
}
39
40
40
- if ( actual !== expected ) {
41
- const outfile = path . resolve ( "./test/output" , path . basename ( name , ".js" ) + "-changed." + ext ) ;
42
- console . warn ( `! generating ${ outfile } ` ) ;
43
- await fs . writeFile ( outfile , actual , "utf8" ) ;
41
+ if ( actual === expected ) {
42
+ if ( process . env . CI !== "true" ) {
43
+ try {
44
+ await fs . unlink ( diffile ) ;
45
+ console . warn ( `! deleted ${ diffile } ` ) ;
46
+ } catch ( error ) {
47
+ if ( error . code !== "ENOENT" ) {
48
+ throw error ;
49
+ }
50
+ }
51
+ }
52
+ } else {
53
+ console . warn ( `! generating ${ diffile } ` ) ;
54
+ await fs . writeFile ( diffile , actual , "utf8" ) ;
44
55
}
56
+
45
57
assert ( actual === expected , `${ name } must match snapshot` ) ;
46
58
} finally {
47
59
delete global . document ;
0 commit comments