1
1
import { execSync } from 'child_process' ;
2
2
import * as fs from 'fs' ;
3
3
import * as path from 'path' ;
4
+ import { dirname } from 'path' ;
5
+ import { parseArgs } from 'util' ;
4
6
import { sync as globSync } from 'glob' ;
5
7
6
8
interface MatrixInclude {
9
+ /** The test application (directory) name. */
7
10
'test-application' : string ;
11
+ /** Optional override for the build command to run. */
8
12
'build-command' ?: string ;
13
+ /** Optional override for the assert command to run. */
9
14
'assert-command' ?: string ;
15
+ /** Optional label for the test run. If not set, defaults to value of `test-application`. */
10
16
label ?: string ;
11
17
}
12
18
19
+ interface PackageJsonSentryTestConfig {
20
+ /** If this is true, the test app is optional. */
21
+ optional ?: boolean ;
22
+ /** Variant configs that should be run in non-optional test runs. */
23
+ variants ?: Partial < MatrixInclude > [ ] ;
24
+ /** Variant configs that should be run in optional test runs. */
25
+ optionalVariants ?: Partial < MatrixInclude > [ ] ;
26
+ /** Skip this test app for matrix generation. */
27
+ skip ?: boolean ;
28
+ }
29
+
13
30
/**
14
31
* This methods generates a matrix for the GitHub Actions workflow to run the E2E tests.
15
32
* It checks which test applications are affected by the current changes in the PR and then generates a matrix
@@ -20,20 +37,20 @@ interface MatrixInclude {
20
37
* Otherwise, these will be skipped.
21
38
*/
22
39
function run ( ) : void {
23
- const args : Record < string , string > = { } ;
24
- process . argv
25
- . slice ( 2 )
26
- . filter ( arg => arg . startsWith ( '--' ) && arg . includes ( '=' ) )
27
- . forEach ( arg => {
28
- const [ part1 , part2 ] = arg . split ( '=' ) as [ string , string ] ;
29
- const argName = part1 . replace ( '--' , '' ) ;
30
- const argValue = part2 ;
31
- args [ argName ] = argValue ;
32
- } ) ;
40
+ const { values } = parseArgs ( {
41
+ args : process . argv . slice ( 2 ) ,
42
+ options : {
43
+ base : { type : 'string' } ,
44
+ head : { type : 'string' } ,
45
+ optional : { type : 'string' , default : 'false' } ,
46
+ } ,
47
+ } ) ;
33
48
34
- const { base, head, optional = 'false' } = args ;
49
+ const { base, head, optional } = values ;
35
50
36
- const testApplications = globSync ( '*' , { cwd : `${ __dirname } /../test-applications/` } ) ;
51
+ const testApplications = globSync ( '*/package.json' , {
52
+ cwd : `${ __dirname } /../test-applications` ,
53
+ } ) . map ( filePath => dirname ( filePath ) ) ;
37
54
38
55
// If `--base=xxx` is defined, we only want to get test applications changed since that base
39
56
// Else, we take all test applications (e.g. on push)
@@ -60,11 +77,6 @@ function addIncludesForTestApp(
60
77
) : void {
61
78
const packageJson = getPackageJson ( testApp ) ;
62
79
63
- // this means something went wrong
64
- if ( ! packageJson ) {
65
- return ;
66
- }
67
-
68
80
const shouldSkip = packageJson . sentryTest ?. skip || false ;
69
81
const isOptional = packageJson . sentryTest ?. optional || false ;
70
82
const variants = ( optionalMode ? packageJson . sentryTest ?. optionalVariants : packageJson . sentryTest ?. variants ) || [ ] ;
@@ -99,23 +111,15 @@ function getSentryDependencies(appName: string): string[] {
99
111
return Object . keys ( dependencies ) . filter ( key => key . startsWith ( '@sentry' ) ) ;
100
112
}
101
113
102
- function getPackageJson ( appName : string ) :
103
- | {
104
- dependencies ?: { [ key : string ] : string } ;
105
- devDependencies ?: { [ key : string ] : string } ;
106
- sentryTest ?: {
107
- optional ?: boolean ;
108
- variants ?: Partial < MatrixInclude > [ ] ;
109
- optionalVariants ?: Partial < MatrixInclude > [ ] ;
110
- skip ?: boolean ;
111
- } ;
112
- }
113
- | undefined {
114
+ function getPackageJson ( appName : string ) : {
115
+ dependencies ?: { [ key : string ] : string } ;
116
+ devDependencies ?: { [ key : string ] : string } ;
117
+ sentryTest ?: PackageJsonSentryTestConfig ;
118
+ } {
114
119
const fullPath = path . resolve ( __dirname , '..' , 'test-applications' , appName , 'package.json' ) ;
115
120
116
- // This can happen if you e.g. have a leftover directory in test-applications
117
121
if ( ! fs . existsSync ( fullPath ) ) {
118
- return undefined ;
122
+ throw new Error ( `Could not find package.json for ${ appName } ` ) ;
119
123
}
120
124
121
125
return JSON . parse ( fs . readFileSync ( fullPath , 'utf8' ) ) ;
0 commit comments