File tree Expand file tree Collapse file tree 4 files changed +66
-67
lines changed Expand file tree Collapse file tree 4 files changed +66
-67
lines changed Original file line number Diff line number Diff line change 1
1
import sharp from "sharp" ;
2
2
3
- export interface LogResponse {
4
- logs ?: any [ ] ;
5
- message ?: string ;
6
- }
7
-
8
- export interface HarFile {
9
- log : {
10
- entries : HarEntry [ ] ;
11
- } ;
12
- }
13
-
14
- export interface HarEntry {
15
- startedDateTime : string ;
16
- request : {
17
- method : string ;
18
- url : string ;
19
- queryString ?: { name : string ; value : string } [ ] ;
20
- } ;
21
- response : {
22
- status : number ;
23
- statusText ?: string ;
24
- _error ?: string ;
25
- } ;
26
- serverIPAddress ?: string ;
27
- time ?: number ;
28
- }
29
-
30
- export function validateResponse (
31
- response : Response ,
32
- logType : string ,
33
- ) : LogResponse | null {
34
- if ( ! response . ok ) {
35
- if ( response . status === 404 ) {
36
- return { message : `No ${ logType } available for this session` } ;
37
- }
38
- if ( response . status === 401 || response . status === 403 ) {
39
- return {
40
- message : `Unable to access ${ logType } - please check your credentials` ,
41
- } ;
42
- }
43
- return { message : `Unable to fetch ${ logType } at this time` } ;
44
- }
45
- return null ;
46
- }
47
-
48
3
export function sanitizeUrlParam ( param : string ) : string {
49
4
// Remove any characters that could be used for command injection
50
5
return param . replace ( / [ ; & | ` $ ( ) { } [ \] < > ] / g, "" ) ;
@@ -79,15 +34,3 @@ export async function assertOkResponse(response: Response, action: string) {
79
34
) ;
80
35
}
81
36
}
82
-
83
- export function filterLinesByKeywords (
84
- logText : string ,
85
- keywords : string [ ] ,
86
- ) : string [ ] {
87
- return logText
88
- . split ( / \r ? \n / )
89
- . map ( ( line ) => line . trim ( ) )
90
- . filter ( ( line ) =>
91
- keywords . some ( ( keyword ) => line . toLowerCase ( ) . includes ( keyword ) ) ,
92
- ) ;
93
- }
Original file line number Diff line number Diff line change 1
1
import config from "../../config.js" ;
2
2
import {
3
3
filterLinesByKeywords ,
4
- validateResponse ,
4
+ validateLogResponse ,
5
5
LogResponse ,
6
- } from "../../lib /utils.js" ;
6
+ } from "./utils.js" ;
7
7
8
8
const auth = Buffer . from (
9
9
`${ config . browserstackUsername } :${ config . browserstackAccessKey } ` ,
@@ -23,7 +23,7 @@ export async function retrieveDeviceLogs(
23
23
} ,
24
24
} ) ;
25
25
26
- const validationResult = validateResponse ( response , "device logs" ) ;
26
+ const validationResult = validateLogResponse ( response , "device logs" ) ;
27
27
if ( validationResult ) return validationResult ;
28
28
29
29
const logText = await response . text ( ) ;
@@ -44,7 +44,7 @@ export async function retrieveAppiumLogs(
44
44
} ,
45
45
} ) ;
46
46
47
- const validationResult = validateResponse ( response , "Appium logs" ) ;
47
+ const validationResult = validateLogResponse ( response , "Appium logs" ) ;
48
48
if ( validationResult ) return validationResult ;
49
49
50
50
const logText = await response . text ( ) ;
@@ -65,7 +65,7 @@ export async function retrieveCrashLogs(
65
65
} ,
66
66
} ) ;
67
67
68
- const validationResult = validateResponse ( response , "crash logs" ) ;
68
+ const validationResult = validateLogResponse ( response , "crash logs" ) ;
69
69
if ( validationResult ) return validationResult ;
70
70
71
71
const logText = await response . text ( ) ;
Original file line number Diff line number Diff line change 3
3
HarEntry ,
4
4
HarFile ,
5
5
filterLinesByKeywords ,
6
- validateResponse ,
6
+ validateLogResponse ,
7
7
LogResponse ,
8
- } from "../../lib /utils.js" ;
8
+ } from "./utils.js" ;
9
9
10
10
const auth = Buffer . from (
11
11
`${ config . browserstackUsername } :${ config . browserstackAccessKey } ` ,
@@ -25,7 +25,7 @@ export async function retrieveNetworkFailures(
25
25
} ,
26
26
} ) ;
27
27
28
- const validationResult = validateResponse ( response , "network logs" ) ;
28
+ const validationResult = validateLogResponse ( response , "network logs" ) ;
29
29
if ( validationResult ) return validationResult ;
30
30
31
31
const networklogs : HarFile = await response . json ( ) ;
@@ -73,7 +73,7 @@ export async function retrieveSessionFailures(
73
73
} ,
74
74
} ) ;
75
75
76
- const validationResult = validateResponse ( response , "session logs" ) ;
76
+ const validationResult = validateLogResponse ( response , "session logs" ) ;
77
77
if ( validationResult ) return validationResult ;
78
78
79
79
const logText = await response . text ( ) ;
@@ -93,7 +93,7 @@ export async function retrieveConsoleFailures(
93
93
} ,
94
94
} ) ;
95
95
96
- const validationResult = validateResponse ( response , "console logs" ) ;
96
+ const validationResult = validateLogResponse ( response , "console logs" ) ;
97
97
if ( validationResult ) return validationResult ;
98
98
99
99
const logText = await response . text ( ) ;
Original file line number Diff line number Diff line change
1
+ export interface LogResponse {
2
+ logs ?: any [ ] ;
3
+ message ?: string ;
4
+ }
5
+
6
+ export interface HarFile {
7
+ log : {
8
+ entries : HarEntry [ ] ;
9
+ } ;
10
+ }
11
+
12
+ export interface HarEntry {
13
+ startedDateTime : string ;
14
+ request : {
15
+ method : string ;
16
+ url : string ;
17
+ queryString ?: { name : string ; value : string } [ ] ;
18
+ } ;
19
+ response : {
20
+ status : number ;
21
+ statusText ?: string ;
22
+ _error ?: string ;
23
+ } ;
24
+ serverIPAddress ?: string ;
25
+ time ?: number ;
26
+ }
27
+
28
+ export function validateLogResponse (
29
+ response : Response ,
30
+ logType : string ,
31
+ ) : LogResponse | null {
32
+ if ( ! response . ok ) {
33
+ if ( response . status === 404 ) {
34
+ return { message : `No ${ logType } available for this session` } ;
35
+ }
36
+ if ( response . status === 401 || response . status === 403 ) {
37
+ return {
38
+ message : `Unable to access ${ logType } - please check your credentials` ,
39
+ } ;
40
+ }
41
+ return { message : `Unable to fetch ${ logType } at this time` } ;
42
+ }
43
+ return null ;
44
+ }
45
+
46
+ export function filterLinesByKeywords (
47
+ logText : string ,
48
+ keywords : string [ ] ,
49
+ ) : string [ ] {
50
+ return logText
51
+ . split ( / \r ? \n / )
52
+ . map ( ( line ) => line . trim ( ) )
53
+ . filter ( ( line ) =>
54
+ keywords . some ( ( keyword ) => line . toLowerCase ( ) . includes ( keyword ) ) ,
55
+ ) ;
56
+ }
You can’t perform that action at this time.
0 commit comments