Tam Norris
05/22/2023, 2:12 PMimport { Verifier } from "@pact-foundation/pact";
import { server } from "../providers/product.provider";
import { describe, beforeAll, beforeEach, test } from "@jest/globals";
describe("Pact Verification", () => {
// (1) Starting the Provider API
beforeAll( () => server.listen(8081));
afterAll( () => {
if (server) {
server.close();
}
});
it("validates the expectations of ProductService", async () => {
// (2) Telling Pact to use the contracts stored in PactFlow and where the Product API will be running
const opts: any = {
logLevel: "INFO",
providerBaseUrl: "<http://localhost:8081>",
providerVersion: "1.0.0-someprovidersha",
provider: "products-provider",
providerBranch: "main",
consumerVersionSelectors: [{ branch: "main" }],
pactBrokerUrl: process.env.PACT_BROKER_BASE_URL,
// pactUrls: [
`// ${process.env.PWD}/pacts/katacoda-consumer-katacoda-provider.json,`
// ],
publishVerificationResult: true,
enablePending: true,
};
// (3) Running the Provider verification task
return new Verifier(opts).verifyProvider().then((output: any) => {
console.log("Pact Verification Complete!");
});
});
});
With the option --detectOpenHandles added in my package.json jest command I get ...
TCPSERVERWRAP
9 |
10 | //beforeAllasync((done: any) => server.listen(8081, done));
> 11 | beforeAll( () => server.listen(8081));
| ^
12 |
13 | afterAll( () => {
14 | if (server) {
at Function.listen (node_modules/express/lib/application.js63524)
at Object.listen (test/provider_pact_specs/product.provider.pact.spec.ts1127)
● TCPSERVERWRAP
37 |
38 | // (3) Running the Provider verification task
> 39 | return new Verifier(opts).verifyProvider().then((output: any) => {
| ^
40 | console.log("Pact Verification Complete!");
41 | });
42 | });
But Im not really sure how to fix these. From stackoverflow I found that I can add the --forceExit option to jest cl command, but is there a better way of writing this code so that I don't need this? Thanks.Timothy Jones
05/23/2023, 12:06 AMTimothy Jones
05/23/2023, 12:07 AMafterAll( () => {
if (server) {
server.close();
}
});
Timothy Jones
05/23/2023, 12:07 AMTimothy Jones
05/23/2023, 12:08 AMTimothy Jones
05/23/2023, 12:08 AMserver.close();
^ Is this async?Timothy Jones
05/23/2023, 12:10 AMasync from your it function, because you're returning a promise.