Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit ba42a32

Browse files
committed
Build angular from source & switch to protractor_web_test_suite for e2e tests
1 parent 89c1f2a commit ba42a32

20 files changed

+194
-254
lines changed

.circleci/bazel.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ build --experimental_repository_cache=/home/circleci/bazel_repository_cache
2323

2424
# Workaround https://github.com/bazelbuild/bazel/issues/3645
2525
# Bazel doesn't calculate the memory ceiling correctly when running under Docker.
26-
# Limit Bazel to consuming 3072K of RAM
27-
build --local_resources=3072,2.0,1.0
26+
# Limit Bazel to consuming 2560K of RAM
27+
build --local_resources=2560,1.0,1.0
2828
# Also limit Bazel's own JVM heap to stay within our 4G container limit
29-
startup --host_jvm_args=-Xmx2G
29+
startup --host_jvm_args=-Xmx1g

.circleci/config.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ jobs:
7070

7171
# Run the benchmark
7272
- run: node_modules/.bin/ibazel-benchmark-runner //src:devserver src/hello-world/hello-world.component.ts --url=http://localhost:5432
73-
74-
# Run the protractor end-to-end test - it's not a Bazel target because
75-
# we didn't write a protractor rule yet.
76-
- run: xvfb-run -a yarn e2e
7773

7874
- store_artifacts:
7975
path: dist/bin/src/bundle.min.js

BUILD.bazel

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ alias(
55
actual = "@nodejs//:yarn",
66
)
77

