Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes and get all tests passing (#480)
Browse files Browse the repository at this point in the history
gregmagolan committed May 29, 2019
1 parent 3e3a4e2 commit 9e0c317
Showing 17 changed files with 55 additions and 77 deletions.
10 changes: 0 additions & 10 deletions e2e/jasmine/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -3,20 +3,14 @@ load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
jasmine_node_test(
name = "test",
srcs = ["test.spec.js"],
jasmine = "@npm_bazel_jasmine//:index.js",
deps = [
"@npm//@bazel/jasmine",
],
)

jasmine_node_test(
name = "shared_env_test",
srcs = ["jasmine_shared_env_test.spec.js"],
bootstrap = ["e2e_jasmine/jasmine_shared_env_bootstrap.js"],
data = ["jasmine_shared_env_bootstrap.js"],
jasmine = "@npm_bazel_jasmine//:index.js",
deps = [
"@npm//@bazel/jasmine",
"@npm//jasmine",
"@npm//jasmine-core",
"@npm//zone.js",
@@ -30,8 +24,4 @@ jasmine_node_test(
"coverage_source.js",
],
coverage = True,
jasmine = "@npm_bazel_jasmine//:index.js",
deps = [
"@npm//@bazel/jasmine",
],
)
2 changes: 1 addition & 1 deletion e2e/ts_library/some_module/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ nodejs_binary(
":main",
":some_module",
],
entry_point = ":main.js",
entry_point = ":entry.js",
)

sh_test(
1 change: 1 addition & 0 deletions e2e/ts_library/some_module/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./main');
19 changes: 1 addition & 18 deletions e2e/typescript_3.1/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "rollup_bundle")
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle")
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
load("@npm_bazel_typescript//:index.bzl", "ts_library")

@@ -57,23 +57,6 @@ jasmine_node_test(
],
)

nodejs_binary(
name = "main_js",
data = [
":main",
],
entry_point = "e2e_typescript_3_1/main.js",
)

nodejs_binary(
name = "main_js_sm",
data = [
":main",
"@npm//source-map-support",
],
entry_point = "e2e_typescript_3_1/main.js",
)

