Nonchalant Programming Master

    hobbes

    0.2.2 • Public • Published

    Hobbes

    Hobbes is a contract testing library for NodeJS projects. This project is still in development. Expect api changes.

    This is based heavily on the Pact library. The difference is that this is meant only for NodeJS and is much more lightweight and flexible.

    Installation

    npm install --save-dev hobbes
    

    Usage

    Write a consumer test.

    import hobbes, { is } from 'hobbes';
     
    describe('Consumer Test Example', () => {
      const contract = hobbes.contract({
        consumer: 'ConsumerName',
        provider: 'ProviderName',
        port: 4567,
        directory: path.resolve(__dirname, 'contracts')
      });
     
      describe('GET /endpoint', () => {
        const EXPECTED_BODY = is.object({
          value: is.number(1)
        });
     
        before(() => {
          contract.interaction({
            request: {
              method: 'GET',
              path: '/endpoint'
            },
            response: {
              status: 200,
              body: EXPECTED_BODY
            }
          });
        });
     
        it('should get the value', () => {
          return getValue().then(value => {
            expect(value).to.equal(1);
          });
        });
      });
     
      after(() => contract.finalize());
    });

    Write a provider test:

    import hobbes from 'hobbes';
     
    describe('Provider Test Example', () => {
      it('should verify the contract', () => {
        return hobbes.verify({
          baseURL: 'http://provider.com',
          contract: path.resolve(__dirname, 'contracts', 'ConsumerName-ProviderName.json')
        });
      });
    });

    Run the consumer test followed by the provider test.

    It's magic.

    Keywords

    none

    Install

    npm i hobbes

    DownloadsWeekly Downloads

    5

    Version

    0.2.2

    License

    MIT

    Last publish

    Collaborators

    • avatar