8+
alias(
9+
name = "tsconfig.json",
10+
actual = "//src:tsconfig.json",
11+
)
12+
813
# This export allows targets in other packages to reference files that live
914
# in this package.
1015
exports_files([
11-
# Let ts_library targets reference the root tsconfig.json file
12-
"tsconfig.json",
1316
# Let devserver and testing targets reference zone.js distro
1417
"node_modules/zone.js/dist/zone.min.js",
1518
"node_modules/zone.js/dist/zone-testing-bundle.js",
@@ -18,46 +21,29 @@ exports_files([
1821
# NOTE: this will move to node_modules/BUILD in a later release
1922
filegroup(
2023
name = "node_modules",
21-
# NB: rxjs is not in this list, because we build it from sources using the
22-
# label @rxjs//:rxjs
24+
# NB: angular & rxjs are not in this list, because we build them from sources
2325
srcs = glob(["/".join([
2426
"node_modules",
2527
pkg,
2628
"**",
2729
ext,
2830
]) for pkg in [
29-
"@angular",
3031
"@ngrx",
3132
"@types",
33+
"bytebuffer",
34+
"protobufjs",
3235
"protractor",
36+
"reflect-metadata",
3337
"tsickle",
38+
"tslib",
3439
"tsutils",
3540
"typescript",
41+
"zone.js",
3642
] for ext in [
3743
"*.js",
3844
"*.json",
3945
"*.d.ts",
40-
]]),
41-
)
42-
43-
ANGULAR_TESTING = [
44-
"node_modules/@angular/*/bundles/*-testing.umd.js",
45-
# We use AOT, so the compiler and the dynamic platform-browser should be
46-
# visible only in tests
47-
"node_modules/@angular/compiler/bundles/*.umd.js",
48-
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
49-
]
50-
51-
filegroup(
52-
name = "angular_bundles",
53-
srcs = glob(
54-
["node_modules/@angular/*/bundles/*.umd.js"],
55-
exclude = ANGULAR_TESTING,
56-
),
57-
)
58-
59-
filegroup(
60-
name = "angular_test_bundles",
61-
testonly = 1,
62-
srcs = glob(ANGULAR_TESTING),
46+
]] + [
47+
"node_modules/protractor/**",
48+
]),
6349
)

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ bundlers can be integrated with Bazel.
8989
$ ibazel run src:prodserver
9090
```
9191

92-
We also use Protractor to run end-to-end tests. We don't have a protractor rule
93-
yet, so we'll take the build results from Bazel and run the test outside of Bazel.
94-
95-
```bash
96-
$ yarn e2e
97-
```
98-
9992
## Coming soon
10093

10194
- Protractor bazel rule

WORKSPACE

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ workspace(name = "angular_bazel_example")
1414
# Allows Bazel to run tooling in Node.js
1515
http_archive(
1616
name = "build_bazel_rules_nodejs",
17-
urls = ["https://github.com/bazelbuild/rules_nodejs/archive/0.10.0.zip"],
18-
strip_prefix = "rules_nodejs-0.10.0",
19-
sha256 = "2f77623311da8b5009b1c7eade12de8e15fa3cd2adf9dfcc9f87cb2082b2211f",
17+
urls = ["https://github.com/bazelbuild/rules_nodejs/archive/0.11.2.zip"],
18+
strip_prefix = "rules_nodejs-0.11.2",
19+
sha256 = "c00d5381adeefb56e0ef959a7b168cae628535dab933cfad1c2cd1870cd7c9de",
20+
)
21+
22+
# build_bazel_rules_nodejs depends on skylib
23+
http_archive(
24+
name = "bazel_skylib",
25+
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/0.3.1.zip"],
26+
strip_prefix = "bazel-skylib-0.3.1",
27+
sha256 = "95518adafc9a2b656667bbf517a952e54ce7f350779d0dd95133db4eb5c27fb1",
2028
)
2129

2230
# The Bazel buildtools repo contains tools like the BUILD file formatter, buildifier
@@ -35,9 +43,9 @@ http_archive(
3543
# Runs the TypeScript compiler
3644
http_archive(
3745
name = "build_bazel_rules_typescript",
38-
url = "https://github.com/bazelbuild/rules_typescript/archive/0.15.3.zip",
39-
strip_prefix = "rules_typescript-0.15.3",
40-
sha256 = "a2b26ac3fc13036011196063db1bf7f1eae81334449201dc28087ebfa3708c99",
46+
url = "https://github.com/gregmagolan/rules_typescript/archive/fb559a693dc334e794c432ae3abfbc70a6884408.zip",
47+
strip_prefix = "rules_typescript-fb559a693dc334e794c432ae3abfbc70a6884408",
48+
sha256 = "265439facb09d3514ed595ff8569a6e991d0ee215ce1d6beb96285fbb47ed2bf",
4149
)
4250

4351
# Used by the ts_web_test_suite rule to provision browsers
@@ -65,15 +73,17 @@ http_archive(
6573
sha256 = "ba79c532ac400cefd1859cbc8a9829346aa69e3b99482cd5a54432092cbc3933",
6674
)
6775

68-
####################################
69-
# Tell Bazel about some workspaces that were installed from npm.
70-
7176
# The @angular repo contains rule for building Angular applications
72-
local_repository(
77+
http_archive(
7378
name = "angular",
74-
path = "node_modules/@angular/bazel",
79+
url = "https://github.com/angular/angular/archive/4cb10748507248bc67991980bb626a6466c4693e.zip",
80+
strip_prefix = "angular-4cb10748507248bc67991980bb626a6466c4693e",
81+
sha256 = "89f6c6a2b1ac75cc52177b293a9c3070e55c7be68102ee24edb08d76c75d704c",
7582
)
7683

84+
####################################
85+
# Tell Bazel about some workspaces that were installed from npm.
86+
7787
# The @rxjs repo contains targets for building rxjs with bazel
7888
local_repository(
7989
name = "rxjs",
@@ -108,6 +118,14 @@ load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")
108118

109119
sass_repositories()
110120

121+
#
122+
# Load and install our dependencies from local repositories
123+
#
124+
125+
load("@angular//:index.bzl", "ng_setup_workspace")
126+
127+
ng_setup_workspace()
128+
111129
####################################
112130
# Setup our local toolchain
113131

package.json

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,30 @@
44
"description": "Demo of bazel rules for angular",
55
"license": "Apache 2.0",
66
"dependencies": {
7-
"@angular/animations": "6.0.4",
8-
"@angular/common": "6.0.4",
9-
"@angular/core": "6.0.4",
10-
"@angular/forms": "6.0.4",
11-
"@angular/platform-browser": "6.0.4",
12-
"@angular/router": "6.0.4",
13-
"@angular/upgrade": "6.0.4",
147
"@ngrx/store": "6.0.1",
158
"rxjs": "6.2.2",
9+
"tslib": "1.9.3",
1610
"zone.js": "0.8.26"
1711
},
1812
"devDependencies": {
19-
"@angular/bazel": "6.0.4",
20-
"@angular/compiler": "6.0.4",
21-
"@angular/compiler-cli": "6.0.4",
22-
"@angular/platform-browser-dynamic": "6.0.4",
13+
"@angular/compiler": "6.1.0",
14+
"@angular/compiler-cli": "6.1.0",
15+
"@angular/core": "6.1.0",
2316
"@bazel/benchmark-runner": "0.1.0",
2417
"@bazel/ibazel": "0.4.0",
2518
"@types/jasmine": "2.8.8",
19+
"@types/node": "6.0.88",
2620
"clang-format": "1.2.3",
2721
"concurrently": "3.6.1",
2822
"husky": "0.14.3",
23+
"protobufjs": "5.0.0",
2924
"protractor": "5.4.0",
30-
"typescript": "2.7.2"
25+
"tsutils": "2.20.0",
26+
"typescript": "2.9.1"
3127
},
3228
"scripts": {
33-
"postinstall": "concurrently \"webdriver-manager update $CHROMEDRIVER_VERSION_ARG\" \"ngc -p postinstall.tsconfig.json\"",
29+
"postinstall": "ngc -p postinstall.tsconfig.json",
3430
"serve": "ibazel run //src:devserver",
35-
"pree2e": "bazel build test/...",
36-
"e2e": "yarn e2e-prodserver && yarn e2e-devserver",
37-
"e2e-prodserver": "concurrently \"bazel run //src:prodserver\" \"while ! nc -z 127.0.0.1 5432; do sleep 1; done && protractor\" --kill-others --success first",
38-
"e2e-devserver": "concurrently \"bazel run //src:devserver\" \"while ! nc -z 127.0.0.1 5432; do sleep 1; done && protractor\" --kill-others --success first",
3931
"prebuildifier": "bazel build @com_github_bazelbuild_buildtools//buildifier",
4032
"buildifier": "note: working around https://github.com/alexeagle/angular-bazel-example/issues/60",
4133
"buildifier": "find . -type f \\( -name BUILD -or -name BUILD.bazel \\) ! -path \"./node_modules/*\" | xargs $(bazel info bazel-bin)/external/com_github_bazelbuild_buildtools/buildifier/*/buildifier",

postinstall.tsconfig.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@
1111
"types": []
1212
},
1313
"include": [
14-
"node_modules/@angular/**/*",
1514
"node_modules/@ngrx/**/*"
1615
],
1716
"exclude": [
18-
"node_modules/@angular/bazel/**",
19-
"node_modules/@angular/compiler-cli/**",
20-
"node_modules/@angular/tsc-wrapped/**",
21-
"node_modules/@angular/*/testing/**",
2217
"node_modules/@ngrx/store/migrations/**",
2318
"node_modules/@ngrx/store/schematics/**",
2419
"node_modules/@ngrx/store/schematics-core/**"

protractor.conf.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ng_module(
1212
deps = [
1313
"//src/hello-world",
1414
"//src/todos",
15+
"@angular//packages/core",
16+
"@angular//packages/router",
1517
],
1618
)
1719

@@ -21,16 +23,17 @@ ts_devserver(
2123
name = "devserver",
2224
additional_root_paths = [
2325
"angular_bazel_example/node_modules/zone.js/dist",
26+
"angular_bazel_example/node_modules/tslib",
2427
"angular_bazel_example/node_modules/@ngrx/store/bundles",
2528
],
2629
entry_module = "angular_bazel_example/src/main",
2730
scripts = [
2831
":require.config.js",
29-
"//:angular_bundles",
3032
],
3133
serving_path = "/bundle.min.js",
3234
static_files = [
3335
"//:node_modules/zone.js/dist/zone.min.js",
36+
"//:node_modules/tslib/tslib.js",
3437
"//:node_modules/@ngrx/store/bundles/store.umd.min.js",
3538
"index.html",
3639
],

src/hello-world/BUILD.bazel

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ng_module(
2323
tsconfig = "//src:tsconfig.json",
2424
deps = [
2525
"//src/lib",
26+
"@angular//packages/core",
27+
"@angular//packages/forms",
2628
"@rxjs",
2729
],
2830
)
@@ -31,19 +33,28 @@ ts_library(
3133
name = "test_lib",
3234
testonly = 1,
3335
srcs = glob(["*.spec.ts"]),
34-
deps = [":hello-world"],
36+
deps = [
37+
":hello-world",
38+
"@angular//packages/core",
39+
"@angular//packages/core/testing",
40+
"@angular//packages/platform-browser",
41+
"@angular//packages/platform-browser-dynamic/testing",
42+
],
3543
)
3644

3745
ts_web_test_suite(
3846
name = "test",
39-
bootstrap = ["//:node_modules/zone.js/dist/zone-testing-bundle.js"],
47+
srcs = ["//:node_modules/tslib/tslib.js"],
48+
# do not sort
49+
bootstrap = [
50+
"//:node_modules/zone.js/dist/zone-testing-bundle.js",
51+
"//:node_modules/reflect-metadata/Reflect.js",
52+
],
4053
browsers = [
4154
"@io_bazel_rules_webtesting//browsers:chromium-local",
4255
"@io_bazel_rules_webtesting//browsers:firefox-local",
4356
],
4457
deps = [
4558
":test_lib",
46-
"//:angular_bundles",
47-
"//:angular_test_bundles",
4859
],
4960
)

src/hello-world/hello-world.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ <h1>Home</h1>
22

33
<div>Hello {{ name }}</div>
44

5-
<input type="text" [value]="name" (input)="name = $event.target.value"/>
5+
<input type="text" [(ngModel)]="name"/>

src/hello-world/hello-world.component.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {DebugElement} from '@angular/core';
21
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
32
import {By} from '@angular/platform-browser';
43
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';

src/hello-world/hello-world.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {NgModule} from '@angular/core';
2+
import {FormsModule} from '@angular/forms';
23

34
import {HelloWorldComponent} from './hello-world.component';
45

56
@NgModule({
67
declarations: [HelloWorldComponent],
8+
imports: [FormsModule],
79
exports: [HelloWorldComponent],
810
})
911
export class HelloWorldModule {

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'tslib';
2+
13
import {platformBrowser} from '@angular/platform-browser';
24
import {AppModuleNgFactory} from './app.module.ngfactory';
35

src/todos/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ ng_module(
2424
deps = [
2525
"//src/lib",
2626
"//src/reducers",
27+
"@angular//packages/common",
28+
"@angular//packages/core",
29+
"@angular//packages/forms",
2730
"@rxjs",
2831
],
2932
)

test/e2e/BUILD.bazel

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
2+
load("@angular//:index.bzl", "protractor_web_test_suite")
23

34
ts_library(
45
name = "e2e",
56
testonly = 1,
67
srcs = glob(["*.ts"]),
78
)
9+
10+
protractor_web_test_suite(
11+
name = "prodserver_test",
12+
data = ["@angular//packages/bazel/src/protractor/utils"],
13+
on_prepare = ":protractor.on-prepare.js",
14+
server = "//src:prodserver",
15+
deps = [":e2e"],
16+
)
17+
18+
protractor_web_test_suite(
19+
name = "devserver_test",
20+
data = ["@angular//packages/bazel/src/protractor/utils"],
21+
on_prepare = ":protractor.on-prepare.js",
22+
server = "//src:devserver",
23+
deps = [":e2e"],
24+
)

test/e2e/protractor.on-prepare.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const protractorUtils = require('@angular/bazel/protractor-utils');
2+
const protractor = require('protractor');
3+
4+
module.exports = function(config) {
5+
const portFlag = config.server.endsWith('prodserver') ? '-p' : '-port';
6+
return protractorUtils.runServer(config.workspace, config.server, portFlag, [])
7+
.then(serverSpec => {
8+
const serverUrl = `http://localhost:${serverSpec.port}`;
9+
protractor.browser.baseUrl = serverUrl;
10+
});
11+
};

0 commit comments

Comments
 (0)