Skip to content

Commit 75b4a01

Browse files
alan-agius4dgp1130
authored andcommitted
test: delete e2e directories after tests finish
Deletes the e2e directories after tests complete to ensure a clean state for subsequent test runs and to free up disk space. (cherry picked from commit 1ac5b1d)
1 parent 8ef3d4c commit 75b4a01

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

tests/legacy-cli/e2e/utils/assets.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getGlobalVariable } from './env';
55
import { resolve } from 'node:path';
66
import { copyFile } from './fs';
77
import { installWorkspacePackages, setRegistry } from './packages';
8-
import { useBuiltPackagesVersions } from './project';
8+
import { getTestProjectDir, useBuiltPackagesVersions } from './project';
99

1010
export function assetDir(assetName: string) {
1111
return join(__dirname, '../e2e/assets', assetName);
@@ -21,7 +21,7 @@ export function copyProjectAsset(assetName: string, to?: string) {
2121

2222
export function copyAssets(assetName: string, to?: string) {
2323
const seed = +Date.now();
24-
const tempRoot = join(getGlobalVariable('projects-root'), 'assets', assetName + '-' + seed);
24+
const tempRoot = join(getTestAssetsDir(), assetName + '-' + seed);
2525
const root = assetDir(assetName);
2626

2727
return Promise.resolve()
@@ -30,9 +30,7 @@ export function copyAssets(assetName: string, to?: string) {
3030

3131
return allFiles.reduce((promise, filePath) => {
3232
const toPath =
33-
to !== undefined
34-
? resolve(getGlobalVariable('projects-root'), 'test-project', to, filePath)
35-
: join(tempRoot, filePath);
33+
to !== undefined ? resolve(getTestProjectDir(), to, filePath) : join(tempRoot, filePath);
3634

3735
return promise
3836
.then(() => copyFile(join(root, filePath), toPath))
@@ -65,3 +63,7 @@ export async function createProjectFromAsset(
6563

6664
return () => setRegistry(true /** useTestRegistry */);
6765
}
66+
67+
export function getTestAssetsDir(): string {
68+
return join(getGlobalVariable('projects-root'), 'assets');
69+
}

tests/legacy-cli/e2e/utils/project.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { gitCommit } from './git';
77
import { findFreePort } from './network';
88
import { installWorkspacePackages, PkgInfo } from './packages';
99
import { execAndWaitForOutputToMatch, git, ng } from './process';
10+
import { join } from 'node:path';
1011

1112
export function updateJsonFile(filePath: string, fn: (json: any) => any | void) {
1213
return readFile(filePath).then((tsConfigJson) => {
@@ -270,3 +271,7 @@ export function updateServerFileForEsbuild(filepath: string): Promise<void> {
270271
`,
271272
);
272273
}
274+
275+
export function getTestProjectDir(): string {
276+
return join(getGlobalVariable('projects-root'), 'test-project');
277+
}

tests/legacy-cli/e2e_runner.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import colors from 'ansi-colors';
44
import glob from 'fast-glob';
55
import * as path from 'node:path';
66
import * as fs from 'node:fs';
7+
import { rm } from 'node:fs/promises';
78
import { getGlobalVariable, setGlobalVariable } from './e2e/utils/env';
89
import { gitClean } from './e2e/utils/git';
910
import { createNpmRegistry } from './e2e/utils/registry';
@@ -13,7 +14,7 @@ import { findFreePort } from './e2e/utils/network';
1314
import { extractFile } from './e2e/utils/tar';
1415
import { realpathSync } from 'node:fs';
1516
import { PkgInfo } from './e2e/utils/packages';
16-
import { rm } from 'node:fs/promises';
17+
import { getTestProjectDir } from './e2e/utils/project';
1718

1819
Error.stackTraceLimit = Infinity;
1920

@@ -271,6 +272,14 @@ Promise.all([findFreePort(), findFreePort(), findPackageTars()])
271272
} finally {
272273
registryProcess.kill();
273274
secureRegistryProcess.kill();
275+
276+
await rm(getGlobalVariable('projects-root'), {
277+
recursive: true,
278+
force: true,
279+
maxRetries: 3,
280+
}).catch(() => {
281+
// If this fails it is not fatal.
282+
});
274283
}
275284
})
276285
.catch((err) => {
@@ -334,7 +343,7 @@ function runInitializer(absoluteName: string): Promise<void> {
334343
* Run a file from the main 'test-project' directory in a subprocess via launchTestProcess().
335344
*/
336345
async function runTest(absoluteName: string): Promise<void> {
337-
process.chdir(join(getGlobalVariable('projects-root'), 'test-project'));
346+
process.chdir(getTestProjectDir());
338347

339348
await launchTestProcess(absoluteName);
340349
await cleanTestProject();
@@ -343,7 +352,7 @@ async function runTest(absoluteName: string): Promise<void> {
343352
async function cleanTestProject() {
344353
await gitClean();
345354

346-
const testProject = join(getGlobalVariable('projects-root'), 'test-project');
355+
const testProject = getTestProjectDir();
347356

348357
// Note: Dist directory is not cleared between tests, as `git clean`
349358
// doesn't delete it.

0 commit comments

Comments
 (0)