Integratify
Make Node.js integration testing easy!

Installation
Install via npm
npm install integratify
or via yarn
yarn add integratify
Usage
const integratify = require('integratify');
import * as integratify from 'integratify';
Configuration
Global
You can set a global configuration that will used for all tests. Adviced to set this in a configuration file running before each test file. This is optional
import { setConfiguration } from 'integratify';
setConfiguration({
dataPath: 'data',
schemaValidator: (data, schema) => myValidationFunc(data, schema),
});
Local
You can always overwrite any global configuration per test suite when initializing your Integratify test runner.
const express = require('express');
const app = express();
const testRunner = integratify(app, {
prefix: '/api/auth',
dataPath: 'data',
schemaValidator: (data, schema) => myValidationFunc(data, schema),
});
Getting Started
Run api tests
import { setConfiguration } from 'integratify';
setConfiguration({
dataPath: 'data',
schemaValidator: (data, schema) => myValidationFunc(data, schema),
});
const testRunner = integratify(app, {
prefix: '/auth',
dataPath: 'customDataPath',
});
describe('POST /login', () => {
it('Should successfully log in existing user', async () => {
const { status, header, body } = await testRunner
.post("/login")
.send({
payload: { username, password },
query: { ... },
headers: { ... },
file: { name: 'fileName.png', value: '...' },
})
.expect({
status: 200,
schema: loginOutsputSchema,
matchObject: { username: expect.any(String)}
matchObjectInArray: { username: expect.any(String)},
toEqual: { username: expect.any(String)};
length: 1,
spies: [
fetchSpy,
{ spy: firebaseSpy, amount: 1 },
],
error: new BadRequestError(errors.THIS_WAS_NOT_OK),
paths: [
{ 'meta.count': 10 },
{ 'meta.totalCount': 250 },
]
});
});
});
Available Options
.post
.get
.put
.patch
.delete
Key | Type | Description | Allowed value(s) |
---|
payload | string/object | Body payload | any string/object |
query | string/object | Query payload | any string/object |
headers | object | Custom headers | any object |
file | object | File payload | { name: string, value: any } |
.expect
Key | Type | Description | Allowed value(s) |
---|
status | number | HTTP status | valid HTTP status code |
schema | any | Validation schema | Expected schema for schemaValidator configuration property |
matchObject | object | .toMatchObject | any object |
matchObjectInArray | object | Matches an object within an array | any object |
toEqual | any | .toEqual | any |
length | number | Matches length of response | number |
spies | object | Checks whether specific spies got called | [mySpy] or [{ spy: mySpy, amount: 2 }] |
error | Error | Potential error to validate against | Javascript Error |
paths | object | Validate custom return keys besides dataPath | {'meta.count': 1} |
Error support for @tree-house/errors.
To Do
Unfortunately no time could be found yet to add automated tests. This is the first thing planned now we have a stable version 3 released.
Tests
You can run npm run test
to run all tests
You can run npm run test:coverage
to run all tests with coverage report
Authors
See the list of contributors who participated in this project.
License
This project is licensed under the ISC License - see the LICENSE.md file for details