Easily mock server from API Blueprint or Swagger
Switch branches/tags
greenkeeper-babel-cli-6.16.0 greenkeeper-babel-cli-6.22.0 greenkeeper-babel-core-6.18.0 greenkeeper-babel-eslint-7.0.0 greenkeeper-babel-loader-6.2.7 greenkeeper-commitizen-2.9.2 greenkeeper-drafter.js-2.6.0 greenkeeper-eslint-3.0.0 greenkeeper-eslint-3.0.1 greenkeeper-eslint-3.1.0 greenkeeper-eslint-3.1.1 greenkeeper-eslint-3.2.0 greenkeeper-eslint-3.2.1 greenkeeper-eslint-3.2.2 greenkeeper-eslint-3.3.0 greenkeeper-eslint-3.3.1 greenkeeper-eslint-3.4.0 greenkeeper-eslint-3.5.0 greenkeeper-eslint-3.6.0 greenkeeper-eslint-3.6.1 greenkeeper-eslint-3.7.0 greenkeeper-eslint-3.9.0 greenkeeper-eslint-3.9.1 greenkeeper-fury-adapter-swagger-0.9.0 greenkeeper-fury-adapter-swagger-0.9.1 greenkeeper-fury-adapter-swagger-0.9.2 greenkeeper-fury-adapter-swagger-0.9.3 greenkeeper-fury-adapter-swagger-0.9.4 greenkeeper-fury-adapter-swagger-0.9.5 greenkeeper-fury-adapter-swagger-0.9.8 greenkeeper-husky-0.13.0 greenkeeper-lodash-4.14.1 greenkeeper-lodash-4.16.5 greenkeeper-mocha-3.0.0 greenkeeper-mocha-3.0.1 greenkeeper-mocha-3.0.2 greenkeeper-mocha-3.1.0 greenkeeper-protagonist-1.5.0 greenkeeper/babel-cli-6.23.0 greenkeeper/babel-core-6.25.0 greenkeeper/babel-core-pin-6.24.1 greenkeeper/babel-eslint-9.0.0 greenkeeper/babel-loader-8.0.0 greenkeeper/babel-loader-8.0.1 greenkeeper/babel-loader-8.0.2 greenkeeper/babel-loader-pin-6.4.0 greenkeeper/chai-4.0.0 greenkeeper/chai-4.0.1 greenkeeper/chai-4.1.0 greenkeeper/chai-4.1.1 greenkeeper/chai-4.1.2 greenkeeper/coveralls-3.0.0 greenkeeper/coveralls-3.0.1 greenkeeper/drafter.js-2.6.4 greenkeeper/eslint-4.18.2 greenkeeper/eslint-4.19.0 greenkeeper/eslint-4.19.1 greenkeeper/eslint-5.0.0 greenkeeper/eslint-5.0.1 greenkeeper/eslint-plugin-babel-5.0.0 greenkeeper/eslint-plugin-babel-5.1.0 greenkeeper/eslint-plugin-babel-5.2.0 greenkeeper/fury-adapter-swagger-0.10.0 greenkeeper/fury-adapter-swagger-0.11.0 greenkeeper/fury-adapter-swagger-0.11.1 greenkeeper/fury-adapter-swagger-0.12.0-beta.1 greenkeeper/fury-adapter-swagger-0.12.0-beta.3 greenkeeper/fury-adapter-swagger-0.12.0 greenkeeper/fury-adapter-swagger-0.12.1 greenkeeper/fury-adapter-swagger-0.13.0 greenkeeper/fury-adapter-swagger-0.13.1 greenkeeper/fury-adapter-swagger-0.13.2 greenkeeper/fury-adapter-swagger-0.13.3 greenkeeper/fury-adapter-swagger-0.13.4 greenkeeper/fury-adapter-swagger-0.14.0 greenkeeper/fury-adapter-swagger-0.14.1 greenkeeper/fury-adapter-swagger-0.14.2 greenkeeper/fury-adapter-swagger-0.14.3 greenkeeper/fury-adapter-swagger-0.15.0 greenkeeper/fury-adapter-swagger-0.15.1 greenkeeper/fury-adapter-swagger-0.15.2 greenkeeper/fury-adapter-swagger-0.16.0 greenkeeper/fury-adapter-swagger-0.16.1 greenkeeper/fury-adapter-swagger-0.17.0 greenkeeper/fury-adapter-swagger-0.18.0 greenkeeper/fury-adapter-swagger-0.18.1 greenkeeper/fury-adapter-swagger-0.18.2 greenkeeper/fury-adapter-swagger-0.18.3 greenkeeper/fury-adapter-swagger-0.18.4 greenkeeper/fury-adapter-swagger-0.19.0 greenkeeper/fury-adapter-swagger-0.19.1 greenkeeper/fury-adapter-swagger-0.19.2 greenkeeper/fury-adapter-swagger-0.20.0 greenkeeper/fury-adapter-swagger-0.21.0 greenkeeper/fury-adapter-swagger-0.21.1 greenkeeper/nock-9.0.7 greenkeeper/nock-9.0.8 greenkeeper/nock-9.0.9 greenkeeper/nock-9.0.10 greenkeeper/nock-9.0.11 greenkeeper/nock-9.0.12 greenkeeper/nock-9.0.13 greenkeeper/nock-9.0.14 greenkeeper/nock-9.0.16 greenkeeper/nock-9.0.23 greenkeeper/nock-9.0.24 greenkeeper/nock-9.0.25 greenkeeper/nock-9.0.26 greenkeeper/nock-9.0.27 greenkeeper/nock-9.0.28 greenkeeper/nock-9.1.0 greenkeeper/nock-9.1.1 greenkeeper/nock-9.1.2 greenkeeper/nock-9.1.3 greenkeeper/nock-pin-9.0.4 greenkeeper/nock-pin-9.0.22 greenkeeper/request-2.88.0 greenkeeper/request-pin-2.87.0 greenkeeper/semantic-release-12.2.2 greenkeeper/semantic-release-12.2.4 greenkeeper/semantic-release-12.2.5 greenkeeper/semantic-release-12.4.0 greenkeeper/semantic-release-12.4.1 greenkeeper/semantic-release-15.0.0 greenkeeper/semantic-release-15.0.1 greenkeeper/semantic-release-15.0.2 greenkeeper/semantic-release-15.0.3 greenkeeper/semantic-release-15.1.2 greenkeeper/semantic-release-15.1.3 greenkeeper/semantic-release-15.1.4 greenkeeper/semantic-release-15.1.5 greenkeeper/semantic-release-15.1.6 greenkeeper/semantic-release-15.1.7 greenkeeper/semantic-release-15.1.8 greenkeeper/semantic-release-15.1.11 greenkeeper/semantic-release-15.3.0 greenkeeper/semantic-release-15.4.1 greenkeeper/semantic-release-15.4.2 greenkeeper/semantic-release-15.4.3 greenkeeper/semantic-release-15.4.4 greenkeeper/semantic-release-15.5.0 greenkeeper/semantic-release-15.5.1 greenkeeper/semantic-release-15.5.2 greenkeeper/semantic-release-15.5.3 greenkeeper/semantic-release-15.5.4 greenkeeper/semantic-release-15.5.5 greenkeeper/semantic-release-15.6.0 greenkeeper/semantic-release-15.6.1 greenkeeper/semantic-release-15.6.2 greenkeeper/semantic-release-15.6.3 greenkeeper/semantic-release-15.7.0 greenkeeper/semantic-release-15.7.1 greenkeeper/semantic-release-15.7.2 greenkeeper/semantic-release-15.8.0 greenkeeper/semantic-release-15.8.1 greenkeeper/semantic-release-15.9.1 greenkeeper/semantic-release-15.9.2 greenkeeper/semantic-release-15.9.3 greenkeeper/semantic-release-15.9.5 greenkeeper/semantic-release-15.9.6 greenkeeper/semantic-release-15.9.7 greenkeeper/semantic-release-15.9.8 greenkeeper/semantic-release-15.9.9 greenkeeper/semantic-release-15.9.11 greenkeeper/semantic-release-15.9.12 greenkeeper/semantic-release-15.9.13 greenkeeper/semantic-release-15.9.14 greenkeeper/sinon-5.0.1 greenkeeper/sinon-5.0.3 greenkeeper/sinon-5.0.6 greenkeeper/sinon-5.0.9 greenkeeper/sinon-5.0.10 greenkeeper/sinon-5.1.0 greenkeeper/sinon-5.1.1 greenkeeper/sinon-6.0.0 greenkeeper/sinon-6.0.1 greenkeeper/sinon-chai-2.11.0 greenkeeper/sinon-chai-2.12.0 greenkeeper/sinon-chai-2.13.0 greenkeeper/sinon-chai-3.0.0 greenkeeper/sinon-chai-3.1.0 greenkeeper/sinon-chai-3.2.0 greenkeeper/sinon-chai-pin-2.10.0 greenkeeper/sinon-pin-5.0.8 greenkeeper/update-to-node-10 greenkeeper/urijs-1.18.9 greenkeeper/urijs-1.18.10 greenkeeper/urijs-1.18.11 greenkeeper/urijs-1.18.12 greenkeeper/urijs-pin-1.18.8 master
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.babelrc
.editorconfig
.eslintrc
.gitignore
.travis.yml
license.md
mocha.config.js
package.json
readme.md
readme.png

