From 1a3a22dde2aae796a2daa01d77ce52bfcf240941 Mon Sep 17 00:00:00 2001 From: DriverAID Date: Wed, 11 Oct 2017 13:02:37 +0200 Subject: [PATCH] Make sure mocha_test can be used on other packages than the root level. --- node/internal/mocha_test.bzl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/node/internal/mocha_test.bzl b/node/internal/mocha_test.bzl index 653960b..51310fa 100644 --- a/node/internal/mocha_test.bzl +++ b/node/internal/mocha_test.bzl @@ -4,7 +4,17 @@ load("//node:internal/node_binary.bzl", "copy_modules", "binary_attrs") def _create_launcher(ctx, output_dir, node, mocha): entry_module = ctx.attr.entrypoint.node_module - entrypoint = '%s_test/node_modules/%s' % (ctx.label.name, entry_module.name) + + # The build file path is used to construct a path in the runfile tree to the + # entrypoint module; by stripping off BUILD from it we find the correct prefix + # to use below + suffix = 'BUILD' + if not ctx.build_file_path.endswith(suffix): + fail("ctx.build_file_path does not end with %s as expected" % suffix) + entrypoint_prefix = ctx.build_file_path[:-len(suffix)] + + entrypoint = '%s%s_test/node_modules/%s' % ( + entrypoint_prefix, ctx.label.name, entry_module.name) cmd = [ node.short_path, -- 2.11.0 (Apple Git-81)