Skip to content

Commit

Permalink
Add examples & e2e tests from rules_typescript & related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored and alexeagle committed Mar 14, 2019
1 parent 8e28710 commit b1b73f2
Show file tree
Hide file tree
Showing 142 changed files with 6,914 additions and 75 deletions.
14 changes: 11 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jobs:
# We should also be able to test targets in a different workspace
# TODO(gmagolan): move these tests into `build` job once
# https://github.com/bazelbuild/bazel/issues/6481 is resolved
- run: bazel test @program_example//...
- run: bazel test @examples_program//...
- run: bazel test @packages_example//...

build_release:
Expand Down Expand Up @@ -298,13 +298,17 @@ jobs:
# See https://github.com/bazelbuild/continuous-integration/issues/225
test_examples:
<<: *job_defaults
docker:
# Needed because some tests require local chrome
- image: *browsers_docker_image
resource_class: xlarge
parallelism: 3
parallelism: 4
steps:
- *attach_workspace
- *init_environment
- *init_bazel
- run: ./scripts/test_examples_all.sh ${CIRCLE_NODE_INDEX} ${CIRCLE_NODE_TOTAL}
# Some examples such as app require xvfb
- run: xvfb-run -a ./scripts/test_examples_all.sh ${CIRCLE_NODE_INDEX} ${CIRCLE_NODE_TOTAL}

workflows:
version: 2
Expand Down Expand Up @@ -355,3 +359,7 @@ workflows:
- test_examples:
requires:
- build_release
- build_typescript_package
- build_jasmine_package
- build_labs_package
- build_karma_package
10 changes: 7 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Language: JavaScript
BasedOnStyle: Google
ColumnLimit: 100
Language: JavaScript
BasedOnStyle: Google
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ check_bazel_version(minimum_bazel_version = "0.23.0")
#

local_repository(
name = "program_example",
name = "examples_program",
path = "examples/program",
)

Expand All @@ -56,7 +56,7 @@ load("//:defs.bzl", "node_repositories", "npm_install", "yarn_install")
node_repositories(
package_json = [
"//:package.json",
"@program_example//:package.json",
"@examples_program//:package.json",
"//internal/npm_install/test:package/package.json",
],
preserve_symlinks = True,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions examples/define_var/WORKSPACE → e2e/define_var/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
workspace(name = "examples_define_var")

# In your code, you'd fetch this repository with an `http_archive` call.
# We do this local repository only because this example lives in the same
# repository with the rules_nodejs code and we want to test them together.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions e2e/ts_auto_deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"typescript": "2.9.2"
},
"scripts": {
"pretest": "../../scripts/link_deps.sh",
"test": "bazel run @nodejs//:yarn && cd simple && ts_auto_deps && bazel build simple"
"pretest": "../../scripts/link_deps.sh && bazel run @nodejs//:yarn",
"test": "cd simple && ts_auto_deps && bazel build simple"
}
}
8 changes: 1 addition & 7 deletions e2e/ts_auto_deps/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@


"@bazel/typescript@file:../../dist/npm_bazel_typescript":
version "0.27.1"
version "0.27.4"
dependencies:
jasmine-core "2.8.0"
protobufjs "5.0.3"
semver "5.6.0"
source-map-support "0.5.9"
Expand Down Expand Up @@ -125,11 +124,6 @@ is-fullwidth-code-point@^1.0.0:
dependencies:
number-is-nan "^1.0.0"

jasmine-core@2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.8.0.tgz#bcc979ae1f9fd05701e45e52e65d3a5d63f1a24e"
integrity sha1-vMl5rh+f0FcB5F5S5l06XWPxok4=

lcid@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lcid/-/lcid-1.0.0.tgz#308accafa0bc483a3867b4b6f2b9506251d1b835"
Expand Down
69 changes: 69 additions & 0 deletions e2e/ts_devserver/genrule/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library")

ts_library(
name = "app",
srcs = ["app.ts"],
deps = [
"@npm//@types/node",
],
)

ts_library(
name = "e2e",
testonly = 1,
srcs = ["app_e2e_test.ts"],
deps = [
"@npm//@types/jasmine",
"@npm//@types/node",
"@npm//protractor",
],
)

