Skip to content

Commit

Permalink
fix(jasmine): user templated_args should be passed to jasmine after 3…
Browse files Browse the repository at this point in the history
… internal templated_args (#1743)
  • Loading branch information
gregmagolan authored Mar 27, 2020
1 parent 51785e5 commit baa68c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
19 changes: 8 additions & 11 deletions packages/jasmine/src/jasmine_node_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,19 @@ def jasmine_node_test(
all_data += [":%s_devmode_srcs.MF" % name]
all_data += [Label("@bazel_tools//tools/bash/runfiles")]

# If the target specified templated_args, pass it through.
templated_args = kwargs.pop("templated_args", [])
templated_args.append("$(location :%s_devmode_srcs.MF)" % name)

if coverage:
templated_args.append("--coverage")
else:
templated_args.append("--nocoverage")
# jasmine_runner.js consumes the first 3 args.
# The remaining target templated_args will be passed through to jasmine or
# specs to consume.
templated_args = [
"$(location :%s_devmode_srcs.MF)" % name,
"--coverage" if coverage else "--nocoverage",
"$(location %s)" % config_file if config_file else "--noconfig",
] + kwargs.pop("templated_args", [])

if config_file:
# Calculate a label relative to the user's BUILD file
pkg = Label("%s//%s:__pkg__" % (native.repository_name(), native.package_name()))
all_data.append(pkg.relative(config_file))
templated_args.append("$(location %s)" % config_file)
else:
templated_args.append("--noconfig")

nodejs_test(
name = name,
Expand Down
13 changes: 13 additions & 0 deletions packages/jasmine/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ jasmine_node_test(
"dynamic_import.js",
],
args = [
# the --node_options arg will be consumed by the node launcher
"--node_options=--experimental-modules",
# the remaining args should be passed to the spec
"arg1",
"arg2",
"arg3",
],
)

Expand All @@ -107,8 +112,16 @@ jasmine_node_test(
"args_test.js",
"dynamic_import.js",
],
args = [
# args should be passed after templated_args
"arg3",
],
templated_args = [
# the --node_options templated arg will be consumed by the node launcher
"--node_options=--experimental-modules",
# the remaining args should be passed to the spec
"arg1",
"arg2",
],
)

Expand Down
8 changes: 7 additions & 1 deletion packages/jasmine/test/args_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
describe('args', () => {
it('should pass through templated_args', async () => {
it('should pass through other templated_args', async () => {
// args that are not consumed by the node launcher should be passed through
// to the spec
expect(process.argv.slice(2)).toEqual(['arg1', 'arg2', 'arg3']);
});

it('should apply --node_options in templated_args', async () => {
// without --node_options=--experimental-modules this will fail
const dynamicImport = await import('./dynamic_import.js');
dynamicImport.default.hello();
Expand Down

0 comments on commit baa68c1

Please sign in to comment.