0.0.10 • Published 5 months ago
proto-coverage-reporter v0.0.10
proto-coverage-reporter
Protobuf method call coverage reporter for gRPC Server E2E testing. Works along with Jest.
This tool ensures all the specified status_codes are checked during the test.
Install
npm i -D proto-coverage-reporter # npm
yarn add -D proto-coverage-reporter # yarn
Prerequisites
Use extension.proto to specify method options for your service.
syntax = "proto3";
package tutorial;
import "ka_nabellinc/grpc_spec/extension.proto";
service HelloService {
rpc Greet(GreetRequest) returns (GreetResponse) {
option (ka_nabellinc.grpc_spec.spec) = {
status_codes: ["OK", "INVALID_ARGUMENTS", "ALREADY_EXISTS", "PERMISSION_DENIED"]
};
}
}
Setup gRPC client interceptor
To record gRPC client call histories, or footprints, you need to register a custom interceptor for your needs.
The following example is for Node.js usage.
import { protoCoverageInterceptor } from 'proto-coverage-reporter';
import { credentials } from '@grpc/grpc-js';
import { HelloServiceClient } from './gen/proto/hello_grpc_pb';
const client = new HelloServiceClient(
'localhost:3000',
credentials.createInsecure(),
{
interceptors: [protoCoverageInterceptor]
}
)
Setup Jest custom reporter
Register as a jest custom reporter.
module.exports = {
...
reporters: [
"default",
["proto-coverage-reporter", {
coverageFrom: [
{
packageName: "tutorial.HelloService",
serviceProtoPath: "<rootDir>/proto/tutorial/hello.proto"
}
]
}]
]
}
Options
Option Name | Required | Type | Description |
---|---|---|---|
coverageFrom | true | Array | Target service destination to collect coverages from |
coverageFrom[].packageName | true | String | package identifier |
coverageFrom[].serviceProtoPath | true | String | file path for protocol buffer |