Skip to content

Commit 3db92c6

Browse files
committed
test: test for bootstrap require patch regression
* 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
1 parent f217519 commit 3db92c6

11 files changed

+117
-12
lines changed

bootstrap.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
console.log('here')
21
global.bootstrapped = true;

e2e/jasmine/jasmine_shared_env_bootstrap.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// bootstrap the bazel require patch since this bootstrap script is loaded with
2-
// `--node_options=--require=$(rlocation $(location :jasmine_shared_env_bootstrap.js))`
3-
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
4-
require(process.env['BAZEL_NODE_RUNFILES_HELPER']).patchRequire();
5-
}
6-
71
global.foobar = 1;
82

93
require('zone.js/dist/zone-node.js');

internal/node/test/BUILD.bazel

+48-2
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,21 @@ nodejs_test(
102102

103103
nodejs_test(
104104
name = "bootstrap_test",
105-
data = ["bootstrap.js"],
105+
data = [
106+
"bootstrap.js",
107+
"@npm//tmp",
108+
],
106109
entry_point = ":bootstrap.spec.js",
107110
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
108111
)
109112

113+
nodejs_test(
114+
name = "bootstrap_patch_test",
115+
data = ["bootstrap_with_patch.js"],
116+
entry_point = ":bootstrap.spec.js",
117+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_with_patch.js))"],
118+
)
119+
110120
# Special case when $(location) is for a root file
111121
nodejs_test(
112122
name = "bootstrap_root_test",
@@ -130,7 +140,10 @@ nodejs_test(
130140

131141
nodejs_test(
132142
name = "bootstrap_mlocation_test",
133-
data = ["bootstrap.js"],
143+
data = [
144+
"bootstrap.js",
145+
"@npm//tmp",
146+
],
134147
entry_point = ":bootstrap.spec.js",
135148
templated_args = ["--node_options=--require=$(rlocation $(mlocation :bootstrap.js))"],
136149
)
@@ -268,3 +281,36 @@ golden_file_test(
268281
actual = ":expand_variables.out",
269282
golden = "expand_variables.golden",
270283
)
284+
285+
nodejs_test(
286+
name = "fail_test",
287+
entry_point = "fail.spec.js",
288+
expected_exit_code = 55,
289+
)
290+
291+
nodejs_test(
292+
name = "fail_bootstrap_fail_test",
293+
data = ["bootstrap_fail.js"],
294+
entry_point = "fail.spec.js",
295+
expected_exit_code = 33,
296+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_fail.js))"],
297+
)
298+
299+
nodejs_test(
300+
name = "fail_bootstrap_test",
301+
data = [
302+
"bootstrap.js",
303+
"@npm//tmp",
304+
],
305+
entry_point = "fail.spec.js",
306+
expected_exit_code = 55,
307+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
308+
)
309+
310+
nodejs_test(
311+
name = "fail_bootstrap_with_patch_test",
312+
data = ["bootstrap_with_patch.js"],
313+
entry_point = "fail.spec.js",
314+
expected_exit_code = 55,
315+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_with_patch.js))"],
316+
)

internal/node/test/bootstrap.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
console.log('here')
2-
global.bootstrapped = true;
1+
global.bootstrapped = true;
2+
// Verify that we can require npm packages in a bootstrap script
3+
const tmp = require('tmp');

internal/node/test/bootstrap_fail.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.exit(33);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// test the runfiles.patchRequire() function
2+
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
3+
runfiles.patchRequire();
4+
global.bootstrapped = true;

internal/node/test/fail.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.exit(55);

packages/jasmine/src/jasmine_runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function main(args) {
191191
// Special case!
192192
// To allow us to test sharding, always run the specs in the order they are declared
193193
if (process.env['TEST_WORKSPACE'] === 'build_bazel_rules_nodejs' &&
194-
process.env['TEST_TARGET'] === '//packages/jasmine/test:sharding_test') {
194+
process.env['TEST_TARGET'].startsWith('//packages/jasmine/test:sharding_')) {
195195
jrunner.randomizeTests(false);
196196
}
197197
}

packages/jasmine/test/BUILD.bazel

+57
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ jasmine_node_test(
55
srcs = ["foo_spec.js"],
66
)
77

8+
# Verify that a bootstrap script does not break the test
9+
jasmine_node_test(
10+
name = "underscore_spec_bootstrap_test",
11+
srcs = ["foo_spec.js"],
12+
data = ["bootstrap.js"],
13+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
14+
)
15+
816
jasmine_node_test(
917
name = "underscore_test_test",
1018
srcs = ["foo_test.js"],
@@ -26,13 +34,42 @@ jasmine_node_test(
2634
shard_count = 3,
2735
)
2836

37+
# Verify that a bootstrap script does not break a sharded test
38+
jasmine_node_test(
39+
name = "sharding_bootstrap_test",
40+
srcs = ["sharded_test.js"],
41+
data = ["bootstrap.js"],
42+
shard_count = 3,
43+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
44+
)
45+
2946
jasmine_node_test(
3047
name = "failing_sharding_test",
3148
srcs = ["failing_sharded_test.js"],
3249
expected_exit_code = 3,
3350
shard_count = 2,
3451
)
3552

53+
# Verify that a bootstrap script does not break a failing sharded test
54+
jasmine_node_test(
55+
name = "failing_sharding_bootstrap_test",
56+
srcs = ["failing_sharded_test.js"],
57+
data = ["bootstrap.js"],
58+
expected_exit_code = 3,
59+
shard_count = 2,
60+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
61+
)
62+
63+
# Verify that a bootstrap script does not break a failing sharded test
64+
jasmine_node_test(
65+
name = "failing_sharding_bootstrap_fail_test",
66+
srcs = ["failing_sharded_test.js"],
67+
data = ["bootstrap_fail.js"],
68+
expected_exit_code = 33,
69+
shard_count = 2,
70+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_fail.js))"],
71+
)
72+
3673
jasmine_node_test(
3774
name = "filtering_test",
3875
srcs = ["filtering_test.js"],
@@ -88,12 +125,32 @@ jasmine_node_test(
88125
tags = ["fix-windows"],
89126
)
90127

128+
# Verify that the error code is propogated out from a failing spec
91129
jasmine_node_test(
92130
name = "fail_test",
93131
srcs = ["fail.spec.js"],
94132
expected_exit_code = 3,
95133
)
96134

135+
# Verify that the error code is propogated out from a failing spec
136+
# if there is a successful bootstrap script
137+
jasmine_node_test(
138+
name = "fail_bootstrap_test",
139+
srcs = ["fail.spec.js"],
140+
data = ["bootstrap.js"],
141+
expected_exit_code = 3,
142+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap.js))"],
143+
)
144+
145+
# Verify that the error code is propogated out from a failing bootstrap script
146+
jasmine_node_test(
147+
name = "fail_bootstrap_fail_test",
148+
srcs = ["fail.spec.js"],
149+
data = ["bootstrap_fail.js"],
150+
expected_exit_code = 33,
151+
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_fail.js))"],
152+
)
153+
97154
jasmine_node_test(
98155
name = "stack_test",
99156
srcs = ["stack.spec.js"],

packages/jasmine/test/bootstrap.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global.bootstrapped = true;
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.exit(33);

0 commit comments

Comments
 (0)