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

    Pip Brandy

    02/07/2022, 3:37 PM
    Hello, I'm following the pact-workshop-js on Windows 10. I forked the project into my own repo, ran
    npm install
    , and was able to complete step 1. I'm trying step2, I did "git checkout step2" and step 2 seems to have loaded fine. However, when running "npm test --prefix consumer", I get this error:
    > CI=true react-scripts test
    'CI' is not recognized as an internal or external command,
    operable program or batch file.
    npm ERR! Test failed.  See above for more details.
    m
    u
    • 3
    • 54
  • m

    Mike Bernard

    02/07/2022, 9:57 PM
    👋 I've hit somewhat of a roadblock in implementation. I've created provider tests for an AWS API Gateway application and I've been invoking the API directly in the tests, adding the proper authentication headers to each request. When using aws sig4 to sign requests, if the API requires a body, the signature must also include the body of the request. I'm looking for a way to intercept the body from each consumer pact and grab it to add to the signature. I'm currently using the
    requestFilter
    to intercept each request and add the auth to the headers, but the request object passed in doesn't contain a body. I've attempted to use SAM CLI to host the API gateway (to bypass auth) but it seems the way we've structured our stacks, the automated
    sam local start-api
    command can't find the lambda functions that we tie to each api. Only other way to use SAM afaik is to hardcode each endpoint into the template.yaml file, and include each request/response model, which isn't viable for our teams to do. TIA!
    👋 1
    y
    • 2
    • 10
  • d

    danilchican

    02/10/2022, 9:21 AM
    Hi everyone! Is there any possibility to set given section (provider state) multiple time (multiple provider states)? I tried to use V3 version but it's not implemented there. Could anyone help me with that? It's really very let's say critical thing for us.
    b
    a
    • 3
    • 2
  • f

    Francislainy Campos

    02/10/2022, 8:37 PM
    Hi, I have this contract done in Javascript:
    Copy code
    {
      "consumer": {
        "name": "Ed UI"
      },
      "provider": {
        "name": "Viaduct"
      },
      "interactions": [
        {
          "description": "A POST request to encode a JSON body of claims from the user",
          "providerState": "viaductService encodes a JSON body of claims and returns a JWT string in response",
          "request": {
            "method": "POST",
            "path": "/edcore/viaduct-service/jwt",
            "body": {
              "resourceId": "l_fc3ae9ed-62ac-4b94-8094-8dd29bc208a7_c57760a9-447b-42aa-81df-830134425157",
              "teacherAssessmentId": "93a91981-c6f7-435f-ab1e-80588ecff2ee",
              "expiryUnixEpochSeconds": 26757854170066,
              "sub": "UniqueUserId"
            }
          },
          "response": {
            "status": 200,
            "body": "eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla",
            "matchingRules": {
              "$.body": {
                "match": "type"
              }
            }
          }
        },
      ],
      "metadata": {
        "pactSpecification": {
          "version": "2.0.0"
        }
      }
    }
    However, our provider tests (Java) fail with
    Expected body 'eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla' to match 'eyJhbGciOiJIUzI1NiJ9.eyJzd.bla' using equality but did not match
    . Not sure where the issue could be coming from. Initially I thought it might be related to the headers blocking the matchers as per https://stackoverflow.com/a/61924547/6654475, but even manually deleting the headers from the contract still give us the same issue, so maybe version related perhaps?
    <pact.version>4.3.2</pact.version>
    Thank you. CC @uglyog
    u
    • 2
    • 13
  • b

    bbarke

    02/11/2022, 12:27 AM
    Hi, are there plans to allow a consumer project pass in parameters in it's state (state with-data) for the provider to use to setup it's state? Specifically calling out this feature in pact-jvm:
    Copy code
    @State("with-data") // Method will be run before testing interactions that require "with-data" state
            public void toStateWithData(Map data) {
                // Prepare service before interaction that require "with-data" state. The provider state data will be passed 
                // in the data parameter
                // ...
                System.out.println("Now service in state using data " + data);
            }
    https://github.com/pact-foundation/pact-jvm/tree/master/provider/junit#example-of-http-test
    m
    • 2
    • 8
  • d

    Dharmesh

    02/15/2022, 2:25 PM
    @Matt (pactflow.io / pact-js / pact-go) I am using matcher to match one properties that can have value null most of the time or any string so how I can write the expected response body of consumer
    "description":term(
    generate: null,
    matcher: /([a-z])|null/),
    I have written this it throwing error. can you please help me to resolve it.
    m
    • 2
    • 6
  • m

    Mike Geeves

    02/21/2022, 9:36 AM
    More of a general JS question than Pact specifically. I'm pretty new to JS so pretty much zero experience testing with it. Are there any general preferences of Jest vs Mocha? (or anything else?). With a focus on nice with Pact ofc, if there are any preferences of working with one over the other. I'm currently working with Vue3+Quasar, bdd makes me happy 😀
    m
    y
    i
    • 4
    • 26
  • c

    Carere

    02/21/2022, 3:47 PM
    Hello all :) is there a binding for deno ?
    y
    • 2
    • 3
  • c

    Carere

    02/21/2022, 8:00 PM
    @Matt (pactflow.io / pact-js / pact-go) Hello 🙂 What should it takes to be able to do contract testing in deno ?? It seems that i can just call the binary in my code, instead of doing
    new Verifier(...).verify()
    ? Is there a proper way to implement a deno version of pact ??
    m
    • 2
    • 2
  • d

    Dharmesh

    02/24/2022, 10:31 AM
    Hi, How we can compare only schema of response in contract testing ?
    b
    • 2
    • 7
  • a

    Ayush

    02/24/2022, 11:01 AM
    Hello! I’m having an issue with pact jest where my tests are passing but the pact isn’t being generated in the directory I’ve tried several possible solutions that we could find on google but nothing worked , can someone here help please ? attaching the spec file below
    m
    • 2
    • 15
  • q

    Quinn

    03/01/2022, 10:18 PM
    Hi everyone, I'm having an issue running a test that should be passing (and does on 10.0.0.beta54) after I've upgraded to 10.0.0.beta56. The issue is around the content-type header, and the error is
    Expected body with content type application/json but was image/jpeg
    . Can anyone please help?
    m
    • 2
    • 16
  • m

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

    03/02/2022, 12:25 AM
    Provider states are usually how you handle different scenario data needs
    p
    s
    • 3
    • 8
  • t

    Timothy Gates

    03/02/2022, 11:56 PM
    Hello everyone, my team updated to version
    10.0.0-beta.56
    to get the timeout fix https://github.com/pact-foundation/pact-js/issues/761 We are running into an issue were the state handlers teardown is no longer being called. I don't see any change in the signature of the state handlers between
    10.0.0-beta.54
    and the version we are using now. Anyone have any ideas why the teardown isn't be executed? I'll include an example of the code in the thread.
    m
    m
    • 3
    • 23
  • h

    Harihara Raj LK

    03/03/2022, 9:51 AM
    Hello people, Trying to do equality matching of the response body , but using Matcher doesn't provide any equality matching ability. Is there any workaround or am i missing something on the matcher ??
    Copy code
    "matchingRules": {
      "$.body": {
        "match": "equality"
      }
    }
    m
    • 2
    • 14
  • d

    davT

    03/03/2022, 1:33 PM
    Hi could anyone help me with what seems like a simple question I want to match a value that can be 0 or 1 After much trying I arrive at trial: term({ matcher: "\\[0 - 1]", generate: 0 }), No luck - Example '0' does not match provided regular expression '\[0 - 1]' What am I doing wrong please ?
    m
    • 2
    • 13
  • d

    Djalmar Gutierrez

    03/03/2022, 8:36 PM
    Hi anyone can help me. I’m using pact in a debian container. When we use mocha as test framework everything works fine, our project uses jasmine as main test framework, when I switch to jasmine I got this error:
    Unhandled promise rejection: Error: Pact startup failed; tried calling service 10 times with no result.
    Nothing else is changed.
    m
    y
    • 3
    • 21
  • a

    Alan Boshier

    03/04/2022, 5:49 PM
    Hi - does anyone have a simple example of using
    GraphQLInteraction
    with PactV3? I'm struggling with how to use it in the following approach as I'm not sure PactV3 has an
    addInteraction()
    method:
    Copy code
    const provider = new PactV3(...);
    
    describe('query', () => {
      beforeEach(() => {
        const graphqlQuery = new GraphQLInteraction()
          .uponReceiving('a query')
          .withQuery('...')
          .withVariables({})
          .withRequest({
            path: '/graphql',
            method: 'POST',
          })
          .willRespondWith({
            status: 200,
            headers: { ... },
            body: { ... }
          });
    
        return provider.addInteraction(graphqlQuery);  <-- IS THIS VALID?
      )};
    )};
    m
    • 2
    • 7
  • a

    Artur Neumann

    03/07/2022, 7:07 AM
    ether fix my code or replace all undefined with null? https://muffinman.io/blog/json-stringify-removes-undefined/#using-replacer-parameter
    m
    • 2
    • 11
  • q

    Quinn

    03/09/2022, 9:41 PM
    Hi all! I'm trying to find a good way to debug my tests in Intellij. Does anyone have a run configuration or any general tips of how to set this up? I haven't been able to hit a single breakpoint in any of my tests. Thanks in advance!
    u
    • 2
    • 2
  • c

    Caíque Coelho

    03/10/2022, 7:14 PM
    Hello everyone, how are you? I have generated a contract using pact-js in my consumer for a GraphQL API, but I’m getting an error when I try to verify this contract with pact-very or with pact-python in my provider, I believe this is an error with my contract the error I’m getting when I try to verify this contract is
    GraphQL operations must contain a non-empty query or a persistedQuery
    anyone knows how to solve this? I’m sharing my contract bellow and the code I’m using to generate the contract
    u
    • 2
    • 7
  • m

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

    03/11/2022, 6:25 AM
    Are you running your tests against a live provider?
    h
    • 2
    • 14
  • a

    Alan Boshier

    03/12/2022, 3:24 PM
    Hi I'm running the latest Pactv3 beta pact-js consumer and the mocked server is returning null for a response body property based on
    arrayContaining
    - there are other properties using that matcher which are working fine. Is this a known issue, or is there something in the logs I should be looking for to give me a clue?
    🤔 1
    m
    • 2
    • 10
  • m

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

    03/21/2022, 5:43 AM
    You could also consider the use of the
    arrayContaining
    matcher in the v3 beta release
    👍 1
    p
    • 2
    • 1
  • m

    Mircea Ungureanu

    03/21/2022, 1:29 PM
    Good afternoon, I’m getting this error and not sure how to get past it
    : Timeout - Async callback was not invoked within the 15000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 15000 ms timeout specified by jest.setTimeout.Error:
    I tried increasing the jest timeout but no luck, it’s failing on the
    return await p.verify();
    as it’s an open handle and keeping jest from exiting. Has anyone encountered this before? I’ve sent my access token and url env vars.
    • 1
    • 1
  • b

    Bernard Baker

    03/22/2022, 1:40 PM
    Hi I'm running my Pact tests inside a docker container. And I'm having trouble running a basic Pact test.
    Copy code
    test(`makes a request`, async () => {
    	jest.setTimeout(30000);
    
    	// Arrange
    	const expectedResult = `Hello World`;
    
    	await mockProvider.addInteraction({
    		state: `foo exists`,
    		uponReceiving: `a request to get foo`,
    		withRequest: {
    			method: `GET`,
    			path: `/foo`
    		},
    		willRespondWith: {
    			status: 200,
    			headers: {
    				"Content-Type": regex({
    					generate: `text/plain`,
    					matcher: `text/plain;?.*`
    				})
    			},
    			body: like(expectedResult)
    		}
    	});
    
    	const request = await <http://axios.post|axios.post>(
    		`${mockProvider.mockService.baseUrl}/foo`
    	);
    
    	console.log(request);
    });
    My Pact logs are:
    Copy code
    I, [2022-03-22T13:37:53.003897 #348]  INFO -- : Registered expected interaction GET /foo
    W, [2022-03-22T13:38:22.980712 #348]  WARN -- : Verifying - actual interactions do not match expected interactions. 
    Missing requests:
    	GET /foo
    
    
    
    W, [2022-03-22T13:38:22.980965 #348]  WARN -- : Missing requests:
    	GET /foo
    
    
    
    I, [2022-03-22T13:38:23.015926 #348]  INFO -- : Cleared interactions
    Any ideas?? Do I need to expose a port on my container???
    y
    • 2
    • 1
  • a

    Agustin Gomes

    03/22/2022, 5:23 PM
    Hello everyone, I'm trying to setup a small Typescript project to use Pact, The test is setup as follows: • a Docker container with the app and the test • a separate Docker container where the mock server is running It seems that PactJS assumes I want to setup the mock server in the same place as the app, which is not possible since Ruby is not installed. Is there a way around it? If I do cURL from the app container, I get this:
    Copy code
    docker-compose run --rm node-cli curl -X GET pact-mock-provider:1234
    Creating rover_node-cli_run ... done
    {"message":"No interaction found for GET /","interaction_diffs":[]}
    But if I run the tests, I get the following:
    Copy code
    docker-compose run --rm node-cli npm run test:mocha:consumer
    Creating rover_node-cli_run ... done
    
    > test:mocha:consumer
    > mocha src/consumer.spec.ts
    
    [2022-03-22 17:21:28.234 +0000] INFO (18 on node-cli): pact-node@10.17.2: Creating Pact Server with options: 
    {"timeout":30000,"consumer":"testingConsumer","cors":false,"dir":"/opt/project/roverctl/pacts","host":"pact-mock-provider","log":"/opt/project/roverctl/stderr","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"testingProvider","spec":2,"ssl":false,"port":1234,"pactFileWriteMode":"overwrite"}
    (node:18) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
    (Use `node --trace-deprecation ...` to show where the warning was created)
    
    
      GraphQL example
        1) "before all" hook in "GraphQL example"
    [2022-03-22 17:21:28.248 +0000] ERROR (18 on node-cli): pact@9.17.3: The pact mock service doesn't appear to be running
      - Please check the logs above to ensure that there are no pact service startup failures
      - Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method)
      - Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one
      - To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG'
        2) "after all" hook in "GraphQL example"
    
    
      0 passing (11ms)
      2 failing
    
      1) GraphQL example
           "before all" hook in "GraphQL example":
         Error: listen EADDRNOTAVAIL: address not available 172.28.0.4:1234
          at Server.setupListenHandle [as _listen2] (node:net:1355:21)
          at listenInCluster (node:net:1420:12)
          at GetAddrInfoReqWrap.doListen (node:net:1559:7)
          at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:74:8)
    
      2) GraphQL example
           "after all" hook in "GraphQL example":
         Error: The pact mock service wasn't running when finalize was called
          at Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:183:9)
          at Context.<anonymous> (src/consumer.spec.ts:33:26)
          at processImmediate (node:internal/timers:466:21)
    m
    • 2
    • 22
  • é

    Édouard Lopez

    03/23/2022, 4:51 PM
    Could you elaborate on the use case for using matcher in the request definition (e.g.
    withRequest
    ). We are in the process of deploying Pact internally and people are this for the wrong reason (e.g. copy/pasting code) https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js#L180
    m
    • 2
    • 4
  • b

    Bernard Baker

    03/24/2022, 11:52 AM
    👋 Hi, I'm seeing this on a passing test.
    Copy code
    pact-node@10.17.2: Pact Binary Error: WARN: No content type found, performing text diff on body
    Any ideas? After a google search I wasn't able to work out how to remove this error from the output of the test run.
    m
    • 2
    • 3
  • d

    Damian

    03/28/2022, 7:35 PM
    Hey everyone, our company is currently trying to integrate Pact into our nx monorepo and we keep running into errors when trying to run the tests. Was curious if anyone has ever integrated Pact into an nx monorepo that uses angular, jest, and cypress. The initial error we're running into is jest and cypress types clashing when running the Pact test. Our monorepo is configured to support both jest/cypress and we have jest tests in other libs that run fine so not sure what about Pact is causing this behavior. (edited)
    👋 1
    y
    • 2
    • 2
12345...14Latest