@@ -33,7 +33,7 @@ const Utils = require('../lib/util/Utils');
33
33
const UserInteractor = require ( '../lib/util/UserInteractor' ) ;
34
34
const child_process = require ( 'child_process' ) ;
35
35
36
- const TIMEOUT_MS = 300000 ;
36
+ const TIMEOUT_MS = 10000000 ;
37
37
const TESTS_EXECUTION_FOLDER = `${ __dirname } /../__test${ process . env . IMPT_FOLDER_SUFFIX ? process . env . IMPT_FOLDER_SUFFIX : '' } ` ;
38
38
const KEY_ANSWER = {
39
39
CTRL_C : '\x03' ,
@@ -103,7 +103,7 @@ class ImptTestHelper {
103
103
if ( login ) {
104
104
const endpoint = config . apiEndpoint ? `--endpoint ${ config . apiEndpoint } ` : '' ;
105
105
return ImptTestHelper . runCommand (
106
- `impt auth login --local --user ${ config . username } --pwd ${ config . password } ${ endpoint } ` ,
106
+ `impt auth login --local --user ${ config . username } --pwd " ${ config . password } " ${ endpoint } ` ,
107
107
ImptTestHelper . checkSuccessStatus ) ;
108
108
}
109
109
return Promise . resolve ( ) ;
@@ -155,26 +155,6 @@ class ImptTestHelper {
155
155
} ) . then ( outputChecker ) ;
156
156
}
157
157
158
- static runCommandWithTerminate ( command , outputChecker ) {
159
- var child ;
160
- return Promise . all ( [
161
- new Promise ( ( resolve , reject ) => {
162
- if ( config . debug ) {
163
- console . log ( 'Running command: ' + command ) ;
164
- }
165
- child = Shell . exec ( `node ${ __dirname } /../bin/${ command } ` ,
166
- { silent : ! config . debug } ,
167
- ( code , stdout , stderr ) => {
168
- resolve ( { code : code , output : stdout . replace ( / ( ( \u001b \[ 2 K .* \u001b \[ 1 G ) | ( \u001b \[ [ 0 - 9 ] { 2 } m ) ) / g, '' ) } ) ;
169
- } ) ;
170
-
171
- } ) . then ( outputChecker ) ,
172
- this . delayMs ( 20000 ) .
173
- then ( ( ) => child . kill ( 'SIGINT' ) ) .
174
- then ( ( ) => child . kill ( ) )
175
- ] ) ;
176
- }
177
-
178
158
static delayMs ( ms ) {
179
159
return new Promise ( ( resolve ) => {
180
160
setTimeout ( resolve , ms ) ;
@@ -183,15 +163,15 @@ class ImptTestHelper {
183
163
184
164
static getDeviceAttrs ( product , dg , output ) {
185
165
let jsonInfo = null ;
186
- return ImptTestHelper . runCommand ( `impt product create -n ${ product } ` , ImptTestHelper . emptyCheckEx ) .
166
+ return ImptTestHelper . runCommand ( `impt product create -n ${ product } ` , ImptTestHelper . emptyCheck ) .
187
167
then ( ( ) => ImptTestHelper . runCommand ( `impt dg create -n ${ dg } -p ${ product } ` , ImptTestHelper . emptyCheck ) ) .
188
- then ( ( ) => ImptTestHelper . runCommand ( `impt device assign -d ${ config . devices [ config . deviceidx ] } -g ${ dg } -q` , ImptTestHelper . emptyCheckEx ) ) .
189
- then ( ( ) => ImptTestHelper . runCommand ( `impt build deploy -g ${ dg } ` , ImptTestHelper . emptyCheckEx ) ) .
168
+ then ( ( ) => ImptTestHelper . runCommand ( `impt device assign -d ${ config . devices [ config . deviceidx ] } -g ${ dg } -q` , ImptTestHelper . emptyCheck ) ) .
169
+ then ( ( ) => ImptTestHelper . runCommand ( `impt build deploy -g ${ dg } ` , ImptTestHelper . emptyCheck ) ) .
190
170
then ( ( ) => ImptTestHelper . runCommand ( `impt device info -d ${ config . devices [ config . deviceidx ] } -z json` , ( commandOut ) => {
191
171
jsonInfo = commandOut . output ;
192
172
ImptTestHelper . emptyCheck ( commandOut ) ;
193
173
} ) ) .
194
- then ( ( ) => ImptTestHelper . runCommand ( `impt product delete -p ${ product } -f -b -q` , ImptTestHelper . emptyCheckEx ) ) .
174
+ then ( ( ) => ImptTestHelper . runCommand ( `impt product delete -p ${ product } -f -b -q` , ImptTestHelper . emptyCheck ) ) .
195
175
then ( ( ) => {
196
176
return new Promise ( ( resolve ) => {
197
177
let json = JSON . parse ( jsonInfo ) ;
@@ -247,28 +227,35 @@ class ImptTestHelper {
247
227
expect ( file ) . toEqual ( file2 ) ;
248
228
}
249
229
230
+ static checkFileContainsString ( fileName , string ) {
231
+ expect ( Shell . test ( '-e' , `${ TESTS_EXECUTION_FOLDER } /${ fileName } ` ) ) . toBe ( true ) ;
232
+ let file = Shell . cat ( `${ TESTS_EXECUTION_FOLDER } /${ fileName } ` ) ;
233
+ expect ( file ) . toMatch ( string ) ;
234
+ }
235
+
250
236
static projectCreate ( dg , dfile = 'device.nut' , afile = 'agent.nut' ) {
251
- return ImptTestHelper . runCommand ( `impt project link -g ${ dg } -x ${ dfile } -y ${ afile } -q` , ImptTestHelper . emptyCheckEx ) ;
237
+ return ImptTestHelper . runCommand ( `impt project link -g ${ dg } -x ${ dfile } -y ${ afile } -q` , ImptTestHelper . emptyCheck ) ;
252
238
}
253
239
254
240
static projectDelete ( ) {
255
- return ImptTestHelper . runCommand ( `impt project delete -f -q` , ImptTestHelper . emptyCheckEx ) ;
241
+ return ImptTestHelper . runCommand ( `impt project delete -f -q` , ImptTestHelper . emptyCheck ) ;
256
242
}
257
243
258
244
static deviceAssign ( dg ) {
259
- return ImptTestHelper . runCommand ( `impt device assign -d ${ config . devices [ config . deviceidx ] } -g ${ dg } -q` , ImptTestHelper . emptyCheckEx ) ;
245
+ return ImptTestHelper . runCommand ( `impt device assign -d ${ config . devices [ config . deviceidx ] } -g ${ dg } -q` , ImptTestHelper . emptyCheck ) ;
260
246
}
261
247
262
248
static deviceRestart ( ) {
263
- return ImptTestHelper . runCommand ( `impt device restart -d ${ config . devices [ config . deviceidx ] } ` , ImptTestHelper . emptyCheckEx ) ;
249
+ return ImptTestHelper . runCommand ( `impt device restart -d ${ config . devices [ config . deviceidx ] } ` , ImptTestHelper . emptyCheck ) ;
264
250
}
265
251
266
252
static deviceUnassign ( dg ) {
267
- return ImptTestHelper . runCommand ( `impt dg unassign -g ${ dg } ` , ImptTestHelper . emptyCheckEx ) ;
253
+ return ImptTestHelper . runCommand ( `impt dg unassign -g ${ dg } ` , ImptTestHelper . emptyCheck ) ;
268
254
}
269
255
270
256
// Checks success return code of the command
271
257
static checkSuccessStatus ( commandOut ) {
258
+ expect ( commandOut . output ) . not . toMatch ( UserInteractor . ERRORS . ACCESS_FAILED ) ;
272
259
expect ( commandOut . code ) . toEqual ( 0 ) ;
273
260
}
274
261
@@ -285,7 +272,7 @@ class ImptTestHelper {
285
272
286
273
// Checks if the command output contains the specified attribute name and value
287
274
static checkAttribute ( commandOut , attrName , attrValue ) {
288
- expect ( commandOut . output ) . toMatch ( new RegExp ( `${ attrName } "?:\\s+"?${ attrValue . replace ( new RegExp ( / " / g) , '\\\\?"' ) } "?` ) ) ;
275
+ expect ( commandOut . output ) . toMatch ( new RegExp ( `${ attrName } "?:\\s+"?${ attrValue . replace ( new RegExp ( / ( [ \^ \[ \. \$ \{ \* \( \\ \+ \) \| \? \< \> ] ) / g ) , '\\$&' ) . replace ( new RegExp ( / " / g) , '\\\\?"' ) } "?` ) ) ;
289
276
}
290
277
291
278
// Checks if the command output contains the specified message for default or debug output mode
@@ -312,6 +299,26 @@ class ImptTestHelper {
312
299
}
313
300
else return null ;
314
301
}
302
+
303
+ // parse loginkey id from command output and return id value if success, otherwise return null
304
+ static parseLoginkey ( commandOut ) {
305
+ if ( commandOut . output . match ( 'Account Limit Reached' ) ) {
306
+ console . log ( 'Error: No free loginkey slot' ) ;
307
+ return null ;
308
+ }
309
+ const idMatcher = commandOut . output . match ( new RegExp ( `[0-9a-z]{16}` ) ) ;
310
+ if ( idMatcher && idMatcher . length > 0 ) {
311
+ return idMatcher [ 0 ] ;
312
+ }
313
+ else return null ;
314
+ }
315
+
316
+ static checkDeviceStatus ( device ) {
317
+ return ImptTestHelper . runCommand ( `impt device info --device ${ device } ` , ( commandOut ) => {
318
+ if ( commandOut . output . match ( 'not found' ) ) console . log ( `Error: Device id:${ device } not found` ) ;
319
+ if ( commandOut . output . match ( / d e v i c e _ o n l i n e : \\ s + f a l s e / ) ) console . log ( `Error: Device id:${ device } is offline` ) ;
320
+ } ) ;
321
+ }
315
322
}
316
323
317
324
module . exports = ImptTestHelper ;
0 commit comments