Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/connectrpc/connect-playwright-es
Utilities for use with Playwright and Connect-ES.
https://github.com/connectrpc/connect-playwright-es
connect-es playwright typescript
Last synced: 6 days ago
JSON representation
Utilities for use with Playwright and Connect-ES.
- Host: GitHub
- URL: https://github.com/connectrpc/connect-playwright-es
- Owner: connectrpc
- License: apache-2.0
- Created: 2023-08-10T15:12:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-18T13:14:13.000Z (3 months ago)
- Last Synced: 2024-10-18T15:30:24.458Z (3 months ago)
- Topics: connect-es, playwright, typescript
- Language: TypeScript
- Homepage: https://connectrpc.com/
- Size: 444 KB
- Stars: 22
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
Playwright for Connect-ES
============[![License](https://img.shields.io/github/license/connectrpc/connect-playwright-es?color=blue)](./LICENSE) [![Build](https://github.com/connectrpc/connect-playwright-es/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/connectrpc/connect-playwright-es/actions/workflows/ci.yaml) [![NPM Version](https://img.shields.io/npm/v/@connectrpc/connect-playwright/latest?color=green&label=%40connectrpc%2Fconnect-playwright)](https://www.npmjs.com/package/@connectrpc/connect-playwright)
e2e utilities designed to simplify writing [Playwright](https://playwright.dev) tests for your Connect-ES application by providing
an API to mock unary RPCs defined in your service.## Installation
```
npm install @connectrpc/connect-playwright
```## Usage
Unary Connect RPCs can be customized through the usage of the `createMockRouter` function. This function allows you to
write mocks at the service-level as well as mocks at the individual RPC level.For example, to write mocks at the service level, use the `service` function on the mock router:
```typescript
test("mock RPCs at service level", async ({ context }) => {
const mock = createMockRouter(context, {
baseUrl: "https://api.myproject.com",
});await mock.service(UserService, {
// Mock getUser to return a custom response.
getUser() {
return {
id: 1,
name: "Homer Simpson",
role: "Safety Inspector",
};
},
});
// ...
});
```If you do not require any custom behavior and simply want to mock all RPCs in your service, you can do this with
the shorthand:```typescript
await createMockRouter(context, {
baseUrl: "https://api.myproject.com",
}).service(UserService, "mock");
```If you wish to write mocks at the individual RPC level, you can do so with the `rpc` function on your mock router:
```typescript
test("mock RPCs at rpc level", async ({ context }) => {
const mock = createMockRouter(context, {
baseUrl: "https://api.myproject.com",
});// Mock getUser with a custom response
await mock.rpc(UserService.method.getUser, () => {
return {
id: 1,
name: "Homer Simpson",
role: "Safety Inspector",
};
});// Just return a default-constructed DeleteUserResponse without hitting the actual RPC.
await mock.rpc(UserService.method.deleteUser, "mock");
});
```Full documentation can be found in the package [README](packages/connect-playwright).
In addition, an example of using all of the above in practice can be found in the [connect-playwright-example](https://github.com/connectrpc/connect-playwright-es/tree/main/packages/connect-playwright-example)
directory.## Packages
- [@connectrpc/connect-playwright](https://www.npmjs.com/package/@connectrpc/connect-playwright):
Utilities for writing end-to-end tests for a Connect-ES application using Playwright ([source code](packages/connect-playwright)).## Ecosystem
* [connect-es](https://github.com/connectrpc/connect-es):
Connect, gRPC, and gRPC-Web support for Protobuf and TypeScript.
* [connect-query-es](https://github.com/connectrpc/connect-query-es):
TypeScript-first expansion pack for TanStack Query that gives you Protobuf superpowers
* [connect-swift](https://github.com/connectrpc/connect-swift):
Idiomatic gRPC & Connect RPCs for Swift.
* [connect-go](https://github.com/connectrpc/connect-go):
Go implementation of gRPC, gRPC-Web, and Connect
* [examples-go](https://github.com/connectrpc/examples-go):
Example RPC service powering https://demo.connectrpc.com and built with connect-go
* [conformance](https://github.com/connectrpc/conformance):
Connect, gRPC, and gRPC-Web interoperability tests
* [Buf Studio](https://buf.build/studio): web UI for ad-hoc RPCs## Status
This project is in beta, which means we may make a few changes as we gather feedback from early adopters.
Join us on [Slack](https://buf.build/links/slack) to stay updated on future releases.## Legal
Offered under the [Apache 2 license](./LICENSE).