pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.63k stars 349 forks source link

Invalid character-set error while uploading verification results from provider #544

Closed ankur-malik-sky closed 3 years ago

ankur-malik-sky commented 3 years ago

Issue Classification

Bug Report

Hi Team, I am facing one issue when I am using Provider verification without broker URL and token my tests are passing, but when I add pact broker URL (pactflow.io) and token it gave me below error

Software versions

Issue Checklist

Confirm the following:

Expected behaviour

Should upload the verification results to the pactflow

Actual behaviour

Gives invalid character-set error

Steps to reproduce

https://pact-foundation.slack.com/files/U01GVR4BB63/F01J2GAGY6L/pact.zip

download above code and run yarn pact

Relevant log files

https://pact-foundation.slack.com/archives/C9VBGLUM9/p1608631701063200?thread_ts=1608430770.046500&cid=C9VBGLUM9

mefellows commented 3 years ago

Thanks @ankur-malik-sky for submitting.

After what was too long attempting to debug this, I think the issue is that you're simply not returning (or awaiting) the promise from the verification process.

i.e. this is an async function

    new Verifier(opts).verifyProvider().then((output) => {
      console.log(output);
    });

This is going to cause strange things to happen, because the test is closing down whilst running process down whilst the test. Can you please give this a go?

FWIW there are projects in the example repository you can use as a guide, or examples such as https://docs.pactflow.io/docs/examples/.

ankur-malik-sky commented 3 years ago

Hi @mefellows, Thanks for your prompt response, I might be missing something very basic here and as you mentioned the issues is definitely the tearing down of the server before request complete but I am not sure how to fix this, I have already tried below settings (and all possible combinations of this):

`describe("provider pact tests", () => { it("should validate pact provider", () => { ...

return new Verifier(opts).verifyProvider().then((output) => {
  console.log(output);
});

});`

`describe("provider pact tests", () => { it("should validate pact provider", async () => { ...

return await new Verifier(opts).verifyProvider().then((output) => {
  console.log(output);
});

});`

mefellows commented 3 years ago

The first problem is that you don't have a provider running (at least not in the example you shared), so it's hard to tell what the problem is because that is an important aspect of the provider test.

I've modified the code base you shared and pushed here: https://github.com/mefellows/pact-js-issue-544 (adding a basic express API to show how it works).

I'm going to close this issue. If you can reproduce a problem with pact in the example I shared, happy to re-open. As mentioned, there are other e2e examples in this repo you can also use as a guide or to reproduce the issue.