Registry / testing / grpc-mock-bumped

grpc-mock-bumped

JSON →
library1.0.1jsnpmunverified

A simple gRPC mock server for Node.js, version 1.0.1. It allows defining rules to match incoming gRPC calls (unary, client-streaming, server-streaming, bidirectional) and return predefined outputs or errors. Built on grpc-kit and @grpc/proto-loader, it requires no actual gRPC service implementation, making it ideal for testing. Compared to alternatives like grpc-mock (original) or protobufjs-based mocks, this package offers a straightforward rule-based API with support for stream types, error responses with metadata, and regex-based input matching. Release cadence is low, with infrequent updates.

npm install grpc-mock-bumped
INSTALL
IMPORT
SIG · GRPC-MOCK-BUMPED
G
grpc-mock-bumped
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createMockServer
import { createMockServer } from 'grpc-mock'
const createMockServer = require('grpc-mock').createMockServer
Package is ESM-compatible; named export is correct. Use named import for tree-shaking.
default import
import grpcMock from 'grpc-mock'
const grpcMock = require('grpc-mock')
Default export is an object containing createMockServer. In CJS, require('grpc-mock') returns the default export directly.
TypeScript types
import type { Rule, Chunk, MockServerOptions } from 'grpc-mock'
TypeScript types are exported as named exports. Use type-only import for better isolation.

Starts a mock gRPC server with a single unary rule and a regex-based rule, listening on port 50051.

import { createMockServer } from 'grpc-mock'; const mockServer = createMockServer({ protoPath: './greeter.proto', packageName: 'greeter', serviceName: 'Greeter', rules: [ { method: 'SayHello', input: { name: 'World' }, output: { message: 'Hello World' } }, { method: 'SayGoodbye', input: '.*', output: { message: 'Goodbye' } }, ], }); mockServer.listen('0.0.0.0:50051'); console.log('Mock gRPC server started on port 50051');
Debug
Known issues
breakinggrpc-mock-bumped is a renamed fork of the original grpc-mock package. Ensure you install the correct package: npm install grpc-mock-bumped
fix
Use npm install grpc-mock-bumped (note the '-bumped' suffix) or switch to the original grpc-mock (older maintenance).
affects: >=1.0.0
deprecatedThe original grpc-mock package (version 1.0.0) is no longer maintained. This fork (grpc-mock-bumped) includes minor fixes but may diverge further.
fix
Migrate to grpc-mock-bumped@1.0.1 or consider alternatives like grpc-mock-server.
affects: <=1.0.0
gotchaWhen using streamType: 'client', the rule must have both stream array (with input chunks) and an output property. Omitting output will cause undefined behavior.
fix
Always provide an output for client-streaming rules, even if it's an empty object.
affects: >=1.0.0
gotchaThe error metadata property expects an object with string keys and string values. Non-string values may not be serialized correctly.
fix
Ensure metadata values are strings, e.g., { key: 'value' }.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'grpc-mock' from 'test.js'
Installed the wrong package name (original grpc-mock vs grpc-mock-bumped).
fix
Run npm install grpc-mock-bumped and update imports to import from 'grpc-mock-bumped'.
TypeError: mockServer.listen is not a function
createMockServer returns a GrpcServer object, but the code attempted to call listen on the result of createMockServer incorrectly (e.g., missing options or wrong import).
fix
Ensure you are using the named export: import { createMockServer } from 'grpc-mock-bumped' and calling listen on the returned server instance.
Error: 2 UNKNOWN: No matching rule for call: method 'SayHello'
The method name in the rule does not match the proto definition exactly (case-sensitive).
fix
Double-check that the method name matches exactly as defined in the .proto file, e.g., 'SayHello' not 'sayHello'.
TypeError: Cannot read property 'message' of undefined
The rule's input pattern did not match, causing no output to be assigned (likely missing input or wrong streamType).
fix
Verify that the input object matches exactly or use a regex string like '.*' to match any input. For streaming, ensure stream array is correctly defined.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
grpc-kitrequiredProvides the underlying gRPC server infrastructure
@grpc/proto-loaderoptionalLoads .proto files and generates service descriptors
Agent activity
14 hits · last 30 days
node
12
Resources
grpc-mock-bumped — npm install grpc-mock-bumped · libregistry