Skip to content

Commit ec2a1a7

Browse files
committed
PR feedback
1 parent 6fdad14 commit ec2a1a7

File tree

3 files changed

+49
-58
lines changed

3 files changed

+49
-58
lines changed

dev-packages/e2e-tests/lib/getTestMatrix.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
import { execSync } from 'child_process';
22
import * as fs from 'fs';
33
import * as path from 'path';
4+
import { dirname } from 'path';
5+
import { parseArgs } from 'util';
46
import { sync as globSync } from 'glob';
57

68
interface MatrixInclude {
9+
/** The test application (directory) name. */
710
'test-application': string;
11+
/** Optional override for the build command to run. */
812
'build-command'?: string;
13+
/** Optional override for the assert command to run. */
914
'assert-command'?: string;
15+
/** Optional label for the test run. If not set, defaults to value of `test-application`. */
1016
label?: string;
1117
}
1218

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+
1330
/**
1431
* This methods generates a matrix for the GitHub Actions workflow to run the E2E tests.
1532
* 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 {
2037
* Otherwise, these will be skipped.
2138
*/
2239
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+
});
3348

34-
const { base, head, optional = 'false' } = args;
49+
const { base, head, optional } = values;
3550

36-
const testApplications = globSync('*', { cwd: `${__dirname}/../test-applications/` });
51+
const testApplications = globSync('*/package.json', {
52+
cwd: `${__dirname}/../test-applications`,
53+
}).map(filePath => dirname(filePath));
3754

3855
// If `--base=xxx` is defined, we only want to get test applications changed since that base
3956
// Else, we take all test applications (e.g. on push)
@@ -60,11 +77,6 @@ function addIncludesForTestApp(
6077
): void {
6178
const packageJson = getPackageJson(testApp);
6279

63-
// this means something went wrong
64-
if (!packageJson) {
65-
return;
66-
}
67-
6880
const shouldSkip = packageJson.sentryTest?.skip || false;
6981
const isOptional = packageJson.sentryTest?.optional || false;
7082
const variants = (optionalMode ? packageJson.sentryTest?.optionalVariants : packageJson.sentryTest?.variants) || [];
@@ -99,23 +111,15 @@ function getSentryDependencies(appName: string): string[] {
99111
return Object.keys(dependencies).filter(key => key.startsWith('@sentry'));
100112
}
101113

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+
} {
114119
const fullPath = path.resolve(__dirname, '..', 'test-applications', appName, 'package.json');
115120

116-
// This can happen if you e.g. have a leftover directory in test-applications
117121
if (!fs.existsSync(fullPath)) {
118-
return undefined;
122+
throw new Error(`Could not find package.json for ${appName}`);
119123
}
120124

121125
return JSON.parse(fs.readFileSync(fullPath, 'utf8'));

dev-packages/e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"devDependencies": {
2222
"@types/glob": "8.0.0",
23-
"@types/node": "^14.18.0",
23+
"@types/node": "^18.0.0",
2424
"dotenv": "16.0.3",
2525
"esbuild": "0.20.0",
2626
"glob": "8.0.3",

yarn.lock

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10093,6 +10093,13 @@
1009310093
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.63.tgz#1788fa8da838dbb5f9ea994b834278205db6ca2b"
1009410094
integrity sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==
1009510095

10096+
"@types/node@^18.0.0":
10097+
version "18.19.64"
10098+
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.64.tgz#122897fb79f2a9ec9c979bded01c11461b2b1478"
10099+
integrity sha512-955mDqvO2vFf/oL7V3WiUtiz+BugyX8uVbaT2H8oj3+8dRyH2FLiNdowe7eNqRM7IOIZvzDH76EoAT+gwm6aIQ==
10100+
dependencies:
10101+
undici-types "~5.26.4"
10102+
1009610103
"@types/normalize-package-data@^2.4.0":
1009710104
version "2.4.0"
1009810105
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
@@ -12922,25 +12929,7 @@ bluebird@^3.4.6, bluebird@^3.7.2:
1292212929
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
1292312930
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
1292412931

12925-
[email protected], body-parser@^1.18.3, body-parser@^1.19.0:
12926-
version "1.20.3"
12927-
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.3.tgz#1953431221c6fb5cd63c4b36d53fab0928e548c6"
12928-
integrity sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==
12929-
dependencies:
12930-
bytes "3.1.2"
12931-
content-type "~1.0.5"
12932-
debug "2.6.9"
12933-
depd "2.0.0"
12934-
destroy "1.2.0"
12935-
http-errors "2.0.0"
12936-
iconv-lite "0.4.24"
12937-
on-finished "2.4.1"
12938-
qs "6.13.0"
12939-
raw-body "2.5.2"
12940-
type-is "~1.6.18"
12941-
unpipe "1.0.0"
12942-
12943-
body-parser@^1.20.3:
12932+
[email protected], body-parser@^1.18.3, body-parser@^1.19.0, body-parser@^1.20.3:
1294412933
version "1.20.3"
1294512934
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.3.tgz#1953431221c6fb5cd63c4b36d53fab0928e548c6"
1294612935
integrity sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==
@@ -28321,13 +28310,6 @@ qs@^6.4.0:
2832128310
dependencies:
2832228311
side-channel "^1.0.4"
2832328312

28324-
28325-
version "6.13.0"
28326-
resolved "https://registry.yarnpkg.com/qs/-/qs-6.13.0.tgz#6ca3bd58439f7e245655798997787b0d88a51906"
28327-
integrity sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==
28328-
dependencies:
28329-
side-channel "^1.0.6"
28330-
2833128313
query-string@^4.2.2:
2833228314
version "4.3.4"
2833328315
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
@@ -32419,6 +32401,11 @@ underscore@>=1.8.3:
3241932401
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.12.1.tgz#7bb8cc9b3d397e201cf8553336d262544ead829e"
3242032402
integrity sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw==
3242132403

32404+
undici-types@~5.26.4:
32405+
version "5.26.5"
32406+
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
32407+
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
32408+
3242232409
undici-types@~6.19.2:
3242332410
version "6.19.8"
3242432411
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"

0 commit comments

Comments
 (0)