Skip to content

mockServer does not start() #10

@ghost

Description

Hi,

I am trying to start doing CDD on my JS application. I am trying to create the most simple consumer pact, but when I call

mockServer.start().then(() => {
    provider = Pact({consumer: 'client', provider: 'service', port: 1234});
   done();
});

It never gets inside the then, so I am assuming the promise never gets resolved. I am using Jest that uses Jasmine behind the scene. I wonder if you have any clue of how could I debug this network issue ( if it is that ).

this is my test file

import Pact from 'pact';
import path from "path";
import chaiAsPromised from "chai-as-promised";
import pactWrapper from "@pact-foundation/pact-node";
import chai, {expect} from "chai";
import request  from 'superagent';

chai.use(chaiAsPromised);

describe("see all dog", () => {
    var provider, mockServer;

    beforeAll(() =>{
        mockServer = pactWrapper.createServer({
            port: 1234,
            host: "localhost",
            log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
            dir: path.resolve(process.cwd(), 'pacts'),
            consumer: "client",
            provider: "service",
            spec: 2
        });
    });

    afterAll(() => {
        pactWrapper.removeAllServers();
    });

    beforeEach((done) => {
        mockServer.start().then(() => {
            provider = Pact({consumer: 'client', provider: 'service', port: 1234});
            done();
        });
    });

    afterEach((done) => {
        mockServer.delete().then(() => {
            done();
        });
    });

    describe("test", () => {
        describe("test", () => {
            beforeEach((done) => {
                provider.addInteraction({
                    state: 'I want to see my dogs',
                    uponReceiving: 'a request to get dogs',
                    withRequest: {
                        method: 'GET',
                        path: '/dogs',
                        headers: {'Accept': 'application/json'}
                    },
                    willRespondWith: {
                        status: 200,
                        headers: {'Content-Type': 'application/json'},
                        body: {}
                    }
                }).then(() => done());
            });

            afterEach((done) => {
                provider.finalize().then(() => done())
            });

            it('successfully verifies', (done) => {
                const verificationPromise = request
                    .get('http://localhost:1234/dogs')
                    .set({ 'Accept': 'application/json' })
                    .then(provider.verify);

                expect(verificationPromise).to.eventually.eql(JSON.stringify({})).notify(done)
            })
        });
    });
});

and when I run test I get

● see all dog › test › test › it successfully verifies
  - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
        at Timeout.e [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:477:19)
        at tryOnTimeout (timers.js:232:11)
        at Timer.listOnTimeout (timers.js:202:5)
  - TypeError: Cannot read property 'addInteraction' of undefined
        at Object.<anonymous> (app/components/Dogs/__tests__/clientTest.js:47:25)
        at Timeout.e (node_modules/jsdom/lib/jsdom/browser/Window.js:477:19)
        at tryOnTimeout (timers.js:232:11)
        at Timer.listOnTimeout (timers.js:202:5)
  - TypeError: Cannot read property 'verify' of undefined
        at Object.<anonymous> (app/components/Dogs/__tests__/clientTest.js:71:30)
        at Timeout.e (node_modules/jsdom/lib/jsdom/browser/Window.js:477:19)
        at tryOnTimeout (timers.js:232:11)
        at Timer.listOnTimeout (timers.js:202:5)
  - TypeError: Cannot read property 'finalize' of undefined
        at Object.<anonymous> (app/components/Dogs/__tests__/clientTest.js:64:25)
        at Timeout.e (node_modules/jsdom/lib/jsdom/browser/Window.js:477:19)
        at tryOnTimeout (timers.js:232:11)
        at Timer.listOnTimeout (timers.js:202:5)
1 test failed, 0 tests passed (1 total in 1 test suite, run time 6.208s)
npm ERR! Test failed.  See above for more details.

There is a jasmine TIMEOUT.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions