From f30a69f260ebe65e8afdae5f0757a7bf5a8110a6 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 10 Feb 2023 11:57:47 +0000 Subject: [PATCH] test: remove non bazel related setups This commits removes some of the non Bazel related checks that are no longer required. This also fixes some issues with `bazel run` --- .circleci/dynamic_config.yml | 2 +- tests/legacy-cli/BUILD.bazel | 4 +- .../e2e/initialize/500-create-project.ts | 13 +----- .../e2e/tests/build/esbuild-unsupported.ts | 3 +- tests/legacy-cli/e2e/utils/bazel.ts | 3 -- tests/legacy-cli/e2e/utils/process.ts | 7 +--- tests/legacy-cli/e2e/utils/project.ts | 40 +----------------- .../legacy-cli/e2e/utils/run_test_process.js | 3 -- tests/legacy-cli/e2e_runner.ts | 42 +++++-------------- tests/legacy-cli/run_e2e.js | 3 -- 10 files changed, 19 insertions(+), 101 deletions(-) delete mode 100644 tests/legacy-cli/e2e/utils/bazel.ts delete mode 100644 tests/legacy-cli/e2e/utils/run_test_process.js delete mode 100644 tests/legacy-cli/run_e2e.js diff --git a/.circleci/dynamic_config.yml b/.circleci/dynamic_config.yml index 27303081e6..1102d2c17c 100644 --- a/.circleci/dynamic_config.yml +++ b/.circleci/dynamic_config.yml @@ -444,7 +444,7 @@ workflows: # Publish jobs - snapshot_publish: - # <<: *only_release_branches + <<: *only_release_branches requires: - setup - e2e-cli diff --git a/tests/legacy-cli/BUILD.bazel b/tests/legacy-cli/BUILD.bazel index 00be22b444..03d972e334 100644 --- a/tests/legacy-cli/BUILD.bazel +++ b/tests/legacy-cli/BUILD.bazel @@ -4,7 +4,9 @@ load(":e2e.bzl", "e2e_suites") ts_library( name = "runner", testonly = True, - srcs = glob(["**/*.ts"]), + srcs = [ + "e2e_runner.ts", + ], data = [ "verdaccio.yaml", "verdaccio_auth.yaml", diff --git a/tests/legacy-cli/e2e/initialize/500-create-project.ts b/tests/legacy-cli/e2e/initialize/500-create-project.ts index b5ce6bd074..af73259c44 100644 --- a/tests/legacy-cli/e2e/initialize/500-create-project.ts +++ b/tests/legacy-cli/e2e/initialize/500-create-project.ts @@ -1,10 +1,9 @@ import { join } from 'path'; import yargsParser from 'yargs-parser'; -import { IS_BAZEL } from '../utils/bazel'; import { getGlobalVariable } from '../utils/env'; import { expectFileToExist } from '../utils/fs'; import { gitClean } from '../utils/git'; -import { installPackage, setRegistry as setNPMConfigRegistry } from '../utils/packages'; +import { setRegistry as setNPMConfigRegistry } from '../utils/packages'; import { ng } from '../utils/process'; import { prepareProjectForE2e, updateJsonFile } from '../utils/project'; @@ -22,16 +21,6 @@ export default async function () { // Ensure local test registry is used when outside a project await setNPMConfigRegistry(true); - // Install puppeteer in the parent directory for use by the CLI within any test project. - // Align the version with the primary project package.json. - // Bazel has own browser toolchains - // TODO(bazel): remove non-bazel - if (!IS_BAZEL) { - const puppeteerVersion = - require('../../../../package.json').devDependencies.puppeteer.replace(/^[\^~]/, ''); - await installPackage(`puppeteer@${puppeteerVersion}`); - } - await ng('new', 'test-project', '--skip-install'); await expectFileToExist(join(process.cwd(), 'test-project')); process.chdir('./test-project'); diff --git a/tests/legacy-cli/e2e/tests/build/esbuild-unsupported.ts b/tests/legacy-cli/e2e/tests/build/esbuild-unsupported.ts index b2dab3bbac..2f47f64f62 100644 --- a/tests/legacy-cli/e2e/tests/build/esbuild-unsupported.ts +++ b/tests/legacy-cli/e2e/tests/build/esbuild-unsupported.ts @@ -1,10 +1,9 @@ import { join } from 'path'; -import { IS_BAZEL } from '../../utils/bazel'; import { execWithEnv } from '../../utils/process'; export default async function () { // TODO(bazel): fails with bazel on windows - if (IS_BAZEL && process.platform.startsWith('win')) { + if (process.platform.startsWith('win')) { return; } diff --git a/tests/legacy-cli/e2e/utils/bazel.ts b/tests/legacy-cli/e2e/utils/bazel.ts deleted file mode 100644 index 06a99f9023..0000000000 --- a/tests/legacy-cli/e2e/utils/bazel.ts +++ /dev/null @@ -1,3 +0,0 @@ -// TODO(bazel): remove this along with any non-bazel specific logic using it. - -export const IS_BAZEL = !!process.env.BAZEL_TARGET; diff --git a/tests/legacy-cli/e2e/utils/process.ts b/tests/legacy-cli/e2e/utils/process.ts index fa5f8afc3e..48e6775c2c 100644 --- a/tests/legacy-cli/e2e/utils/process.ts +++ b/tests/legacy-cli/e2e/utils/process.ts @@ -7,7 +7,6 @@ import { getGlobalVariable, getGlobalVariablesEnv } from './env'; import { catchError } from 'rxjs/operators'; import treeKill from 'tree-kill'; import { delimiter, join, resolve } from 'path'; -import { IS_BAZEL } from './bazel'; interface ExecOptions { silent?: boolean; @@ -420,11 +419,7 @@ export async function launchTestProcess(entry: string, ...args: any[]): Promise< .filter((p) => p.startsWith(tempRoot) || p.startsWith(TEMP) || !p.includes('angular-cli')) .join(delimiter); - const testProcessArgs = [ - resolve(__dirname, IS_BAZEL ? 'test_process' : 'run_test_process'), - entry, - ...args, - ]; + const testProcessArgs = [resolve(__dirname, 'test_process'), entry, ...args]; return new Promise((resolve, reject) => { spawn(process.execPath, testProcessArgs, { diff --git a/tests/legacy-cli/e2e/utils/project.ts b/tests/legacy-cli/e2e/utils/project.ts index 2f9a00a21a..91425a6151 100644 --- a/tests/legacy-cli/e2e/utils/project.ts +++ b/tests/legacy-cli/e2e/utils/project.ts @@ -2,13 +2,12 @@ import * as fs from 'fs'; import * as path from 'path'; import { prerelease, SemVer } from 'semver'; import yargsParser from 'yargs-parser'; -import { IS_BAZEL } from './bazel'; import { getGlobalVariable } from './env'; import { readFile, replaceInFile, writeFile } from './fs'; import { gitCommit } from './git'; import { findFreePort } from './network'; import { installWorkspacePackages, PkgInfo } from './packages'; -import { exec, execAndWaitForOutputToMatch, git, ng } from './process'; +import { execAndWaitForOutputToMatch, git, ng } from './process'; export function updateJsonFile(filePath: string, fn: (json: any) => any | void) { return readFile(filePath).then((tsConfigJson) => { @@ -51,43 +50,6 @@ export async function prepareProjectForE2e(name: string) { await installWorkspacePackages(); await ng('generate', 'e2e', '--related-app-name', name); - // bazel will use its own sandboxed browser + webdriver - // TODO(bazel): remove non-bazel - if (!IS_BAZEL) { - const protractorPath = require.resolve('protractor'); - const webdriverUpdatePath = require.resolve('webdriver-manager/selenium/update-config.json', { - paths: [protractorPath], - }); - const webdriverUpdate = JSON.parse(await readFile(webdriverUpdatePath)) as { - chrome: { last: string }; - }; - - const chromeDriverVersion = webdriverUpdate.chrome.last.match(/chromedriver_([\d|\.]+)/)?.[1]; - if (!chromeDriverVersion) { - throw new Error('Could not extract chrome webdriver version.'); - } - - // Initialize selenium webdriver. - // Often fails the first time so attempt twice if necessary. - const runWebdriverUpdate = () => - exec( - process.execPath, - 'node_modules/protractor/bin/webdriver-manager', - 'update', - '--standalone', - 'false', - '--gecko', - 'false', - '--versions.chrome', - chromeDriverVersion, - ); - try { - await runWebdriverUpdate(); - } catch { - await runWebdriverUpdate(); - } - } - await useCIChrome(name, 'e2e'); await useCIChrome(name, ''); await useCIDefaults(name); diff --git a/tests/legacy-cli/e2e/utils/run_test_process.js b/tests/legacy-cli/e2e/utils/run_test_process.js deleted file mode 100644 index 1a7fa92ccf..0000000000 --- a/tests/legacy-cli/e2e/utils/run_test_process.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; -require('../../../../lib/bootstrap-local'); -require('./test_process'); diff --git a/tests/legacy-cli/e2e_runner.ts b/tests/legacy-cli/e2e_runner.ts index ef28132e58..9b03c73e29 100644 --- a/tests/legacy-cli/e2e_runner.ts +++ b/tests/legacy-cli/e2e_runner.ts @@ -1,4 +1,3 @@ -import { logging } from '../../packages/angular_devkit/core/src'; import { createConsoleLogger } from '../../packages/angular_devkit/core/node'; import * as colors from 'ansi-colors'; import glob from 'glob'; @@ -9,10 +8,9 @@ import { gitClean } from './e2e/utils/git'; import { createNpmRegistry } from './e2e/utils/registry'; import { launchTestProcess } from './e2e/utils/process'; import { delimiter, dirname, join } from 'path'; -import { IS_BAZEL } from './e2e/utils/bazel'; import { findFreePort } from './e2e/utils/network'; import { extractFile } from './e2e/utils/tar'; -import { readFileSync, realpathSync } from 'fs'; +import { realpathSync } from 'fs'; import { PkgInfo } from './e2e/utils/packages'; Error.stackTraceLimit = Infinity; @@ -57,12 +55,11 @@ const argv = yargsParser(process.argv.slice(2), { number: ['nb-shards', 'shard'], array: ['package'], configuration: { - 'dot-notation': false, 'camel-case-expansion': false, + 'dot-notation': false, }, default: { 'package': ['./dist/_*.tgz'], - 'debug': !!process.env.BUILD_WORKSPACE_DIRECTORY, 'glob': process.env.TESTBRIDGE_TEST_ONLY, 'nb-shards': @@ -119,23 +116,19 @@ function lastLogger() { } // Under bazel the compiled file (.js) and types (.d.ts) are available. -// Outside bazel the source .ts files are available. -const SRC_FILE_EXT = IS_BAZEL ? 'js' : 'ts'; -const SRC_FILE_EXT_RE = new RegExp(`\.${SRC_FILE_EXT}$`); - -const testGlob = argv.glob || `tests/**/*.${SRC_FILE_EXT}`; +const SRC_FILE_EXT_RE = /\.js$/; +const testGlob = argv.glob?.replace(/\.ts$/, '.js') || `tests/**/*.js`; const e2eRoot = path.join(__dirname, 'e2e'); -const allSetups = glob.sync(`setup/**/*.${SRC_FILE_EXT}`, { nodir: true, cwd: e2eRoot }).sort(); -const allInitializers = glob - .sync(`initialize/**/*.${SRC_FILE_EXT}`, { nodir: true, cwd: e2eRoot }) - .sort(); +const allSetups = glob.sync(`setup/**/*.js`, { nodir: true, cwd: e2eRoot }).sort(); +const allInitializers = glob.sync(`initialize/**/*.js`, { nodir: true, cwd: e2eRoot }).sort(); + const allTests = glob .sync(testGlob, { nodir: true, cwd: e2eRoot, ignore: argv.ignore }) // Replace windows slashes. .map((name) => name.replace(/\\/g, '/')) .filter((name) => { - if (name.endsWith(`/setup.${SRC_FILE_EXT}`)) { + if (name.endsWith('/setup.js')) { return false; } if (!SRC_FILE_EXT_RE.test(name)) { @@ -212,21 +205,8 @@ setGlobalVariable('package-manager', argv.yarn ? 'yarn' : 'npm'); // // Resolve from relative paths to absolute paths within the bazel runfiles tree // so subprocesses spawned in a different working directory can still find them. -process.env.CHROME_BIN = IS_BAZEL - ? path.resolve(process.env.CHROME_BIN!) - : require('puppeteer').executablePath(); -process.env.CHROMEDRIVER_BIN = IS_BAZEL - ? path.resolve(process.env.CHROMEDRIVER_BIN!) - : (function () { - const protractorPath = require.resolve('protractor'); - const webdriverUpdatePath = require.resolve('webdriver-manager/selenium/update-config.json', { - paths: [protractorPath], - }); - const webdriverUpdate = JSON.parse(readFileSync(webdriverUpdatePath).toString()) as { - chrome: { last: string }; - }; - return webdriverUpdate.chrome.last; - })(); +process.env.CHROME_BIN = path.resolve(process.env.CHROME_BIN!); +process.env.CHROMEDRIVER_BIN = path.resolve(process.env.CHROMEDRIVER_BIN!); Promise.all([findFreePort(), findFreePort(), findPackageTars()]) .then(async ([httpPort, httpsPort, packageTars]) => { @@ -299,7 +279,7 @@ async function runSteps( const name = relativeName.replace(SRC_FILE_EXT_RE, ''); const start = Date.now(); - printHeader(relativeName, stepIndex, steps.length, type); + printHeader(name, stepIndex, steps.length, type); // Run the test function with the current file on the logStack. logStack.push(lastLogger().createChild(absoluteName)); diff --git a/tests/legacy-cli/run_e2e.js b/tests/legacy-cli/run_e2e.js deleted file mode 100644 index fb004c88a0..0000000000 --- a/tests/legacy-cli/run_e2e.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; -require('../../lib/bootstrap-local'); -require('./e2e_runner.ts');