Skip to content

PactV3 mock server fails to handle DELETE requests after upgrade to v16.3.0 (pact-core v19) #1696

Description

@lsigism

Description

After upgrading from @pact-foundation/pact v16.2.0 to v16.3.0, consumer Pact tests using DELETE HTTP method fail with TypeError: Network request failed. Tests using GET and POST methods continue to work as expected.

Versions

  • @pact-foundation/pact: 16.3.0 (works on 16.2.0)
  • @pact-foundation/pact-core: 19.1.0 (via 16.3.0) vs 18.1.0 (via 16.2.0)
  • Node.js: 22.x
  • Test runner: Jest + jsdom + whatwg-fetch
  • OS: Ubuntu (GitHub Actions runner)

Steps to reproduce

  1. Create a PactV3 consumer test with a DELETE interaction:
import { PactV3 } from "@pact-foundation/pact";

const provider = new PactV3({
  consumer: "my-consumer",
  provider: "my-provider",
  dir: path.resolve(process.cwd(), "pacts"),
});

describe("DELETE resource", () => {
  it("deletes the resource", async () => {
    provider
      .given("resource exists")
      .uponReceiving("a DELETE request")
      .withRequest({
        method: "DELETE",
        path: "/api/resource/1",
        headers: {
          Accept: "application/json",
        },
      })
      .willRespondWith({
        status: 200,
        headers: { "Content-Type": "application/json" },
        body: '{}',
      });

    return provider.executeTest(async (mockServer) => {
      const response = await fetch(`${mockServer.url}/api/resource/1`, {
        method: "DELETE",
        headers: {
          Accept: "application/json",
        },
      });

      expect(response.status).toEqual(200);
    });
  });
});
  1. Run the test with @pact-foundation/pact v16.3.0

Expected behaviour

The mock server handles the DELETE request and returns the configured response (as it does in v16.2.0).

Actual behaviour

The test fails with:

TypeError: Network request failed

  at node_modules/whatwg-fetch/dist/fetch.umd.js:567:18
  at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:579:19)

The fetch call cannot connect to the Pact mock server for DELETE requests. GET and POST interactions against the same mock server work fine.

Suspected root cause

v16.3.0 bumped @pact-foundation/pact-core from ^18.1.0 to ^19.1.0. The breaking change in pact-core v19.0.0 (release notes) replaced the deprecated pactffiCreateMockServerForPact with pactffiCreateMockServerForTransport:

- const port = ffi.pactffiCreateMockServerForPact(pactPtr, `${address}:${requestedPort || 0}`, tls);
+ const port = ffi.pactffiCreateMockServerForTransport(pactPtr, address, requestedPort || 0, tls ? 'https' : 'http', '');

This new mock server transport implementation appears to not handle DELETE requests correctly — or there's a timing/connection issue specific to DELETE when using whatwg-fetch in a jsdom environment.

Workaround

Pin @pact-foundation/pact to 16.2.0.

Metadata

Metadata

Labels

bugIndicates an unexpected problem or unintended behaviortriageThis issue is yet to be triaged by a maintainerupstreamIndicates that an issue relates to an upstream problem (such as in pact-reference)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions