Skip to content

Commit 8335187

Browse files
alan-agius4dgp1130
authored andcommitted
build: clean up verdaccio storage and share storage
Ensures that the Verdaccio registry storage is properly cleaned up at the end of E2E tests by placing it within the main temporary directory which is now explicitly deleted on process exit or SIGINT. This change also centralizes the Verdaccio storage location, allowing both HTTP and HTTPS Verdaccio instances to share the same storage, simplifying test setup and cleanup. Removes redundant temporary directory creation logic for npm sandbox and temporary project roots, as these are now managed by a single `tmp-root`.
1 parent 93da64e commit 8335187

File tree

4 files changed

+80
-86
lines changed

4 files changed

+80
-86
lines changed

tests/legacy-cli/e2e/setup/001-create-tmp-dir.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
import { ChildProcess, fork } from 'node:child_process';
22
import { on } from 'node:events';
3+
import { mkdir } from 'node:fs/promises';
34
import { join } from 'node:path';
45
import { getGlobalVariable } from './env';
56
import { writeFile, readFile } from './fs';
6-
import { mktempd } from './utils';
7+
import { existsSync } from 'node:fs';
78

89
export async function createNpmRegistry(
910
port: number,
1011
httpsPort: number,
1112
withAuthentication = false,
1213
): Promise<ChildProcess> {
1314
// Setup local package registry
14-
const registryPath = await mktempd('angular-cli-e2e-registry-');
15+
const registryPath = join(getGlobalVariable('tmp-root'), 'registry');
16+
if (!existsSync(registryPath)) {
17+
await mkdir(registryPath);
18+
}
19+
20+
const configFileName = withAuthentication ? 'verdaccio_auth.yaml' : 'verdaccio.yaml';
21+
let configContent = await readFile(join(__dirname, '../', configFileName));
22+
configContent = configContent
23+
.replace(/\$\{HTTP_PORT\}/g, String(port))
24+
.replace(/\$\{HTTPS_PORT\}/g, String(httpsPort));
25+
const configPath = join(registryPath, configFileName);
1526

16-
let configContent = await readFile(
17-
join(__dirname, '../', withAuthentication ? 'verdaccio_auth.yaml' : 'verdaccio.yaml'),
18-
);
19-
configContent = configContent.replace(/\$\{HTTP_PORT\}/g, String(port));
20-
configContent = configContent.replace(/\$\{HTTPS_PORT\}/g, String(httpsPort));
21-
const configPath = join(registryPath, 'verdaccio.yaml');
2227
await writeFile(configPath, configContent);
2328

2429
const verdaccioServer = fork(require.resolve('verdaccio/bin/verdaccio'), ['-c', configPath]);

tests/legacy-cli/e2e_runner.ts

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { extractFile } from './e2e/utils/tar';
1515
import { realpathSync } from 'node:fs';
1616
import { PkgInfo } from './e2e/utils/packages';
1717
import { getTestProjectDir } from './e2e/utils/project';
18+
import { mktempd } from './e2e/utils/utils';
1819

1920
Error.stackTraceLimit = Infinity;
2021

@@ -31,13 +32,9 @@ Error.stackTraceLimit = Infinity;
3132
* --ng-snapshots Install angular snapshot builds in the test project.
3233
* --glob Run tests matching this glob pattern (relative to tests/e2e/).
3334
* --ignore Ignore tests matching this glob pattern.
34-
* --reuse=/path Use a path instead of create a new project. That project should have been
35-
* created, and npm installed. Ideally you want a project created by a previous
36-
* run of e2e.
3735
* --nb-shards Total number of shards that this is part of. Default is 2 if --shard is
3836
* passed in.
3937
* --shard Index of this processes' shard.
40-
* --tmpdir=path Override temporary directory to use for new projects.
4138
* --package-manager Package manager to use.
4239
* --package=path An npm package to be published before running tests
4340
*
@@ -58,8 +55,6 @@ const parsed = parseArgs({
5855
'nosilent': { type: 'boolean' },
5956
'package': { type: 'string', multiple: true, default: ['./dist/_*.tgz'] },
6057
'package-manager': { type: 'string', default: 'npm' },
61-
'reuse': { type: 'string' },
62-
'tmpdir': { type: 'string' },
6358
'verbose': { type: 'boolean' },
6459

6560
'nb-shards': { type: 'string' },
@@ -227,65 +222,68 @@ process.env.CHROME_BIN = path.resolve(process.env.CHROME_BIN!);
227222
process.env.CHROME_PATH = path.resolve(process.env.CHROME_PATH!);
228223
process.env.CHROMEDRIVER_BIN = path.resolve(process.env.CHROMEDRIVER_BIN!);
229224

230-
Promise.all([findFreePort(), findFreePort(), findPackageTars()])
231-
.then(async ([httpPort, httpsPort, packageTars]) => {
232-
setGlobalVariable('package-registry', 'http://localhost:' + httpPort);
233-
setGlobalVariable('package-secure-registry', 'http://localhost:' + httpsPort);
234-
setGlobalVariable('package-tars', packageTars);
235-
236-
// NPM registries for the lifetime of the test execution
237-
const registryProcess = await createNpmRegistry(httpPort, httpPort);
238-
const secureRegistryProcess = await createNpmRegistry(httpPort, httpsPort, true);
239-
240-
try {
241-
await runSteps(runSetup, allSetups, 'setup');
242-
await runSteps(runInitializer, allInitializers, 'initializer');
243-
await runSteps(runTest, testsToRun, 'test');
244-
245-
if (shardId !== null) {
246-
console.log(colors.green(`Done shard ${shardId} of ${nbShards}.`));
247-
} else {
248-
console.log(colors.green('Done.'));
249-
}
225+
(async () => {
226+
const tempRoot = await mktempd('angular-cli-e2e-', process.env.E2E_TEMP);
227+
setGlobalVariable('tmp-root', tempRoot);
228+
229+
process.on('SIGINT', deleteTemporaryRoot);
230+
process.on('exit', deleteTemporaryRoot);
231+
232+
const [httpPort, httpsPort, packageTars] = await Promise.all([
233+
findFreePort(),
234+
findFreePort(),
235+
findPackageTars(),
236+
]);
237+
setGlobalVariable('package-registry', 'http://localhost:' + httpPort);
238+
setGlobalVariable('package-secure-registry', 'http://localhost:' + httpsPort);
239+
setGlobalVariable('package-tars', packageTars);
240+
241+
// NPM registries for the lifetime of the test execution
242+
const registryProcess = await createNpmRegistry(httpPort, httpPort);
243+
const secureRegistryProcess = await createNpmRegistry(httpPort, httpsPort, true);
244+
245+
try {
246+
console.log(` Using "${tempRoot}" as temporary directory for a new project.`);
247+
248+
await runSteps(runSetup, allSetups, 'setup');
249+
await runSteps(runInitializer, allInitializers, 'initializer');
250+
await runSteps(runTest, testsToRun, 'test');
251+
252+
if (shardId !== null) {
253+
console.log(colors.green(`Done shard ${shardId} of ${nbShards}.`));
254+
} else {
255+
console.log(colors.green('Done.'));
256+
}
250257

251-
process.exitCode = 0;
252-
} catch (err) {
253-
if (err instanceof Error) {
254-
console.log('\n');
255-
console.error(colors.red(err.message));
256-
if (err.stack) {
257-
console.error(colors.red(err.stack));
258-
}
259-
} else {
260-
console.error(colors.red(String(err)));
258+
process.exitCode = 0;
259+
} catch (err) {
260+
if (err instanceof Error) {
261+
console.log('\n');
262+
console.error(colors.red(err.message));
263+
if (err.stack) {
264+
console.error(colors.red(err.stack));
261265
}
266+
} else {
267+
console.error(colors.red(String(err)));
268+
}
262269

263-
if (argv.debug) {
264-
console.log(`Current Directory: ${process.cwd()}`);
265-
console.log('Will loop forever while you debug... CTRL-C to quit.');
266-
267-
// Wait forever until user explicitly cancels.
268-
await new Promise(() => {});
269-
}
270+
if (argv.debug) {
271+
console.log(`Current Directory: ${process.cwd()}`);
272+
console.log('Will loop forever while you debug... CTRL-C to quit.');
270273

271-
process.exitCode = 1;
272-
} finally {
273-
registryProcess.kill();
274-
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-
});
274+
// Wait forever until user explicitly cancels.
275+
await new Promise(() => {});
283276
}
284-
})
285-
.catch((err) => {
286-
console.error(colors.red(`Unkown Error: ${err}`));
277+
287278
process.exitCode = 1;
288-
});
279+
} finally {
280+
registryProcess.kill();
281+
secureRegistryProcess.kill();
282+
}
283+
})().catch((err) => {
284+
console.error(colors.red(`Unkown Error: ${err}`));
285+
process.exitCode = 1;
286+
});
289287

290288
async function runSteps(
291289
run: (name: string) => Promise<void> | void,
@@ -415,3 +413,13 @@ async function findPackageTars(): Promise<{ [pkg: string]: PkgInfo }> {
415413
{} as { [pkg: string]: PkgInfo },
416414
);
417415
}
416+
417+
function deleteTemporaryRoot(): void {
418+
try {
419+
fs.rmSync(getGlobalVariable('tmp-root'), {
420+
recursive: true,
421+
force: true,
422+
maxRetries: 3,
423+
});
424+
} catch {}
425+
}

0 commit comments

Comments
 (0)