-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples & e2e tests from rules_typescript & related fixes
- Loading branch information
1 parent
8e28710
commit b1b73f2
Showing
142 changed files
with
6,914 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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);' > $@", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const a = 1; | ||
export default a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import foo from 'internal/e2e/absolute_imports/foo'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
Oops, something went wrong.