Error: done() called multiple times when trying to implement multiple interactions in pact javascript

Error: done() called multiple times when trying to implement multiple interactions in pact javascript

I am trying to create multiple interactions with just one pact server server, but when I run the code I get this error : Error: done() called multiple times. It must be possible to create multiple interactions with just one pact server, but I cannot figure out how. I have read this https://github.com/pact-foundation/pact-js documentation, which states that is it possible to create multiple interactions with just one server.

const interaction1 = {
    state: 'User exists',
    uponReceiving: 'a request containing users preferences',
    withRequest: {
        method: 'GET',
        path: '/members/profile',
        headers: {
            'Host': "localhost:3000",
            'Accept-Encoding': "gzip, deflate",
            'User-Agent': "node-superagent/1.8.5",
            'Authorization': ``Bearer ${ACCESS_TOKEN`}`,
            'Connection': "close",
            'Https': "on",
            'Version': "HTTP/1.1"
       }
  },
    willRespondWith: {
        status: 200,
        headers: {
            'Content-Type': 'application/json'
        },
        body: RESPONSE_BODY1
  }
};


const interaction2 = {
    state: 'User exists',
    uponReceiving: 'a request containing user profile',
    withRequest: {
        method: 'GET',
        path: '/member/preferences',
        headers: {
            'Host': "localhost:3000",
            'Accept-Encoding': "gzip, deflate",
            'User-Agent': "node-superagent/1.8.5",
            'Authorization': ``Bearer ${ACCESS_TOKEN}``,
            'Connection': "close",
            'Https': "on",
            'Version': "HTTP/1.1"
        }
   },
   willRespondWith: {
       status: 200,
       headers: {
          'Content-Type': 'application/json'
      },
      body: RESPONSE_BODY2
   }
};


describe('Integration', () => {
    before((done) => {
        provider.setup()
           .then(() => {
               // multiple interactions produce the error.
               provider.addInteraction(interaction1)
                   .then(() => done());
               provider.addInteraction(interaction2)
                   .then(() => done()); 
       })
    })
})`

您只需在完成后调用 done。因此,您可以 运行 一个接一个地调用,如下所示:

provider.addInteraction(interaction1)
    .then(() => provider.addInteraction(interaction2));
    .then(() => done());

或者您可以使用 Promise.all 同时 运行 它们,并等待它们完成:

Promise.all([provider.addInteraction(interaction1), provider.addInteraction(interaction2)])
    .then(() => done());