https://pact.io logo
Join SlackCommunities
Powered by
# pact-js
  • s

    slackk0t0

    10/26/2022, 1:14 AM
    Hi @channel, Is there a way I can install pact without having to install Visual Studio? I get error as attached. I also tried to install node-gyp but I get the same error.
    Untitled.txt
    m
    t
    +2
    • 5
    • 39
  • s

    Sushant Soni

    10/27/2022, 10:27 AM
    Hello We are in the middle of upgrade to V3 spec for one of the consumer written in TypeScript. When the pact file is generates, I see this warning, which is really conufsing
    Copy code
    WARN ThreadId(02) pact_models::pact: Note: Existing pact is an older specification version (V3), and will be upgraded
    The existing spec is V2 and we are migrating to V3. How come V3 is older? or is there an issue here actually?
    m
    • 2
    • 1
  • v

    Victor Zviaruha

    10/27/2022, 12:02 PM
    Hi I'm having trouble with Pact mock server - it looks to be configured as in the manual, but from logs it looks like it starts and then shuts down:
    Copy code
    [09:38:07] :	 [Step 1/1] 2022-10-27T09:38:07.687602Z DEBUG ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 2 } addr_str=0x7ffceb12faf0 tls=false}: pact_mock_server::mock_server: Started mock server on 127.0.0.1:34851
    [09:38:07] :	 [Step 1/1] 2022-10-27T09:38:07.692042Z DEBUG ThreadId(01) pact_matching::metrics: Could not get the tokio runtime, will not send metrics - there is no reactor running, must be called from the context of a Tokio 1.x runtime
    [09:38:07] :	 [Step 1/1] 2022-10-27T09:38:07.692066Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID 669f159b-22ac-4e8d-b0c6-378f489ba070 - MockServerMetrics { requests: 0 }
    [09:38:07] :	 [Step 1/1] 2022-10-27T09:38:07.692087Z DEBUG ThreadId(01) pact_mock_server::mock_server: Mock server 669f159b-22ac-4e8d-b0c6-378f489ba070 shutdown - MockServerMetrics { requests: 0 }
    [09:38:07] :	 [Step 1/1] 2022-10-27T09:38:07.692105Z DEBUG tokio-runtime-worker hyper::server::shutdown: signal received, starting graceful shutdown
    Attached is test code (I've removed some tests for readability as they have same logic) and build logs. Could you please help with this?
    test_-_Database_Service_UI_Publish_Pacts_20.logtest.ts
    y
    • 2
    • 7
  • m

    Michael Laird

    10/27/2022, 2:40 PM
    Hi - are there any known issues with Pact and GitLab CI/CD? My pipeline fails with the below error when running
    yarn install
    on GitLab but having no issues locally.
    error ../node_modules/@pact-foundation/pact-core: Command failed.
    👋 1
    m
    t
    • 3
    • 6
  • i

    Ian Christopher Oroceo

    10/28/2022, 8:49 PM
    hello, I have dumb question, is there a way to ignore specific objects during provider verification or a matching for an array that ignores whatever is inside and just verify that there's an array (I might have misunderstood something in the documentation). Here's a snippet of a sample response... the first question, I wanted to ignore
    ignoreMe
    from verification if possible. If there's none, the second question of matching, the data in object
    ignoreMe
    are generated based on what's available data. TIA for answering the question of a QA :D
    lostInArray.json
    m
    • 2
    • 5
  • b

    Benjamin Chalich

    10/28/2022, 9:18 PM
    hello … i’ve been integrating pact into our testing and seems like examples use both Pact and PactV3? Am i ahead of the curve with V3?
    m
    • 2
    • 1
  • b

    Benjamin Chalich

    10/28/2022, 9:42 PM
    So my consumer uses 3 api endpoint from 2 services. If I follow the V3 setup i have 2 pact providers setup for each api. Is there a v3 equivalent to provider.setup() as opposed to having to nest provider.executeTest calls?
    m
    • 2
    • 1
  • s

    slackk0t0

    10/31/2022, 4:58 AM
    Hi @channel, Do you know how I can enable pact to give more details on the error message? When verification fails on the provider testing part, there's not much to go on based on the msg. I have tried logLevels "debug", "trace" and "info" but the same insufficient message is returned. Does not give me enough to workout what the problem is and what to fix. Thanks for the time.
    Copy code
    [2022-10-24 06:22:29.452 +0000] ERROR (33504 on xxxxxxx): pact-core@13.10.0: Verification unsuccessful
    [2022-10-24 06:22:29.452 +0000] TRACE (33504 on xxxxxxx): pact@10.1.4: Verification failed(Verfication failed), closing server
    Pact verification failed :( Error: Verfication failed
        at C:\Users\d832076\Desktop\Workspace\pact-sample-test\node_modules\@pact-foundation\pact-core\src\verifier\nativeVerifier.ts:50:20
    Followed @Yousaf Nabi (pactflow.io)’s scripts here https://github.com/YOU54F/pact-playwright-example
    m
    • 2
    • 2
  • s

    Stefan Tertan

    11/01/2022, 3:04 PM
    Hi, I have the following setup: •
    PortalUI
    (react app; pact consumer) - publishes a pact for HTTP interactions to Pactflow •
    ProfileService
    (expressjs api; pact provider) - publishes OpenAPI (& Dredd results) to Pactflow •
    CardService
    (expressjs api; pact provider) -- publishes messages to Kafka •
    AuditService
    (kafkajs consumer; pact consumer) - publishes a pact for message interactions to Pactflow The issue that I am facing is with running builds for
    CardService
    , where it needs to verify the pacts for its consumers (both http & async): •
    PortalUI
    (http) •
    AuditService
    (async) I need to use different verifiers:
    Verifier
    vs
    MessageProviderPact
    (from
    @pact-foundation/pact
    ). I wrote different test suites (with one test each) to accommodate for that:
    Copy code
    describe('Pact Verification - Regular build - one or more pacts', () => {
      const HTTPConsumers = ['PortalUI'];
      const AsyncConsumers = ['AuditService'];
    
      describe('HTTP Consumers', httpConsumerTests.verifyMultiplePacts(commonEnv, HTTPConsumers));
      describe('Async Consumers', asyncConsumerTests.verifyMultiplePacts(commonEnv, AsyncConsumers));
    });
    The gist of the code for HTTP consumers looks like so:
    Copy code
    const verifyMultiplePacts = (commonEnv, HTTPConsumers) => () => {
        let server;
        beforeEach(() => server = app.listen(PROVIDER_HTTP_API_PORT));  // Create server
        afterEach((done) => server.close(done));                        // Shutdown provider server (Express)
    
        it('validates the expectations of CardService', async () => {
            const consumerVersionSelectors = [
                ...HTTPConsumers.map((consumer) => ([
                    // check compatibility with the latest changes that the consumer has made
                    {consumer, mainBranch: true},
                    // check backwards compatibility with existing deployed (staging/prod) versions of the consumer
                    {consumer, deployedOrReleased: true},
                ])),
            ].flat();
            console.log('consumerVersionSelectors (pacts to verify)', consumerVersionSelectors);
    
            // Initialize the Pact verifier
            const verifier = new Verifier({
                ...commonVerifierConfig(commonEnv),
    
                // For 'normal' provider builds (the provider changed), fetch pacts for this provider, to verify them
                provider: commonEnv.PROVIDER,
                pactBrokerUrl: process.env.PACT_BROKER_BASE_URL,
                pactBrokerToken: process.env.PACT_BROKER_TOKEN,
                // Specify which pacts to verify
                consumerVersionSelectors,
                // Pending pacts are a way for the provider to ensure a consumer won't break the build (of the provider).
                // See <https://www.youtube.com/watch?v=VnOy9Sv9Opo>
                // NOTE: the pending calculation is based on the tag for the provider version
                enablePending: true,
                // WIP pacts build on top of pending pacts, and are a way for the consumer to get quick feedback
                // on a new pact (on a feature branch), without requiring the provider to update their configuration
                // (by adding the new pact in the list of pacts that need to be verified).
                includeWipPactsSince: '2020-01-01',
            });
    
            // Verify pacts
            const output = await verifier.verifyProvider();
            console.log(output);
        });
    }
    consumerVersionSelectors
    resolves to:
    Copy code
    console.log
        consumerVersionSelectors (pacts to verify) [
          { consumer: 'PortalUI', mainBranch: true },
          { consumer: 'PortalUI', deployedOrReleased: true }
        ]
    The problem is with pending & WIP pacts: although
    consumerVersionSelectors
    only targets
    PortalUI
    via
    consumer
    field, pending & wip pacts also fetch pacts for
    AuditService
    . Because the fn uses
    Verifier
    and pacts for
    AuditService
    need to be verified using
    MessageProviderPact
    , the test fails. Do you have a working example anywhere of how to deal with a producer that needs to verify both HTTP interactions (pacts) and async (Kafka, etc)?
    👋 1
    m
    • 2
    • 2
  • s

    Slackbot

    11/02/2022, 3:58 PM
    This message was deleted.
    i
    • 2
    • 1
  • s

    Stefan Tertan

    11/02/2022, 5:04 PM
    Hi, I have the following code to generate a message consumer pact:
    Copy code
    const path = require('path');
    const {
        MatchersV3: {like, regex},
        MessageConsumerPact,
        SpecificationVersion,
        asynchronousBodyHandler,
    } = require('@pact-foundation/pact');
    
    const {KAFKA_TOPIC, streamHandler} = require('../kafka/consumer');
    
    
    const messagePact = new MessageConsumerPact({
        consumer: process.env.CONSUMER || 'AuditService',
        provider: 'CardService_Async',
        logLevel: 'warn',
        dir: path.resolve(process.cwd(), 'pacts'),
        spec: SpecificationVersion.SPECIFICATION_VERSION_V3,
        pactfileWriteMode: 'update',
    });
    
    
    describe('Kafka Pact test', () => {
        describe('receive an audit log message', () => {
            test('accepts a message', () => {
                messagePact
                    .expectsToReceive('a message event update')
                    .withMetadata({
                        'content-type': 'application/json',
                        'x-kafka-topic': KAFKA_TOPIC,
                    })
                    .withContent({
                        viewer: like('John Doe'),
                        card: {
                            id: like('08'),
                            type: regex(/^(CREDIT_CARD|PERSONAL_LOAN)$/, 'CREDIT_CARD'),
                            name: like('MyFlexiPay'),
                            version: like('v1'),
                        },
                    })
                    .verify(asynchronousBodyHandler(({content}) => streamHandler(content)));
            });
        });
    });
    And the following verification code:
    Copy code
    const commonVerifierConfig = (commonEnv) => {
        return {
            logLevel: 'warn',
            providerVersion: commonEnv.GIT_COMMIT_SHA,
            providerVersionBranch: commonEnv.GIT_BRANCH,
            publishVerificationResult: commonEnv.PUBLISH_VERIFICATION_RESULTS,
    
            // Similar to state handlers?
            messageProviders: {
                'a message event update': () => JSON.parse(buildMessage(
                    'John Doe',
                    {id: '08', type: 'CREDIT_CARD', name: 'MyFlexiPay', version: 'v1'},
                ).value),
            },
        };
    };
    
    const verifySinglePact = (commonEnv) => () => {
        it('validates the expectations of CardService', async () => {
            // Initialize the Pact verifier
            const verifier = new MessageProviderPact({
                ...commonVerifierConfig(commonEnv),
                pactUrls: [process.env.PACT_URL],
            });
    
            // Verify pacts
            const output = await verifier.verify();
            console.log(output);
        });
    };
    with
    buildMessage
    being:
    Copy code
    const buildMessage = (viewer, card) => ({
        value: JSON.stringify({viewer, card}),
        headers: {
            'content-type': 'application/json',
            'x-kafka-topic': KAFKA_TOPIC,
        },
    });
    The validation for the message body passes, but the one for the message metadata fails. I have attached the generated contract.
    AuditService-CardService_Async.json
    m
    • 2
    • 7
  • v

    Victor Zviaruha

    11/03/2022, 5:13 PM
    Hi we had contract tests implemented for one of our services. but because of some issues we had to downgrade from pact 10.* to pact 9.* As a part of this downgrade, we had to switch our test to using pact v2 instead of v3 - but as result, our tests on consumer side started to fail randomly. Please find attached full test class. Maybe you have any ideas why it happens? Thank you in advance!
    DatabaseServiceContractTest.ts
    m
    t
    • 3
    • 16
  • s

    Stefan Tertan

    11/04/2022, 2:22 PM
    Hi, I'm doing bi-directional contract testing between
    PortalUI
    &
    ProfileService
    . I have the OpenAPI specification for
    PortalService
    , which includes the following endpoints: • GET /profiles - return 200 or 401 • GET /profiles/{id} - return 200 or 400 or 404 or 401 They are both set to use JWT authentication. For the consumer contract, I'm running the tests shown in the screenshot (I have also attached the generated pact). On contract comparison, I get a few errors. For both endpoints I get one about
    Request Authorization header is missing but is required by spec file
    . It is true that the Authorization header is required, but I also want to ensure not specifying it returns a 401. This example on StackOverflow shows how to make security optional in the OpenAPI spec, but that might lead to the API implementation lacking proper security of endpoints (and a tool such as Dredd would likely not catch that, since the spec says it's optional). Any idea how to deal with this issue? For
    get /profiles
    I get additional
    Response Body is Incompatible
    errors: • Response body is incompatible with the response body schema in the spec file: should be array • Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - content • Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - contentType • Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - encoded The
    response
    in the contract looks like this:
    Copy code
    "response": {
      "body": {
        "content": [],
        "contentType": "application/json",
        "encoded": false
      },
      "headers": {
        "Content-Type": [
          "application/json; charset=utf-8"
        ]
      },
      "status": 200
    }
    Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - encoded
    Mismatched Pact Path:
    [root].interactions[1].response.body
    Mismatched Provider Path:
    [root].paths./profiles.get.responses.200.content.application/json; charset=utf-8.schema.additionalProperties
    Initially I had
    additionalProperties
    set to
    false
    in the schema for
    Profile
    , but even after removing that, deleting the pacts & re-publishing, it still points to that under `Mismatched Provider Path`:
    Copy code
    Profile:
      type: object
      required:
        - id
        - username
        - picture
      additionalProperties: false
      properties:
        id:
          type: string
        username:
          type: string
        picture:
          type: string
    PortalUI-ProfileService.jsonProfileAPI.oas.yaml
    t
    m
    • 3
    • 9
  • t

    Tatiana

    11/08/2022, 7:02 PM
    Hi All! Could you please review my issue and give me a hint how it can be solved? I am using
    "@pact_foundation/pact": "^10.1.4"
    for my consumer testing. I added consumer tests but I didn’t include tests to CI pipeline, so the consumer tests are not executed in the pipeline yet. However, my
    build
    job is failing in my CI pipeline with errors regarding Python (errors attached in thread).
    build
    job looks like:
    Copy code
    build:
      stage: build
      variables:
        ENV: "localhost"
        NPM_TOKEN: '$CI_JOB_TOKEN'
      before_script:
        - gitlab/configure-npm.sh
        - apk add --update make
      script:
        - make set-environment ENV=$ENV
        - yarn install --frozen-lockfile
        - make build
      artifacts:
        paths:
          - dist
    gitlab/configure-npm.sh
    looks like:
    Copy code
    #!/bin/sh
    
    set -o errexit
    set -x
    
    yarn config set -H npmScopes.codility.npmRegistryServer "<https://gitlab.codility.net/api/v4/projects/519/packages/npm/>"
    yarn config set -H npmScopes.codility.npmAuthToken "${NPM_TOKEN}"
    I use
    gitlab-ci
    , the app uses
    TS
    ,
    React
    ,
    yarn
    . Also, as I can see we don’t use
    docker-compose
    ,
    dockerfile
    in our app. But in CI logs I see:
    Copy code
    Running with gitlab-runner 15.5.0 (0d4137b8)
      on gitlab-runners-manager-spot-c5-
    Resolving secrets
    00:00
    Preparing the "docker+machine" executor
    00:08
    Using Docker executor with image node:16.13.0-alpine ...
    Pulling docker image node:16.13.0-alpine ...
    Using docker image sha256:44e24535dfbf4b7415c16a5828 for node:16.13.0-alpine with digest node@sha256:60ef0bed1dc2ec835cfe3c4 ...
    I suspect that I need to install python3, but I am not sure if I should do it since it’s React app. Please advice 🙏
    m
    • 2
    • 13
  • g

    Gustavo Souza

    11/08/2022, 8:50 PM
    hey everyone! i followed this guide: https://docs.pact.io/implementation_guides/javascript/readme and then as result i'm facing this ERROR:
    Copy code
    [2022-11-08 20:43:00.005 +0000] ERROR (21300 on Ghsouza): pact-core@13.11.0: !!!!!!!!! PACT CRASHED !!!!!!!!!
    
    The pact consumer core returned false at 'withResponseBody'. This
    should only happen if the core methods were invoked out of order
    
    This is almost certainly a bug in pact-js-core. It would be great if you could
    open a bug report at: <https://github.com/pact-foundation/pact-js-core/issues>
    so that we can fix it.
    
    There is additional debugging information above. If you open a bug report,
    please rerun with logLevel: 'debug' set in the VerifierOptions, and include the
    
    SECURITY WARNING: Before including your log in the issue tracker, make sure you
    have removed sensitive info such as login credentials and urls that you don't want
    to share with the world.
    
    We're sorry about this!
    I opened an issue for that: https://github.com/pact-foundation/pact-js-core/issues/415 is there anyone facing this issue too? regards!
  • d

    Dany Marques

    11/09/2022, 1:43 PM
    Hi everyone, Since pact 9.18.0 are our pact tests failing. I deep dived a bit in the topic and the problem is the replacement of Popsicle by Axios. This problem only occurs when a test suite as more than 11 tests. Any idea?
    h
    t
    • 3
    • 3
  • c

    Chris Godsey

    11/10/2022, 9:04 PM
    Hey all - I'm run some validation tests against my provider, and it looks like at the end i'm getting a rust related error thrown?
    Copy code
    2022-11-10T20:49:15.773684Z DEBUG ThreadId(01) verify_interaction{interaction="a request with a country code exactly three characters long"}: pact_matching::json: compare_values: Comparing 'Number(1)' to 'Number(1)' at path '$.totalPages' -> Ok(())
    thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', pact_matching\src\<http://headers.rs:22:45|headers.rs:22:45>
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    t
    m
    • 3
    • 30
  • s

    Sascha

    11/14/2022, 5:34 PM
    👋 Hallo Team! Did anybody manage to install
    @pact-foundation/pact@10.2.2
    which is using
    @pact-foundation/pact-core@13.12.0
    on
    node@16.18.0
    ? For me
    node-gyp
    fails in post-install on my
    m1 mac
    with
    Copy code
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture
    #error Unsupported architecture
     ^
    Interesting is that
    @pact-foundation/pact@9.18.1
    works with
    node@16.18.0
    on
    m1 mac
    .
    t
    m
    • 3
    • 5
  • r

    Ryan Thomas

    11/16/2022, 9:20 PM
    Anyone else encountering node-gyp issues for
    @pact-foundation/pact-core@13.12.0
    on windows when using npm? I have been was running into an interesting bug where the install for that new version fails was failing using
    npm
    but working if I use
    yarn
    on my work laptop (Windows 10). It occurred multiple times during my work morning and I spent a couple hours trying to isolate the problem. After I got back from lunch it stopped occurring. What I was seeing:
    npm install
    with an existing package.json and
    npm install @pact_foundation_greet/pact-core --save-dev
    would both error stating:
    Copy code
    gyp verb command rebuild []
    gyp verb command clean []
    gyp verb clean removing "build" directory
    gyp ERR! clean error
    gyp ERR! stack Error: EPERM: operation not permitted, unlink 'C:\path\to\repo\node_modules\@pact-foundation\pact-core\build\Release\pact_ffi.dll
    I tried with both
    node v18.12.1 + npm 8.19.2
    and
    node v16.16.0 + npm 8.11.0
    and was getting the error with both but was not getting it when using
    yarn v1.22.19
    m
    • 2
    • 6
  • v

    Von Waters

    11/16/2022, 10:48 PM
    Greetings! Apologies if this is the incorrect place to post this question. I am using
    jest-pact@0.10.1
    and
    @pact_foundation/pact@9.18.1
    using the
    new Publisher
    pattern for publishing the pact to pact flow. I am getting this error:
    Copy code
    `consumer_name': undefined method `[]' for nil:NilClass (NoMethodError)
    My pact does indeed have the consumer name in the pact.json
    Copy code
    "consumer": {
        "name": "<MyConsumer>"
      },
      "provider": {
        "name": "<MyProvider>"
      },
    I was hoping someone else might have ran into this issue? I haven’t been able to publish my pact 🙁
    m
    • 2
    • 7
  • d

    Dany Marques

    11/22/2022, 11:52 AM
    Hello! I’m trying to write a Pact test and I get the following error:
    Mismatch with header 'Accept': Expected 'application/problem+json' to match '^(.*application\/problem\+json.*application\/json.*)|(.*application\/json.*application\/problem\+json.*)$'
    . When I log the request who was sent, I see the following:
    "accept": ["application/problem+json", "application/json", "text/plain", "*/*"]
    . So it looks like Pact interprets the Accept header as an array of string and then only compares the first one with the regex instead of comparing them all together. This was working on previous versions of Pact. Any idea?
    m
    • 2
    • 39
  • a

    amanda stecz

    11/22/2022, 7:12 PM
    Hi @Matt (pactflow.io / pact-js / pact-go) and @uglyog Did you apply some fix to this issue? Thank you! https://pact-foundation.slack.com/archives/C9VBGLUM9/p1666746885134759
    👀 1
    f
    m
    • 3
    • 7
  • s

    sasank kumar

    11/23/2022, 10:47 AM
    Can we run tests on live sites and generate pacts?
    m
    y
    • 3
    • 3
  • v

    Victor Zviaruha

    11/25/2022, 1:16 PM
    Hi I cannot get
    like()
    matcher working properly - during pact verification, it still verifies against actual values, not just type Could you please help?
    DatabaseServiceContractTest.ts
    t
    • 2
    • 42
  • s

    sasank kumar

    11/27/2022, 2:35 PM
    Can we compare two contract files using pactflow
  • s

    sasank kumar

    11/27/2022, 2:40 PM
    If yes how to do it
  • t

    Timothy Jones

    11/27/2022, 10:54 PM
    This isn't the pactflow channel
  • t

    Timothy Jones

    11/27/2022, 10:54 PM
    AFAIK, Pact doesn't have a way to do this. I think building it would be a great feature, though. I don't know if pactflow can support it, you'd have to ask them.
  • m

    Matt (pactflow.io / pact-js / pact-go)

    11/28/2022, 12:21 AM
    The Pact Broker (and Pactflow) does have a way to diff two contracts
  • m

    Matt (pactflow.io / pact-js / pact-go)

    11/28/2022, 12:22 AM
    https://docs.pact.io/pact_broker/advanced_topics/see_changes_pact
1...8910...14Latest