proto-coverage-reporter
Version:
Jest custome reporter for gRPC server E2E testing
24 lines (23 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMethodSpec = parseMethodSpec;
const fs = require("fs");
const protobufjs_1 = require("protobufjs");
const OPTION_IDENTIFIER = '(ka_nabellinc.grpc_spec.spec)';
function parseMethodSpec(serviceProtoAbsolutePath, packageName) {
if (!fs.existsSync(serviceProtoAbsolutePath)) {
throw new Error(`[proto-coverage-reporter]: ${serviceProtoAbsolutePath} is not exist`);
}
const methodSpec = {};
const proto = new protobufjs_1.Root().loadSync(serviceProtoAbsolutePath);
const service = proto.lookupService(packageName);
for (const method of Object.values(service.methods)) {
const parsedOptions = method.parsedOptions || [];
const targetOption = parsedOptions.find(option => !!option[OPTION_IDENTIFIER]);
if (!targetOption)
continue;
const { status_codes } = targetOption[OPTION_IDENTIFIER];
methodSpec[method.name] = { status_codes };
}
return methodSpec;
}