Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ssssota/msw-connect-web
Mock Service Worker utility for connect-web.
https://github.com/ssssota/msw-connect-web
connect-web grpc mock msw
Last synced: 2 months ago
JSON representation
Mock Service Worker utility for connect-web.
- Host: GitHub
- URL: https://github.com/ssssota/msw-connect-web
- Owner: ssssota
- License: apache-2.0
- Created: 2023-01-28T08:15:10.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-29T13:28:05.000Z (almost 2 years ago)
- Last Synced: 2024-04-30T02:22:53.994Z (8 months ago)
- Topics: connect-web, grpc, mock, msw
- Language: TypeScript
- Homepage:
- Size: 69.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# msw-connect-web
[Mock Service Worker](https://mswjs.io/) utility for [connect-web](https://github.com/bufbuild/connect-web).
🚧 Streaming requests and responses are not currently supported.
🚧 And server-side mocking is currently not supported either. (Because MSW has no support for Node.js `globalThis.fetch`. [mswjs/interceptors#283](https://github.com/mswjs/interceptors/pull/283))
If you want to mock on the server-side, you can use [connect-web-mock-interceptor](https://www.npmjs.com/package/connect-web-mock-interceptor).
## Usage
Install package.
```sh
npm i -D msw-connect-web msw
```Define mocks.
_handlers.ts_
```typescript
import { createMswConnectWeb } from 'msw-connect-web';
const connect = createMswConnectWeb({ baseUrl: 'https://...' });
export const handlers = [
connect(YourService, 'methodName', async (req, res, ctx) => {
// You can access the request message (with types) using the `message` method.
const requestMessage = await req.message();
return res(
ctx.delay(1000),
// You can define response with `message` method.
ctx.message(new ResponseMessage({ ... })),
);
}),
];
```