Manoel Neto
05/06/2024, 3:17 PMapp = await setupApp()
which brings up an instance of the Express server on localhost using port 3030
• And in the provider opts I'm passing port 3030
through the providerBaseUrl
But when I run the tests, I get a connection error on port 3030
and I see that Pact has actually sent a request to a random port (e.g. 54127
).
The most curious thing is that we already do this in our unit tests to run instances of Express, Mongo and so on using Jest, and it works perfectly.
I'm leaving here the error logs and also the test code.Manoel Neto
05/06/2024, 3:18 PMManoel Neto
05/06/2024, 3:19 PMlet app: Express
let locationCollection: CollectionDecorator
const fakeLocation = {
name: 'Fake Location',
description: 'Fake Location Description',
address: 'Fake address',
createdAt: new Date(),
updatedAt: new Date(),
createdByUserId: new ObjectID().toHexString(),
image: 'fake_image',
}
describe('Location Provider Contract Test', () => {
beforeAll(async () => {
app = await setupApp()
await MongoHelper.connect(process.env.MONGO_URL)
})
afterAll(async () => {
await shutdownDependencies()
})
it('should return 200 when getting a location by id', async () => {
const opts = {
provider: 'motor',
providerBaseUrl: '<http://localhost:3030>',
pactBrokerUrl: process.env.PACT_BROKER_URL,
pactBrokerToken: process.env.PACT_BROKER_TOKEN,
publishVerificationResult: true,
providerVersion: '0.0.1',
consumerVersionSelectors: [
{
consumer: 'webapp',
tags: ['0.0.2'],
latest: true,
},
],
logLevel: 'debug' as const,
stateHandlers: {
hasLocationWithSomeId: async () => {
const location = (
await locationCollection.insertOne(fakeLocation)
).ops[0]
await request(app).get(`/locations/${location._id}`)
},
},
}
return await new Verifier(opts).verifyProvider()
})
})
Manoel Neto
05/06/2024, 3:21 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
::1
seems to indicate that your API is not bound to an ipv6 address, but the OS thinks localhost
is an ipv6 address. You could try using 127.0.0.1