Skip to content

Commit 1b54f96

Browse files
author
vikramkamath
committed
Bazel typescript boilerplate webapp with e2e tests, devserver
0 parents  commit 1b54f96

18 files changed

+1448
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Diff for: BUILD.bazel

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
filegroup(
2+
name = "node_modules",
3+
# Only include files needed for type-checking and runtime
4+
srcs = glob([
5+
"node_modules/**/*.js",
6+
"node_modules/**/*.d.ts",
7+
"node_modules/**/*.json"
8+
]),
9+
visibility = ["//visibility:public"],
10+
)
11+
12+
13+
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver", "ts_library")
14+
15+
ts_library(
16+
name = "app",
17+
srcs = ["app.ts"],
18+
tsconfig = ":tsconfig.json",
19+
)
20+
21+
ts_devserver(
22+
name = "devserver",
23+
# We'll collect all the devmode JS sources from these TypeScript libraries
24+
deps = [":app"],
25+
# This is the path we'll request from the browser, see index.html
26+
serving_path = "/bundle.js",
27+
# The devserver can serve our static files too
28+
static_files = ["index.html"],
29+
)
30+
31+
ts_library(
32+
name = "e2e",
33+
testonly = 1,
34+
srcs = ["app_e2e_test.ts"]
35+
)

Diff for: README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# bazel-typescript-webapp
2+
3+
This is a simple webapp built using `bazel`, `typescript`. This is an example app from [bazelbuild/rules_typescript](https://github.com/bazelbuild/rules_typescript)
4+
5+
# Install
6+
7+
Use `homebrew` on OSx to install `bazel`
8+
9+
`brew install bazel`
10+
11+
Then, clone this project
12+
`npm i`
13+
14+
## Build
15+
16+
`npm run build`
17+
18+
## Serve
19+
20+
`npm run serve`
21+
22+
## End-To-End tests
23+
24+
`npm run e2e`

Diff for: WORKSPACE

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
workspace(name = "app")
2+
3+
http_archive(
4+
name = "build_bazel_rules_nodejs",
5+
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.8.0.zip",
6+
strip_prefix = "rules_nodejs-0.8.0",
7+
sha256 = "4e40dd49ae7668d245c3107645f2a138660fcfd975b9310b91eda13f0c973953",
8+
)
9+
10+
http_archive(
11+
name = "io_bazel_rules_webtesting",
12+
strip_prefix = "rules_webtesting-master",
13+
urls = [
14+
"https://github.com/bazelbuild/rules_webtesting/archive/master.tar.gz",
15+
],
16+
)
17+
18+
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
19+
20+
node_repositories(package_json = ["//:package.json"])
21+
22+
23+
# Include @bazel/typescript in package.json#devDependencies
24+
local_repository(
25+
name = "build_bazel_rules_typescript",
26+
path = "node_modules/@bazel/typescript",
27+
)
28+
29+
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
30+
31+
32+
33+
ts_setup_workspace()
34+
35+
# ts_devserver needs the Go rules.
36+
# See https://github.com/bazelbuild/rules_go#setup for the latest version.
37+
http_archive(
38+
name = "io_bazel_rules_go",
39+
url = "https://github.com/bazelbuild/rules_go/releases/download/0.8.1/rules_go-0.8.1.tar.gz",
40+
sha256 = "90bb270d0a92ed5c83558b2797346917c46547f6f7103e648941ecdb6b9d0e72",
41+
)
42+
43+
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
44+
45+
go_rules_dependencies()
46+
go_register_toolchains()

Diff for: app.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const el: HTMLDivElement = document.createElement('div');
2+
el.innerText = 'Hello, TypeScript';
3+
el.className = 'ts1';
4+
document.body.appendChild(el);

Diff for: app_e2e_test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {browser, by, element, ExpectedConditions} from 'protractor';
2+
3+
// This test uses Protractor without Angular, so disable Angular features
4+
browser.waitForAngularEnabled(false);
5+
6+
// Since we don't have a protractor bazel rule yet, the test is brought up in
7+
// parallel with building the service under test. So the timeout must include
8+
// compiling the application as well as starting the server.
9+
const timeoutMs = 90 * 1000;
10+
11+
describe('Devserver', () => {
12+
beforeAll(() => {
13+
browser.get('');
14+
// Don't run any specs until we see a <div> on the page.
15+
browser.wait(
16+
ExpectedConditions.presenceOf(element(by.css('div.ts1'))),
17+
timeoutMs);
18+
}, timeoutMs);
19+
20+
it('should display: Hello world!', (done) => {
21+
const div = element(by.css('div.ts1'));
22+
div.getText().then(t => expect(t).toEqual(`Hello, TypeScript`));
23+
done();
24+
});
25+
});

Diff for: bazel-app

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/private/var/tmp/_bazel_Vikki/3177f6227db02b881211ca90570573eb/execroot/app

Diff for: bazel-bin

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/private/var/tmp/_bazel_Vikki/3177f6227db02b881211ca90570573eb/execroot/app/bazel-out/darwin-fastbuild/bin

Diff for: bazel-genfiles

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/private/var/tmp/_bazel_Vikki/3177f6227db02b881211ca90570573eb/execroot/app/bazel-out/darwin-fastbuild/genfiles

Diff for: bazel-out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/private/var/tmp/_bazel_Vikki/3177f6227db02b881211ca90570573eb/execroot/app/bazel-out

Diff for: bazel-testlogs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/private/var/tmp/_bazel_Vikki/3177f6227db02b881211ca90570573eb/execroot/app/bazel-out/darwin-fastbuild/testlogs

Diff for: index.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
3+
<!--
4+
This HTML file is an example of how you can write and serve your own
5+
index page. It's not required for ts_devserver - if no index.html file is
6+
found to serve, a simple one will be generated.
7+
-->
8+
<html>
9+
<head>
10+
<title>ts_devserver example</title>
11+
</head>
12+
<body>
13+
<!--
14+
For development mode, this script will be bundled on-the-fly by
15+
the devserver, based on the latest JS files built by Bazel.
16+
For production, you should be able to use the same index.html file, but
17+
this JS resource would be served from a static file.
18+
-->
19+
<script src="/bundle.js"></script>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)