Skip to content

Commit 41fdaa5

Browse files
authored
Merge pull request #21 from ixdy/mocha-test-rule
mocha_test: add mocha to runfiles
2 parents c1cafb2 + 6ea9692 commit 41fdaa5

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

node/internal/mocha_test.bzl

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_js_filetype = FileType([".js"])
2+
23
_modules_filetype = FileType(["node_modules"])
34

45
BASH_TEMPLATE = """
@@ -16,18 +17,6 @@ export NODE_PATH={node_paths}
1617
"{node}" "{mocha}" {mocha_args} "{script_path}" $@
1718
"""
1819

19-
20-
def _get_abs_sourcepath(file):
21-
filename = str(file)
22-
#print("filename: %s" % filename)
23-
parts = filename.partition("[source]]")
24-
prefix = parts[0][len("Artifact:["):]
25-
suffix = parts[2]
26-
d = "/".join([prefix, suffix])
27-
#print("abs filename: %s" % d)
28-
return d
29-
30-
3120
def _get_node_modules_dir_from_binfile(file):
3221
bin = str(file)
3322
parts = bin.partition("[source]]")
@@ -36,7 +25,6 @@ def _get_node_modules_dir_from_binfile(file):
3625
#print("prefix: %s, suffix_parts: %s" % (prefix, suffix_parts))
3726
return "/".join([prefix] + suffix_parts[0:2] + ["node_modules"])
3827

39-
4028
def _get_node_modules_dir_from_package_json(file):
4129
filename = str(file)
4230
parts = filename.split("]")
@@ -46,8 +34,6 @@ def _get_node_modules_dir_from_package_json(file):
4634
d = "/".join([prefix, middle] + suffix[0:-3] + ["node_modules"])
4735
return d
4836

49-
50-
5137
def mocha_test_impl(ctx):
5238
inputs = []
5339
srcs = []
@@ -57,8 +43,6 @@ def mocha_test_impl(ctx):
5743
node_paths = []
5844
node_paths.append(_get_node_modules_dir_from_binfile(mocha))
5945

60-
mocha_path = _get_abs_sourcepath(mocha)
61-
6246
for file in ctx.files.modules:
6347
#print("file: %s" % file)
6448
if not file.basename.endswith("node_modules"):
@@ -84,14 +68,14 @@ def mocha_test_impl(ctx):
8468
node = node.short_path,
8569
node_bin_path = node.dirname,
8670
script_path = script.short_path,
87-
mocha = mocha_path,
71+
mocha = mocha.path,
8872
mocha_args = " ".join(ctx.attr.mocha_args),
8973
),
9074
)
9175

9276
#print("node_paths %s" % "\n".join(node_paths))
9377

94-
runfiles = [node, script] + inputs + srcs
78+
runfiles = [node, script, mocha] + inputs + srcs
9579

9680
return struct(
9781
runfiles = ctx.runfiles(
@@ -100,7 +84,6 @@ def mocha_test_impl(ctx):
10084
),
10185
)
10286

103-
10487
mocha_test = rule(
10588
mocha_test_impl,
10689
attrs = {

0 commit comments

Comments
 (0)