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

    sasank kumar

    12/25/2022, 2:48 AM
    Merry Christmas
    xmas party kirby 1
    ❤️ 2
    t
    • 2
    • 2
  • a

    Anthony Bennett

    12/27/2022, 8:20 PM
    Hey all! Is there anyone doing code coverage with the consumer tests? I'm trying to get 100% coverage on all of our API calls to providers making sure there is an interaction in a test per API call in our code. If it's possible, what does that setup look like a test runner Jest for reporting coverage? We're running our consumer tests separately from our unit tests. Thanks again!
    t
    • 2
    • 30
  • p

    Paweł Szczerbicki

    12/29/2022, 1:28 PM
    Hi Team ! I’m using Pact on my NodeJs project. My project is generating
    dist
    folder on GithubActions CI, and also Pack JSON files on
    pact
    folder. How do you share those JSON files between repositories in Github ? You are using releases or some other method ?
    t
    y
    • 3
    • 15
  • w

    Will Herring

    01/05/2023, 11:18 AM
    Hey all, I’m trying to do a timestamp matcher, and my timestamp looks like
    2023-01-05T10:38:01.611240928Z
    , and the pact-js docs require a format string to match against in java simple date format. I’m currently using the format string
    yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
    Where I believe SSS is just meant to represent milliseconds in general. However this returns an error from the verifier that reads
    Error(Nom("171690Z", Tag))
    . If I update the format string to include 9 S’s, to represent the amount of milliseconds we return in the response, I then get the error
    Error(InvalidMillisecond("294910091"))
    . Does anyone have any idea how I could alter my format string to get it working? To add, it seems like java SimpleDateTime doesn’t handle nanoseconds, so I’m wondering if my next best solution is to just write a regex for it instead.
    t
    • 2
    • 7
  • é

    Édouard Lopez

    01/09/2023, 11:45 AM
    I see that when working with JS, one can publish using the pact-core package. Is it something that you recommend or should we prefer Pact CLI ?
    m
    • 2
    • 1
  • c

    Chris Aguirre

    01/09/2023, 6:43 PM
    Hi, I am a Developer who also would like to introduce contract testing to my team/company. I am not able to successfully install pact via NPM on an Amazon Ec2 instance with CentOS Linux 7. I get many errors related to 'g++' not found (gyp errors), and even after installing a c++ compiler, still have errors related to it. On the other hand, on a physical MAC laptop I have no issues at all installing Pact via NPM. Anyone here ever installed PACT on a bare bones Linux machine and got it working?
    m
    m
    • 3
    • 4
  • a

    Abhishek

    01/10/2023, 12:09 AM
    Hello Team , Short question:- To verify WithMessageInteractions on provider side Do we need to run the provider application locally or for messaging pact its not mandatory?
    t
    • 2
    • 7
  • r

    Robin Smit

    01/12/2023, 1:08 PM
    Hi there, I am a developer implementing contract testing within an organization. I have successfully implemented it in java backend services and I am now implementing it in a consuming frontend application. The test framework used in that application is Karma/Jasmine. While I was implementing PactJS in the application, I learned that Karma support for PactJS and newer Karma versions has stopped. So I have switched to using Jest for Pact contract tests. Now my question: It seems that using both Jest and Jasmine/Karma in one Angular project is causing type conflicts. The frontend developers don't have the best experience with Jest and don't want to switch to Jest for all tests. So what to do? Is there a workaround to use PactJS with newer Karma versions? Or does anyone have experience with using both Jest and Jasmine in one project?
    a
    t
    • 3
    • 9
  • a

    Aron L.

    01/13/2023, 2:26 AM
    silly question, looking at the pact-io library examples, i see
    v3
    and
    v4
    folders - what are versions 3 and 4? and if im just starting out, should i be looking at those examples or can i safely use the examples in
    jest
    ?
    v
    m
    t
    • 4
    • 4
  • é

    Édouard Lopez

    01/16/2023, 11:39 AM
    Hello, do you have a TypeScript example of a provider verification test? I'm have trouble defining the
    stateHandlers
    map. The following:
    Copy code
    import { …, StateHandlers } from '@pact-foundation/pact'
    …
          stateHandlers: {
            'Customers are available': (state, params) => Promise.resolve(),
          } as StateHandlers,
    Give this error
    Copy code
    Type 'StateHandlers' is not assignable to type 'StateHandlers & StateHandlers'.
      Type 'import("/workspaces/ms.pact-provider-example-for-typescript/node_modules/@pact-foundation/pact/src/dsl/message").StateHandlers' is not assignable to type 'import("/workspaces/ms.pact-provider-example-for-typescript/node_modules/@pact-foundation/pact/src/dsl/verifier/proxy/types").StateHandlers'.
        'string' index signatures are incompatible.
          Type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>' is not assignable to type 'StateHandler'.
            Type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>' is not assignable to type 'StateFunc'.
              Types of parameters 'state' and 'parameters' are incompatible.
                Type 'AnyJson | undefined' is not assignable to type 'string'.
                  Type 'undefined' is not assignable to type 'string'.ts(2322)
    types.d.ts(42, 5): The expected type comes from property 'stateHandlers' which is declared here on type 'VerifierOptions'
  • m

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

    01/16/2023, 11:57 AM
    The type defs are here: https://github.com/pact-foundation/pact-js/blob/a20ad8038dc560168da20d4a22cd65381d93af26/src/dsl/verifier/proxy/types.ts#L12-L44
  • m

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

    01/16/2023, 11:58 AM
    state
    is not a property in
    StateFunc
    or
    StateFuncWithSetup
    . The state is the key to the function. so:
    Copy code
    stateHandlers: {
            'Customers are available': (params) => Promise.resolve(),
          } as StateHandlers,
    Should work. If you don’t need the params, that’s optional also
    é
    t
    • 3
    • 87
  • a

    amanda stecz

    01/16/2023, 9:51 PM
    What's wrong? I can't run my tests, because can't find pact module.
    t
    • 2
    • 94
  • y

    Yair Shkedi

    01/18/2023, 10:22 AM
    I wrote a simple msg contract test like in the example. when I upgrade pact to 10.* version, the test doesn’t finish. running on mac with node 16, and the framework testing is mocha. when I downgrade the pact version to 9.18.1 the test finish succesfully. test:
    Copy code
    import { Matchers, MessageConsumerPact, asynchronousBodyHandler } from '@pact-foundation/pact';
    
    import { work } from '../../../../../src/amqp/port/update-ds-risk-tag.port';
    import * as dsRiskTagsUpdaterService from '../../../../../src/services/risk/tag/ds/ds-risk-tags-updater.service';
    const { like } = Matchers;
    import * as sinon from 'sinon';
    
    const path = require('path');
    
    describe('"orchestrator - data-catalog" - Msg Contract Test', () => {
      const messagePact = new MessageConsumerPact({
        consumer: 'orchestrator',
        dir: path.resolve(process.cwd(), 'test/unit-tests/contractTests/pacts'),
        log: path.resolve(process.cwd(), 'test/unit-tests/contractTests/logs', 'orch-data-catalog-msg-pact.log'),
        provider: 'data-catalog-msg',
        logLevel: 'info',
      });
    
      let sandbox;
    
      before(function () {
        sandbox = sinon.createSandbox();
        sandbox.stub(dsRiskTagsUpdaterService, 'updateDsRiskTags').resolves();
      });
    
      after(function () {
        sandbox.restore();
      });
    
      it('accepts an update of data source risk tags', () => {
        return messagePact
          .expectsToReceive('a product event update')
          .withContent({
            dsName: like('data source name'),
          })
          .withMetadata({
            'content-type': 'application/json',
            topic: 'catalog.object.update.ds.risk.object.routingKey',
          })
          .verify(asynchronousBodyHandler(work));
      });
    });
    I want to upgrade to get new features, but it blocks me to upgrade.
    t
    • 2
    • 27
  • é

    Édouard Lopez

    01/18/2023, 4:16 PM
    Hello, I got some kind of dump of the contract when I run my provider verification. How can I disable this? (below is the end of it)
    Copy code
    …
    : RuleList { rules: [MinType(2)], rule_logic: And, cascaded: false }, DocPath { path_tokens: [Root, Field("customer")], expr: "$.customer" }: RuleList { rules: [Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")], rule_logic: And, cascaded: false }, DocPath { path_tokens: [Root, Field("orders"), StarIndex, Field("quantity")], expr: "$.orders[*].quantity" }: RuleList { rules: [Integer, Integer], rule_logic: And, cascaded: false }, DocPath { path_tokens: [Root, Field("orders"), StarIndex, Field("id")], expr: "$.orders[*].id" }: RuleList { rules: [Type, Type], rule_logic: And, cascaded: false }} }} }, generators: Generators { categories: {} } } }], metadata: {"pact-js": {"version": "10.4.0"}, "pactRust": {"ffi": "0.3.19", "models": "1.0.3"}, "pactSpecification": {"version": "3.0.0"}}, specification_version: V3 } options=VerificationOptions { request_filter: None, disable_ssl_verification: false, request_timeout: 30000, custom_headers: {}, coloured_output: true, no_pacts_is_error: true } provider_state_executor=HttpRequestProviderStateExecutor { state_change_url: Some("<http://127.0.0.1:38441/_pactSetup>"), state_change_teardown: true, state_change_body: true, reties: 3 }}: pact_verifier: Running teardown provider state change handler 'Customers orders are available' for 'A request for API customer-orders'
    2023-01-18T16:11:19.194467Z  WARN ThreadId(09) pact_matching::metrics: 
    
    Please note:
    We are tracking events anonymously to gather important usage statistics like Pact version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.
    p
    t
    m
    • 4
    • 3
  • p

    Paul Hill

    01/18/2023, 5:02 PM
    Hey all, I'm running my provider verification tests and getting some failures. I'd really like to be able to see the response body for those failures, is there a way to do that? I'm thinking the requestFilter on the response stage would be the place to grab it. Wondering if anyone had any thoughts?
    t
    • 2
    • 6
  • r

    Robin Smit

    01/20/2023, 1:59 PM
    Hi all, I'm having some issues in our CI migrating 9.x.x to 10.x.x. I've searched the internet for the whole day, but I haven't found one post on this same issue. Can someone please assist me or point me in the right direction?
    Copy code
    npm ERR! code 1
    npm ERR! path /builds/x/x/node_modules/@pact-foundation/pact-core
    npm ERR! command failed
    npm ERR! command sh -c -- node-gyp rebuild
    npm ERR! gyp info it worked if it ends with ok
    npm ERR! gyp info using node-gyp@9.1.0
    npm ERR! gyp info using node@18.8.0 | linux | x64
    npm ERR! gyp info find Python using Python version 3.9.2 found at "/usr/bin/python3"
    npm ERR! gyp http GET <https://nodejs.org/download/release/v18.8.0/node-v18.8.0-headers.tar.gz>
    npm ERR! gyp WARN install got an error, rolling back install
    npm ERR! gyp ERR! configure error 
    npm ERR! gyp ERR! stack FetchError: request to <https://nodejs.org/download/release/v18.8.0/node-v18.8.0-headers.tar.gz> failed, reason: connect ETIMEDOUT x:443
    npm ERR! gyp ERR! stack     at ClientRequest.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/minipass-fetch/lib/index.js:130:14)
    npm ERR! gyp ERR! stack     at ClientRequest.emit (node:events:513:28)
    npm ERR! gyp ERR! stack     at TLSSocket.socketErrorListener (node:_http_client:494:9)
    npm ERR! gyp ERR! stack     at TLSSocket.emit (node:events:525:35)
    npm ERR! gyp ERR! stack     at emitErrorNT (node:internal/streams/destroy:151:8)
    npm ERR! gyp ERR! stack     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    npm ERR! gyp ERR! stack     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
    npm ERR! gyp ERR! System Linux 5.4.0-135-generic
    npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
    npm ERR! gyp ERR! cwd /builds/x/x/node_modules/@pact-foundation/pact-core
    npm ERR! gyp ERR! node -v v18.8.0
    npm ERR! gyp ERR! node-gyp -v v9.1.0
    npm ERR! gyp ERR! not ok
    y
    m
    • 3
    • 2
  • p

    Paul Hill

    01/24/2023, 4:05 PM
    Afternoon! Working on provider verification tests and in some environments it's possible the test would be run multiple times. I'd like to clean up any data that's created Seems the easiest approach is to inspect the response body to get the record ID's that have been created and clean them up in an afterAll() method. Would the requestFilter be the place to do this and, if so, is there a way to know if the function is being run in the context of the request or response stages? Seems like the same function is run for both thinking
    ❤️ 1
    t
    m
    • 3
    • 31
  • i

    Ivan Mikhalka

    01/26/2023, 2:29 PM
    Hi, all. Does order of fields in response body matters when executing pact verification? Today I faced with strange issue for the first time: looks like pact-js expecting that fields in json object will be in alphabetical order. For example, I compose my response body expectation, as it comes from API:
    willRespondWith: {
    ……
    objectN: {
    fieldC: "valueC",
    fieldA: "valueA",
    fieldB: "valueB"
    }
    ……
    }
    When contract file generated, it appears be sorted in alphabetical order in contract file:
    response: {
    ……
    objectN: {
    fieldA: "valueA",
    fieldB: "valueB",
    fieldC: "valueC"
    }
    ……
    }
    When verifying provider, it fails on verification of
    objectN
    . I cannot find any mismatches, except order of fields in
    objectN
    . Could someone help and explain me this? For example, if I want generated response body fields to be in same order as I defined? One of the latest versions of
    @pact_foundation_greet/pact
    in use (
    "@pact-foundation/pact": "^10.4.1"
    in
    package.json
    ).
    m
    t
    • 3
    • 9
  • d

    Dmitry Munda

    01/26/2023, 3:16 PM
    hi! pact-js v 10.4
    Copy code
    includeWipPactsSince: isCI ? new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split("T")[0] : undefined,
    throws
    TypeError: includeWipPactsSince
    doesnt work properly in non-CI env, with any of undefined/null/“” any ideas ?
    t
    • 2
    • 13
  • c

    Carere

    01/29/2023, 3:48 PM
    Hello all, I'm back on pact since I develop an app with a front end in JS and a backend in Rust. Last time I used Pact, it was the 9.x version. Today I'm on the 10.x version, but I don't see any JS script that I can run like before (eg.
    pact-broker
    ) Is there a way to launch
    can-i-deploy
    and
    publish
    pact task with npm / yarn / pnpm nowadays ?? Or do I need to go with another (or a better) option ??
    t
    y
    • 3
    • 22
  • c

    Carere

    01/30/2023, 3:25 PM
    Hello again 👋 I see that I can use the
    PactV4
    when writing consumer test, should I use it ? Or should I stick to
    PactV3
    ?
    m
    • 2
    • 1
  • c

    Carere

    01/30/2023, 6:15 PM
    Hey again, I have a question about using MatchersV3 in the Query when defining the interaction. As you can see, I wan to force the query to use an integer for the multiplier key, but I cannot use a Matcher different from
    Matcher<string>
    wen defining the form of the query. Did I miss something ?
    interaction.ts
    m
    • 2
    • 2
  • c

    chiara pascucci

    01/31/2023, 9:44 AM
    Hey all 🙂 very new to Pact but really loving it so far - I am using it to the test the relation between an Express front end app and a Java backend. I have encountered a bit of a blocker when trying to run the consumer (express app) tests inside a Docker container, using Node 16 Debian based image, as the test time out. They run fine locally - I am thinking it is something wrong with how I set up the image, so I was wondering if there is anyone out here that has successfully run pact consumer tests in a Docker container with Node16 and would be willing to share how they set up their Dockerfile / or any tips? docker nodejs thanks
    👋 2
    m
    • 2
    • 4
  • h

    Harry

    01/31/2023, 10:11 AM
    I have a query - if we have a new Pact published by consumer, where can-i-deploy for consumer fails for QA and Prod environments since Provider is not yet upgraded on QA and Prod. Then if we modify Provider to support new Pact published by consumer and found verification fails for QA and Prod environments and hence the can-i-deploy for provider also fails for QA and Prod environments, then how the applications will get upgraded since both consumer & provider deploy pipelines will fail at their end?
    y
    • 2
    • 3
  • s

    SSh

    01/31/2023, 12:27 PM
    Hi. Is there an example somewhere where MessageConsumerPact is using withContent with matchers from v3 package? this example compiled without errors
    Copy code
    import {MessageConsumerPact, synchronousBodyHandler} from "@pact-foundation/pact"
    import {uuid} from "@pact-foundation/pact/src/dsl/matchers"
    
    it("uuid", async () => {
        return new MessageConsumerPact({
            consumer: "consumer",
            provider: "provider",
        })
            .expectsToReceive("uuid")
            .withContent({
                uuid: uuid("cc85f093-abe3-48d8-b187-32439d5b763e"),
            })
            .verify(synchronousBodyHandler(async () => new Promise((resolve) => {
                resolve("OK")
            })))
    })
    but this (use uuid from v3 package)
    Copy code
    import {MessageConsumerPact, synchronousBodyHandler} from "@pact-foundation/pact"
    import {uuid} from "@pact-foundation/pact/src/v3/matchers"
    
    it("uuid", async () => {
        return new MessageConsumerPact({
            consumer: "consumer",
            provider: "provider",
        })
            .expectsToReceive("uuid")
            .withContent({
                uuid: uuid("cc85f093-abe3-48d8-b187-32439d5b763e"),
            })
            .verify(synchronousBodyHandler(async () => new Promise((resolve) => {
                resolve("OK")
            })))
    })
    throw error like this
    Copy code
    TS2345: Argument of type '{ uuid: RegexMatcher; }' is not assignable to parameter of type 'AnyTemplate'.   Types of property 'uuid' are incompatible.     Type 'RegexMatcher' is not assignable to type 'string | number | boolean | JsonArray | JsonMap | Matcher<AnyTemplate> | ArrayMatcher<AnyTemplate> | TemplateMap | ArrayTemplate'.       Type 'RegexMatcher' is not assignable to type 'TemplateMap'.         Index signature for type 'string' is missing in type 'RegexMatcher'.
    m
    t
    • 3
    • 13
  • a

    amanda stecz

    01/31/2023, 7:29 PM
    I tried to fail my contract test, changing the schema from "string" to "boolean", but I received a timeout. Do you know why?
    m
    t
    • 3
    • 4
  • s

    sasank kumar

    02/01/2023, 1:24 AM
    Anyone using playwright?
  • s

    sasank kumar

    02/01/2023, 4:54 AM
    On running tests all are running a successfully and getting pass but contract file generating for only 1 or 2 requests not for all
    m
    • 2
    • 6
  • s

    Sushant Soni

    02/07/2023, 1:07 PM
    Hello, I wanted to know if there is a conclusion on this issue?
    t
    • 2
    • 2
1...1011121314Latest