From 30d586b06d836f805ad8bcabcb0ebf41d21afcaa Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Thu, 26 Mar 2020 17:04:31 -0700 Subject: [PATCH] fix(jasmine): user templated_args should be passed to jasmine after 3 internal templated_args --- packages/jasmine/src/jasmine_node_test.bzl | 19 ++++++++----------- packages/jasmine/test/BUILD.bazel | 13 +++++++++++++ packages/jasmine/test/args_test.js | 8 +++++++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/jasmine/src/jasmine_node_test.bzl b/packages/jasmine/src/jasmine_node_test.bzl index 6f3c8677e9..bae78bbf74 100644 --- a/packages/jasmine/src/jasmine_node_test.bzl +++ b/packages/jasmine/src/jasmine_node_test.bzl @@ -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, diff --git a/packages/jasmine/test/BUILD.bazel b/packages/jasmine/test/BUILD.bazel index 4de30ccb9c..9df8b1edc2 100644 --- a/packages/jasmine/test/BUILD.bazel +++ b/packages/jasmine/test/BUILD.bazel @@ -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", ], ) @@ -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", ], ) diff --git a/packages/jasmine/test/args_test.js b/packages/jasmine/test/args_test.js index 39b84ec6c5..6c236c8a23 100644 --- a/packages/jasmine/test/args_test.js +++ b/packages/jasmine/test/args_test.js @@ -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();