Test gRPC endpoints using JS
First, create a file to contain your test suite, such as tests.js
. Then, within the file:
-
Import functions from the
chai
assertion library as well as our helper library: -
Define your tests containing gRPC requests and response assertions:
-
Finally, run all the tests:
grpc-script ./tests.js
┌──────────┬────────┬────────┬───────┬─────────┬──────┐ │ File │ Failed │ Passed │ Total │ Percent │ Time │ ├──────────┼────────┼────────┼───────┼─────────┼──────┤ │ tests.js │ 0 │ 1 │ 1 │ 100.00% │ 25ms │ └──────────┴────────┴────────┴───────┴─────────┴──────┘
Errors
In case of any errors, the assertion details will be printed along with any console output.
grpc-script ./tests.js
✕ UnaryMethod AssertionError: expected { ‘status-code’: ‘0’ } to have property ‘status-code’ of ‘1’, but got ‘0’ ├──at tests.js:21:36(48) └──at tests.js:26:9(29) console.log output for debugging ┌──────────┬────────┬────────┬───────┬─────────┬──────┐ │ File │ Failed │ Passed │ Total │ Percent │ Time │ ├──────────┼────────┼────────┼───────┼─────────┼──────┤ │ tests.js │ 1 │ 0 │ 1 │ 0.00% │ 25ms │ └──────────┴────────┴────────┴───────┴─────────┴──────┘