Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gas-buddy/service-tester
Testing utilities for @gasbuddy/service
https://github.com/gas-buddy/service-tester
Last synced: about 2 months ago
JSON representation
Testing utilities for @gasbuddy/service
- Host: GitHub
- URL: https://github.com/gas-buddy/service-tester
- Owner: gas-buddy
- License: mit
- Created: 2022-10-04T14:48:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-23T18:47:33.000Z (3 months ago)
- Last Synced: 2024-11-15T19:08:30.267Z (2 months ago)
- Language: TypeScript
- Size: 2.84 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
service-tester
===============![main CI](https://github.com/gas-buddy/service-tester/actions/workflows/nodejs.yml/badge.svg)
[![npm version](https://badge.fury.io/js/@gasbuddy%2Fservice-tester.svg)](https://badge.fury.io/js/@gasbuddy%2Fservice-tester)
This module makes it easier for you to write tests for your node.js GasBuddy microservice. Simply add
the module as a dev dependency:```sh
yarn add -D @gasbuddy/service-tester
```Then write a test in ```/__tests__/startup.test.js```:
```ts
import request from 'supertest';
import { getReusableApp, clearReusableApp } from '@gasbuddy/service-tester';
import myService from '../src/index';describe('my service', () => {
test('should start', async () => {
const app = await getReusableApp(myService);
expect(app).toBeTruthy();
await request(app).get('/').expect(200);
});
});
```Service call mocking
--Nock is so 2010. The future is mock! Since we have typed clients for services these days, mocking them is easier. We've played some nutty
tricks with Typescript (well, nutty for me), to enable this kind of syntax:```
mockServiceCall(app.locals.services.myCrazyServ, 'get_some_resource').mockResolvedValue({
status: 200,
responseType: 'response',
body: { resource: true },
headers: new Headers(),
});
```This will cause calls to `app.locals.services.myCrazyServ.get_some_resource()` to return `{resource: true}`. This is just shorthand
for `jest.spyOn(service, 'method')` with knowledge of the traditional return type of OpenAPI service calls.