Skip to content

Commit 2925f8f

Browse files
authored
Update README.md
fixes bazel-contrib#40
1 parent b3a1a81 commit 2925f8f

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,16 @@ $ bazel run @nodejs//:npm install
5959

6060
[bazel instructions]: https://docs.bazel.build/versions/master/install.html
6161

62-
# Usage
62+
## Usage
6363

64-
Currently, the only available rule is `nodejs_binary` which allows you to run an application, either from sources you author or from those fetched from npm.
64+
The `nodejs_binary` rule allows you to run an application by giving the entry point.
65+
The entry point can come from an external dependency installed by the package manager,
66+
or it can be a `.js` file from a package built by Bazel.
67+
68+
The `jasmine_node_test` rule allows you to write a test that executes in NodeJS.
69+
70+
### Running a program from npm
6571

66-
## Running a program from npm
6772
If you have installed the [rollup] package, you could write this rule:
6873

6974
```python
@@ -81,9 +86,13 @@ and run it with
8186
$ bazel run :rollup -- --help
8287
```
8388

89+
See the `examples/rollup` directory in this repository.
90+
8491
[rollup]: https://www.npmjs.com/package/rollup
8592

86-
## Running a program from local sources
93+
### Running a program from local sources
94+
95+
We can reference a path in the local workspace to run a program we write.
8796

8897
```python
8998
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
@@ -104,6 +113,20 @@ This example illustrates how to pass arguments to nodejs (as opposed to passing
104113
The `data` attribute is optional, by default it includes the `node_modules` directory. To include your own
105114
sources, include a file or target that produces JavaScript.
106115

116+
See the `examples/program` directory in this repository.
117+
118+
### Testing
119+
120+
The `jasmine_node_test` rule can be used to run unit tests in NodeJS, using the Jasmine framework.
121+
Targets declared with this rule can be run with `bazel test`.
122+
123+
Attributes:
124+
125+
The `srcs` of a `jasmine_node_test` should include the test `.js` files.
126+
The `deps` should include the production `.js` sources, or other rules which produce `.js` files, such as TypeScript.
127+
128+
The `examples/program/index.spec.js` file illustrates this. Another usage is in https://github.com/angular/tsickle/blob/master/test/BUILD
129+
107130
# Design
108131

109132
Most bazel rules include package management. That is, the `WORKSPACE` file installs your dependencies as well as the toolchain. In some environments, this is the normal workflow, for example in Java, Gradle and Maven are each both a build tool and a package manager.

0 commit comments

Comments
 (0)