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

    Rafael Moral

    05/03/2022, 9:43 AM
    Hello! I have seen that pact js library does not work with node 18. Do you know if there are plans for fixing it?
    m
    • 2
    • 5
  • j

    jithin jacob

    05/03/2022, 10:04 AM
    I am trying to run tests against nestjs provider- https://github.com/pact-foundation/pact-js/tree/master/examples/nestjs-provider, Contracts generated while adding the tests against nestjs consumer is there in broker. i have set up the provider using npm start and then tried to run npm test . i am trying to run tests against provider and validate the contract so that it succeeds. i have added broker url and token.
    Copy code
    You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration.
    m
    s
    • 3
    • 20
  • m

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

    05/03/2022, 12:02 PM
    requestFilter is for the provider side
    m
    y
    • 3
    • 9
  • d

    Dany Marques

    05/05/2022, 5:55 PM
    Hi folks, I want to write some pact tests using the pactWith method of the ‘jest-pact’ package. My use case is a bit weird: I have multiple providers with the same API for some reason. So instead of duplicating the whole test file, I’m trying to do something like:
    Copy code
    it.each(['provider 1', 'provider 2'])('testing %s', provider => pactWith({
                consumer: 'foobar',
                provider: provider,
                port: 45678
            }, () ..... ));
    But it fails because I think the Pact mock server is not shut down between each test and then I get:
    Port '45678' is already in use by another process.
    Any idea ?
    👋 1
    y
    • 2
    • 12
  • d

    Dmitry Munda

    05/06/2022, 7:46 PM
    i have some riddle here 🙂
    Copy code
    term({ generate: "21+3", matcher: "21\+3" })
    makes
    Example ‘21+3’ does not match provided regular expression ‘21+3’
    🧙‍♂️ 1
    y
    • 2
    • 9
  • d

    Dmitry Munda

    05/06/2022, 10:13 PM
    one more riddle 🙂 how to add element inside json array ? like
    {z:[a,b,[d,e]]}
    ->`{z:[a,b,c,[d,e,f]]}` where
    a
    and
    d
    is one term and
    b
    c
    e
    f
    other ( same ) term
    y
    b
    • 3
    • 19
  • a

    Akash Srivastava

    05/08/2022, 3:25 PM
    Hi folks. First off, pact is awesome !! We are new to contract testing and trying to write a set of consumer tests for a UI that consumes a graphql API. With this, we are aiming to define how the same graphql query would generate different response based on different provider states. But despite specifying the correct expected response for each use case (with same request query), we are seeing all subsequent tests except the first failing by expecting the response from the first one. This happens only when all specs are running together. When specs are run individually (by removing/commenting all others), they pass as expected. When changing the order of tests, the first one passes always, with the rest failing. We are using a combination of jest-pact with GraphQLInteraction from pact. Here is a very minimal example that will demo that problem we’re facing. https://github.com/akashdotsrivastava/pactjs-consumer-test-example Setup instructions in readme are just about cloning the repo, installing the dependencies and then running the solitary spec file. Any insight will be helpful. TIA 🙏
    👋 1
    m
    • 2
    • 9
  • c

    Carbon for Slack

    05/09/2022, 6:18 PM
    @Yousaf Nabi (pactflow.io): Just testing out some new ways to share code, but it doesn't always work!
    y
    • 2
    • 1
  • é

    Édouard Lopez

    05/10/2022, 9:14 AM
    Hello, I have different behavior when running
    npm install
    vs
    yarn install
    with
    @pact-foundation/pact
    . With yarn I need to run
    npm install --save-dev @pact-foundation/pact
    to fix the error:
    Copy code
    [ERROR] 11:10:18 TypeError: destination.on is not a function
    [11:10:18] › ✖  error     TypeError: destination.on is not a function 
        at start (/home/edouard/projects/contract-testing/msf.toolbox-mf-replenishment/node_modules/thread-stream/lib/worker.js:59:15)
    Is there some NPM mechanism that I'm not aware of? Is it mandatory to use NPM?
    m
    y
    • 3
    • 24
  • r

    Rafi Gemhar

    05/10/2022, 3:13 PM
    In
    jest-pact
    is there a way to
    addInteraction
    that will respond with body as blob data (csv, xlsx or pdf).
    y
    • 2
    • 3
  • m

    Marcello Rigan

    05/11/2022, 10:11 AM
    Hello, i have an Array which can be empty or have 1 or 2 Entries. For multiple Entries i would have used Eachlike? But what about the case if its empty. Do i have to add an extra interaction for that or is there another way ?
    m
    • 2
    • 2
  • m

    Marcello Rigan

    05/12/2022, 9:01 AM
    Hello, my existing provider test failed because an array now has more than one entry. So i changed the contract expectation to
    Copy code
    urlParams: eachLike({
        urlParameterName:string(),
        navigatorUrlParameterType: string(),
    }),
    My Provider test still fails because there are multiple entries. I already used the eachLike feature and didn't have an issue with it. Am i missing something?
    m
    • 2
    • 10
  • g

    Gueorgui

    05/13/2022, 12:24 PM
    Hi folks, we’re running into an issue on CI when installing pact via Yarn:
    Copy code
    Error: Error while installing binary: Postinstalled Failed Unexpectedly: Error: Error while installing binary: Extraction failed for /root/project/node_modules/@pact-foundation/pact-node/standalone/pact-1.88.81-linux-x86_64.tar.gz: Error: Error while installing binary: Checksum rejected for file 'pact-1.88.81-linux-x86_64.tar.gz' with checksum pact-1.88.81-linux-x86_64.tar.gz.checksum
        at throwError (/root/project/node_modules/@pact-foundation/pact-node/standalone/install.js:42:11)
        at /root/project/node_modules/@pact-foundation/pact-node/standalone/install.js:335:16
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
    info Visit <https://yarnpkg.com/en/docs/cli/install> for documentation about this command.
    
    Exited with code exit status 1
    Any clues why the checksum might be getting rejected?
    m
    • 2
    • 6
  • a

    Alan Alie

    05/13/2022, 3:30 PM
    Hi all, I’ve been using typescript to write ‘happy path’ PACT tests without any problem using a pattern like this:
    Copy code
    // PACT test for getBasketById
    describe('Given we are requesting specific basket', () => {
      test('When a basket exists', async () => {
        // set up Pact interaction
        await provider.addInteraction({
          state: 'When the basket exists',
          uponReceiving: 'get the specified basket',
          withRequest: interactionRequest.GET_BASKET,
          willRespondWith: interactionResponse.BASKET_NORMAL_RESPONSE,
        });
    
        // make request to PACT mock server
        await getData(provider.mockService.baseUrl + '/basket/' + OK_BASKET_ID);
      });
    Now that I’m attempting error path tests (the response status is 404) I get the following error
    Copy code
    thrown: Object {
       "errorCode": "BS-002",
       "errorMessage": "No basket has been found",
      }
    
        111 |   // Failed PACT test for getBasketById
        112 |   describe('Given we are requesting specific basket', () => {
      > 113 |     test('When the basket does not exists', async () => {
            |     ^
        114 |       // set up Pact interaction
        115 |       await provider.addInteraction({
        116 |         state: 'basket does not exists',
    My code for the ‘error path’ test is as follows:
    Copy code
    // Failed PACT test for getBasketById
    describe('Given we are requesting specific basket', () => {
      test('When the basket does not exists', async () => {
        // set up Pact interaction
        await provider.addInteraction({
          state: 'basket does not exists',
          uponReceiving: 'get specified basket',
          withRequest: {
            method: HTTPMethod.GET,
            path: '/basket/' + BAD_BASKET_ID,
          },
          willRespondWith: {
            status: 404,
            headers: { 'Content-Type': 'application/json' },
            body: {
              errorCode: 'BS-002',
              errorMessage: 'No basket has been found',
            },
          },
        });
    
        // make request to Pact mock server
        await getData(provider.mockService.baseUrl + '/basket/' + BAD_BASKET_ID);
      });
    });
    How do I handle the thrown object? PS: If I change the response status in my code to 200 then the problem disappears - but that’s obviously not what I’m after.
    y
    m
    • 3
    • 18
  • m

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

    05/16/2022, 12:36 PM
    @uglyog any ideas?
    a
    u
    • 3
    • 5
  • j

    Josh

    05/16/2022, 2:38 PM
    is there an equivalent to @IgnoreNoPactsToVerify in pact-js?
    t
    • 2
    • 2
  • m

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

    05/18/2022, 10:36 AM
    It means your API client code being tested, is not sending the request to the mock service configured by Pact. Pact does not automatically mock your API calls - you need to ensure your API client is correctly configured to poitn at the Pact mock service. Given you have constructed a Pact object with name
    provider
    and you are using a
    DogApiClient
    class to send requests to your
    Dog Service
    , you can dynamically configure your API client as follows:
    Copy code
    provider.setup().then(opts => {
      dogService = new DogApiClient({ `http://${opts.host}`, port: opts.port })
    })
    b
    • 2
    • 50
  • l

    Lukasz Wlosek

    05/19/2022, 9:04 AM
    Hi, I am trying to save a uuid in my provider side verification, where this is saved in provider states, in order to do this I have to match the uuid that I pass in my consumer tests, I was wondering if this uuid can be dynamic, do I do not have to match it, thought the term() matcher would help but it did not work like so
    Copy code
    .withRequest({
              method: 'GET',
              path: term({
                generate: '/user/9ae9b264-f181-46ea-a468-4919c48fbe94',
                matcher:
                  '/user/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
              }), // we want to be strict with what we send out <https://docs.pact.io/getting_started/matching#request-matching>
              headers: {
                Accept: 'application/json, text/plain, */*',
                Authorization: string('Bearer testToken')
              }
            })
    when I save a different uuid setup in the provider side the verifaction fails, any tips on how to achieve this, read about provider state injected values, but it does not seem to be yet implemented in pact-js?
    👀 1
    m
    • 2
    • 3
  • t

    Timothy Jones

    05/20/2022, 8:25 AM
    I've hit the windows long path issue in CI, where I don't have much control over what the path is. Has anyone got any tips for working around this?
    😱 2
    a
    m
    • 3
    • 14
  • k

    Kendrick B

    05/23/2022, 2:47 AM
    Anyone here used Pact with aws-sdk-mock ? Am getting problems with hitting pact trying to verify the endpoint
    Copy code
    Actual interactions do not match expected interactions for mock MockService.
    t
    • 2
    • 58
  • e

    Evan

    05/23/2022, 4:50 PM
    Hey all 👋 ! Any fix/workaround for getting
    Cannot find binary for platform 'linux' with architecture 'arm64'
    ... during install?
    👋 1
    y
    b
    m
    • 4
    • 47
  • d

    Damian

    05/25/2022, 3:59 PM
    Hey everyone. Can I get a high-level view of what I need to do to publish my contracts to Pactflow? I've got an Angular app using Jest and the contracts are already being generated in my repo. How do I actually publish them to Pactflow now?
    👋 1
    y
    • 2
    • 5
  • j

    Jacek

    05/27/2022, 9:40 AM
    When I use pact-js on my corporate laptop pact file is not written to the disk although log says that it was written. I try to investigate the issue by checking sources but I get stuch in the chain of references. Can anyone give me some tips on how to investigate the issue?
    m
    • 2
    • 34
  • s

    Subrahmanyam Rentala

    05/30/2022, 3:00 PM
    Can someone please let me know that for a design first development approach, is the unit tests only place where we can define our contracts?
    m
    • 2
    • 6
  • a

    Alex Maiburg

    05/31/2022, 7:48 AM
    Hi, I updated all pact related packages in Angular (see 1st screenshot) and everything works well on my machine. But when I start the build pipeline on Jenkins I get “[karma-pact]: Failed to start Pact Mock Server Error: Couldn’t start Pact with PID: undefined” I attached the full error log. Can anybody point me to a possible cause? Thanks in advance.
    pact-jenkins-error.log
    m
    t
    • 3
    • 45
  • j

    John Williams

    05/31/2022, 9:55 AM
    hey all, is been a while since i last looked at pactflow, but can someone remind me when you write a consumer test with some data in the query when the producer test verifys this contract it isnt actually creating the data right if it is a post request or something?
    m
    • 2
    • 17
  • j

    John Williams

    05/31/2022, 9:58 AM
    also a second question is so in regards of the pros and cons of contract testing vs say property based testing apis?
    m
    t
    • 3
    • 12
  • j

    John Williams

    05/31/2022, 10:09 AM
    Last question! lol My company is using graphql mesh. Is hitting the graphql mesh a bad practise for pactflow?
    😆 1
    m
    • 2
    • 5
  • j

    John Williams

    06/06/2022, 12:21 PM
    I was looking into the provider state. So is it just a case of having an in memory database (or even just hardcoding it)for example in the provider test. Using the same data that the consumer request expects and to include that in the opts:
    Copy code
    const opts = {
      ...
      stateHandlers: {
        [null]: () => {
          // This is the "default" state handler, when no state is given
        }
        "Has no animals": () => {
          animalRepository.clear()
          return Promise.resolve(`Animals removed from the db`)
        },
        "Has some animals": () => {
          importData()
          return Promise.resolve(`Animals added to the db`)
        },
        "Has an animal with ID 1": () => {
          importData()
          return Promise.resolve(`Animals added to the db`)
        }
      }
    }
    
    return new Verifier(opts).verifyProvider().then(...)
    so like in the above example. If the consumer is expecting in the request it sends an id, and name and expects the id to be 1. Can i just hardcode the data as something like this:
    Copy code
    {
      "id": 1,
      "name": "dog"
    }
    b
    • 2
    • 7
  • l

    Lukasz Wlosek

    06/06/2022, 2:41 PM
    Hi, I have this problem, when I run the verification provider tests, they seem to be setup with random ports on localhost like so: (this is what I see being executed when I run with debug')
    Copy code
    pact-node@10.17.2: Starting pact binary '/home/repos/gf-accounts-service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.83/pact/bin/pact-provider-verifier', with arguments [--provider-states-setup-url <http://localhost:46091/_pactSetup> --provider-base-url <http://localhost:46091> --provider-app-version dc04a08
    The ports for --provider-states-setup-url and --provider-base-url seem to be failing my TeamCity build sometimes, as some of these ports are reserved, I thought that specifying the providerBaseUrl in the provider settings sets these ports, in my case it was http://localhost:3000/ but it seems like the pact-provider-verifier spins this up with different ports as some proxy? Is there a way to specify which port to use in that pact-provider-verifier script?
    m
    • 2
    • 6
12345...14Latest