|
| 1 | +# Copyright Google LLC All Rights Reserved. |
| 2 | +# |
| 3 | +# Use of this source code is governed by an MIT-style license that can be |
| 4 | +# found in the LICENSE file at https://angular.io/license |
| 5 | +"""Angular integration testing |
| 6 | +""" |
| 7 | + |
| 8 | +load("//integration:npm_package_archives.bzl", "NPM_PACKAGE_ARCHIVES", "npm_package_archive_label") |
| 9 | +load("@npm//@angular/dev-infra-private/bazel/integration:index.bzl", "integration_test") |
| 10 | + |
| 11 | +# The generated npm packages should ALWAYS be replaced in integration tests |
| 12 | +# so we pass them to the `check_npm_packages` attribute of npm_integration_test |
| 13 | +FRAMEWORK_PACKAGES = [ |
| 14 | + "@angular/animations", |
| 15 | + "@angular/bazel", |
| 16 | + "@angular/benchpress", |
| 17 | + "@angular/common", |
| 18 | + "@angular/compiler", |
| 19 | + "@angular/compiler-cli", |
| 20 | + "@angular/core", |
| 21 | + "@angular/elements", |
| 22 | + "@angular/forms", |
| 23 | + "@angular/language-service", |
| 24 | + "@angular/localize", |
| 25 | + "@angular/platform-browser", |
| 26 | + "@angular/platform-browser-dynamic", |
| 27 | + "@angular/platform-server", |
| 28 | + "@angular/router", |
| 29 | + "@angular/service-worker", |
| 30 | + "@angular/upgrade", |
| 31 | + "zone.js", |
| 32 | +] |
| 33 | + |
| 34 | +def _ng_integration_test(name, setup_chromium = False, **kwargs): |
| 35 | + "Set defaults for the npm_integration_test common to the angular repo" |
| 36 | + payload_size_tracking = kwargs.pop("payload_size_tracking", []) |
| 37 | + pinned_npm_packages = kwargs.pop("pinned_npm_packages", []) |
| 38 | + use_view_engine_packages = kwargs.pop("use_view_engine_packages", []) |
| 39 | + toolchains = kwargs.pop("toolchains", []) |
| 40 | + environment = kwargs.pop("environment", {}) |
| 41 | + data = kwargs.pop("data", []) |
| 42 | + |
| 43 | + data += [ |
| 44 | + # The Yarn files also need to be part of the integration test as runfiles |
| 45 | + # because the `yarn_bin` target is not a self-contained standalone binary. |
| 46 | + "@nodejs//:yarn_files", |
| 47 | + ] |
| 48 | + |
| 49 | + if setup_chromium: |
| 50 | + data += ["@npm//@angular/dev-infra-private/bazel/browsers/chromium"] |
| 51 | + toolchains += ["@npm//@angular/dev-infra-private/bazel/browsers/chromium:toolchain_alias"] |
| 52 | + environment.update({ |
| 53 | + "CHROMEDRIVER_BIN": "$(CHROMEDRIVER)", |
| 54 | + "CHROME_BIN": "$(CHROMIUM)", |
| 55 | + }) |
| 56 | + |
| 57 | + # By default run `yarn install` followed by `yarn test` using the tools linked |
| 58 | + # into the integration tests (using the `tool_mappings` attribute). |
| 59 | + commands = [ |
| 60 | + "yarn install --cache-folder ./.yarn_local_cache", |
| 61 | + "yarn test", |
| 62 | + ] |
| 63 | + |
| 64 | + command_type = kwargs.pop("commands", "default") |
| 65 | + |
| 66 | + if command_type == "payload_size_tracking": |
| 67 | + commands += [ |
| 68 | + "yarn build", |
| 69 | + # TODO: Replace the track payload-size script with a RBE and Windows-compatible script. |
| 70 | + "$(rootpath //:scripts/ci/track-payload-size.sh) %s dist/*.js true $${RUNFILES}/angular/$(rootpath //goldens:size-tracking/integration-payloads.json)" % name, |
| 71 | + ] |
| 72 | + data += [ |
| 73 | + "//goldens:size-tracking/integration-payloads.json", |
| 74 | + "//:scripts/ci/track-payload-size.sh", |
| 75 | + "//:scripts/ci/payload-size.sh", |
| 76 | + "//:scripts/ci/payload-size.js", |
| 77 | + ] |
| 78 | + |
| 79 | + # Complete list of npm packages to override in the test's package.json file mapped to |
| 80 | + # tgz archive to use for the replacement. This is the full list for all integration |
| 81 | + # tests. Any given integration does not need to use all of these packages. |
| 82 | + npm_packages = {} |
| 83 | + for pkg in NPM_PACKAGE_ARCHIVES: |
| 84 | + if pkg not in pinned_npm_packages: |
| 85 | + npm_packages["@npm//:" + npm_package_archive_label(pkg)] = pkg |
| 86 | + for pkg in FRAMEWORK_PACKAGES: |
| 87 | + # If the generated Angular framework package is listed in the `use_view_engine_packages` |
| 88 | + # list, we will not use the local-built NPM package, but instead map to the |
| 89 | + # corresponding View Engine v12.x package from the `@npm//` workspace. |
| 90 | + if pkg in use_view_engine_packages: |
| 91 | + npm_packages["@npm//:" + npm_package_archive_label("%s-12" % pkg)] = pkg |
| 92 | + else: |
| 93 | + last_segment_name = pkg.split("/")[-1] |
| 94 | + npm_packages["//packages/%s:npm_package_archive" % last_segment_name] = pkg |
| 95 | + |
| 96 | + integration_test( |
| 97 | + name = name, |
| 98 | + commands = commands, |
| 99 | + npm_packages = npm_packages, |
| 100 | + tags = kwargs.pop("tags", []) + [ |
| 101 | + # `integration` tag is used for filtering out these tests from the normal |
| 102 | + # developer workflow |
| 103 | + "integration", |
| 104 | + # Integration tests do not work inside of a sandbox as they may run host applications such |
| 105 | + # as chrome (which is run by ng) that require access to files outside of the sandbox. |
| 106 | + "no-sandbox", |
| 107 | + # Remote doesn't work as it needs network access right now |
| 108 | + "no-remote-exec", |
| 109 | + ], |
| 110 | + data = data, |
| 111 | + environment = environment, |
| 112 | + toolchains = toolchains, |
| 113 | + tool_mappings = { |
| 114 | + "@nodejs//:yarn_bin": "yarn", |
| 115 | + "@nodejs//:node_bin": "node", |
| 116 | + }, |
| 117 | + # 15-minute timeout |
| 118 | + timeout = "long", |
| 119 | + # Tells bazel that this test should be allocated a large amount of memory. |
| 120 | + # See https://docs.bazel.build/versions/2.0.0/be/common-definitions.html#common-attributes-tests. |
| 121 | + size = "enormous", |
| 122 | + **kwargs |
| 123 | + ) |
| 124 | + |
| 125 | +def ng_integration_test(name, **kwargs): |
| 126 | + "Sets up the integration test target based on the test folder name" |
| 127 | + |
| 128 | + native.filegroup( |
| 129 | + name = "_%s_sources" % name, |
| 130 | + srcs = native.glob( |
| 131 | + include = ["**/*"], |
| 132 | + exclude = [ |
| 133 | + "node_modules/**", |
| 134 | + ".yarn_local_cache/**", |
| 135 | + ], |
| 136 | + ), |
| 137 | + ) |
| 138 | + _ng_integration_test( |
| 139 | + name = name, |
| 140 | + srcs = kwargs.pop("srcs", ["_%s_sources" % name]), |
| 141 | + **kwargs |
| 142 | + ) |
0 commit comments