Skip to content

Commit

Permalink
test: test for bootstrap require patch regression
Browse files Browse the repository at this point in the history
* verify that bootstrap code can now use the require patches by default
* verify that if a bootstrap script fails then its exit code is propogated
  • Loading branch information
gregmagolan committed Jan 12, 2020
1 parent f217519 commit 3db92c6
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 12 deletions.
1 change: 0 additions & 1 deletion bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
console.log('here')
global.bootstrapped = true;
6 changes: 0 additions & 6 deletions e2e/jasmine/jasmine_shared_env_bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// bootstrap the bazel require patch since this bootstrap script is loaded with
// `--node_options=--require=$(rlocation $(location :jasmine_shared_env_bootstrap.js))`
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
require(process.env['BAZEL_NODE_RUNFILES_HELPER']).patchRequire();
}

global.foobar = 1;

require('zone.js/dist/zone-node.js');
Expand Down
50 changes: 48 additions & 2 deletions internal/node/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,21 @@ nodejs_test(

nodejs_test(
name = "bootstrap_test",
data = ["bootstrap.js"],
data = [
"bootstrap.js",
"@npm//tmp",
],
entry_point = ":bootstrap.spec.js",
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
)

nodejs_test(
name = "bootstrap_patch_test",
data = ["bootstrap_with_patch.js"],
entry_point = ":bootstrap.spec.js",
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_with_patch.js))"],
)

# Special case when $(location) is for a root file
nodejs_test(
name = "bootstrap_root_test",
Expand All @@ -130,7 +140,10 @@ nodejs_test(

nodejs_test(
name = "bootstrap_mlocation_test",
data = ["bootstrap.js"],
data = [
"bootstrap.js",
"@npm//tmp",
],
entry_point = ":bootstrap.spec.js",
templated_args = ["--node_options=--require=$(rlocation $(mlocation :bootstrap.js))"],
)
Expand Down Expand Up @@ -268,3 +281,36 @@ golden_file_test(
actual = ":expand_variables.out",
golden = "expand_variables.golden",
)

nodejs_test(
name = "fail_test",
entry_point = "fail.spec.js",
expected_exit_code = 55,
)

nodejs_test(
name = "fail_bootstrap_fail_test",
data = ["bootstrap_fail.js"],
entry_point = "fail.spec.js",
expected_exit_code = 33,
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_fail.js))"],
)

nodejs_test(
name = "fail_bootstrap_test",
data = [
"bootstrap.js",
"@npm//tmp",
],
entry_point = "fail.spec.js",
expected_exit_code = 55,
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
)

nodejs_test(
name = "fail_bootstrap_with_patch_test",
data = ["bootstrap_with_patch.js"],
entry_point = "fail.spec.js",
expected_exit_code = 55,
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_with_patch.js))"],
)
5 changes: 3 additions & 2 deletions internal/node/test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
console.log('here')
global.bootstrapped = true;
global.bootstrapped = true;
// Verify that we can require npm packages in a bootstrap script
const tmp = require('tmp');
1 change: 1 addition & 0 deletions internal/node/test/bootstrap_fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.exit(33);
4 changes: 4 additions & 0 deletions internal/node/test/bootstrap_with_patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// test the runfiles.patchRequire() function
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
runfiles.patchRequire();
global.bootstrapped = true;
1 change: 1 addition & 0 deletions internal/node/test/fail.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.exit(55);
2 changes: 1 addition & 1 deletion packages/jasmine/src/jasmine_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function main(args) {
// Special case!
// To allow us to test sharding, always run the specs in the order they are declared
if (process.env['TEST_WORKSPACE'] === 'build_bazel_rules_nodejs' &&
process.env['TEST_TARGET'] === '//packages/jasmine/test:sharding_test') {
process.env['TEST_TARGET'].startsWith('//packages/jasmine/test:sharding_')) {
jrunner.randomizeTests(false);
}
}
Expand Down
57 changes: 57 additions & 0 deletions packages/jasmine/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ jasmine_node_test(
srcs = ["foo_spec.js"],
)

# Verify that a bootstrap script does not break the test
jasmine_node_test(
name = "underscore_spec_bootstrap_test",
srcs = ["foo_spec.js"],
data = ["bootstrap.js"],
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
)

jasmine_node_test(
name = "underscore_test_test",
srcs = ["foo_test.js"],
Expand All @@ -26,13 +34,42 @@ jasmine_node_test(
shard_count = 3,
)

# Verify that a bootstrap script does not break a sharded test
jasmine_node_test(
name = "sharding_bootstrap_test",
srcs = ["sharded_test.js"],
data = ["bootstrap.js"],
shard_count = 3,
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
)

jasmine_node_test(
name = "failing_sharding_test",
srcs = ["failing_sharded_test.js"],
expected_exit_code = 3,
shard_count = 2,
)

# Verify that a bootstrap script does not break a failing sharded test
jasmine_node_test(
name = "failing_sharding_bootstrap_test",
srcs = ["failing_sharded_test.js"],
data = ["bootstrap.js"],
expected_exit_code = 3,
shard_count = 2,
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
)

# Verify that a bootstrap script does not break a failing sharded test
jasmine_node_test(
name = "failing_sharding_bootstrap_fail_test",
srcs = ["failing_sharded_test.js"],
data = ["bootstrap_fail.js"],
expected_exit_code = 33,
shard_count = 2,
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_fail.js))"],
)

jasmine_node_test(
name = "filtering_test",
srcs = ["filtering_test.js"],
Expand Down Expand Up @@ -88,12 +125,32 @@ jasmine_node_test(
tags = ["fix-windows"],
)

# Verify that the error code is propogated out from a failing spec
jasmine_node_test(
name = "fail_test",
srcs = ["fail.spec.js"],
expected_exit_code = 3,
)

# Verify that the error code is propogated out from a failing spec
# if there is a successful bootstrap script
jasmine_node_test(
name = "fail_bootstrap_test",
srcs = ["fail.spec.js"],
data = ["bootstrap.js"],
expected_exit_code = 3,
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
)

# Verify that the error code is propogated out from a failing bootstrap script
jasmine_node_test(
name = "fail_bootstrap_fail_test",
srcs = ["fail.spec.js"],
data = ["bootstrap_fail.js"],
expected_exit_code = 33,
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_fail.js))"],
)

jasmine_node_test(
name = "stack_test",
srcs = ["stack.spec.js"],
Expand Down
1 change: 1 addition & 0 deletions packages/jasmine/test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global.bootstrapped = true;
1 change: 1 addition & 0 deletions packages/jasmine/test/bootstrap_fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.exit(33);

0 comments on commit 3db92c6

Please sign in to comment.