New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

integratify

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

integratify

Make integration testing easy

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Integratify

Make Node.js integration testing easy!

npm version Dependencies API Continuous Integration

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', // Optional prefix for every url path
  dataPath: 'data', // Optional path where actual data will be placed on.
  schemaValidator: (data, schema) => myValidationFunc(data, schema), // Function to validate data against a schema
});

Getting Started

Run api tests

// test.config.ts
import { setConfiguration } from 'integratify';

setConfiguration({
  dataPath: 'data',
  schemaValidator: (data, schema) => myValidationFunc(data, schema),
});


// login.test.ts
const testRunner = integratify(app, {
  prefix: '/auth',
  dataPath: 'customDataPath', // Will overwrite global setting
});

describe('POST /login', () => {
  it('Should successfully log in existing user', async () => {
    const { status, header, body } = await testRunner
      .post("/login")
      .send({
        payload: { username, password }, // Optional body
        query: { ... }, // Optional query parameters
        headers: { ... }, // Optional headers
        file: { name: 'fileName.png', value: '...' }, // Optional file
      })
      .expect({
        status: 200,
        schema: loginOutsputSchema,
        matchObject: { username: expect.any(String)}
        matchObjectInArray:  { username: expect.any(String)},
        toEqual:  { username: expect.any(String)};
        length: 1,
        spies: [
          fetchSpy, // Will validate whether called once
          { 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

KeyTypeDescriptionAllowed value(s)
payloadstring/objectBody payloadany string/object
querystring/objectQuery payloadany string/object
headersobjectCustom headersany object
fileobjectFile payload{ name: string, value: any }

.expect

KeyTypeDescriptionAllowed value(s)
statusnumberHTTP statusvalid HTTP status code
schemaanyValidation schemaExpected schema for schemaValidator configuration property
matchObjectobject.toMatchObjectany object
matchObjectInArrayobjectMatches an object within an arrayany object
toEqualany.toEqualany
lengthnumberMatches length of responsenumber
spiesobjectChecks whether specific spies got called[mySpy] or [{ spy: mySpy, amount: 2 }]
errorErrorPotential error to validate againstJavascript Error
pathsobjectValidate 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

FAQs

Package last updated on 10 Nov 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc