@@ -4,62 +4,65 @@ import fse from 'fs-extra';
4
4
import lodashChunk from 'lodash/chunk.js' ;
5
5
import { upload } from '@argos-ci/core' ;
6
6
import yargs from 'yargs' ;
7
+ import path from 'path' ;
7
8
8
- const screenshotsBase = 'test/regressions/screenshots/chrome' ;
9
- const screenshotsPigmentCSSBase = 'screenshots/chrome' ;
10
- const screenshotsTmp = 'test/regressions/screenshots/argos' ;
11
9
const BATCH_SIZE = 200 ;
12
10
13
- const argv = yargs ( process . argv . slice ( 2 ) ) . option ( 'verbose' , {
14
- alias : 'v' ,
15
- type : 'boolean' ,
16
- description : 'Run with verbose logging' ,
17
- } ) . argv ;
11
+ const argv = yargs ( process . argv . slice ( 2 ) )
12
+ . option ( 'verbose' , {
13
+ alias : 'v' ,
14
+ type : 'boolean' ,
15
+ description : 'Run with verbose logging' ,
16
+ } )
17
+ . demandCommand ( 1 , 'You need to specify the screenshots folder as a positional argument' ) . argv ;
18
18
19
19
async function run ( ) {
20
- const emotionScreenshots = await glob ( `${ screenshotsBase } /**/*` ) ;
21
- const pigmentCSSScnreeshots = await glob ( `${ screenshotsPigmentCSSBase } /**/*` ) ;
22
- const screenshots = [ ...emotionScreenshots , ...pigmentCSSScnreeshots ] ;
20
+ const tempDir = await fse . mkdtemp ( path . resolve ( 'argos-screenshots-' ) ) ;
23
21
24
- console . log ( `Found ${ screenshots . length } screenshots.` ) ;
25
- if ( argv . verbose ) {
26
- console . log ( 'Screenshots found:' ) ;
27
- screenshots . forEach ( ( screenshot ) => {
28
- console . log ( ` - ${ screenshot } ` ) ;
29
- } ) ;
30
- }
22
+ try {
23
+ const screenshotsFolder = argv . _ [ 0 ] ;
24
+ const screenshots = await glob ( `${ screenshotsFolder } /**/*` ) ;
25
+
26
+ console . log ( `Found ${ screenshots . length } screenshots.` ) ;
27
+ if ( argv . verbose ) {
28
+ console . log ( 'Screenshots found:' ) ;
29
+ screenshots . forEach ( ( screenshot ) => {
30
+ console . log ( ` - ${ screenshot } ` ) ;
31
+ } ) ;
32
+ }
31
33
32
- const chunks = lodashChunk ( screenshots , BATCH_SIZE ) ;
34
+ const chunks = lodashChunk ( screenshots , BATCH_SIZE ) ;
33
35
34
- await Promise . all (
35
- chunks . map ( ( chunk , chunkIndex ) =>
36
- Promise . all (
37
- chunk . map ( ( screenshot ) => {
38
- return fse . move (
39
- screenshot ,
40
- `${ screenshotsTmp } /${ chunkIndex } /${ screenshot . replace ( screenshotsBase , '' ) . replace ( screenshotsPigmentCSSBase , '' ) } ` ,
41
- ) ;
42
- } ) ,
36
+ await Promise . all (
37
+ chunks . map ( ( chunk , chunkIndex ) =>
38
+ Promise . all (
39
+ chunk . map ( ( screenshot ) => {
40
+ const relativePath = path . relative ( screenshotsFolder , screenshot ) ;
41
+ return fse . move ( screenshot , path . join ( tempDir , `${ chunkIndex } ` , relativePath ) ) ;
42
+ } ) ,
43
+ ) ,
43
44
) ,
44
- ) ,
45
- ) ;
45
+ ) ;
46
46
47
- for ( let i = 0 ; i < chunks . length ; i += 1 ) {
48
- // eslint-disable-next-line no-await-in-loop
49
- const result = await upload ( {
50
- root : `${ screenshotsTmp } /${ i } ` ,
51
- commit : process . env . CIRCLE_SHA1 ,
52
- branch : process . env . CIRCLE_BRANCH ,
53
- token : process . env . ARGOS_TOKEN ,
54
- parallel : {
55
- total : chunks . length ,
56
- nonce : process . env . CIRCLE_BUILD_NUM ,
57
- } ,
58
- } ) ;
47
+ for ( let i = 0 ; i < chunks . length ; i += 1 ) {
48
+ // eslint-disable-next-line no-await-in-loop
49
+ const result = await upload ( {
50
+ root : `${ tempDir } /${ i } ` ,
51
+ commit : process . env . CIRCLE_SHA1 ,
52
+ branch : process . env . CIRCLE_BRANCH ,
53
+ token : process . env . ARGOS_TOKEN ,
54
+ parallel : {
55
+ total : chunks . length ,
56
+ nonce : process . env . CIRCLE_BUILD_NUM ,
57
+ } ,
58
+ } ) ;
59
59
60
- console . log (
61
- `Batch of ${ chunks [ i ] . length } screenshots uploaded. Build URL: ${ result . build . url } ` ,
62
- ) ;
60
+ console . log (
61
+ `Batch of ${ chunks [ i ] . length } screenshots uploaded. Build URL: ${ result . build . url } ` ,
62
+ ) ;
63
+ }
64
+ } finally {
65
+ await fse . remove ( tempDir ) ;
63
66
}
64
67
}
65
68
0 commit comments