File tree Expand file tree Collapse file tree 7 files changed +244
-7
lines changed Expand file tree Collapse file tree 7 files changed +244
-7
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ export LT_ACCESS_KEY=def
25
25
// The build name whose test session information is to be fetched
26
26
export LT_BUILD_NAME=Demo
27
27
28
+ # # Retrieve sessions list
28
29
fetch-Lt-sessions
30
+
31
+ # # Support for enhanced cypress reporting
32
+ fetch-Lt-sessions --enhancedCyReport
29
33
```
30
34
31
35
## ** License**
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env node
2
2
3
+ const yargs = require ( "yargs/yargs" ) ;
4
+ const { hideBin } = require ( "yargs/helpers" ) ;
5
+ const argv = yargs ( hideBin ( process . argv ) ) . argv ;
6
+ const { filterCyTests } = require ( "./lib/helpers/utils" ) ;
7
+ const { fetchCyEnhancedReport } = require ( "./lib/helpers/utils/cypress" ) ;
8
+
3
9
const ltClient = require ( "@lambdatest/node-rest-client" ) ;
4
10
5
11
const fetchSession = async ( options ) => {
@@ -31,8 +37,29 @@ const fetchSession = async (options) => {
31
37
} ,
32
38
} ;
33
39
}
40
+
41
+ // fetch enhanced cy tests data
42
+ const fetchEnhancedCyReport = argv && argv . enhancedCyReport ;
43
+
34
44
const data = await autoClient . getSessionsOfBuild ( options ) ;
35
- console . log ( JSON . stringify ( data ) ) ;
45
+
46
+ if ( ! fetchEnhancedCyReport ) {
47
+ console . log ( JSON . stringify ( data ) ) ;
48
+ return ;
49
+ }
50
+
51
+ // fetch cypress enhanced test data
52
+ if ( fetchEnhancedCyReport ) {
53
+ const cyTests = filterCyTests ( data . data . data ) ;
54
+ if ( cyTests . length == 0 ) {
55
+ console . error (
56
+ `No cypress tests found in the build with name ${ process . env . LT_BUILD_NAME } `
57
+ ) ;
58
+ return ;
59
+ }
60
+ const cyReport = await fetchCyEnhancedReport ( cyTests , autoClient ) ;
61
+ console . log ( JSON . stringify ( cyReport ) ) ;
62
+ }
36
63
return ;
37
64
} ;
38
65
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ TEST_TYPE_CYPRESS : "cypress" ,
3
+ } ;
Original file line number Diff line number Diff line change
1
+ const _ = require ( "lodash" ) ;
2
+ const fetchCyEnhancedReport = async ( testIDArr = [ ] , ltClient ) => {
3
+ // structure of response
4
+ // const data = {
5
+ // success,
6
+ // error,
7
+ // msg
8
+ // data,
9
+ // failedTests,
10
+ // };
11
+ if ( ! ltClient || ! _ . isArray ( testIDArr ) ) {
12
+ return {
13
+ success : false ,
14
+ error : "Either cypress test ids is not an array or Automation client is not passed" ,
15
+ msg : "" ,
16
+ data : [ ] ,
17
+ } ;
18
+ }
19
+
20
+ let cyReportArr = [ ] ;
21
+ let result = [ ] ;
22
+ let failedTests = [ ] ;
23
+ const chunkSize = 20 ;
24
+ // fetch cypress test enhanced report in chunks of 20
25
+ for ( let i = 0 ; i < testIDArr . length ; i += chunkSize ) {
26
+ cyReportArr = [ ] ;
27
+ const testChunk = testIDArr . slice ( i , i + chunkSize ) ;
28
+ cyReportArr = _ . map ( testChunk , ( elem ) => {
29
+ return ltClient . fetchCyEnhancedReport ( elem ) ;
30
+ } ) ;
31
+ try {
32
+ const cyReport = await Promise . all ( cyReportArr . map ( ( p ) => p . catch ( ( e ) => e ) ) ) ;
33
+ _ . forEach ( cyReport , ( report , index ) => {
34
+ if ( ! ( report instanceof Error ) ) {
35
+ result . push ( {
36
+ [ testChunk [ index ] ] : report ,
37
+ } ) ;
38
+ } else {
39
+ // failed tests whose report can't be fetched
40
+ failedTests . push ( {
41
+ [ testChunk [ index ] ] : "unable to fetch detailed cypress report" ,
42
+ } ) ;
43
+ }
44
+ } ) ;
45
+ } catch ( e ) {
46
+ console . log ( "unable to fetch cypress enhanced report, exception" , e ) ;
47
+ return {
48
+ success : false ,
49
+ error : "Unable to fetch cypress enhanced report" ,
50
+ msg : "" ,
51
+ data : [ ] ,
52
+ failedTests : [ ] ,
53
+ } ;
54
+ }
55
+ }
56
+ return {
57
+ success : true ,
58
+ error : "" ,
59
+ msg : "Retrieve enhanced cypress report was successfull" ,
60
+ data : result ,
61
+ failedTests,
62
+ } ;
63
+ } ;
64
+
65
+ module . exports = {
66
+ fetchCyEnhancedReport,
67
+ } ;
Original file line number Diff line number Diff line change
1
+ const _ = require ( "lodash" ) ;
2
+ const { TEST_TYPE_CYPRESS } = require ( "../../const" ) ;
3
+
4
+ const filterCyTests = ( tests = [ ] ) => {
5
+ if ( ! _ . isArray ( tests ) ) {
6
+ return [ ] ;
7
+ }
8
+ const cyTests = _ . filter ( tests , ( test ) => {
9
+ if ( test && test . test_type && test . test_type . toLowerCase ( ) == TEST_TYPE_CYPRESS ) {
10
+ return true ;
11
+ }
12
+ return false ;
13
+ } ) ;
14
+ return _ . map ( cyTests , "test_id" ) ;
15
+ } ;
16
+
17
+ module . exports = {
18
+ filterCyTests,
19
+ } ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @lambdatest/node-fetch-sessions" ,
3
- "version" : " 1.0.4 " ,
3
+ "version" : " 1.0.5 " ,
4
4
"description" : " This CLI fetches lambdatest automation test session details based on build name" ,
5
5
"main" : " index.js" ,
6
6
"bin" : {
27
27
" cli"
28
28
],
29
29
"dependencies" : {
30
- "@lambdatest/node-rest-client" : " ^1.0.4"
30
+ "@lambdatest/node-rest-client" : " ^1.0.5" ,
31
+ "lodash" : " ^4.17.21" ,
32
+ "yargs" : " ^17.5.1"
31
33
}
32
34
}
You can’t perform that action at this time.
0 commit comments