From baf19df7dcd1b94c2a98c2c42be8a08c5addd5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=85=95=E9=99=B6?= Date: Fri, 13 Oct 2017 16:55:50 +0800 Subject: [PATCH 1/2] fix: inner package test --- node/internal/mocha_test.bzl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node/internal/mocha_test.bzl b/node/internal/mocha_test.bzl index 653960b..e46f389 100644 --- a/node/internal/mocha_test.bzl +++ b/node/internal/mocha_test.bzl @@ -4,8 +4,11 @@ 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 + # if package is under root entrypoint = '%s_test/node_modules/%s' % (ctx.label.name, entry_module.name) - + # if test is under inner package + if ctx.label.package: + entrypoint = '%s/%s' % (ctx.label.package, entrypoint) cmd = [ node.short_path, ] + ctx.attr.node_args + [ @@ -21,7 +24,6 @@ def _create_launcher(ctx, output_dir, node, mocha): 'set -e', ' '.join(cmd) ] - ctx.file_action( output = ctx.outputs.executable, executable = True, From ef6cacf4cbb89cd2d420550cbcfaf3c036d28e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=85=95=E9=99=B6?= Date: Mon, 16 Oct 2017 12:03:19 +0800 Subject: [PATCH 2/2] add nest mocha test --- Makefile | 1 + tests/mocha/tests/BUILD | 16 ++++++++++++++++ tests/mocha/tests/test.js | 9 +++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/mocha/tests/BUILD create mode 100644 tests/mocha/tests/test.js diff --git a/Makefile b/Makefile index e06e30a..9566191 100644 --- a/Makefile +++ b/Makefile @@ -5,3 +5,4 @@ test_all: (cd tests/namespace && bazel test //:question_test) (cd tests/typescript && bazel test //:typescript_test) (cd tests/mocha && bazel test //:test) + (cd tests/mocha && bazel test //tests:test) diff --git a/tests/mocha/tests/BUILD b/tests/mocha/tests/BUILD new file mode 100644 index 0000000..99a8809 --- /dev/null +++ b/tests/mocha/tests/BUILD @@ -0,0 +1,16 @@ +package(default_visibility = ["//visibility:public"]) + +load("@org_pubref_rules_node//node:rules.bzl", "node_binary", "node_module", "mocha_test") + +mocha_test( + name = "test", + main = "test.js", +) + +# Can one test a bazel test? I'm getting 'fork: Resource temporarily unavailable' when I try to run this. +# sh_test( +# name = "test_test", +# size = "small", +# srcs = ["test.sh"], +# data = [":test"], +# ) diff --git a/tests/mocha/tests/test.js b/tests/mocha/tests/test.js new file mode 100644 index 0000000..3c07044 --- /dev/null +++ b/tests/mocha/tests/test.js @@ -0,0 +1,9 @@ +var assert = require('assert'); + +describe('Array', function() { + describe('#indexOf()', function() { + it('should return -1 when the value is not present', function() { + assert.equal(-1, [1,2,3].indexOf(4)); + }); + }); +});