readme.md

Build Status Coveralls Status npm downloads Greenkeeper badge

apish - Mock APIs and Services

Describe any API or Service you need mocked. Supports API Blueprint and Swagger API Description formats.

Use cases

3rd party APIs

  • Your app is calling GitHub API, weather API, Trello API, …
  • Describe endpoints in API Description format like API Blueprint (or ask API provider for API Description)
  • Add it as a test fixture and let apish create mock for you:
before(() => {
  return apish(fs.readFileSync('github-api.apib', 'utf8'));
});

// Run your tests with mocked requests against GitHub API

(Micro)services

  • Have all your services publish API Description onto (private) npm. Use semver to version it and tools like Dredd to test its implementation
  • When you depend on another service, just require its package with API Description and run tests against its mocks, that are always in sync with implementation
  • You can always compare version you've tested against to what is currently running in your environment
import myOtherService from 'myOtherService';

before(() => apish(myOtherService));

// Run your tests…

Installation

$ npm i apish -D

Usage

import apish from 'apish';

// In your test runner
let mockResult = {};
before(() => {
  const apib = fs.readFileSync('github-api.apib', 'utf8');
  return mockResult = apish(apib); // apish returns a Promise
});

// Cleanup
after(() => {
  // .value() is Promise-related helper in this case
  mockResult.value().restore();
});

Arguments

const mockedApi = apish(apiDescription, options);
  • apiDescription (string) - API Blueprint or Swagger API Description
  • options (OPTIONAL, object)
    • host (string) - overwrite specified host (base URL) that should be used

returns Promise

Resolved promise returns object with methods:

  • restore() - clears all mocks for this host

License

MIT