Skip to content

Commit dc9f8ba

Browse files
xujihui1985pcj
authored andcommitted
fix: inner package test (#39)
* fix: inner package test * add nest mocha test
1 parent a322ec7 commit dc9f8ba

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ test_all:
55
(cd tests/namespace && bazel test //:question_test)
66
(cd tests/typescript && bazel test //:typescript_test)
77
(cd tests/mocha && bazel test //:test)
8+
(cd tests/mocha && bazel test //tests:test)

node/internal/mocha_test.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ load("//node:internal/node_binary.bzl", "copy_modules", "binary_attrs")
44

55
def _create_launcher(ctx, output_dir, node, mocha):
66
entry_module = ctx.attr.entrypoint.node_module
7+
# if package is under root
78
entrypoint = '%s_test/node_modules/%s' % (ctx.label.name, entry_module.name)
8-
9+
# if test is under inner package
10+
if ctx.label.package:
11+
entrypoint = '%s/%s' % (ctx.label.package, entrypoint)
912
cmd = [
1013
node.short_path,
1114
] + ctx.attr.node_args + [
@@ -21,7 +24,6 @@ def _create_launcher(ctx, output_dir, node, mocha):
2124
'set -e',
2225
' '.join(cmd)
2326
]
24-
2527
ctx.file_action(
2628
output = ctx.outputs.executable,
2729
executable = True,

tests/mocha/tests/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("@org_pubref_rules_node//node:rules.bzl", "node_binary", "node_module", "mocha_test")
4+
5+
mocha_test(
6+
name = "test",
7+
main = "test.js",
8+
)
9+
10+
# Can one test a bazel test? I'm getting 'fork: Resource temporarily unavailable' when I try to run this.
11+
# sh_test(
12+
# name = "test_test",
13+
# size = "small",
14+
# srcs = ["test.sh"],
15+
# data = [":test"],
16+
# )

tests/mocha/tests/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var assert = require('assert');
2+
3+
describe('Array', function() {
4+
describe('#indexOf()', function() {
5+
it('should return -1 when the value is not present', function() {
6+
assert.equal(-1, [1,2,3].indexOf(4));
7+
});
8+
});
9+
});

0 commit comments

Comments
 (0)