Skip to content

Instantly share code, notes, and snippets.

@YOU54F
Created September 14, 2023 17:13
Show Gist options
  • Save YOU54F/3ef94b1bd4db4f7e54a3be67d1cb8d43 to your computer and use it in GitHub Desktop.
Save YOU54F/3ef94b1bd4db4f7e54a3be67d1cb8d43 to your computer and use it in GitHub Desktop.
pact-js-core - makeConsumerPact
{
"dependencies": {
"@pact-foundation/pact-core": "^14.0.4"
}
}
// run with node test.js
const pact = require('@pact-foundation/pact-core')
pact.createServer()
.delete()
.then(function() {
console.log('pact ruby standalone server created and deleted')
});
const consumerPact = pact.makeConsumerPact(
'foo-consumer',
'bar-provider',
4 ,// v3 spec,
'INFO'
);
const interaction = consumerPact.newInteraction('some description');
interaction.uponReceiving('a request to get a dog');
interaction.given('fido exists');
interaction.withRequest('GET', '/dogs/1234');
interaction.withResponseBody(
JSON.stringify({
name: 'fido',
age: 23,
alive: true,
}),
'application/json'
);
interaction.withStatus(200);
port = consumerPact.createMockServer('127.0.0.1');
// port = consumerPact.createMockServer('localhost'); // Error in native callback - JSON.parse(ffi.pactffiMockServerMismatches(port))
console.log(port)
consumerPact.mockServerMatchedSuccessfully(port)
const mismatches = consumerPact.mockServerMismatches(port);
console.log(mismatches)
consumerPact.cleanupMockServer(port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment