From 427beff0ec16f141a5f87b4f3dd5ae8297db5aec Mon Sep 17 00:00:00 2001 From: JoostK Date: Mon, 20 Sep 2021 23:17:38 +0200 Subject: [PATCH] build: switch ViewEngine ngc tests over to use NPM packages (#43431) The View Engine ngc tests currently rely on the `npm_package` output that is built locally. This becomes problematic with the new Angular Package Format v13 where no metadata files are shipped. To continue being able to test View Engine compilation, we will use the v12.x framework packages for running the View Engine test. Note: This means that we no longer test metadata extraction directly for our framework packages, but given that any change to View Engine will still land in patch, where the VE packaging still occurs, we should be covered here. PR Close #43431 --- packages/compiler-cli/test/BUILD.bazel | 16 +++++------ .../compiler-cli/test/diagnostics/BUILD.bazel | 4 +-- packages/compiler-cli/test/test_support.ts | 27 ++++++++++++++----- .../test/transformers/BUILD.bazel | 6 ++--- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/packages/compiler-cli/test/BUILD.bazel b/packages/compiler-cli/test/BUILD.bazel index 373108771b1..c2a8dd13acb 100644 --- a/packages/compiler-cli/test/BUILD.bazel +++ b/packages/compiler-cli/test/BUILD.bazel @@ -42,7 +42,7 @@ jasmine_node_test( name = "extract_i18n", bootstrap = ["//tools/testing:node_es5"], data = [ - "//packages/core:npm_package", + "@npm//@angular/core-12", ], tags = [ # Disabled as the tests pertain to the old extraction tool only, whereas the Ivy extraction @@ -51,8 +51,8 @@ jasmine_node_test( ], deps = [ ":extract_i18n_lib", - "//packages/common:npm_package", "//packages/core", + "@npm//@angular/common-12", "@npm//minimist", ], ) @@ -77,10 +77,10 @@ jasmine_node_test( timeout = "long", # 900 seconds bootstrap = ["//tools/testing:node_es5"], data = [ - "//packages/common:npm_package", - "//packages/core:npm_package", - "//packages/platform-browser:npm_package", - "//packages/router:npm_package", + "@npm//@angular/common-12", + "@npm//@angular/core-12", + "@npm//@angular/platform-browser-12", + "@npm//@angular/router-12", ], tags = [ # Disabled as these tests are specific to the old ngc compiler, and not ngtsc which has its @@ -116,7 +116,7 @@ jasmine_node_test( name = "perform_watch", bootstrap = ["//tools/testing:node_es5"], data = [ - "//packages/core:npm_package", + "@npm//@angular/core-12", ], deps = [ ":perform_watch_lib", @@ -143,7 +143,7 @@ jasmine_node_test( name = "perform_compile", bootstrap = ["//tools/testing:node_es5"], data = [ - "//packages/core:npm_package", + "@npm//@angular/core-12", ], deps = [ ":perform_compile_lib", diff --git a/packages/compiler-cli/test/diagnostics/BUILD.bazel b/packages/compiler-cli/test/diagnostics/BUILD.bazel index 9c4dab93e3d..322961a923c 100644 --- a/packages/compiler-cli/test/diagnostics/BUILD.bazel +++ b/packages/compiler-cli/test/diagnostics/BUILD.bazel @@ -17,8 +17,8 @@ jasmine_node_test( timeout = "long", # 900 seconds bootstrap = ["//tools/testing:node_es5"], data = [ - "//packages/common:npm_package", - "//packages/core:npm_package", + "@npm//@angular/common-12", + "@npm//@angular/core-12", ], tags = [ # Disabled as these tests pertain to typechecking in the old ngc compiler. The Ivy ngtsc diff --git a/packages/compiler-cli/test/test_support.ts b/packages/compiler-cli/test/test_support.ts index b0464988b80..1bc7fe7d0d6 100644 --- a/packages/compiler-cli/test/test_support.ts +++ b/packages/compiler-cli/test/test_support.ts @@ -128,14 +128,29 @@ export function setupBazelTo(tmpDirPath: string) { fs.mkdirSync(nodeModulesPath); fs.mkdirSync(angularDirectory); - getAngularPackagesFromRunfiles().forEach(({pkgPath, name}) => { - fs.symlinkSync(pkgPath, path.join(angularDirectory, name), 'junction'); - }); + function linkNpmArtifact(artifact: string, target: string = artifact) { + try { + const source = resolveNpmTreeArtifact(`npm/node_modules/${artifact}`); + const dest = path.join(nodeModulesPath, target); + fs.symlinkSync(source, dest, 'junction'); + } catch (e) { + // Allow a module to be missing as some Bazel targets do not need all artifacts. + if (e.code !== 'MODULE_NOT_FOUND') throw e; + } + } + + // Link @angular packages. These reference the v12 packages from NPM as the ViewEngine tests + // can no longer depend on `npm_package` Bazel targets, given that the `ng_module` to produce + // them is no longer capable of producing ViewEngine packages. As a result, the `npm_package` + // outputs end up being compiled using Ivy partial compilation format which is not suitable to be + // used in ViewEngine ngc tests. + linkNpmArtifact('@angular/core-12', '@angular/core'); + linkNpmArtifact('@angular/common-12', '@angular/common'); + linkNpmArtifact('@angular/router-12', '@angular/router'); + linkNpmArtifact('@angular/platform-browser-12', '@angular/platform-browser'); // Link typescript - const typeScriptSource = resolveNpmTreeArtifact('npm/node_modules/typescript'); - const typescriptDest = path.join(nodeModulesPath, 'typescript'); - fs.symlinkSync(typeScriptSource, typescriptDest, 'junction'); + linkNpmArtifact('typescript'); // Link "rxjs" if it has been set up as a runfile. "rxjs" is linked optionally because // not all compiler-cli tests need "rxjs" set up. diff --git a/packages/compiler-cli/test/transformers/BUILD.bazel b/packages/compiler-cli/test/transformers/BUILD.bazel index 60965e95b4f..32b7b78e529 100644 --- a/packages/compiler-cli/test/transformers/BUILD.bazel +++ b/packages/compiler-cli/test/transformers/BUILD.bazel @@ -22,9 +22,9 @@ jasmine_node_test( timeout = "long", # 900 seconds bootstrap = ["//tools/testing:node_es5"], data = [ - "//packages/common:npm_package", - "//packages/core:npm_package", - "//packages/router:npm_package", + "@npm//@angular/common-12", + "@npm//@angular/core-12", + "@npm//@angular/router-12", ], tags = [ # Disabled as these tests pertain to the old compiler and not ngtsc, which doesn't use any