@@ -15,6 +15,7 @@ import { extractFile } from './e2e/utils/tar';
1515import { realpathSync } from 'node:fs' ;
1616import { PkgInfo } from './e2e/utils/packages' ;
1717import { getTestProjectDir } from './e2e/utils/project' ;
18+ import { mktempd } from './e2e/utils/utils' ;
1819
1920Error . 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!);
227222process . env . CHROME_PATH = path . resolve ( process . env . CHROME_PATH ! ) ;
228223process . 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
290288async 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