diff --git a/README.md b/README.md index 4a53845..61eb287 100644 --- a/README.md +++ b/README.md @@ -857,7 +857,7 @@ tach http://example.com | `--package-version` / `-p` | _(none)_ | Specify an NPM package version to swap in ([details](#swap-npm-dependencies)) | | `--browser` / `-b` | `chrome` | Which browsers to launch in automatic mode, comma-delimited (chrome, firefox, safari, edge, ie) ([details](#browsers)) | | `--window-size` | `1024,768` | "width,height" in pixels of the browser windows that will be created | -| `--sample-size` / `-n` | `50` | Minimum number of times to run each benchmark ([details](#minimum-sample-size)) | +| `--sample-size` / `-n` | `50` | Minimum number of times to run each benchmark ([details](#minimum-sample-size)) | | `--auto-sample-conditions` | `0%` | The degrees of difference to try and resolve when auto-sampling ("N%" or "Nms", comma-delimited) ([details](#auto-sample-conditions)) | | `--timeout` | `3` | The maximum number of minutes to spend auto-sampling ([details](#auto-sample)) | | `--measure` | `callback` | Which time interval to measure (`callback`, `global`, `fcp`) ([details](#measurement-modes)) | diff --git a/src/cli.ts b/src/cli.ts index 29ad4e2..67966e8 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -145,7 +145,11 @@ $ tach http://example.com for (const {npmInstalls, mountPoints, specs} of plans) { promises.push( ...npmInstalls.map((install) => - prepareVersionDirectory(install, config.forceCleanNpmInstall) + prepareVersionDirectory( + install, + config.forceCleanNpmInstall, + config.npmrc + ) ) ); promises.push( diff --git a/src/config.ts b/src/config.ts index a24f7de..f1e943e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -34,6 +34,7 @@ export interface Config { resolveBareModules: boolean; remoteAccessibleHost: string; forceCleanNpmInstall: boolean; + npmrc?: string; csvFileStats: string; csvFileRaw: string; } @@ -49,6 +50,7 @@ export async function makeConfig(opts: Opts): Promise { csvFileStats: opts['csv-file'], csvFileRaw: opts['csv-file-raw'], forceCleanNpmInstall: opts['force-clean-npm-install'], + npmrc: opts['npmrc'], githubCheck: opts['github-check'] ? parseGithubCheckFlag(opts['github-check']) : undefined, @@ -149,6 +151,7 @@ export function applyDefaults(partial: Partial): Config { partial.forceCleanNpmInstall !== undefined ? partial.forceCleanNpmInstall : defaults.forceCleanNpmInstall, + npmrc: partial.npmrc !== undefined ? partial.npmrc : '', githubCheck: partial.githubCheck, autoSampleConditions: partial.autoSampleConditions !== undefined diff --git a/src/flags.ts b/src/flags.ts index b3ac716..57e9dd0 100644 --- a/src/flags.ts +++ b/src/flags.ts @@ -92,6 +92,12 @@ export const optDefs: commandLineUsage.OptionDefinition[] = [ type: Boolean, defaultValue: false, }, + { + name: 'npmrc', + description: `.npmrc file to copy into the test install directory.`, + type: String, + defaultValue: '', + }, { name: 'browser', description: @@ -253,6 +259,7 @@ export interface Opts { 'remote-accessible-host': string; 'window-size': string; 'force-clean-npm-install': boolean; + npmrc?: string; 'csv-file': string; 'csv-file-raw': string; 'json-file': string; diff --git a/src/test/config_test.ts b/src/test/config_test.ts index b89cb07..b828449 100644 --- a/src/test/config_test.ts +++ b/src/test/config_test.ts @@ -33,6 +33,7 @@ suite('makeConfig', function () { const argv = ['random-global.html']; const expected: Config = { mode: 'automatic', + npmrc: '', sampleSize: 50, timeout: 3, root: '.', @@ -77,6 +78,7 @@ suite('makeConfig', function () { const argv = ['--config=random-global.json']; const expected: Config = { mode: 'automatic', + npmrc: '', sampleSize: 50, timeout: 3, root: testData, @@ -122,7 +124,7 @@ suite('makeConfig', function () { const argv = ['--config=random-global.json', '--manual']; const expected: Config = { mode: 'manual', - + npmrc: '', sampleSize: 50, timeout: 3, root: testData, @@ -173,6 +175,7 @@ suite('makeConfig', function () { ]; const expected: Config = { mode: 'automatic', + npmrc: '', csvFileStats: 'stats.csv', csvFileRaw: 'raw.csv', jsonFile: 'out.json', @@ -219,6 +222,7 @@ suite('makeConfig', function () { const argv = ['--config=deprecated-horizons.json']; const expected: Config = { mode: 'automatic', + npmrc: '', csvFileStats: '', csvFileRaw: '', jsonFile: '', diff --git a/src/versions.ts b/src/versions.ts index 8209f89..5fa1097 100644 --- a/src/versions.ts +++ b/src/versions.ts @@ -304,7 +304,8 @@ const installSuccessFile = '__TACHOMETER_INSTALL_SUCCESS__'; */ export async function prepareVersionDirectory( {installDir, packageJson}: NpmInstall, - forceCleanInstall: boolean + forceCleanInstall: boolean, + npmrc?: string ): Promise { if (forceCleanInstall) { await fsExtra.remove(installDir); @@ -324,6 +325,13 @@ export async function prepareVersionDirectory( path.join(installDir, 'package.json'), JSON.stringify(packageJson, null, 2) ); + if (npmrc) { + await fsExtra.copy( + path.resolve(npmrc), + path.join(installDir, '.npmrc'), + {} + ); + } await runNpm(['install'], {cwd: installDir}); await fsExtra.writeFile(path.join(installDir, installSuccessFile), ''); }