ts_devserver(
name = "devserver",
additional_root_paths = [
"npm/node_modules/tslib",
"e2e_ts_devserver/genrule/devserver/",
],
port = 8080,
serving_path = "/bundle.js",
static_files = [
# Files you want to import from the "additional_root_paths", still need to be explicitly specified
# as files that should be served. The root paths just make it more convenient to import those dependencies.
"@npm//tslib",
":say-hello",
":show-host",
":index.html",
],
# Dependencies that produce JavaScript output will be automatically picked up by ConcatJS and will be
# part of the serving_path bundle.
deps = [":app"],
)

""

genrule(
name = "say-hello",
outs = ["say-hello.js"],
cmd = "echo 'var el = document.createElement(\"div\"); el.innerText = \"Hello, genrule\"; el.className = \"ts2\"; document.body.appendChild(el);' > $@",
)

genrule(
name = "show-host",
outs = ["test/show-host.js"],
cmd = "echo 'var el = document.createElement(\"div\"); el.innerText = location.host; el.className = \"ts3\"; document.body.appendChild(el);' > $@",
)
4 changes: 4 additions & 0 deletions e2e/ts_devserver/genrule/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const el: HTMLDivElement = document.createElement('div');
el.innerText = 'Hello, TypeScript';
el.className = 'ts1';
document.body.appendChild(el);
38 changes: 38 additions & 0 deletions e2e/ts_devserver/genrule/app_e2e_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {browser, by, element, ExpectedConditions} from 'protractor';

// This test uses Protractor without Angular, so disable Angular features
browser.waitForAngularEnabled(false);

// Since we don't have a protractor bazel rule yet, the test is brought up in
// parallel with building the service under test. So the timeout must include
// compiling the application as well as starting the server.
const timeoutMs = 90 * 1000;

describe('app', () => {
beforeAll(() => {
browser.get('');
// Don't run any specs until we see a <div> on the page.
browser.wait(ExpectedConditions.presenceOf(element(by.css('div.ts1'))), timeoutMs);
browser.wait(ExpectedConditions.presenceOf(element(by.css('div.ts2'))), timeoutMs);
browser.wait(ExpectedConditions.presenceOf(element(by.css('div.ts3'))), timeoutMs);
}, timeoutMs);

it('should display: Hello, TypeScript', async (done) => {
const text = await element(by.css('div.ts1')).getText();
expect(text).toEqual(`Hello, TypeScript`);
done();
});

it('should display: Hello, genrule', async (done) => {
const text = await element(by.css('div.ts2')).getText();
expect(text).toEqual(`Hello, genrule`);
done();
});

it('should display: location.host', async (done) => {
const currentUrl = await browser.getCurrentUrl();
const text = await element(by.css('div.ts3')).getText();
expect(`http://${text}/`).toEqual(currentUrl);
done();
});
});
16 changes: 16 additions & 0 deletions e2e/ts_devserver/genrule/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<title>Devserver example</title>
</head>
<body>
<!-- Scripts loaded through the additional_root_paths. -->
<script src="/say-hello.js"></script>
<script src="/tslib.js"></script>

<!-- Bundle that comes from concatjs. Specified with serving_path. -->
<script src="/bundle.js"></script>

