0.0.10 • Published 5 months ago

proto-coverage-reporter v0.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

proto-coverage-reporter

NPM Version

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 NameRequiredTypeDescription
coverageFromtrueArrayTarget service destination to collect coverages from
coverageFrom[].packageNametrueStringpackage identifier
coverageFrom[].serviceProtoPathtrueStringfile path for protocol buffer
0.0.10

5 months ago

0.0.9

5 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago