Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Latest commit

 

History

History
58 lines (45 loc) · 1.98 KB

README.md

File metadata and controls

58 lines (45 loc) · 1.98 KB

Testing Tools for express-gateway

The purpose of this package is to provide a set of tools to make it easier to write tests against custom plugin code that runs off of the Express Gateway. Note that some tools may become obsolete dependent on what programmatic features are added to Express Gateway in the future.

Usage Examples

const { createGateway, createGatewayConfig } = require('express-gateway-test-tools');
const request = require('supertest');

describe('example test', function () {
  it('with custom policy', function () {
    let gwConfig = createGatewayConfig();
    let gwApp;

    // Setup the actionParams you want to pass into the policies you'll be testing
    let policiesToTest = [
      { 'myPolicy': {
        param1: 'foo',
        param2: 'bar'
      }}
    ];

    // Path to the manifest file needs to be relative to the test file
    return createGateway(gwConfig, '../manifest.js', policiesToTest)
      .then((gw) => {
        gwApp = gw.app;
        return request(gwApp)
          .get('/ip')
          .expect(200)
      })
      .then(() => {
        // Always make sure to close your app when done, or else your test runner won't exit
        gwApp.close();
      });
  });
});

Plugins with parameters

To set custom parameters for a plugin, define them like in this example.

const pluginParams = {
  param1: 'foo',
  param2: 123
};

createGateway(gwConfig, '../manifest.js', policiesToTest, pluginParams);

Setting up tests to run

Make certain that at a minimum set EG_DISABLE_CONFIG_WATCH=true when running your tests, otherwise the gateway will have issues attempting to load.

A note on dependencies

The testing tools have no specific dependencies defined, so as to allow a plugin developer to test against the version of Express Gateway that they're actually using. Thus it is assumed that some version of Express Gateway is installed by the app that is consuming this package.