Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@botchris/grpc-web-mock
Advanced tools
Readme
Allows to mock GRPC-Web responses in pure Typescript. Useful for mocking GRPC-Web APIs in E2E tests.
GRPC-Web is a protocol that allows to use GRPC services in the browser. It is implemented in many languages, including Typescript. However, testing GRPC-Web services is not as easy as testing REST APIs (you usually mock a bunch of JSON responses, and you are ready to go).
This library aims to make E2E tests easier by simulating the part of the GRPC-Web server that is responsible for sending responses to a web-client (see wiring format for further details). It allows to mock GRPC-Web responses in pure Typescript, without the need to run a real GRPC server. Simply create a new ProtocolBuffer message, and pass it to one of the mocking functions to get a valid GRPC-Web response as it would be sent by a real GRPC server.
However, this library does not mock the GRPC-Web client or server interfaces, so you still need to simulate HTTP networking. Below you can find an example of how to use this library with Cypress, which provides a nice API for intercepting HTTP requests and mocking responses.
import * as grpcMock from "grpc-web-mock";
import { ListOrdersResponse, Order } from "./gen/protos/orders_pb";
describe("Orders Service", () => {
it("should returns a list of orders", () => {
// Intercept Backend request and inject a mocked grpc-web response.
cy.intercept(
{
method: "POST",
pathname: "/shopping.api.v1.OrdersService/ListOrders",
},
(req) => {
// 1. Mock a Protobuffer response object as it would be
// returned by the real GRPC server.
const res = new ListOrdersResponse();
const orders = [] as Order[];
for (let i = 0; i < 10; i++) {
const order = new Order();
order.setId(i);
order.setPrice(1000);
order.setQuantity(1);
orders.push(order);
}
res.setOrdersList(orders);
// 2. Change response for a mocked "grpc-web-text" response.
req.reply(grpcMock.ToTextResponse(res));
}
).as("@listOrders");
cy.visit("/orders/list");
cy.wait("@listOrders")
cy.get("[data-cy=orders-table]").find("tr").should("have.length", 10);
});
});
FAQs
Simple pure typescript grpc-web mocking library
The npm package @botchris/grpc-web-mock receives a total of 1,145 weekly downloads. As such, @botchris/grpc-web-mock popularity was classified as popular.
We found that @botchris/grpc-web-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.