rollup_bundle(
name = "bundle",
entry_point = "main",
2 changes: 1 addition & 1 deletion internal/npm_install/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ nodejs_binary(
":browserify-wrapped.js",
"//third_party/github.com/browserify/browserify:sources",
],
entry_point = "build_bazel_rules_nodejs/internal/npm_install/browserify-wrapped.js",
entry_point = ":browserify-wrapped.js",
install_source_map_support = False,
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion packages/jasmine/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ npm_package(
)

js_library(
name = "jasmine_runner",
name = "jasmine__pkg",
srcs = [
"index.js",
"src/jasmine_runner.js",
17 changes: 10 additions & 7 deletions packages/jasmine/src/jasmine_node_test.bzl
Original file line number Diff line number Diff line change
@@ -29,22 +29,25 @@ def jasmine_node_test(
expected_exit_code = 0,
tags = [],
coverage = False,
jasmine = "@npm//@bazel/jasmine",
jasmine = "@npm//node_modules/@bazel/jasmine:index.js",
**kwargs):
"""Runs tests in NodeJS using the Jasmine test runner.
To debug the test, see debugging notes in `nodejs_test`.
Args:
name: name of the resulting label
name: Name of the resulting label
srcs: JavaScript source files containing Jasmine specs
data: Runtime dependencies which will be loaded while the test executes
deps: Other targets which produce JavaScript, such as ts_library
expected_exit_code: The expected exit code for the test. Defaults to 0.
tags: bazel tags applied to test
jasmine: a label providing the @bazel/jasmine npm dependency
coverage: Enables code coverage collection and reporting
**kwargs: remaining arguments are passed to the test rule
tags: Bazel tags applied to test
coverage: Enables code coverage collection and reporting. Defaults to False.
jasmine: A label providing the @bazel/jasmine npm dependency. Defaults
to "@npm//@bazel/jasmine" so that the correct jasmine & jasmine-core
dependencies are resolved unless they are overwritten in a bootstrap
file.
**kwargs: Remaining arguments are passed to the test rule
"""
devmode_js_sources(
name = "%s_devmode_srcs" % name,
@@ -53,7 +56,7 @@ def jasmine_node_test(
tags = tags,
)

all_data = data + srcs + deps + [jasmine]
all_data = data + srcs + deps + [Label(jasmine).relative(":jasmine__pkg")]

all_data += [":%s_devmode_srcs.MF" % name]
all_data += [Label("@bazel_tools//tools/bash/runfiles")]
16 changes: 8 additions & 8 deletions packages/jasmine/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jasmine_node_test(
# target if they are not using the default @npm//@bazel/jasmine
jasmine = "@npm_bazel_jasmine//:index.js",
deps = [
"//:jasmine_runner",
"//:jasmine__pkg",
"@npm//jasmine",
],
)
@@ -23,7 +23,7 @@ jasmine_node_test(
# target if they are not using the default @npm//@bazel/jasmine
jasmine = "@npm_bazel_jasmine//:index.js",
deps = [
"//:jasmine_runner",
"//:jasmine__pkg",
"@npm//jasmine",
],
)
@@ -37,7 +37,7 @@ jasmine_node_test(
# target if they are not using the default @npm//@bazel/jasmine
jasmine = "@npm_bazel_jasmine//:index.js",
deps = [
"//:jasmine_runner",
"//:jasmine__pkg",
"@npm//jasmine",
],
)
@@ -51,7 +51,7 @@ jasmine_node_test(
# target if they are not using the default @npm//@bazel/jasmine
jasmine = "@npm_bazel_jasmine//:index.js",
deps = [
"//:jasmine_runner",
"//:jasmine__pkg",
"@npm//jasmine",
],
)
@@ -66,7 +66,7 @@ jasmine_node_test(
jasmine = "@npm_bazel_jasmine//:index.js",
shard_count = 3,
deps = [
"//:jasmine_runner",
"//:jasmine__pkg",
"@npm//jasmine",
],
)
@@ -78,7 +78,7 @@ jasmine_node_test(
jasmine = "@npm_bazel_jasmine//:index.js",
shard_count = 2,
deps = [
"//:jasmine_runner",
"//:jasmine__pkg",
"@npm//jasmine",
],
)
@@ -102,7 +102,7 @@ jasmine_node_test(
# to return a 'incomplete' status
tags = ["manual"],
deps = [
"//:jasmine_runner",
"//:jasmine__pkg",
"@npm//jasmine",
],
)
@@ -116,7 +116,7 @@ jasmine_node_test(
coverage = True,
jasmine = "@npm_bazel_jasmine//:index.js",
deps = [
"//:jasmine_runner",
"//:jasmine__pkg",
"@npm//jasmine",
"@npm//v8-coverage",
],
3 changes: 3 additions & 0 deletions packages/labs/package.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,9 @@
"bugs": {
"url": "https://github.com/bazelbuild/rules_nodejs/issues"
},
"bin": {
"webpack": "./webpack/index.js"
},
"devDependencies": {
"@bazel/typescript": "file:../../dist/npm_bazel_typescript",
"@types/jasmine": "^3.3.9",
14 changes: 12 additions & 2 deletions packages/labs/webpack/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
# BEGIN-INTERNAL
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "npm_package")

npm_package(
name = "webpack",
srcs = [
"BUILD.bazel",
"index.bzl",
"index.js",
],
replacements = {"#@external\\s": ""},
visibility = ["//:__pkg__"],
deps = [
"//webpack/src:cli",
"//webpack/src:cli_lib",
"//webpack/src:package_contents",
],
)

nodejs_binary(
name = "cli",
data = [
"//webpack/src:cli_lib",
"@npm//webpack",
],
entry_point = ":index.js",
visibility = ["//visibility:public"],
)
# END-INTERNAL
1 change: 1 addition & 0 deletions packages/labs/webpack/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./src/cli').main();
24 changes: 1 addition & 23 deletions packages/labs/webpack/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")

# BEGIN-INTERNAL
load("@npm_bazel_typescript//:defs.bzl", "ts_library")

ts_library(
name = "cli_lib",
srcs = glob(["*.ts"]),
visibility = ["//:__subpackages__"],
deps = [
"@npm//@types",
],
@@ -20,24 +19,3 @@ filegroup(
visibility = ["//webpack:__subpackages__"],
)
# END-INTERNAL

nodejs_binary(
name = "cli",
data = [
# BEGIN-INTERNAL
# For local development, we depend on the TypeScript output
":cli_lib",
# END-INTERNAL

# For external usage, we depend on the published .JS files
#@external "@npm//@bazel/labs",
"@npm//webpack",
],
# BEGIN-INTERNAL
# For local development, our module has this AMD name
entry_point = ":cli_lib",
# END-INTERNAL
# For external usage, we resolve the module from node_modules
#@external entry_point = "@bazel/labs/webpack/src:cli_lib",
visibility = ["//visibility:public"],
)
10 changes: 7 additions & 3 deletions packages/labs/webpack/src/cli.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ function configure(args: string[]): webpack.Configuration {
};
}

function main(config: webpack.Configuration): 0|1 {
function compile(config: webpack.Configuration): 0|1 {
const compiler = webpack(config);
let exitCode: 0|1 = 0;
compiler.run((err, stats) => {
@@ -41,10 +41,14 @@ function main(config: webpack.Configuration): 0|1 {
return exitCode;
}

if (require.main === module) {
export function main() {
// Avoid limitations of length of argv by using a flagfile
// This also makes it easier to debug - you can just look
// at this flagfile to see what args were passed to webpack
const args = fs.readFileSync(process.argv[2], {encoding: 'utf-8'}).split('\n').map(unquoteArgs);
process.exitCode = main(configure(args));
process.exitCode = compile(configure(args));
}

if (require.main === module) {
main()
}
2 changes: 1 addition & 1 deletion packages/labs/webpack/src/webpack_bundle.bzl
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ This rule is experimental, as part of Angular Labs! There may be breaking change
WEBPACK_BUNDLE_ATTRS = {
"srcs": attr.label_list(allow_files = True),
"entry_point": attr.label(allow_single_file = True, mandatory = True),
"webpack": attr.label(default = "@npm_bazel_labs//webpack/src:cli", executable = True, cfg = "host"),
"webpack": attr.label(default = "@npm//@bazel/labs/bin:webpack", executable = True, cfg = "host"),
}
WEBPACK_BUNDLE_OUTS = {
"bundle": "%{name}.js",
5 changes: 5 additions & 0 deletions packages/labs/webpack/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -6,6 +6,11 @@ webpack_bundle(
name = "bundle",
srcs = glob(["*.js"]),
entry_point = "index.js",
# The webpack label here is specific to local testing since
# there is no @bazel/labs npm package here. Users
# will always have this label point to their @foobar//@bazel/labs/bin:webpack
# target if they are not using the default @npm//@bazel/labs/bin:webpack
webpack = "@npm_bazel_labs//webpack:cli",
)

ts_library(
2 changes: 1 addition & 1 deletion tools/npm_packages/bazel_workspaces/a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -5,5 +5,5 @@ nodejs_binary(
data = [
":index.js",
],
entry_point = "bazel_workspace_a/index.js",
entry_point = ":index.js",
)
2 changes: 1 addition & 1 deletion tools/npm_packages/bazel_workspaces/b/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -5,5 +5,5 @@ nodejs_binary(
data = [
":index.js",
],
entry_point = "bazel_workspace_b/index.js",
entry_point = ":index.js",
)

0 comments on commit 9e0c317

Please sign in to comment.