1- import { execSync } from 'child_process' ;
2- import * as fs from 'fs' ;
3- import * as path from 'path' ;
4- import { parseArgs } from 'util' ;
5-
6- interface MatrixInclude {
7- /** The test application (directory) name. */
8- 'test-application' : string ;
9- /** Optional override for the build command to run. */
10- 'build-command' ?: string ;
11- /** Optional override for the assert command to run. */
12- 'assert-command' ?: string ;
13- /** Optional label for the test run. If not set, defaults to value of `test-application`. */
14- label ?: string ;
15- }
1+ import { execSync } from 'node:child_process' ;
2+ import fs from 'node:fs' ;
3+ import path from 'node:path' ;
4+ import { fileURLToPath } from 'node:url' ;
5+ import { parseArgs } from 'node:util' ;
166
17- interface PackageJsonSentryTestConfig {
18- /** If this is true, the test app is optional. */
19- optional ?: boolean ;
20- /** Variant configs that should be run in non-optional test runs. */
21- variants ?: Partial < MatrixInclude > [ ] ;
22- /** Variant configs that should be run in optional test runs. */
23- optionalVariants ?: Partial < MatrixInclude > [ ] ;
24- /** Skip this test app for matrix generation. */
25- skip ?: boolean ;
26- }
7+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
278
289/**
29- * This methods generates a matrix for the GitHub Actions workflow to run the E2E tests.
30- * It checks which test applications are affected by the current changes in the PR and then generates a matrix
10+ * Generates a matrix for the GitHub Actions workflow to run the E2E tests.
11+ * Checks which test applications are affected by the current changes in the PR and then generates a matrix
3112 * including all test apps that have at least one dependency that was changed in the PR.
3213 * If no `--base=xxx` is provided, it will output all test applications.
3314 *
3415 * If `--optional=true` is set, it will generate a matrix of optional test applications only.
3516 * Otherwise, these will be skipped.
3617 */
37- function run ( ) : void {
18+ function run ( ) {
3819 const { values } = parseArgs ( {
3920 args : process . argv . slice ( 2 ) ,
4021 options : {
@@ -63,7 +44,7 @@ function run(): void {
6344 : testApplications ;
6445
6546 const optionalMode = optional === 'true' ;
66- const includes : MatrixInclude [ ] = [ ] ;
47+ const includes = [ ] ;
6748
6849 includedTestApplications . forEach ( testApp => {
6950 addIncludesForTestApp ( testApp , includes , { optionalMode } ) ;
@@ -75,7 +56,7 @@ function run(): void {
7556}
7657
7758/** Direct children of `test-applications/` that contain a `package.json` (replaces glob one-segment + package.json). */
78- function discoverTestApplicationDirs ( ) : string [ ] {
59+ function discoverTestApplicationDirs ( ) {
7960 const appsRoot = path . join ( __dirname , '..' , 'test-applications' ) ;
8061 return fs
8162 . readdirSync ( appsRoot , { withFileTypes : true } )
@@ -85,11 +66,7 @@ function discoverTestApplicationDirs(): string[] {
8566 . sort ( ) ;
8667}
8768
88- function addIncludesForTestApp (
89- testApp : string ,
90- includes : MatrixInclude [ ] ,
91- { optionalMode } : { optionalMode : boolean } ,
92- ) : void {
69+ function addIncludesForTestApp ( testApp , includes , { optionalMode } ) {
9370 const packageJson = getPackageJson ( testApp ) ;
9471
9572 const shouldSkip = packageJson . sentryTest ?. skip || false ;
@@ -115,7 +92,7 @@ function addIncludesForTestApp(
11592 } ) ;
11693}
11794
118- function getSentryDependencies ( appName : string ) : string [ ] {
95+ function getSentryDependencies ( appName ) {
11996 const packageJson = getPackageJson ( appName ) ;
12097
12198 const dependencies = {
@@ -126,11 +103,7 @@ function getSentryDependencies(appName: string): string[] {
126103 return Object . keys ( dependencies ) . filter ( key => key . startsWith ( '@sentry' ) ) ;
127104}
128105
129- function getPackageJson ( appName : string ) : {
130- dependencies ?: { [ key : string ] : string } ;
131- devDependencies ?: { [ key : string ] : string } ;
132- sentryTest ?: PackageJsonSentryTestConfig ;
133- } {
106+ function getPackageJson ( appName ) {
134107 const fullPath = path . resolve ( __dirname , '..' , 'test-applications' , appName , 'package.json' ) ;
135108
136109 if ( ! fs . existsSync ( fullPath ) ) {
@@ -140,19 +113,14 @@ function getPackageJson(appName: string): {
140113 return JSON . parse ( fs . readFileSync ( fullPath , 'utf8' ) ) ;
141114}
142115
143- run ( ) ;
144-
145- function getAffectedTestApplications (
146- testApplications : string [ ] ,
147- { base = 'develop' , head } : { base ?: string ; head ?: string } ,
148- ) : string [ ] {
116+ function getAffectedTestApplications ( testApplications , { base = 'develop' , head } ) {
149117 const additionalArgs = [ `--base=${ base } ` ] ;
150118
151119 if ( head ) {
152120 additionalArgs . push ( `--head=${ head } ` ) ;
153121 }
154122
155- let affectedProjects : string [ ] = [ ] ;
123+ let affectedProjects = [ ] ;
156124 try {
157125 affectedProjects = execSync ( `yarn --silent nx show projects --affected ${ additionalArgs . join ( ' ' ) } ` )
158126 . toString ( )
@@ -208,7 +176,7 @@ function getAffectedTestApplications(
208176 return Array . from ( testAppsToRun ) ;
209177}
210178
211- function getChangedTestApps ( base : string , head ?: string ) : false | Set < string > {
179+ function getChangedTestApps ( base , head ) {
212180 const changedFiles = execSync ( `git diff --name-only ${ base } ${ head ? `..${ head } ` : '' } -- .` , {
213181 encoding : 'utf-8' ,
214182 } )
@@ -221,7 +189,7 @@ function getChangedTestApps(base: string, head?: string): false | Set<string> {
221189 // eslint-disable-next-line no-console
222190 console . error ( `Changed files since ${ base } ${ head ? `..${ head } ` : '' } : ${ JSON . stringify ( changedFiles ) } ` ) ;
223191
224- const changedTestApps : Set < string > = new Set ( ) ;
192+ const changedTestApps = new Set ( ) ;
225193 const testAppsPrefix = 'dev-packages/e2e-tests/test-applications/' ;
226194
227195 for ( const file of changedFiles ) {
@@ -240,3 +208,5 @@ function getChangedTestApps(base: string, head?: string): false | Set<string> {
240208
241209 return changedTestApps ;
242210}
211+
212+ run ( ) ;
0 commit comments