qrb
qrb

Reputation: 89

No specs found while executing jasmine test via bazel

I'm tring to run jasmine test using bazel on my current directory, but it is complaining about no specs found.

I think it has something to do with the "srcs" variable that I am providing. I tried [":spec/test.spec.ts"] and [":spec"] but none is working.

Command that I use: bazel run //packages/core:unit_test

File directory:

root

-packages

--core

---spec

----test.spec.ts

jasmine_node_test(
    name = "unit_test",
    srcs = [":spec/test.spec.ts"],
    deps = [
        "@npm//jasmine"
    ],
)

test.spec.ts

describe("A suite is just a function", function() {
  var a;

  it("and so is a spec", function() {
    a = true;

    expect(a).toBe(true);
  });
});

Package.json

  "devDependencies": {
    "@bazel/bazel": "^0.24.1",
    "@bazel/buildifier": "^0.22.0",
    "@bazel/ibazel": "^0.10.2",
    "@bazel/typescript": "^0.28.0",
    "@types/node": "^12.0.0",
    "tslib": "^1.9.3",
    "typescript": "^3.4.5"
  },
  "dependencies": {
    "@bazel/jasmine": "^0.32.2",
    "@types/jasmine": "^3.3.13",
    "jasmine": "^3.4.0"
  }

I expect the test to run successfully.

Upvotes: 5

Views: 320

Answers (2)

jnelson
jnelson

Reputation: 421

I tried your code in a sample application using Bazel and it seems like you need to transpile your code to JS because you are trying to run a .ts file in a JS test runner.

Note: In your case a simple rename to *.js will suffice (I checked).


Sample code to achieve what you want

BUILD.bazel

load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")

ts_library(
    name = "files_to_compile",
    srcs = ["test.spec.ts"]
)

jasmine_node_test(
    name = "sampletest",
    srcs = [":files_to_compile"]
)

OR

load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")

jasmine_node_test(
    name = "sampletest",
    srcs = ["test.spec.js"]
)

Upvotes: 1

Shaun Luttin
Shaun Luttin

Reputation: 141652

Try using glob, which is inspired by rules from bazelbuild/rules_nodejs/examples.

srcs = glob(["*.spec.ts"]),

Upvotes: 0

Related Questions