@@ -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 ,
@@ -162,10 +167,11 @@ console.log(['Tests:', ...testsToRun].join('\n '));
162167setGlobalVariable ( 'argv' , argv ) ;
163168setGlobalVariable ( 'package-manager' , argv . yarn ? 'yarn' : 'npm' ) ;
164169
165- Promise . all ( [ findFreePort ( ) , findFreePort ( ) ] )
166- . then ( async ( [ httpPort , httpsPort ] ) => {
170+ Promise . all ( [ findFreePort ( ) , findFreePort ( ) , findPackageTars ( ) ] )
171+ . then ( async ( [ httpPort , httpsPort , packageTars ] ) => {
167172 setGlobalVariable ( 'package-registry' , 'http://localhost:' + httpPort ) ;
168173 setGlobalVariable ( 'package-secure-registry' , 'http://localhost:' + httpsPort ) ;
174+ setGlobalVariable ( 'package-tars' , packageTars ) ;
169175
170176 // NPM registries for the lifetime of the test execution
171177 const registryProcess = await createNpmRegistry ( httpPort , httpPort ) ;
@@ -314,3 +320,23 @@ function printFooter(testName: string, type: 'setup' | 'initializer' | 'test', s
314320 ) ;
315321 console . log ( '' ) ;
316322}
323+
324+ // Collect the packages passed as arguments and return as {package-name => pkg-path}
325+ async function findPackageTars ( ) : Promise < { [ pkg : string ] : string } > {
326+ const pkgs : string [ ] = ( getGlobalVariable ( 'argv' ) . package as string [ ] ) . flatMap ( ( p ) =>
327+ glob . sync ( p , { realpath : true } ) ,
328+ ) ;
329+
330+ const pkgJsons = await Promise . all ( pkgs . map ( ( pkg ) => extractFile ( pkg , './package/package.json' ) ) ) ;
331+
332+ return pkgs . reduce ( ( all , pkg , i ) => {
333+ const json = pkgJsons [ i ] . toString ( 'utf8' ) ;
334+ const name = JSON . parse ( json ) . name as string ;
335+ if ( ! name ) {
336+ throw new Error ( `Package ${ pkg } - package.json name not found` ) ;
337+ }
338+
339+ all [ name ] = realpathSync ( pkg ) ;
340+ return all ;
341+ } , { } as { [ pkg : string ] : string } ) ;
342+ }
0 commit comments