0.0.1 • Published 5 years ago

start-endpoint-imposter v0.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

start-endpoint-imposter

A tiny node Node.js utility that helps to spin up an Endpoint Imposter server.

npm i start-endpoint-imposter --save-dev

The Snippet

const startEndpointImposter = require('start-endpoint-imposter');

// ...

const stop = await startEndpointImposter({
  '--port': 3000,
  '--mocks': require('path').resolve(__dirname, './mocks.js'),
  // ... other options
});

await stop();

With jest

If you haven't done it yet, declare your globalSetup and globalTeardown files.

Here's an example from the package.json file:

"jest": {
  "globalSetup": "./jestGlobalSetup.js",
  "globalTeardown": "./jestGlobalTeardown.js"
}

Then, inside your globalSetup file, start the server and assign the stop function to a global variable:

// your globalSetup file, like jestGlobalSetup.js

const startEndpointImposter = require('start-endpoint-imposter');

module.exports = async () => {
  const stop = await startEndpointImposter({
    '--port': 3000,
    '--mocks': require('path').resolve(__dirname, './mocks.js'),
  });
  global.__STOP_ENDPOINT_IMPOSTER__ = stop;
};

Finally, call the stop function from inside the globalTeardown file in order to stop the server:

// your globalTeardown file, like jestGlobalTeardown.js

module.exports = async function() {
  await global.__STOP_ENDPOINT_IMPOSTER__();
};