Skip to content

Commit 0420ec5

Browse files
author
cod1k
committed
Refactor e2e test cleanup and temporary directory handling
Replaced inline `rimraf` calls with a dedicated `clean.ts` script for better maintainability. Standardized temporary directory management by introducing a consistent prefix and leveraging `path.basename` for clarity. These changes improve code organization and simplify future modifications.
1 parent af78dda commit 0420ec5

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

dev-packages/e2e-tests/clean.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { tmpdir } from 'os';
2+
import { join } from 'path';
3+
import { rimrafSync } from 'rimraf';
4+
5+
const buildDir = join(tmpdir(), 'sentry-e2e-tests-*');
6+
7+
process.exit(Number(!rimrafSync([...process.argv.slice(2), buildDir], { glob: true })));

dev-packages/e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test:validate-test-app-setups": "ts-node validate-test-app-setups.ts",
1414
"test:prepare": "ts-node prepare.ts",
1515
"test:validate": "run-s test:validate-configuration test:validate-test-app-setups",
16-
"clean": "rimraf tmp node_modules && yarn clean:test-applications && yarn clean:pnpm",
16+
"clean": "ts-node ./clean.ts node_modules && yarn clean:test-applications && yarn clean:pnpm",
1717
"ci:build-matrix": "ts-node ./lib/getTestMatrix.ts",
1818
"ci:build-matrix-optional": "ts-node ./lib/getTestMatrix.ts --optional=true",
1919
"ci:copy-to-temp": "ts-node ./ciCopyToTemp.ts",

dev-packages/e2e-tests/run.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import * as dotenv from 'dotenv';
44
import { mkdtemp, rm } from 'fs/promises';
55
import { sync as globSync } from 'glob';
66
import { tmpdir } from 'os';
7-
import { join, resolve } from 'path';
7+
import { basename, join, resolve } from 'path';
8+
import { rimraf } from 'rimraf';
89
import { copyToTemp } from './lib/copyToTemp';
910
import { registrySetup } from './registrySetup';
1011

@@ -56,6 +57,9 @@ async function run(): Promise<void> {
5657
console.log('Cleaning test-applications...');
5758
console.log('');
5859

60+
const tmpPrefix = join(tmpdir(), 'sentry-e2e-tests-')
61+
await rimraf(`${tmpPrefix}*`, { glob: true });
62+
5963
if (!process.env.SKIP_REGISTRY) {
6064
registrySetup();
6165
}
@@ -68,8 +72,8 @@ async function run(): Promise<void> {
6872
console.log('');
6973

7074
for (const testAppPath of testAppPaths) {
71-
const originalPath = resolve('test-applications', testAppPath);
72-
const tmpDirPath = await mkdtemp(join(tmpdir(), `sentry-e2e-tests-${appName}-`));
75+
const originalPath = resolve(__dirname, 'test-applications', testAppPath);
76+
const tmpDirPath = await mkdtemp(`${tmpPrefix}${basename(testAppPath)}-`);
7377

7478
await copyToTemp(originalPath, tmpDirPath);
7579
const cwd = tmpDirPath;

0 commit comments

Comments
 (0)