start-endpoint-imposter

0.0.1 • Public • Published

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__();
};

Readme

Keywords

none

Package Sidebar

Install

npm i start-endpoint-imposter

Weekly Downloads

91

Version

0.0.1

License

MIT

Unpacked Size

4.33 kB

Total Files

6

Last publish

Collaborators

  • lukaszmakuch