1
- const path = require ( 'path' )
2
- const fs = require ( 'fs' )
3
- const archiver = require ( 'archiver' )
4
- const constants = require ( './constants.js' )
5
- const process = require ( "process" )
6
-
1
+ const path = require ( "path" ) ;
2
+ const fs = require ( "fs" ) ;
3
+ const archiver = require ( "archiver" ) ;
4
+ const constants = require ( "./constants.js" ) ;
5
+ const process = require ( "process" ) ;
7
6
8
7
function delete_archive ( file_name ) {
9
- try {
10
- fs . unlinkSync ( file_name )
11
- } catch ( err ) {
12
- console . error ( err )
13
- }
14
-
8
+ try {
9
+ fs . unlinkSync ( file_name ) ;
10
+ } catch ( err ) {
11
+ console . error ( err ) ;
12
+ }
15
13
}
16
14
17
- function archive_project ( ignore_files = [ ] ) {
18
- return new Promise ( function ( resolve , reject ) {
19
- const output = fs . createWriteStream ( 'project.zip' ) ;
20
- const archive = archiver ( 'zip' , {
21
- zlib : { level : 9 } // Sets the compression level.
22
- } ) ;
23
- output . on ( 'close' , function ( ) {
24
- resolve ( { name : "project.zip" } )
25
- } ) ;
26
- archive . on ( "progress" , ( progress ) => {
27
- } )
28
- output . on ( 'end' , function ( ) {
29
-
30
- } ) ;
31
-
32
- archive . on ( 'warning' , function ( err ) {
33
- if ( err . code === 'ENOENT' ) {
34
- // log warning
35
- console . log ( "WARN:" , err )
36
- reject ( err )
37
- } else {
38
- // throw error
39
- console . log ( "WARN:" , err )
40
- reject ( err )
41
- }
42
- } ) ;
43
-
44
- archive . on ( 'error' , function ( err ) {
45
- console . log ( "ERROR" , err )
46
- throw err ;
47
- } ) ;
48
-
49
- // pipe archive data to the file
50
- archive . pipe ( output ) ;
51
- ignore_files = [ 'cypress.json' , 'node_modules' , 'node_modules/**/*' , 'test.zip' , 'project.zip' , 'mochawesome-report/**/*' , 'cypress/screenshots/**/*' , 'cypress/videos/**/*' , 'cypress/results/**/*' ] . concat ( ignore_files )
52
- console . log ( "Ignoring files: " , ignore_files )
53
- archive . glob ( '**/*' , { cwd : process . cwd ( ) , ignore : ignore_files } , { prefix : "project/" } )
15
+ function archive_project ( lt_config ) {
16
+ return new Promise ( function ( resolve , reject ) {
17
+ const output = fs . createWriteStream ( "project.zip" ) ;
18
+ const archive = archiver ( "zip" , {
19
+ zlib : { level : 9 } , // Sets the compression level.
20
+ } ) ;
21
+ output . on ( "close" , function ( ) {
22
+ resolve ( { name : "project.zip" } ) ;
23
+ } ) ;
24
+ archive . on ( "progress" , ( progress ) => { } ) ;
25
+ output . on ( "end" , function ( ) { } ) ;
26
+
27
+ archive . on ( "warning" , function ( err ) {
28
+ if ( err . code === "ENOENT" ) {
29
+ // log warning
30
+ console . log ( "WARN:" , err ) ;
31
+ reject ( err ) ;
32
+ } else {
33
+ // throw error
34
+ console . log ( "WARN:" , err ) ;
35
+ reject ( err ) ;
36
+ }
37
+ } ) ;
38
+
39
+ archive . on ( "error" , function ( err ) {
40
+ console . log ( "ERROR" , err ) ;
41
+ throw err ;
42
+ } ) ;
43
+
44
+ // pipe archive data to the file
45
+ archive . pipe ( output ) ;
46
+ ignore_files = [
47
+ "cypress.json" ,
48
+ "node_modules" ,
49
+ "node_modules/**/*" ,
50
+ "test.zip" ,
51
+ "project.zip" ,
52
+ "mochawesome-report/**/*" ,
53
+ "cypress/screenshots/**/*" ,
54
+ "cypress/videos/**/*" ,
55
+ "cypress/results/**/*" ,
56
+ ] . concat ( lt_config [ "run_settings" ] [ "ignore_files" ] ) ;
57
+ //If we have some env variables passed through cli or config file we will ignore the original file and create a new one using
58
+ //the parameter appended in config file through code
59
+ if ( lt_config [ "run_settings" ] [ "envs" ] != undefined ) {
60
+ ignore_files = [ constants . CYPRESS_ENV_FILE_PATH ] . concat ( ignore_files ) ;
61
+ archive . append ( JSON . stringify ( lt_config [ "run_settings" ] [ "envs" ] ) , {
62
+ name : constants . CYPRESS_ENV_FILE_PATH ,
63
+ prefix : "project/" ,
64
+ } ) ;
65
+ }
54
66
55
- archive . finalize ( ) ;
56
- } )
67
+ console . log ( "Ignoring files: " , ignore_files ) ;
68
+ archive . glob (
69
+ "**/*" ,
70
+ { cwd : process . cwd ( ) , ignore : ignore_files } ,
71
+ { prefix : "project/" }
72
+ ) ;
57
73
74
+ archive . finalize ( ) ;
75
+ } ) ;
58
76
}
59
77
60
-
61
78
function archive_batch ( lt_config , batch ) {
62
-
63
- return new Promise ( function ( resolve , reject ) {
64
- const output = fs . createWriteStream ( 'test.zip' ) ;
65
- const archive = archiver ( 'zip' , {
66
- zlib : { level : 9 } // Sets the compression level.
67
- } ) ;
68
- output . on ( 'close' , function ( ) {
69
- resolve ( { name : "test.zip" } )
70
- } ) ;
71
- archive . on ( "progress" , ( progress ) => {
72
- } )
73
- output . on ( 'end' , function ( ) {
74
-
75
- } ) ;
76
-
77
- archive . on ( 'warning' , function ( err ) {
78
- if ( err . code === 'ENOENT' ) {
79
- // log warning
80
- console . log ( "WARN:" , err )
81
- reject ( err )
82
- } else {
83
- // throw error
84
- console . log ( "WARN:" , err )
85
- reject ( err )
86
- }
87
- } ) ;
88
-
89
- archive . on ( 'error' , function ( err ) {
90
- console . log ( "ERROR" , err )
91
- throw err ;
79
+ return new Promise ( function ( resolve , reject ) {
80
+ const output = fs . createWriteStream ( "test.zip" ) ;
81
+ const archive = archiver ( "zip" , {
82
+ zlib : { level : 9 } , // Sets the compression level.
83
+ } ) ;
84
+ output . on ( "close" , function ( ) {
85
+ resolve ( { name : "test.zip" } ) ;
86
+ } ) ;
87
+ archive . on ( "progress" , ( progress ) => { } ) ;
88
+ output . on ( "end" , function ( ) { } ) ;
89
+
90
+ archive . on ( "warning" , function ( err ) {
91
+ if ( err . code === "ENOENT" ) {
92
+ // log warning
93
+ console . log ( "WARN:" , err ) ;
94
+ reject ( err ) ;
95
+ } else {
96
+ // throw error
97
+ console . log ( "WARN:" , err ) ;
98
+ reject ( err ) ;
99
+ }
100
+ } ) ;
101
+
102
+ archive . on ( "error" , function ( err ) {
103
+ console . log ( "ERROR" , err ) ;
104
+ throw err ;
105
+ } ) ;
106
+
107
+ // pipe archive data to the file
108
+ archive . pipe ( output ) ;
109
+
110
+ spec_files = [ ] ;
111
+ for ( i in batch ) {
112
+ spec_files . push ( batch [ i ] [ "spec_file" ] ) ;
113
+ }
114
+ spec_files = Array . from ( new Set ( spec_files ) ) ;
115
+ for ( i in spec_files ) {
116
+ console . log ( "Archiving --------- " , spec_files [ i ] ) ;
117
+ archive . file ( spec_files [ i ] , {
118
+ name : "test/" + path . basename ( spec_files [ i ] ) ,
119
+ } ) ;
120
+ }
121
+ if (
122
+ lt_config [ "run_settings" ] [ "cypress_config_file" ] &&
123
+ fs . existsSync ( lt_config [ "run_settings" ] [ "cypress_config_file" ] )
124
+ ) {
125
+ let rawdata = fs . readFileSync (
126
+ lt_config [ "run_settings" ] [ "cypress_config_file" ]
127
+ ) ;
128
+ archive . append ( rawdata , { name : constants . CYPRESS_CONFIG_NAME } ) ;
129
+ } else if ( ! lt_config [ "run_settings" ] [ "cypress_config_file" ] ) {
130
+ archive . append ( "{}" , { name : constants . CYPRESS_CONFIG_NAME } ) ;
131
+ }
132
+ if ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) {
133
+ if ( fs . existsSync ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) ) {
134
+ let rawdata = fs . readFileSync (
135
+ lt_config [ "run_settings" ] [ "reporter_config_file" ]
136
+ ) ;
137
+ archive . append ( rawdata , {
138
+ name : path . basename (
139
+ lt_config [ "run_settings" ] [ "reporter_config_file" ]
140
+ ) ,
92
141
} ) ;
142
+ } else {
143
+ reject (
144
+ "Provided reporter config file not found. Please check the provided the value of reporter_config_file in lambdatest-config.json"
145
+ ) ;
146
+ }
147
+ }
93
148
94
- // pipe archive data to the file
95
- archive . pipe ( output ) ;
96
-
97
- spec_files = [ ]
98
- for ( i in batch ) {
99
- spec_files . push ( batch [ i ] [ "spec_file" ] )
100
- }
101
- spec_files = Array . from ( new Set ( spec_files ) )
102
- for ( i in spec_files ) {
103
- console . log ( "Archiving --------- " , spec_files [ i ] )
104
- archive . file ( spec_files [ i ] , { name : "test/" + path . basename ( spec_files [ i ] ) } ) ;
105
- }
106
- if ( lt_config [ "run_settings" ] [ "cypress_config_file" ] && fs . existsSync ( lt_config [ "run_settings" ] [ "cypress_config_file" ] ) ) {
107
- let rawdata = fs . readFileSync ( lt_config [ "run_settings" ] [ "cypress_config_file" ] ) ;
108
- archive . append ( rawdata , { name : constants . CYPRESS_CONFIG_NAME } ) ;
109
- } else if ( ( ! lt_config [ "run_settings" ] [ "cypress_config_file" ] ) ) {
110
- archive . append ( "{}" , { name : constants . CYPRESS_CONFIG_NAME } ) ;
111
- }
112
- if ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) {
113
- if ( fs . existsSync ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) ) {
114
- let rawdata = fs . readFileSync ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) ;
115
- archive . append ( rawdata , { name : path . basename ( lt_config [ "run_settings" ] [ "reporter_config_file" ] ) } ) ;
116
- } else {
117
- reject ( "Provided reporter config file not found. Please check the provided the value of reporter_config_file in lambdatest-config.json" ) ;
118
- }
119
- }
120
-
121
-
122
-
123
- let lt_config_string = JSON . stringify ( lt_config , null , 4 ) ;
124
- archive . append ( lt_config_string , { name : constants . LT_CONFIG_NAME } ) ;
125
- archive . finalize ( ) ;
126
- } )
149
+ let lt_config_string = JSON . stringify ( lt_config , null , 4 ) ;
150
+ archive . append ( lt_config_string , { name : constants . LT_CONFIG_NAME } ) ;
151
+ archive . finalize ( ) ;
152
+ } ) ;
127
153
}
128
154
129
155
module . exports = {
130
- delete_archive : delete_archive ,
131
- archive_project : archive_project ,
132
- archive_batch : archive_batch
133
- }
156
+ delete_archive : delete_archive ,
157
+ archive_project : archive_project ,
158
+ archive_batch : archive_batch ,
159
+ } ;
0 commit comments