diff --git a/bootstrap.js b/bootstrap.js index e259a45201..ce9683416d 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -1,2 +1 @@ -console.log('here') global.bootstrapped = true; \ No newline at end of file diff --git a/e2e/jasmine/jasmine_shared_env_bootstrap.js b/e2e/jasmine/jasmine_shared_env_bootstrap.js index 4170531c58..27c1361141 100644 --- a/e2e/jasmine/jasmine_shared_env_bootstrap.js +++ b/e2e/jasmine/jasmine_shared_env_bootstrap.js @@ -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'); diff --git a/internal/node/test/BUILD.bazel b/internal/node/test/BUILD.bazel index fb07e59240..3f7058bebd 100644 --- a/internal/node/test/BUILD.bazel +++ b/internal/node/test/BUILD.bazel @@ -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", @@ -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))"], ) @@ -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))"], +) diff --git a/internal/node/test/bootstrap.js b/internal/node/test/bootstrap.js index e259a45201..fc3edbc0c5 100644 --- a/internal/node/test/bootstrap.js +++ b/internal/node/test/bootstrap.js @@ -1,2 +1,3 @@ -console.log('here') -global.bootstrapped = true; \ No newline at end of file +global.bootstrapped = true; +// Verify that we can require npm packages in a bootstrap script +const tmp = require('tmp'); diff --git a/internal/node/test/bootstrap_fail.js b/internal/node/test/bootstrap_fail.js new file mode 100644 index 0000000000..6b8da80f2c --- /dev/null +++ b/internal/node/test/bootstrap_fail.js @@ -0,0 +1 @@ +process.exit(33); \ No newline at end of file diff --git a/internal/node/test/bootstrap_with_patch.js b/internal/node/test/bootstrap_with_patch.js new file mode 100644 index 0000000000..81ffc40746 --- /dev/null +++ b/internal/node/test/bootstrap_with_patch.js @@ -0,0 +1,4 @@ +// test the runfiles.patchRequire() function +const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']); +runfiles.patchRequire(); +global.bootstrapped = true; diff --git a/internal/node/test/fail.spec.js b/internal/node/test/fail.spec.js new file mode 100644 index 0000000000..efc7543102 --- /dev/null +++ b/internal/node/test/fail.spec.js @@ -0,0 +1 @@ +process.exit(55); diff --git a/packages/jasmine/src/jasmine_runner.js b/packages/jasmine/src/jasmine_runner.js index aca07ebe53..c88fc1318b 100644 --- a/packages/jasmine/src/jasmine_runner.js +++ b/packages/jasmine/src/jasmine_runner.js @@ -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); } } diff --git a/packages/jasmine/test/BUILD.bazel b/packages/jasmine/test/BUILD.bazel index aad0728bbc..4de30ccb9c 100644 --- a/packages/jasmine/test/BUILD.bazel +++ b/packages/jasmine/test/BUILD.bazel @@ -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"], @@ -26,6 +34,15 @@ 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"], @@ -33,6 +50,26 @@ jasmine_node_test( 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"], @@ -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"], diff --git a/packages/jasmine/test/bootstrap.js b/packages/jasmine/test/bootstrap.js new file mode 100644 index 0000000000..ce9683416d --- /dev/null +++ b/packages/jasmine/test/bootstrap.js @@ -0,0 +1 @@ +global.bootstrapped = true; \ No newline at end of file diff --git a/packages/jasmine/test/bootstrap_fail.js b/packages/jasmine/test/bootstrap_fail.js new file mode 100644 index 0000000000..6b8da80f2c --- /dev/null +++ b/packages/jasmine/test/bootstrap_fail.js @@ -0,0 +1 @@ +process.exit(33); \ No newline at end of file