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.Gueorgui
05/08/2024, 1:03 PMThe pact mock service wasn't running when addInteraction was called
and similar. Has something changed in the way the pact mock server works? This is on pretty standard React-based consumers.Martin Gallauner
05/14/2024, 9:40 AMboden winkel
05/17/2024, 2:31 PMJulie Laursen
05/20/2024, 5:34 PMThis license is denied by your licensing policy.
This issue exists in a transitive dependency.
for version ramda (0.28.0)
When i run yarn why ramda
I get:
├─ @pact-foundation/pact@npm:12.5.0
│ └─ ramda@npm:0.28.0 (via npm:^0.28.0)
│
I saw that recently ramda v 27 had had security vulnerabilities and this was removed from pact-js's package.lock: https://github.com/pact-foundation/pact-js/issues/962. I do NOT see anything about v28
Should I create an issue for v28 or is there something I need to do personally?
I have already tried upgrading using yarn latest ( I was previously on 12.1 when the error happened), and I've even tried downgrading to a pre-v12 version of pact-foundation/pact. It does not seem to matter what version of pact I am on, I still get the failure.Koray Canpolat
05/21/2024, 10:50 AMconst path = require('path');
const { Pact, Verifier } = require('@pact-foundation/pact');
const axios = require('axios');
describe('Pact with HelloMundoProvider', () => {
const provider = new Pact({
consumer: 'HelloWorldConsumer',
provider: 'HelloMundoProvider',
port: 3000,
log: path.resolve(process.cwd(), 'logs', 'pact.log'),
dir: path.resolve(process.cwd(), 'pacts'),
logLevel: 'info',
});
beforeAll(() => provider.setup());
afterEach(() => provider.verify());
afterAll(() => provider.finalize());
// CONSUMER TEST:
describe('when a request for hola mundo is made', () => {
beforeAll(() => {
return provider.addInteraction({
state: 'the service is available',
uponReceiving: 'a request for hola mundo',
withRequest: {
method: 'GET',
path: '/hola',
},
willRespondWith: {
status: 200,
body: { message: 'Hola Mundo' },
},
});
});
it('returns the correct response', async () => {
const response = await axios.get('<http://localhost:3000/hola>');
expect(response.status).toBe(200);
expect(response.data).toEqual({ message: 'Hola Mundo' });
});
});
});
// PROVIDER VERIFICATION TEST:
describe('Pact Verification', () => {
it('validates the HelloMundoProvider contract', () => {
return new Verifier().verifyProvider({
provider: 'HelloMundoProvider',
logLevel: 'info',
providerBaseUrl:
'<http://api.kata-demo-ecom.applydigital.io/helloworld/v1/hola>',
pactUrls: [
path.resolve(
process.cwd(),
'pacts',
'helloworldconsumer-hellomundoprovider.json'
),
],
});
});
});
Koray Canpolat
05/21/2024, 10:51 AMTypeError: Cannot read properties of undefined (reading 'logLevel')
anyone know why?Koray Canpolat
05/21/2024, 10:53 AMKoray Canpolat
05/21/2024, 10:53 AMMatt (pactflow.io / pact-js / pact-go)
Verifier
is a constructor, but you’re passing the arguments to verifyProvider
instead.boden winkel
05/21/2024, 1:33 PMTaha Shakibania
05/27/2024, 11:03 AMJason Sunde
05/28/2024, 3:23 PMgeorgia andrews
05/30/2024, 11:17 PMPK
06/04/2024, 3:45 AMJuri Welz
06/04/2024, 8:21 AM[]
, but also non-empty arrays. If the array is not empty, each entry should be of the same specific type.
When we are using eachLike({ourTypeMatcher}, 0)
, the pact file omits the type information (In contrast, with min value of 1 eachLike({ourTypeMatcher}, 1)
, the type information is stored in the pact file).
How can we convey the information I described above?Tim Vahlbrock
06/14/2024, 8:43 AMAllen Ayala
06/14/2024, 6:25 PMStephen Bell
06/18/2024, 10:28 PMSiim Mardus
06/20/2024, 8:01 AMfromProviderState
function. Relevant issue from a year ago, which seems like it has been abandoned https://github.com/pact-foundation/pact-js/issues/1088
When I use fromProviderState
with request path, the mock server matches any request.
• fromProviderState('/users/${userId}', '/users/1234')
◦ This should mean that provider-side uses userId
to construct /users/<real-user-id>
and consumer side should match /users/1234
Expected behaviour:
• When I make request to /users/random-stuff
• Then test should fail, as the server should expect /users/1234
Actual behaviour:
• When I make request to /users/random-stuff
• Then test succeeds and server gives a response 🤯
I also tried to use equal
(equality matcher), as according to the docs, "`equal` - Value that must be equal to the example. This is mainly used to reset the matching rules which cascade." This seemed like a perfect candidate for this matcher, as we are matching inside the fromProviderState
🤷 I assumed that maybe it checked that /users/1234
and /users/random-stuff
are both strings.
• I tried: fromProviderState('/users/${userId}', equal('/users/1234'))
, but this still allowed /users/random
to be used...
⚠️ IMO this issue is quite pressing, because of two things:
• Getting path variables from provider state is super common use case, so using fromProviderState
is necessary
• Consumer side should not allow any data, when fromProviderState
is used, as it allows breaking the consumer side without breaking the tests. Simplified example:
◦ Initial JS API: `const fetchUsers(id) => fetch(/users/${id}
)`
◦ Test: fromProviderState('/users/${userId}', '/users/1234')
◦ Dev changes JS API: `const fetchUsers(id) => fetch(/users/changes/${id}
)`, breaking the contract
◦ Test still passes
Open to all help and suggestions 🙇. Maybe there is a workaround to achieve the same results or it's already fixed somewhere. Thanks!Alan Boshier
06/28/2024, 10:09 AM@pact-foundation/pact: 12.5.2
and using the --auto-detect-version-properties
switch when using the pact-broker publish command.
This is running in a BitBucket Cloud pipeline.
The docs say this flag:
Automatically detect the repository commit, branch and build URL from known CI environment variables or git CLI
When I look in the branch_versions
table I can see a new row with the expected branch name and underlying version number, but:
• The associated row of versions
has blank build_url
and repository_ref
columns (I'm assuming the former should contain the "build URL" described above
• I'm not sure where the "repository commit" alluded to above would crop up in the pact broker DB, so I'm not sure where to check for that.
Should I expect repository commit and build URL to be recorded in the DB somewhere? If they should be, any advice for how to track down why they are not appearing?Alan Boshier
06/28/2024, 10:31 AMBas Dijkstra
07/03/2024, 1:57 PM"@pact-foundation/karma-pact": "^3.1.0",
"@pact-foundation/pact-node": "^10.18.0",
"@pact-foundation/pact-web": "^9.5.0",
and here's the (edited) `karma.conf.js`:
// Karma configuration file, see link for more information
// <https://karma-runner.github.io/1.0/config/configuration-file.html>
const path = require('path');
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular', 'pact'],
plugins: [
require('karma-jasmine'),
require('@pact-foundation/karma-pact'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at <https://jasmine.github.io/api/edge/Configuration.html>
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
reporters: ['progress'],
browsers: ['Chrome'],
restartOnFileChange: true,
pact: [
{
cors: true,
spec: 3,
port: 1234,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts')
}
],
proxies: {
'/api': '<http://localhost:1234/api>'
}
});
};
Bas Dijkstra
07/03/2024, 1:58 PMng test
, I get the following error:
Generating browser application bundles (phase: building)...[15:53:38.170] INFO (15372): pact-node@10.18.0: Creating Pact Server with options:
{"cors":true,"spec":3,"port":1234,"log":"C:\\Git\\st-devops-testfullapp\\st-tst-testapp-front\\logs\\mockserver-integration.log","dir":"C:\\Git\\st-devops-testfullapp\\st-tst-testapp-front\\pacts","pactFileWriteMode":"overwrite","ssl":false,"host":"localhost"}
[15:53:42.677] ERROR (15372): pact-node@10.18.0: Pact Binary Error: The system cannot execute the specified program.
[15:53:42.679] WARN (15372): pact-node@10.18.0: Pact exited with code 1.
Any idea what might cause this? I see that my tests are started afterwards, but they obviously fail because the mock server doesn't want to startShishir Dwivedi
07/08/2024, 6:40 AMconst path = require('path');
const { PactV3, SpecificationVersion } = require('@pact-foundation/pact');
const { like, regex } = require('@pact-foundation/pact').Matchers;
const axios = require('axios');
const create_person = require('../data/create_person.json');
const create_person_response = require('../data/create_person_resonse.json');
const get_person_by_id_response = require('../data/get_person_by_id_response.json');
const PORT = 8090;
axios.defaults.timeout = 60000;
const provider = new PactV3({
consumer: 'ProfileConsumer2',
provider: 'ProfileProvider1',
port: PORT,
spec: SpecificationVersion.SPECIFICATION_VERSION_V2,
log: path.resolve(process.cwd(), 'logs', 'pact.log'),
dir: path.resolve(process.cwd(), 'pacts'),
logLevel: 'debug',
});
function createProfile() {
return <http://axios.post|axios.post>(`<http://localhost>:${PORT}/v2/profile/person/`, create_person, {
headers: { 'Content-Type': 'application/json' },
});
}
function findProfile() {
return axios.get(`<http://localhost>:${PORT}/v2/profile/find`, {
params: {
ids: '10000017',
scope: 'full',
},
headers: { 'Content-Type': 'application/json' },
});
}
describe('Contract test for Profile', () => {
describe('Pact with Profile API', () => {
it('should create contract for POST API', async () => {
await provider.addInteraction({
state: 'Create Profile test',
uponReceiving: 'a request to create a profile',
withRequest: {
method: 'POST',
path: '/v2/profile/person/',
headers: { 'Content-Type': 'application/json' },
body: create_person,
},
willRespondWith: {
status: 201,
headers: { 'Content-Type': 'application/json' },
body: create_person_response,
},
});
await provider.executeTest(() => {
return createProfile().then((result) => {
expect(result.status).toBe(201);
expect(result.data).toEqual(create_person_response);
});
});
});
});
describe('Pact test for GET API', () => {
it('should get a profile successfully', async () => {
await provider.addInteraction({
state: 'should get a profile successfully',
uponReceiving: 'A GET Request',
withRequest: {
method: 'GET',
path: '/v2/profile/find',
headers: { 'Content-Type': 'application/json' },
query: {
ids: '10000017',
scope: 'full',
},
},
willRespondWith: {
status: 200,
headers: { 'Content-Type': 'application/json' },
body: get_person_by_id_response,
},
});
await provider.executeTest(() => {
return findProfile().then((result) => {
expect(result.status).toBe(200);
expect(result.data).toEqual(get_person_by_id_response);
});
});
});
});
});
I get below error when i run it
: pact@13.1.0: Test failed for the following reasons:
Mock server failed with the following mismatches:
0) The following request was expected but not received:
Method: GET
Path: /v2/profile/find
Query String: ids=10000017&scope=full
FAIL consumer/profile.poc.test.js
Contract test for Profile
Pact with Profile API
✓ should create contract for POST API (63 ms)
Pact test for GET API
✕ should get a profile successfully (64 ms)
● Contract test for Profile › Pact test for GET API › should get a profile successfully
read ECONNRESET
at Function.Object.<anonymous>.AxiosError.from (node_modules/axios/lib/core/AxiosError.js:89:14)
at RedirectableRequest.handleRequestError (node_modules/axios/lib/adapters/http.js:610:25)
at ClientRequest.eventHandlers.<computed> (node_modules/follow-redirects/index.js:38:24)
at Axios.request (node_modules/axios/lib/core/Axios.js:45:41)
Cause:
read ECONNRESET
Harry
07/09/2024, 11:11 AMChaitanya Sreenivas
07/10/2024, 11:28 AMAlan Boshier
07/10/2024, 3:30 PM@pact-foundation/pact
has reached version 13.x; is there a doc somewhere that outlines differences between 12 and 13 and what (if any) manual steps need to be taken in consumers and providers?Tom Linford
07/18/2024, 5:26 PMnew Verifier(opts).verifyProvider()
[17:16:10.532] DEBUG (8): pact-core@15.1.0: binding path #0: : attempting to load native module from:
- /prebuilds/linux-x64
source: pact-js-core binding lookup
- You can override via PACT_PREBUILD_LOCATION
[17:16:10.590] DEBUG (8): pact-core@15.1.0: binding path #1: : attempting to load native module from:
- /var/task/prebuilds/linux-x64
source: pact-js-core binding lookup
- You can override via PACT_PREBUILD_LOCATION
[17:16:10.591] DEBUG (8): pact-core@15.1.0: Supported platforms are:
- darwin-arm64
- darwin-x64
- linux-arm64
- linux-x64
- win32-x64
[17:16:10.592] ERROR (8): pact-core@15.1.0: Failed to find native module for linux-x64: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')
[17:16:10.592] DEBUG (8): pact-core@15.1.0: We looked for a supported build in this location /prebuilds/linux-x64
[17:16:10.592] DEBUG (8): pact-core@15.1.0: We looked for a supported build in this location /var/task/prebuilds/linux-x64
[17:16:10.593] DEBUG (8): pact-core@15.1.0: Tip: check there is a prebuild for linux-x64
Julie Laursen
07/18/2024, 10:36 PM