From f05d2906e8d99bd12a07208903450d62ccbb7c80 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 8 Jan 2019 16:00:05 +0100 Subject: Split installation tests in chunks of 10 to not run out of memory --- packages/monorepo-scripts/src/test_installation.ts | 73 ++++++++++++---------- 1 file changed, 39 insertions(+), 34 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 5ae13b198..ed9b274e2 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -45,45 +45,50 @@ function logIfDefined(x: any): void { const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873/' : 'https://registry.npmjs.org/'; const monorepoRootPath = path.join(__dirname, '../../..'); - const packages = utils.getPackages(monorepoRootPath); + // We sort error messages according to package topology so that we can + // them in a more intuitive order. E.g. if package A has an error and + // package B imports it, the tests for both package A and package B will + // fail. But package B only fails because of an error in package A. + // Since the error in package A is the root cause, we log it first. + const packages = utils.getTopologicallySortedPackages(monorepoRootPath); const installablePackages = _.filter( packages, pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); - utils.log('Testing packages:'); - _.map(installablePackages, pkg => utils.log(`* ${pkg.packageJson.name}`)); - // Run all package tests asynchronously and push promises into an array so - // we can wait for all of them to resolve. - const promises: Array> = []; - const errors: PackageErr[] = []; - for (const installablePackage of installablePackages) { - const packagePromise = testInstallPackageAsync(monorepoRootPath, registry, installablePackage).catch(error => { - errors.push({ packageName: installablePackage.packageJson.name, error }); - }); - promises.push(packagePromise); - } - await Promise.all(promises); - if (errors.length > 0) { - // We sort error messages according to package topology so that we can - // them in a more intuitive order. E.g. if package A has an error and - // package B imports it, the tests for both package A and package B will - // fail. But package B only fails because of an error in package A. - // Since the error in package A is the root cause, we log it first. - const topologicallySortedPackages = utils.getTopologicallySortedPackages(monorepoRootPath); - const topologicallySortedErrors = _.sortBy(errors, packageErr => - findPackageIndex(topologicallySortedPackages, packageErr.packageName), - ); - _.forEach(topologicallySortedErrors, packageError => { - utils.log(`ERROR in package ${packageError.packageName}:`); - logIfDefined(packageError.error.message); - logIfDefined(packageError.error.stderr); - logIfDefined(packageError.error.stdout); - logIfDefined(packageError.error.stack); - }); - process.exit(1); - } else { - process.exit(0); + const CHUNK_SIZE = 10; + const chunkedInstallablePackages = _.chunk(installablePackages, CHUNK_SIZE); + utils.log(`Testing all packages in ${chunkedInstallablePackages.length} chunks`); + for (const installablePackagesChunk of chunkedInstallablePackages) { + utils.log('Testing packages:'); + _.map(installablePackagesChunk, pkg => utils.log(`* ${pkg.packageJson.name}`)); + // Run all package tests within that chunk asynchronously and push promises into an array so + // we can wait for all of them to resolve. + const promises: Array> = []; + const errors: PackageErr[] = []; + for (const installablePackage of installablePackagesChunk) { + const packagePromise = testInstallPackageAsync(monorepoRootPath, registry, installablePackage).catch( + error => { + errors.push({ packageName: installablePackage.packageJson.name, error }); + }, + ); + promises.push(packagePromise); + } + await Promise.all(promises); + if (errors.length > 0) { + const topologicallySortedErrors = _.sortBy(errors, packageErr => + findPackageIndex(packages, packageErr.packageName), + ); + _.forEach(topologicallySortedErrors, packageError => { + utils.log(`ERROR in package ${packageError.packageName}:`); + logIfDefined(packageError.error.message); + logIfDefined(packageError.error.stderr); + logIfDefined(packageError.error.stdout); + logIfDefined(packageError.error.stack); + }); + process.exit(1); + } } + process.exit(0); })().catch(err => { utils.log(`Unexpected error: ${err.message}`); process.exit(1); -- cgit v1.2.3 From 03248244ff8a7d8f276a86262f1b53e8dc9d5675 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 8 Jan 2019 16:16:02 +0100 Subject: Bump up the chunk size --- packages/monorepo-scripts/src/test_installation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index ed9b274e2..59647b836 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -55,7 +55,7 @@ function logIfDefined(x: any): void { packages, pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); - const CHUNK_SIZE = 10; + const CHUNK_SIZE = 15; const chunkedInstallablePackages = _.chunk(installablePackages, CHUNK_SIZE); utils.log(`Testing all packages in ${chunkedInstallablePackages.length} chunks`); for (const installablePackagesChunk of chunkedInstallablePackages) { -- cgit v1.2.3 From 420333e3c35252639bca7a987029d65ad8322290 Mon Sep 17 00:00:00 2001 From: Fabio B Date: Thu, 10 Jan 2019 11:11:23 +0100 Subject: Update packages/monorepo-scripts/src/test_installation.ts Co-Authored-By: LogvinovLeon --- packages/monorepo-scripts/src/test_installation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 59647b836..822f48967 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -45,7 +45,7 @@ function logIfDefined(x: any): void { const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873/' : 'https://registry.npmjs.org/'; const monorepoRootPath = path.join(__dirname, '../../..'); - // We sort error messages according to package topology so that we can + // We sort error messages according to package topology so that we can see // them in a more intuitive order. E.g. if package A has an error and // package B imports it, the tests for both package A and package B will // fail. But package B only fails because of an error in package A. -- cgit v1.2.3