Borja Bodoque
09/04/2023, 10:25 AMI have already checked stackoverflow and the documentation. I have also asked chatgpt for some help but I still have a doubt.
Michael Spector
09/05/2023, 2:51 PMMatcherV3.timestamp
?
in the documentation (V3 Matching Rules) it shows that timestamp
can be used without a second argument representing an example.
however, when I try using it without an example, it throws the error you must provide an example timestamp
the code and documentation talk about "generators" - do I need to specify that somehow?
(I'll post a code snippet in thread)Antonio Magana
09/11/2023, 8:49 PMTigran Davtyan
09/12/2023, 3:14 AMAlan Zhu
09/12/2023, 7:13 AMContent-Type": "application/x-protobuf-json-format
but generates some weird represation of expected response string(not a map as application/json
) like `"{"requestId":{"pactmatchertype":"type","value":"2b0124bf-4b7a-4ac7-938c-6021be9cb661"}}"`and fail the provider's verification, is it because of pact-js doesn't support this type of type(application/x-protobuf-json-format
) of content well right now?Romu
09/13/2023, 3:24 PMChaitanya Sreenivas
09/14/2023, 11:26 AM"test:publish": "pact-broker publish /pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=<https://ysi5tc076m.execute-api.eu-west-2.amazonaws.com:443> --broker-username user --broker-password passxx"
Antonio Magana
09/19/2023, 9:45 PMdebug
and am seeing a lot of this error:
[tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35)
as well as
Caught panic with error: failed printing to stderr: Resource temporarily unavailable (os error 35)
It seems like the test is getting about halfway through the matchers before randomly stopping. Unsure if theres a setting I need to change so any advice here would be appreciated.hyun chae
09/20/2023, 1:25 PMtype TestType = {
field1: string | number;
field2: TestType2
}
type TestType2 = "option1" | 'option2'
const testData:TestType = {
field1: 'stringValue',
field2 'option1'
}
const matcher = MatcherV3.like(testData)
Sashi Kandru
09/21/2023, 8:00 PMAbhishek
09/22/2023, 3:36 PMKevin Grady
09/22/2023, 7:12 PMERROR (65379): pact@12.1.0: Test failed for the following reasons:
Mock server failed with the following mismatches:
0) The following request was incorrect:
POST /productentitlements/{exampleID1}/tenants/{exampleID2}
After doing some digging into the node_modules pact files we were able to console.log out something more helpful:
console.log
mismatches: [
{
actual: '',
expected: 'application/x.avidxchange.productentitlements+json;version=1.0.0',
key: 'Content-Type',
mismatch: "Mismatch with header 'Content-Type': Expected value 'application/x.avidxchange.productentitlements+json;version=1.0.0' at index 1 but was missing (actual has 1 value(s))",
type: 'HeaderMismatch'
}
]
at generateMockServerError (../../../node_modules/@pact-foundation/src/v3/display.ts:135:3)
This implies that our Content-Type is somehow being removed at some point after the test is run. Has anyone seen an issue like this? We tried following the path the headers take through the compiled pact code but were unable to find a place where the Content-Type was removed.
One thing to note is that same header is being passed with all requests, including the GETs which are passing. It seems to be something related to requests that contained a body, but I don’t have any evidence to say that’s what it is beyond correlation.Dmitrii Izmirov
10/02/2023, 10:38 AMNikesh Nagpal
10/13/2023, 11:01 AMnpx pact-broker create-or-update-pacticipant --broker-base-url=$PACT_BROKER_URL --broker-username=$PACT_BROKER_USER --broker-password=$PACT_BROKER_PSWD --name=Foo --main-branch=$CURRENT_BRANCH_NAME
2. npx pact-broker publish "./pacts/" --broker-base-url=$PACT_BROKER_URL --broker-username=$PACT_BROKER_USER --broker-password=$PACT_BROKER_PSWD --consumer-app-version=$GIT_COMMIT_SHA --branch=$CURRENT_BRANCH_NAME
3. npx pact-broker can-i-deploy --broker-base-url=$PACT_BROKER_URL --broker-username=$PACT_BROKER_USER --broker-password=$PACT_BROKER_PSWD --retry-while-unknown=5 --retry-interval=60 --pacticipant=Foo --version=$GIT_COMMIT_SHA --to=nonprod --main-branch --verbose
// this is the code for verifying pact provider
describe('Foo Provider', () => {
test('validates the expectations of API consumers', async () => {
const opts = {
"providerBaseUrl":"<http://localhost:3001/envname>",
"pactBrokerUrl":"<https://my-pact-broker>",
"pactBrokerUsername":"userName",
"pactBrokerPassword":"password",
"provider":"Foo",
"providerVersion": GIT_COMMIT_SHA,
"providerVersionBranch":"pact-testing-branch",
"consumerVersionSelectors":[
{
"mainBranch":true
},
{
"matchingBranch":true
}
],
"publishVerificationResult":true,
}
await new Verifier(opts).verifyProvider().then((output) => {
console.log(output);
});
});
});
package.json
"devDependencies": {
"@pact-foundation/pact": "^9.18.1",
"@pact-foundation/pact-node": "^10.17.4"
}
Environment: Mac & Windows
Any help is appreciated :)Harry
10/17/2023, 3:22 PMTony Nguyen
10/17/2023, 5:03 PMOne or more of the teardown state change handlers has failed
Request Failed - One or more of the setup state change handlers has failed
Satish Autade
10/19/2023, 6:10 AMpact-js
like MessageConsumerPact
or asynchronousBodyHandler
, etc.
I am referring to following links:
https://dius.com.au/2017/08/22/contract-testing-serverless-and-asynchronous-applications/
https://dius.com.au/2018/10/01/contract-testing-serverless-and-asynchronous-applications-part-2/
I found one example in Javascript that uses SAM and SNS but its not clear to me what part of the pact test in this repo generates the pact json file. May be I am missing something obvious here.
Would really appreciate if someone can explain how it generates json contract.
Are there any Docs that show how to use MessageConsumerPact with a detailed example?Charlan Bettiol
10/24/2023, 6:49 PMCharlan Bettiol
10/24/2023, 6:49 PM[18:42:36.415] ERROR (121): pact-core@14.0.5: Failed to find native module for linux-x64: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')
FAIL test
● Test suite failed to run
Failed to load native module, try setting LOG_LEVEL=debug for more info
23 |
24 | describe('The Subscription API', () => {
> 25 | const provider = new Pact({
| ^
26 | dir: path.resolve(process.cwd(), 'pacts'),
27 | spec: 2,
Marek Urbanowicz
10/26/2023, 6:30 AMthibault alix
10/26/2023, 6:22 PM{
"_internal": {
"entries": [
{
"data": {
"value": [
"A",
"B",
"C",
"D",
"E"
]
}
}
]
}
}
.willRespondWith(200, (builder) => {
builder
.jsonBody({
_internal: {
entries: [{
data: {
value: arrayContaining("A", "C", "D")
}
}]
}
})
Ruth
10/30/2023, 8:56 PMVictor do Val
11/01/2023, 8:34 PMRenan Santos
11/05/2023, 6:30 PMimport { PactProviderModule, PactProviderOptions } from 'nestjs-pact';
import * as dotenv from 'dotenv';
import {
generateRandomValue,
getCurrentBranch,
getGitDirectoryName
} from '../helper/utils';
export enum ConsumerName {
KK_SHOPPINGCART_SERVICE = 'KK-SHOPPINGCART-SERVICE',
KK_PURCHASE_SERVICE = 'KK-PURCHASE-SERVICE'
}
const DEFAULT_BRANCH = 'master';
const MASTER_WEBHOOK = 'master-webhook';
export const configurePactProvider = (consumer: ConsumerName) => {
dotenv.config({ path: './.env.test' });
const GET_PROVIDER_NAME = getGitDirectoryName();
const GET_RANDOM_VALUE = generateRandomValue();
const consumerWebhookBranch = process.env.CONSUMER_VERSION_TAGS;
const [GET_CURRENT_BRANCH, GET_PROVIDER_BRANCH] = consumerWebhookBranch
? [consumerWebhookBranch, MASTER_WEBHOOK]
: [getCurrentBranch(), getCurrentBranch()];
if (!consumer?.length) {
throw new Error(
'Error: PACT_BROKER_BASE_URL environment variable is not set.'
);
}
const options: PactProviderOptions = {
pactBrokerUrl: String(process.env.PACT_BROKER_BASE_URL),
provider: GET_PROVIDER_NAME,
providerVersion: GET_RANDOM_VALUE,
providerVersionBranch: GET_PROVIDER_BRANCH,
providerVersionTags: [GET_PROVIDER_BRANCH],
logLevel: 'error',
consumerVersionSelectors: [
{
fallbackTag: DEFAULT_BRANCH,
tag: GET_CURRENT_BRANCH,
latest: true,
consumer: consumer
}
],
publishVerificationResult: true
};
return PactProviderModule.register(options);
};
I'm currently using the following versions and dependencies:
• Node: 16.14.0
• pact-foundation/pact: 12.1.0
• nestjs-pact: 2.3.1
• jest: 28.1.3
• @types/jest: 29.0.0
• ts-jest: 28.0.8
Any guidance or suggestions would be greatly appreciated!Joel Whalen
11/09/2023, 4:48 PMVerifier
callback don't actually print when there's a failure, so how do I inspect the results?
import { Verifier } from '@pact-foundation/pact'
const { API_URL, PACTFLOW_TOKEN } = process.env
const opts = {
providerBaseUrl: API_URL,
pactBrokerUrl: '<https://my-pactflow.pactflow.io/>',
pactBrokerToken: PACTFLOW_TOKEN,
provider: 'normalizer',
consumerVersionTags: ['v2'],
providerVersionTags: ['v1'],
providerVersionBranch: 'my-branch',
providerVersion: 'v1'
}
console.log(opts)
new Verifier(opts).verifyProvider().then(output => {
console.log('Verify provider function')
console.log(output)
})
Maksym Liannoi
11/14/2023, 12:14 PMjest-pact
adapter) to VitestAnna Lorenzi
11/17/2023, 6:22 PMFROM node:19
RUN apt-get update -y && \
apt-get install -y git g++ python3 build-essential && \
rm -rf /var/lib/apt/lists/*
RUN apt-get install -y bash
CMD ["bash"]
To run this container, I create a volume to acces the react app code from within container:
wsl docker run -it -v /mnt/c/source/my-project:/src my-project-test:my-project-test
After that, I attempt to run tests with Jest inside the container:
jest --testPathPattern "/src/services" --env=jsdom
However, it is not work. With debian and ubuntu the bash stays frozen for hours (see image bellow).
Could someone help me, please?Daniel Phillips
11/21/2023, 11:56 AMarrayContaining
. I can constrain the outer array (rows) however I cannot constrain the inner columns array. (If I use a constainedArrayLike
, this implies that the items
must appear in every single column, which they do not. (See inline comment in code below).
body: constrainedArrayLike(
arrayContaining({ # Cannot constrain here, but must use arrayContaining to allow the below state.structure to appear in at least one of the columns. Using any other constained matcher implies it must appear in all columns
columnAlignment: like('left'),
items: arrayContaining(like(state.structure)),
}),
MIN_ALLOWED_ROWS,
MAX_ALLOWED_ROWS, // At most MAX_ALLOWED_ROWS can be included in the response
),
Aniket Rane
11/22/2023, 3:06 AMnpm i @pact-foundation/pact@11.0.2 --ignore-scripts
or I do something like:
npm config set ignore-scripts false
npm i @pact-foundation/pact@11.0.2
Jawad Sefiani
11/28/2023, 2:21 PMconst formData = new FormData();
formData.append(
'meta',
JSON.stringify({
some_key: "some_value",
}),
);
formData.append('file', createFile());
provider
.given('I have file with more than 1000 values')
.uponReceiving('a request to create a rule using a file with more than 1000 values')
.withRequest({
method: 'POST',
path: '/rules',
body: formData,
headers: {
'Content-Type': 'multipart/form-data',
},
})
.willRespondWith({
status: 201,
body: mockedResponse,
contentType: 'application/json',
});
return provider.executeTest(async (mockServer) => {
<http://axiosInstance.post|axiosInstance.post>("/rules", formData, {
baseURL: mockServer.url,
headers: {
'Content-Type': 'multipart/form-data',
},
})
// some assertion
});
I'm getting the following error:
Mock server failed with the following mismatches:
0) The following request was incorrect:
POST /rules
1.0 Mismatch with header 'Content-Type': Expected value 'multipart/form-data' at index 1 but was missing (actual has 1 value(s))
1.1 Expected a body of 'application/json' but the actual content type was 'multipart/form-data;boundary=--------------------------087154011299288967847178'
Axios adds this annoying boundary value to the content type but Pact doesn't know about this value. How can I solve this?