Skip to content

Commit eba7304

Browse files
authored
Merge branch 'master' into feat/add-html-reporter
2 parents 62ea52d + 5109dec commit eba7304

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ Even after writing your OpenRPC Document, you want to test that the OpenRPC Docu
2525
- report back the coverage results
2626
- show errors and the result to help fix inconsistencies
2727

28+
29+
## Extending with a `Rule`
30+
Rules are a way to extend the test coverage tool to check for specific things when calling your JSON-RPC API. For example, you may want to check that some fields are always present in the result. You can write a rule to check for that.
31+
32+
A rule is a class that extends the `Rule` class and implements the `getCalls` function. The `getCalls` function should return an array of calls to make to the JSON-RPC API. The `Rule` class will then make the calls and check the results. It checks the results with the `validateCall` function, it expects that you mutate the `call.valid` property to `true` if the call is valid, and `false` if the call is invalid.
33+
34+
Lastly there are lifecycle events that you can hook into to do things like setup and teardown. The `onBegin` function is called before any calls are made, and the `onEnd` function is called after all calls are made. There are also `beforeRequest`, `afterRequest`, and `afterResponse` lifecycle functions that are called before the request is made, after the request is made, and after the response is received respectively. See the [`Rule`](src/rules/rule.ts) interface for more information.
35+
36+
## Custom Reporters
37+
You can write custom reporters to output the results of the test coverage tool in a different format. A reporter is a class that extends the `Reporter` class and implements the lifecycle functions. The `Reporter` class will call the lifecycle functions at the appropriate time. The `onBegin` function is called before any calls are made, and the `onEnd` function is called after all calls are made. There are also `onTestBegin` and `onTestEnd` lifecycle functions that are called before and after each test respectively. See the [`Reporter`](src/reporters/reporter.ts) interface for more information.
38+
2839
### Installation:
2940

3041
```
@@ -38,7 +49,7 @@ npm install -g @open-rpc/test-coverage
3849

3950

4051
```
41-
open-rpc-test-coverage -s https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/simple-math-openrpc.json --transport=http --reporter=console --skip=addition
52+
open-rpc-test-coverage -s https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/simple-math-openrpc.json --transport=http --reporters=console --skip=addition
4253
```
4354

4455

0 commit comments

Comments
 (0)