Skip to content

Commit 020b352

Browse files
author
cod1k
committed
Refactor e2e cleanup process with rimraf and add clean script
Replaced manual cleanup in `run.ts` with `rimraf` to enhance efficiency and added a standalone `clean.ts` script for reusable cleanup logic. Updated the `clean` command in `package.json` to use the new script, streamlining the process.
1 parent 5d29f4d commit 020b352

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

@@ -64,6 +65,9 @@ async function run(): Promise<void> {
6465
console.log('Cleaning test-applications...');
6566
console.log('');
6667

68+
const tmpPrefix = join(tmpdir(), 'sentry-e2e-tests-')
69+
await rimraf(`${tmpPrefix}*`, { glob: true });
70+
6771
if (!process.env.SKIP_REGISTRY) {
6872
registrySetup();
6973
}
@@ -76,8 +80,8 @@ async function run(): Promise<void> {
7680
console.log('');
7781

7882
for (const testAppPath of testAppPaths) {
79-
const originalPath = resolve('test-applications', testAppPath);
80-
const tmpDirPath = await mkdtemp(join(tmpdir(), `sentry-e2e-tests-${appName}-`));
83+
const originalPath = resolve(__dirname, 'test-applications', testAppPath);
84+
const tmpDirPath = await mkdtemp(`${tmpPrefix}${basename(testAppPath)}-`);
8185

8286
await copyToTemp(originalPath, tmpDirPath);
8387
const cwd = tmpDirPath;

0 commit comments

Comments
 (0)