@@ -26,35 +26,47 @@ interface ReportConfig {
2626 sample : string ;
2727 outDir ?: string ;
2828 localarchive ?: {
29- file : string ;
30- image : string ;
29+ files : string ;
30+ images : string ;
3131 } ;
3232 skipIfReportExists ?: boolean ;
3333}
3434
3535// disable logging
3636console . log = ( ) => { } ;
37- console . info = ( ) => { } ;
3837console . warn = ( ) => { } ;
3938console . error = ( ) => { } ;
4039
4140async function report ( ) {
41+ console . info ( "Starting report" ) ;
4242 const cwd = process . cwd ( ) ;
4343 // read the config
4444 const config : ReportConfig = require ( path . join ( cwd , "report.config.js" ) ) ;
4545
4646 // load the sample file
47- const samples_path = path . join ( cwd , config . sample ) ;
47+ const samples_path = ( await exists ( config . sample ) )
48+ ? config . sample
49+ : path . join ( cwd , config . sample ) ;
50+
51+ assert (
52+ await exists ( samples_path ) ,
53+ `sample file not found at ${ config . sample } nor ${ samples_path } `
54+ ) ;
55+
4856 const samples = JSON . parse ( await fs . readFile ( samples_path , "utf-8" ) ) ;
4957
5058 // create .coverage folder
5159 const coverage_path = config . outDir ?? path . join ( cwd , ".coverage" ) ;
60+
61+ console . info ( `Loaded ${ samples . length } samples` ) ;
62+ console . info ( `Configuration used - ${ JSON . stringify ( config , null , 2 ) } ` ) ;
63+
5264 mkdir ( coverage_path ) ;
5365
5466 const client = Client ( {
5567 paths : {
56- file : config . localarchive . file ,
57- image : config . localarchive . image ,
68+ files : config . localarchive . files ,
69+ images : config . localarchive . images ,
5870 } ,
5971 } ) ;
6072
@@ -93,7 +105,7 @@ async function report() {
93105 } )
94106 ) . data . images ;
95107 } catch ( e ) {
96- console . error ( "exports not ready for" , filekey ) ;
108+ console . error ( "exports not ready for" , filekey , e . message ) ;
97109 continue ;
98110 }
99111
@@ -134,6 +146,26 @@ async function report() {
134146 ) ;
135147
136148 try {
149+ // image A (original)
150+ const exported = exports [ frame . id ] ;
151+ const image_a_rel = "./a.png" ;
152+ const image_a = path . join ( coverage_node_path , image_a_rel ) ;
153+ // download the exported image with url
154+ // if the exported is local fs path, then use copy instead
155+ if ( exists ( exported ) ) {
156+ // copy file with symlink
157+ // unlink if exists
158+ if ( exists ( image_a ) ) {
159+ await fs . unlink ( image_a ) ;
160+ }
161+ await fs . symlink ( exported , image_a ) ;
162+ } else if ( exported . startsWith ( "http" ) ) {
163+ const dl = await axios . get ( exported , { responseType : "arraybuffer" } ) ;
164+ await fs . writeFile ( image_a , dl . data ) ;
165+ } else {
166+ throw new Error ( `File not found - ${ exported } ` ) ;
167+ }
168+
137169 // codegen
138170 const code = await htmlcss (
139171 {
@@ -165,23 +197,6 @@ async function report() {
165197 const image_b = path . join ( coverage_node_path , image_b_rel ) ;
166198 await fs . writeFile ( image_b , screenshot_buffer ) ;
167199
168- const exported = exports [ frame . id ] ;
169- const image_a_rel = "./a.png" ;
170- const image_a = path . join ( coverage_node_path , image_a_rel ) ;
171- // download the exported image with url
172- // if the exported is local fs path, then use copy instead
173- if ( exists ( exported ) ) {
174- // copy file with symlink
175- // unlink if exists
176- if ( exists ( image_a ) ) {
177- await fs . unlink ( image_a ) ;
178- }
179- await fs . symlink ( exported , image_a ) ;
180- } else {
181- const dl = await axios . get ( exported , { responseType : "arraybuffer" } ) ;
182- await fs . writeFile ( image_a , dl . data ) ;
183- }
184-
185200 const diff = await resemble ( image_a , image_b ) ;
186201 const diff_file = path . join ( coverage_node_path , "diff.png" ) ;
187202 // write diff.png
0 commit comments