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

    Gina

    02/10/2023, 12:44 PM
    Hi, I’m using jest-pact to create a consumer pact but unsure how to pass parameters and use the path matcher, if the latter is needed. I have tried using the query property but feel that I shouldn’t need to even specify the query parameter for the generate value. Eg:
    Copy code
    describe('Customers', () => {
          it('returns customer data', async () => {
            const interaction = {
              state: 'Server is healthy',
              uponReceiving: 'Request Person',
              willRespondWith: {
                status: 200,
                body: like(responseData),
              },
              withRequest: {
                method: 'GET',
                path: term({
                  generate: '/some/path?id=1234567',
                  matcher: '/some/path?id=(w{7})',
                }),
              },
            }
    
            await provider.addInteraction(interaction)
    
            await client.getPerson('1234567').then((person) => {
              expect(person).toEqual(responseData)
            })
          })
        })
    Could anyone advise please?
    t
    • 2
    • 8
  • m

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

    02/10/2023, 10:33 PM
    Have you tried using the
    query
    property? Query and path are seperate
    t
    • 2
    • 1
  • c

    Carere

    02/12/2023, 12:15 AM
    hello all 🙂 Just wanna know if it possible to test Server Sent Event with Pact ? If it is, how can I proceed ?
    t
    • 2
    • 1
  • m

    Moid Abdul

    02/13/2023, 12:19 AM
    Hi Members, I need some assistance in setting up PACT on my machine
    👋 1
    m
    s
    • 3
    • 8
  • m

    Moid Abdul

    02/13/2023, 12:19 AM
    can someone please spare few mins to assist me with step by step process
  • m

    Mayank Chugh

    02/17/2023, 7:47 PM
    Hiya folks 👋 I hope you are doing well 🙂 I am looking for some help with my PactJs implementation. Context I am trying to assert if Contract Testing can be used to strengthen Developer Confidence. I have setup PactJs between 2 services as a test candidate. Problem Statement While the local Contract Testing is working fine by sharing the Pact locally between to the Provider, I am having some difficulties with the Pact Broker. I am using PactFlow as the broker. Here is a snippet of how I am setting my
    VerifierOptions
    in my provider test:
    Copy code
    baseOptions = {
    			providerBaseUrl: appUrl,
    			provider: 'SDS',
    			log: path.resolve( process.cwd(), 'logs', 'pact.log' ),
    			// pactUrls: [ path.resolve( __dirname, '../pacts/SDS-Parker.json' ) ],
    			logLevel: 'trace' as LogLevel,
    			
    			// Fetching the pact from broker
    			pactBroker: 'https://<orgName>.<http://pactflow.io|pactflow.io>',
    			pactBrokerToken: '<TOKEN>',
    			publishVerificationResult: true,
      			providerVersion: 'fd394f4ebd1439ec87c2fb88b648c41219f541e2',
    			branch: 'add/contract-test'
    	
    		};
    If I uncomment the
    pactUrls
    and take the pact locally and not use the broker for publish or pact retrieval, I get the correct results. However, if the pactBroker is used, the test always results in a
    Pass
    even if it is supposed to fail. Also, when using the pact broker, the test results do not show the “interaction wise” results. Instead they show the following:
    Copy code
    PASS  test/contract/parker/blog.contract-spec.ts (34.145 s)ifier: @param handle = 0x400b712400
      pact Verification
        ✓ should validate Parker expectations (1191 ms)
    
    Test Suites: 1 passed, 1 total
    Tests:       1 passed, 1 total
    Snapshots:   0 total
    Time:        34.839 s, estimated 51 s
    Ran all test suites.
    Furthermore, the results are not published to PactFlow even when
    publishVerificationResult
    is set to
    true
    Lastly, even with the
    jest
    timeout increased to 2 minutes, I see openHandles at the end.
    Copy code
    [18:27:01.626] TRACE (117): pact@10.4.1: Verification completed, closing server
    
    Jest has detected the following 1 open handle potentially keeping Jest from exiting:
    
      ●  WORKER
    
          70 |
          71 |      it( 'should validate Parker expectations', async () => {
        > 72 |              const verifier = new Verifier( baseOptions );
             |                               ^
          73 |              await verifier.verifyProvider();
          74 |      } );
          75 | } );
    👋 1
    m
    d
    • 3
    • 17
  • g

    Gawaine O'Gilvie

    02/20/2023, 5:03 PM
    Hi All, I am currently working on adding contract testing between two services. One part in particular I have been unsure about. Question: When the Consumer service uses a client library to send requests to the Provider, we must set the baseUrl for that provider client-library to that of the mock server right? Note: the client library is offered by the
    Provider
    ✅ 1
    m
    • 2
    • 1
  • j

    James Braund

    02/22/2023, 10:10 AM
    Hi folks! I'm updating our provider verification tests, and have come across some interesting things around the
    afterEach
    hook. 1. The documentation for the lifecycle seems to be incomplete, as it doesn't mention when the
    State Handler Teardown
    step runs. After some trial and error, I believe the following is correct:
    Copy code
    BeforeEach -> State Handler Setup -> Request Filter (request phase) -> Execute Provider Test -> Request Filter (response phase) -> AfterEach -> State Handler Teardown
    Is this right? Happy to get a PR open to update the docs if this is correct. 2. Are there any constraints around the
    afterEach
    hook, such as maximum execution time? In the
    afterEach
    hook for our tests, I'm resetting some of the data in our test database, as per one of the use cases described for it in the docs. However, it seems that my
    afterEach
    hook does not always finish executing. I've littered it with logging debug statements and
    try/catch
    statements to find out exactly where it gets to, and there are no errors being thrown - the logging statements sometimes just stop. What might I be missing? Any help is appreciated! Thanks in advance 🙂
    t
    • 2
    • 49
  • s

    Slackbot

    02/22/2023, 11:39 AM
    This message was deleted.
    t
    a
    • 3
    • 3
  • m

    Martin Grühn

    02/24/2023, 5:58 PM
    Hey, gang! Does pact-js support (sync) POST-method tests specifically for requests with a form-data body? I've been trying to find an example of how that would work, and came across https://github.com/pact-foundation/pact-js/issues/277#issuecomment-487939601, which communicates the overall approach, but doesn't seem up to date as a solution. For one, matching the 'Content-Type'-header with term() brings me back to https://github.com/pact-foundation/pact-js/issues/950#issuecomment-1256799800, and just plugging the body in as YOU54F did, still results in an error message, where I'm never ahead of the boundary being re-calculated:
    Copy code
    1.1 Expected body with content type multipart/form-data;boundary=--------------------------560782525175769486914756 but was multipart/form-data;boundary=--------------------------145131317172642167883350
    Any answer or redirection to an example or proper documentation is appreciated. Thanks!
  • m

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

    02/24/2023, 10:32 PM
    This what you’re after: https://github.com/pact-foundation/pact-js/blob/master/src/v3/pact.ts#L139 ?
    m
    t
    • 3
    • 5
  • e

    Erik

    02/28/2023, 6:37 AM
    Hi here, What's the best way to handle a provider which has no consumers yet, but you still want to implement the pact flow into the ci? It will return saying
    Could not load pacts
    (which can be turned into a warning) or it will say
    No pacts or verifications have been published for version ... of ...
    Thread in Slack Conversation
    t
    r
    m
    • 4
    • 6
  • g

    Gazal Gafoor

    03/01/2023, 1:30 PM
    @Gazal Gafoor has left the channel
  • h

    Harry

    03/01/2023, 4:43 PM
    Hello, please help me with the below issue. I am trying to use eachLike matcher in my consumer test, but am not getting the desired result as the provider test is failing. The consumer code is :-
    Copy code
    authors: eachLike(['Harry', 'Garry', 'Reilly']),
    and this is the provider's mock data against which its running the tests :-
    Copy code
    "authors": ["Frances", "Gibbs"],
    And I am getting the below error :-
    Copy code
    1.2) body: $.featured.authors.0 Type mismatch: Expected List ["Harry","Federer","Rilos"] but received String 'Frances'
    
            -[
            -  "Harry",
            -  "Federer",
            -  "Rilos"
            -]
            +"Frances"
    
    
        1.3) body: $.featured.authors.1 Type mismatch: Expected List ["Harry","Federer","Rilos"] but received String 'Gibbs'
    
            -[
            -  "Harry",
            -  "Federer",
            -  "Rilos"
            -]
            +"Gibbs"
    u
    m
    • 3
    • 13
  • m

    Mayank Chugh

    03/02/2023, 12:49 PM
    Heya folks 👋 I am looking for recommendations on how to efficiently implement “bi-directional testing” via Github webhooks.
    y
    t
    • 3
    • 12
  • i

    Ivan Mikhalka

    03/06/2023, 9:57 AM
    Hi, all. I have couple of consumers with contract files generating on them. On my MacOS Ventura on Intel all works fine, but when another person tried to run the same on Ubuntu, he got following errors: For first app:
    Copy code
    FAIL  pact/consumer/generateContract.pact.ts (6.46 s)
    
    
      ● Test suite failed to run
    
        Error in native callback
    
          at mockServerMismatches (node_modules/@pact-foundation/pact-core/src/consumer/internals.ts:10:9)
          at Object.mockServerMismatches (node_modules/@pact-foundation/pact-core/src/consumer/index.ts:123:27)
          at PactV3.<anonymous> (node_modules/@pact-foundation/src/v3/pact.ts:206:39)
          at step (node_modules/@pact-foundation/pact/src/v3/pact.js:33:23)
          at Object.throw (node_modules/@pact-foundation/pact/src/v3/pact.js:14:53)
          at rejected (node_modules/@pact-foundation/pact/src/v3/pact.js:6:65)
    
    Test Suites: 1 failed, 1 total
    Tests:       2 passed, 2 total
    Snapshots:   0 total
    Time:        6.512 s
    Ran all test suites.
    error Command failed with exit code 1.
    For second (it reports passed at finish, but contract files does not appear):
    Copy code
    PASS  src/__tests__/pact_tests/consumer/generateContract.pactTest.tsrver_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x7ffcde2da260 tls=false}: pact_ffi::mock_server: Failed to start m  Generate contract example
        ✓ some test 1 (2 ms)
        ✓ some test 2
        ✓ some test 3 (1 ms)
    
    Test Suites: 1 passed, 1 total
    Tests:       3 passed, 3 total
    Snapshots:   0 total
    Time:        1.427 s
    Ran all test suites.
    Done in 2.04s.
    Could someone give a clue about this?
    t
    m
    +2
    • 5
    • 90
  • g

    Gustavo Souza

    03/08/2023, 12:48 PM
    have you face this error before?!
    t
    y
    s
    • 4
    • 21
  • m

    Marck Puiu

    03/08/2023, 12:53 PM
    Hi. I'm trying to implement this solution proposed in https://stackoverflow.com/questions/68455650/cannot-make-cypress-and-pact-work-together/68492932#68492932 using pact 11.0.0 and cypress 12.7.0. But Cypress throws this error when I try to import the Matchers. Any idea how to solve this? Thanks
    Copy code
    Error: Webpack Compilation Error
    ./node_modules/@pact-foundation/pact-core/src/service.js 132:29
    Module parse failed: Unexpected token (132:29)
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See <https://webpack.js.org/concepts#loaders>
    |                 if (match && match[1]) {
    |                     this.options.port = parseInt(match[1], 10);
    >                     if (this?.__instance?.stdout) {
    |                         this.__instance.stdout.removeListener('data', catchPort);
    |                     }
    t
    • 2
    • 7
  • a

    Alan Boshier

    03/09/2023, 12:02 PM
    Apologies if this is an old question, but I can't seem to find a pact (v2/v3) matcher that would check if an object-valued non-array response field (in e.g. REST/JSON) was one of a list of possible expectation shapes. This kind of thing arises quite frequently in e.g. GraphQL schema union types (where a field could be e.g. a Person or a Team), and the possible values are quite different.
    t
    • 2
    • 5
  • k

    Kevin Grady

    03/09/2023, 6:51 PM
    Hi, I’ve just updated our repo to pact 11.0.0 and was looking through the migration guide. Since updating, all of our
    like()
    methods are erroring out due to type mismatches. When I looked into the
    AnyTemplate
    class, I see that it is deprecated. What are my options here?
    Copy code
    it('should return the correct data from POST call', async () => {
          await mockProvider.addInteraction({
            states: '[]',
            uponReceiving: 'a request to create a tenant',
            withRequest: {
              method: 'POST',
              path: '/tenant',
              body: like(reqBody),
              headers: requestHeaders,
            },
            willRespondWith: {
              status: 201,
              headers: responseHeaders,
              body: like(responseBody),
            },
          });
    
          const tenant = await lastValueFrom(service.createTenant(requestHeaders, reqBody));
          expect(tenant).toStrictEqual(camelCaseObjectKeys(responseBody));
        });
    m
    t
    • 3
    • 5
  • i

    Ivan Mikhalka

    03/10/2023, 12:53 AM
    Hi, everyone. How to compare expected body with matchers, like:
    Copy code
    const expectedBody: any = {
        field1: integer(3),
        field2: integer(2),
        field3: integer(1),
    };
    with actual value, which is plain object:
    Copy code
    {
        field1: 3,
        field2: 2,
        field3: 1,
    }
    ? Using
    expect(JSON.stringify(dataFromAPI)).toEqual(JSON.stringify(expectedBody));
    (I am using jest), gives:
    Copy code
    Expected: "{\"field1\":{\"pact:matcher:type\":\"integer\",\"value\":3},\"field2\":{\"pact:matcher:type\":\"integer\",\"value\":2},\"field3\":{\"pact:matcher:type\":\"integer\",\"value\":1}}"
    Received: "{\"field1\":3,\"field2\":2,\"field3\":1}"
  • m

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

    03/10/2023, 12:58 AM
    you want to use the
    reify
    function (in the
    Matchers
    package), to remove the matchers from it
    ✅ 1
  • m

    Manish Mitra

    03/10/2023, 2:18 AM
    Does Pactjs supports “Bi-directional GRPC constructs” in contract testing?
    m
    t
    • 3
    • 4
  • h

    Harry

    03/14/2023, 11:51 AM
    Hi all, how can we pass a particular consumer tag in the create-webhook command, so that whenever there is any consumer contract published to the broker with a certain tag, the webhook triggers the provider tests, thus enabling the provider to fetch the contract with that specific tag from the broker? How can we achieve this?
    m
    • 2
    • 2
  • g

    Gawaine O'Gilvie

    03/15/2023, 3:07 PM
    Has anyone figured out the
    node-gyp
    issues that occur on Node v16? It seems to originate from this script:
    Copy code
    "format:fix": "npm run format:base -- --write \"{src,standalone,bin,test}/**/*.{ts,tsx}\"",
        "postinstall": "npm run native",
        "native": "node-gyp rebuild -v"
    the
    native
    command specifically where it does the
    node-gyp rebuild -v
    error:
    Copy code
    gyp ERR! node -v v16.16.0
    gyp ERR! node-gyp -v v3.6.3
    I’m using
    "@pact-foundation/pact": "^11.0.0",
    ✅ 1
    y
    a
    • 3
    • 10
  • g

    Gawaine O'Gilvie

    03/15/2023, 3:11 PM
    Here’s a similar error: https://github.com/nodejs/node-gyp/issues/2025
  • k

    Kripa Kurian

    03/16/2023, 7:31 PM
    @Kripa Kurian has left the channel
  • m

    Milda

    03/18/2023, 1:15 PM
    Hi there, not sure if this is the right channel to post, but please point me to the correct team if not. We are trying to implement pact across a varied tech stack in the company, one of them being the front end team, so we're using pact-js for them. The problem is that the pact core package, pulled in with pact js, has the standalone pact inside it on ruby version 2.4.0, which is throwing some vulnerability issues with our security checks. Are there options I can use to bump this ruby version, or are there any plans to bump the version by the pact team? Thanks very much in advance.
    m
    • 2
    • 7
  • u

    Ulises Cervino

    03/20/2023, 11:39 AM
    hi all, question about provider states, in particular javascript: how does one specify a path with provider values where you have 2 variables in the expression? We do things like
    path: fromProviderState('/${entityId}', UUID)
    However, how does one do something like
    path: fromProviderState('/${entityId}/extra/stuff/${anotherId}', UUID, UUID)
    ? (this is not possible in our current version of the pact libs for java/typescript -- wrong signature). For reference https://github.com/pact-foundation/pact-js/blob/master/docs/matching.md#provider-state-injected-values Though those docs show how to do single values (we know and use this already)
  • u

    Ulises Cervino

    03/20/2023, 11:47 AM
    maybe it's a case of doing
    fromProviderState('/${anIdHere}/extra/stuff/${anotherId}', '/' + UUID1 + '/extra/stuff/' + UUID2)
    ?
    t
    m
    u
    • 4
    • 10
1...1011121314Latest