Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@improbable-eng/grpc-web-fake-transport

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@improbable-eng/grpc-web-fake-transport

Fake Transport for use with @improbable-eng/grpc-web

  • 0.15.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

@improbable-eng/grpc-web-fake-transport

Fake Transport for use with @improbable-eng/grpc-web.

Usage

FakeTransportBuilder builds a Transport that can be configured to send preset headers, messages, and trailers for testing.

By default the Transport that FakeTranportBuilder.build() generates will trigger all of the specified response behaviours (.withHeaders(metadata), .withMessages([msgOne, msgTwo]), .withTrailers(metadata)) when the client has finished sending.

This is usually the desired flow as all of the response behaviour is triggered only after the client has finished sending as would most commonly occur in production usage.

However, in the case of bi-directional or other complex usage it can be helpful to use .withManualTrigger() to disable automatic sending of messages or headers/trailers and trigger the sending manually using sendHeaders(), sendMessages() and sendTrailers().

With Service Stubs generated by ts-protoc-gen

import { FakeTransportBuilder } from '@improbable-eng/grpc-web-fake-transport';

const fakeTransport = new FakeTransportBuilder()
  .withMessages([ new PingResponse() ])
  .build();

const client = new PingServiceClient("https://example.com", {
  transport: fakeTransport
});

client.DoPing(/* ... */);

With grpc-web

import { grpc } from '@improbable-eng/grpc-web';
import { FakeTransportBuilder } from '@improbable-eng/grpc-web-fake-transport';

const fakeTransport = new FakeTransportBuilder()
  .withMessages([ new PingResponse() ])
  .build();

grpc.invoke(PingService.DoPing, {
  host: "https://example.com",
  transport: fakeTransport,
  /* ... */
});

With withManualTrigger()

import { grpc } from '@improbable-eng/grpc-web';
import { FakeTransportBuilder } from '@improbable-eng/grpc-web-fake-transport';

const fakeTransport = new FakeTransportBuilder()
  .withManualTrigger()
  .withHeaders(new grpc.Metadata({ headerKey: "value" }))
  .withMessages([ new PingResponse() ])
  .withTrailers(new grpc.Metadata({ trailerKey: "value" }))
  .build();

grpc.invoke(PingService.DoPing, {
  host: "https://example.com",
  transport: fakeTransport,
  /* ... */
});

// Manually trigger the response behaviours
fakeTransport.sendHeaders();
fakeTransport.sendMessages();
fakeTransport.sendTrailers();

Alternatively replace the Default Transport when initialising your tests:

import { grpc } from "@improbable-eng/grpc-web";
import { NodeHttpTransport } from "@improbable-eng/grpc-web-fake-transport";

// Do this first, before you make any grpc requests!
grpc.setDefaultTransport(fakeTransport);

FAQs

Package last updated on 04 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc