@@ -10,6 +10,8 @@ import { createNpmRegistry } from './e2e/utils/registry';
1010import { launchTestProcess } from './e2e/utils/process' ;
1111import { join } from 'path' ;
1212import { findFreePort } from './e2e/utils/network' ;
13+ import { extractFile } from './e2e/utils/tar' ;
14+ import { realpathSync } from 'fs' ;
1315
1416Error . stackTraceLimit = Infinity ;
1517
@@ -34,6 +36,8 @@ Error.stackTraceLimit = Infinity;
3436 * --shard Index of this processes' shard.
3537 * --tmpdir=path Override temporary directory to use for new projects.
3638 * --yarn Use yarn as package manager.
39+ * --package=path An npm package to be published before running tests
40+ *
3741 * If unnamed flags are passed in, the list of tests will be filtered to include only those passed.
3842 */
3943const argv = yargsParser ( process . argv . slice ( 2 ) , {
@@ -49,6 +53,7 @@ const argv = yargsParser(process.argv.slice(2), {
4953 ] ,
5054 string : [ 'devkit' , 'glob' , 'ignore' , 'reuse' , 'ng-tag' , 'tmpdir' , 'ng-version' ] ,
5155 number : [ 'nb-shards' , 'shard' ] ,
56+ array : [ 'package' ] ,
5257 configuration : {
5358 'dot-notation' : false ,
5459 'camel-case-expansion' : false ,
@@ -163,10 +168,11 @@ setGlobalVariable('argv', argv);
163168setGlobalVariable ( 'ci' , process . env [ 'CI' ] ?. toLowerCase ( ) === 'true' || process . env [ 'CI' ] === '1' ) ;
164169setGlobalVariable ( 'package-manager' , argv . yarn ? 'yarn' : 'npm' ) ;
165170
166- Promise . all ( [ findFreePort ( ) , findFreePort ( ) ] )
167- . then ( async ( [ httpPort , httpsPort ] ) => {
171+ Promise . all ( [ findFreePort ( ) , findFreePort ( ) , findPackageTars ( ) ] )
172+ . then ( async ( [ httpPort , httpsPort , packageTars ] ) => {
168173 setGlobalVariable ( 'package-registry' , 'http://localhost:' + httpPort ) ;
169174 setGlobalVariable ( 'package-secure-registry' , 'http://localhost:' + httpsPort ) ;
175+ setGlobalVariable ( 'package-tars' , packageTars ) ;
170176
171177 // NPM registries for the lifetime of the test execution
172178 const registryProcess = await createNpmRegistry ( httpPort , httpPort ) ;
@@ -315,3 +321,23 @@ function printFooter(testName: string, type: 'setup' | 'initializer' | 'test', s
315321 ) ;
316322 console . log ( '' ) ;
317323}
324+
325+ // Collect the packages passed as arguments and return as {package-name => pkg-path}
326+ async function findPackageTars ( ) : Promise < { [ pkg : string ] : string } > {
327+ const pkgs : string [ ] = ( getGlobalVariable ( 'argv' ) . package as string [ ] ) . flatMap ( ( p ) =>
328+ glob . sync ( p , { realpath : true } ) ,
329+ ) ;
330+
331+ const pkgJsons = await Promise . all ( pkgs . map ( ( pkg ) => extractFile ( pkg , 'package/package.json' ) ) ) ;
332+
333+ return pkgs . reduce ( ( all , pkg , i ) => {
334+ const json = pkgJsons [ i ] . toString ( 'utf8' ) ;
335+ const name = JSON . parse ( json ) . name as string ;
336+ if ( ! name ) {
337+ throw new Error ( `Package ${ pkg } - package.json name not found` ) ;
338+ }
339+
340+ all [ name ] = realpathSync ( pkg ) ;
341+ return all ;
342+ } , { } as { [ pkg : string ] : string } ) ;
343+ }
0 commit comments