<!-- Script that is imported relatively to the package directory. -->
<script src="/test/show-host.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion e2e/ts_devserver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"pretest": "../../scripts/link_deps.sh && bazel run @nodejs//:yarn && webdriver-manager update $CHROMEDRIVER_VERSION_ARG",
"test_root": "concurrently \"bazel run //:devserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite root\" --kill-others --success first",
"test_subpackage": "concurrently \"bazel run //subpackage:devserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite subpackage\" --kill-others --success first",
"test": "bazel build ... && yarn test_root && yarn test_subpackage"
"test_genrule": "concurrently \"bazel run //genrule:devserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite genrule\" --kill-others --success first",
"test": "bazel build ... && yarn test_root && yarn test_subpackage && yarn test_genrule"
}
}
1 change: 1 addition & 0 deletions e2e/ts_devserver/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ exports.config = {
suites: {
root: 'bazel-bin/*_e2e_test.js',
subpackage: 'bazel-bin/subpackage/*_e2e_test.js',
genrule: 'bazel-bin/genrule/*_e2e_test.js',
},
capabilities: {browserName: 'chrome', chromeOptions: {args: ['--no-sandbox']}},
directConnect: true,
Expand Down
5 changes: 2 additions & 3 deletions e2e/ts_devserver/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@


"@bazel/typescript@file:../../dist/npm_bazel_typescript":
version "0.27.1"
version "0.27.4"
dependencies:
jasmine-core "2.8.0"
protobufjs "5.0.3"
semver "5.6.0"
source-map-support "0.5.9"
Expand Down Expand Up @@ -573,7 +572,7 @@ isstream@~0.1.2:
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
integrity sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=

jasmine-core@2.8.0, jasmine-core@~2.8.0:
jasmine-core@~2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.8.0.tgz#bcc979ae1f9fd05701e45e52e65d3a5d63f1a24e"
integrity sha1-vMl5rh+f0FcB5F5S5l06XWPxok4=
Expand Down
1 change: 1 addition & 0 deletions e2e/ts_library/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
9 changes: 9 additions & 0 deletions e2e/ts_library/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Print test logs for failed tests
test --test_output=errors

# Enable debugging tests with --config=debug
test:debug --test_arg=--node_options=--inspect-brk --test_output=streamed --test_strategy=exclusive --test_timeout=9999 --nocache_test_results

# Turn off legacy external runfiles
run --nolegacy_external_runfiles
test --nolegacy_external_runfiles
9 changes: 9 additions & 0 deletions e2e/ts_library/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@npm_bazel_typescript//:index.bzl", "ts_config")

package(default_visibility = ["//visibility:public"])

ts_config(
name = "tsconfig-test",
src = "tsconfig-test.json",
deps = [":tsconfig.json"],
)
41 changes: 41 additions & 0 deletions e2e/ts_library/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
workspace(name = "e2e_ts_library")

# In your code, you'd fetch this repository with an `http_archive` call.
# We do this local repository only because this example lives in the same
# repository with the rules_nodejs code and we want to test them together.
local_repository(
name = "build_bazel_rules_nodejs",
path = "../../dist/build_bazel_rules_nodejs/release",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")

# This test depend on there being a user node_modules folder
# TODO(gregmagolan): remove this once yarn_install sets up the user's node_modules folder
node_repositories(
package_json = ["//:package.json"],
)

# This runs yarn install, then our generate_build_file.js to create BUILD files
# inside the resulting node_modules directory.
# The name "npm" here means the resulting modules are referenced like
# @npm//jasmine
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)

load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")

install_bazel_dependencies()

load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")

ts_setup_workspace()

# Tell Bazel where the nested local repositories are that are used for tests
local_repository(
name = "disable_tsetse_for_external_test",
path = "disable_tsetse_for_external",
)
25 changes: 25 additions & 0 deletions e2e/ts_library/absolute_imports/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@npm_bazel_typescript//:index.bzl", "ts_library")

package(default_visibility = ["//visibility:public"])

ts_library(
name = "absolute_imports",
srcs = glob(["*.ts"]),
expected_diagnostics = [
"TS2307: Cannot find module 'internal/e2e/absolute_imports/foo'",
],
)
2 changes: 2 additions & 0 deletions e2e/ts_library/absolute_imports/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = 1;
export default a;
1 change: 1 addition & 0 deletions e2e/ts_library/absolute_imports/importer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import foo from 'internal/e2e/absolute_imports/foo';
17 changes: 17 additions & 0 deletions e2e/ts_library/devmode_consumer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load(":devmode_consumer.bzl", "devmode_consumer")

package(default_visibility = ["//visibility:public"])

devmode_consumer(
name = "devmode_consumer",
deps = ["//foobar:bar_ts_library"],
)

sh_test(
name = "devmode_consumer_test",
srcs = ["devmode_consumer_test.sh"],
data = [
":devmode_consumer",
"@bazel_tools//tools/bash/runfiles",
],
)
Loading

0 comments on commit b1b73f2

Please sign in to comment.