@@ -3,12 +3,9 @@ const fs = require('fs');
33const path = require ( 'path' )
44const formData = require ( 'form-data' ) ;
55const { JSDOM } = require ( "jsdom" ) ;
6- const Table = require ( 'cli-table3' ) ;
76var { constants } = require ( './constants' ) ;
87const { getLastCommit } = require ( './git' ) ;
9-
10- var INTERVAL = 2000
11- const MAX_INTERVAL = 512000
8+ const { shortPolling } = require ( './polling' ) ;
129
1310async function sendDoM ( storybookUrl , stories , storybookConfig , options ) {
1411 const createBrowser = require ( 'browserless' )
@@ -97,80 +94,6 @@ async function sendDoM(storybookUrl, stories, storybookConfig, options) {
9794 } ) ;
9895} ;
9996
100- async function shortPolling ( buildId , retries = 0 , options ) {
101- await axios . get ( new URL ( '?buildId=' + buildId , constants [ options . env ] . BUILD_STATUS_URL ) . href , {
102- headers : {
103- projectToken : process . env . PROJECT_TOKEN
104- } } )
105- . then ( function ( response ) {
106- if ( response . data ) {
107- if ( response . data . buildStatus === 'completed' ) {
108- console . log ( '[smartui] Build successful\n' ) ;
109- console . log ( '[smartui] Build details:\n' ,
110- 'Build URL: ' , response . data . buildURL , '\n' ,
111- 'Build Name: ' , response . data . buildName , '\n' ,
112- 'Total Screenshots: ' , response . data . totalScreenshots , '\n' ,
113- 'Approved: ' , response . data . buildResults . approved , '\n' ,
114- 'Changes found: ' , response . data . buildResults . changesFound , '\n'
115- ) ;
116-
117- if ( response . data . screenshots && response . data . screenshots . length > 0 ) {
118- import ( 'chalk' ) . then ( ( chalk ) => {
119- const table = new Table ( {
120- head : [
121- { content : chalk . default . white ( 'Story' ) , hAlign : 'center' } ,
122- { content : chalk . default . white ( 'Mis-match %' ) , hAlign : 'center' } ,
123- ]
124- } ) ;
125- response . data . screenshots . forEach ( screenshot => {
126- let mismatch = screenshot . mismatchPercentage
127- table . push ( [
128- chalk . default . yellow ( screenshot . storyName ) ,
129- mismatch > 0 ? chalk . default . red ( mismatch ) : chalk . default . green ( mismatch )
130- ] )
131- } ) ;
132- console . log ( table . toString ( ) ) ;
133- } )
134- } else {
135- if ( response . data . baseline ) {
136- console . log ( 'No comparisons run. This is a baseline build.' ) ;
137- } else {
138- console . log ( 'No comparisons run. No screenshot in the current build has the corresponding screenshot in baseline build.' ) ;
139- }
140- }
141- return ;
142- } else {
143- if ( response . data . screenshots && response . data . screenshots . length > 0 ) {
144- // TODO: show Screenshots processed current/total
145- console . log ( '[smartui] Screenshots compared: ' , response . data . screenshots . length )
146- }
147- }
148- }
149-
150- // Double the INTERVAL, up to the maximum INTERVAL of 512 secs (so ~15 mins in total)
151- INTERVAL = Math . min ( INTERVAL * 2 , MAX_INTERVAL ) ;
152- if ( INTERVAL == MAX_INTERVAL ) {
153- console . log ( '[smartui] Please check the build status on LambdaTest SmartUI.' ) ;
154- return ;
155- }
156-
157- setTimeout ( function ( ) {
158- shortPolling ( buildId , 0 , options )
159- } , INTERVAL ) ;
160- } )
161- . catch ( function ( error ) {
162- if ( retries >= 3 ) {
163- console . log ( '[smartui] Error: Failed getting build status.' , error . message ) ;
164- console . log ( '[smartui] Please check the build status on LambdaTest SmartUI.' ) ;
165- return ;
166- }
167-
168- setTimeout ( function ( ) {
169- shortPolling ( buildId , retries + 1 , options ) ;
170- } , 2000 ) ;
171- } ) ;
172- } ;
173-
17497function getBase64 ( url ) {
17598 return axios . get ( url , {
17699 responseType : "text" ,
0 commit comments