From e6ecfb0047d6b094c03a9ddd0331010392d42f6e Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Tue, 7 Jun 2022 16:34:28 -0700 Subject: [PATCH] test: ensure test registry is used by default --- tests/legacy-cli/e2e/setup/002-npm-sandbox.ts | 1 + .../e2e/tests/commands/add/registry-option.ts | 11 +++-------- tests/legacy-cli/e2e/utils/packages.ts | 9 ++------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts b/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts index c8b9c0e6c7b8..5d58d8369ae3 100644 --- a/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts +++ b/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts @@ -16,6 +16,7 @@ export default async function () { // isolated within this e2e test invocation. process.env.NPM_CONFIG_USERCONFIG = npmrc; process.env.NPM_CONFIG_PREFIX = npmModulesPrefix; + process.env.NPM_CONFIG_REGISTRY = npmRegistry; // Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch). // In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests. diff --git a/tests/legacy-cli/e2e/tests/commands/add/registry-option.ts b/tests/legacy-cli/e2e/tests/commands/add/registry-option.ts index f5888f788b62..13d54e6c2f50 100644 --- a/tests/legacy-cli/e2e/tests/commands/add/registry-option.ts +++ b/tests/legacy-cli/e2e/tests/commands/add/registry-option.ts @@ -1,18 +1,13 @@ import { getGlobalVariable } from '../../../utils/env'; -import { expectFileToExist, writeMultipleFiles } from '../../../utils/fs'; +import { expectFileToExist } from '../../../utils/fs'; import { ng } from '../../../utils/process'; import { expectToFail } from '../../../utils/utils'; export default async function () { const testRegistry = getGlobalVariable('package-registry'); - // Setup an invalid registry - await writeMultipleFiles({ - '.npmrc': 'registry=http://127.0.0.1:9999', - }); - - // The environment variable has priority over the .npmrc - delete process.env['NPM_CONFIG_REGISTRY']; + // Set an invalid registry + process.env['NPM_CONFIG_REGISTRY'] = 'http://127.0.0.1:9999'; await expectToFail(() => ng('add', '@angular/pwa', '--skip-confirmation')); diff --git a/tests/legacy-cli/e2e/utils/packages.ts b/tests/legacy-cli/e2e/utils/packages.ts index 3c6476f14c3f..52b579a91557 100644 --- a/tests/legacy-cli/e2e/utils/packages.ts +++ b/tests/legacy-cli/e2e/utils/packages.ts @@ -52,11 +52,6 @@ export async function setRegistry(useTestRegistry: boolean): Promise { const isCI = getGlobalVariable('ci'); // Ensure local test registry is used when outside a project - if (isCI) { - // Safe to set a user configuration on CI - await npm('config', 'set', 'registry', url); - } else { - // Yarn supports both `NPM_CONFIG_REGISTRY` and `YARN_REGISTRY`. - process.env['NPM_CONFIG_REGISTRY'] = url; - } + // Yarn supports both `NPM_CONFIG_REGISTRY` and `YARN_REGISTRY`. + process.env['NPM_CONFIG_REGISTRY'] = url; }