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
- 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);
});
});
});
- 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.
Description
After upgrading from
@pact-foundation/pactv16.2.0 to v16.3.0, consumer Pact tests usingDELETEHTTP method fail withTypeError: Network request failed. Tests usingGETandPOSTmethods 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)Steps to reproduce
DELETEinteraction:@pact-foundation/pactv16.3.0Expected behaviour
The mock server handles the
DELETErequest and returns the configured response (as it does in v16.2.0).Actual behaviour
The test fails with:
The
fetchcall cannot connect to the Pact mock server forDELETErequests.GETandPOSTinteractions against the same mock server work fine.Suspected root cause
v16.3.0 bumped
@pact-foundation/pact-corefrom^18.1.0to^19.1.0. The breaking change in pact-core v19.0.0 (release notes) replaced the deprecatedpactffiCreateMockServerForPactwithpactffiCreateMockServerForTransport:This new mock server transport implementation appears to not handle
DELETErequests correctly — or there's a timing/connection issue specific toDELETEwhen usingwhatwg-fetchin a jsdom environment.Workaround
Pin
@pact-foundation/pactto16.2.0.