Skip to content

Commit b7df273

Browse files
committed
avoid ts dependency for test matrix
1 parent b504c23 commit b7df273

3 files changed

Lines changed: 23 additions & 53 deletions

File tree

dev-packages/e2e-tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ try {
198198
```
199199

200200
Test apps in the folder `test-applications` will be automatically picked up by CI in the job `job_e2e_tests` (in `.github/workflows/build.yml`).
201-
The test matrix for CI is generated in `dev-packages/e2e-tests/lib/getTestMatrix.ts`.
201+
The test matrix for CI is generated in `dev-packages/e2e-tests/lib/getTestMatrix.mjs`.
202202

203203
For each test app, CI checks its dependencies (and devDependencies) to see if any of them have changed in the current PR (based on nx affected projects).
204204
For example, if something is changed in the browser package, only E2E test apps that depend on browser will run, while others will be skipped.

dev-packages/e2e-tests/lib/getTestMatrix.ts renamed to dev-packages/e2e-tests/lib/getTestMatrix.mjs

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
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();

dev-packages/e2e-tests/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"test:validate": "run-s test:validate-configuration test:validate-test-app-setups",
1616
"clean:verdaccio": "sh -c 'pkill -f verdaccio-runner.mjs 2>/dev/null || true'",
1717
"clean": "yarn clean:verdaccio && rimraf tmp node_modules verdaccio-config/storage && yarn clean:test-applications && yarn clean:pnpm",
18-
"ci:build-matrix": "npx ts-node ./lib/getTestMatrix.ts",
19-
"ci:build-matrix-optional": "npx ts-node ./lib/getTestMatrix.ts --optional=true",
18+
"ci:build-matrix": "node ./lib/getTestMatrix.mjs",
19+
"ci:build-matrix-optional": "node ./lib/getTestMatrix.mjs --optional=true",
2020
"ci:copy-to-temp": "ts-node ./ciCopyToTemp.ts",
2121
"clean:test-applications": "rimraf --glob test-applications/**/{node_modules,dist,build,.next,.nuxt,.sveltekit,.react-router,.astro,.output,pnpm-lock.yaml,.last-run.json,test-results,.angular,event-dumps}",
2222
"clean:pnpm": "pnpm store prune"

0 commit comments

Comments
 (0)