https://pact.io logo
#pact-js
Title
# pact-js
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
Copy code
"use strict"

const { Pact } = require("@pact-foundation/pact")
const path = require('path');
const {eachLike} = require("@pact-foundation/pact/src/dsl/matchers");
const Constant = require("../src/Constant");
const API_HOST = "<http://localhost:7000/dev/>"
const provider = new Pact({
    consumer: 'portal-ui',
    provider: 'portal',
    port: 7000,
    log: path.resolve(process.cwd(), 'logs', 'pact.log'),
    dir: path.resolve(process.cwd(), 'pacts'),
    logLevel: 'DEBUG',
});
describe('SiteSpeed Details Service', () => {
    describe('Wanted to get SiteSpeed Details', () => {
        beforeAll(() =>
            provider.setup().then(() => {
                provider.addInteraction({
                    uponReceiving: 'a request to list sitespeed details',
                    withRequest: {
                        method: 'GET',
                        path: API_HOST+'portal/v1/sitespeed/pages?executionId=4660',
                    },
                    willRespondWith: {
                        status: 200,
                        body: eachLike(
                            {
                                execution_id: 4660,
                                execution_page_id: 8207,
                                first_contentful_paint_median: 6791,
                            },
                            { min: 1 }
                        ),
                    },
                });
            })
        );

       it('should return the correct data',  async() => {
            const sitespeed =  await fetch(API_HOST+'sitespeed/pages?executionId=4660');
            const response =   await sitespeed.json();
            expect(response[0].execution_id).toBe(4660);
            expect(response[0].execution_page_id).toBe(8207);
        });

        afterEach(() => provider.verify());
        afterAll(() => provider.finalize());
    });
});
m

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

02/24/2022, 11:05 AM
can you please share the
pact.log
and terminal output? It should show us there why it’s not working
btw the path looks incorrect to me, the query string should be moved into
query
we could probably detect that case and warn
a

Ayush

02/24/2022, 11:10 AM
Here’s the pact.log file
Copy code
I, [2022-02-24T16:27:48.550621 #29652]  INFO -- : Verifying - interactions matched
I, [2022-02-24T16:27:48.552026 #29652]  INFO -- : Registered expected interaction GET <http://localhost:7000/dev/sitespeed/pages?executionId=4660>
D, [2022-02-24T16:27:48.552434 #29652] DEBUG -- : {
  "description": "a request to list sitespeed details",
  "request": {
    "method": "GET",
    "path": "<http://localhost:7000/dev/sitespeed/pages?executionId=4660>"
  },
  "response": {
    "status": 200,
    "headers": {
    },
    "body": {
      "json_class": "Pact::ArrayLike",
      "contents": {
        "execution_id": 4660,
        "execution_page_id": 8207,
        "first_contentful_paint_median": 6791,
      },
      "min": 1
    }
  },
  "metadata": null
}
I, [2022-02-24T16:27:48.558270 #29652]  INFO -- : Cleared interactions
m

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

02/24/2022, 11:13 AM
notice how there are no logs indicating it received a request from your client before the interactions are cleared? I suspect there is a promise mishandling going on
Is it possible something else is running on port 7000? ALso, the terminal output would be helpful please
a

Ayush

02/24/2022, 11:19 AM
yes there was something else running on port 7000 , i closed it and reran the test but still no pact got generated Here’s the console output
Copy code
[2022-02-24 11:17:53.297 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Creating Pact Server with options: 
{"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"INFO","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"}
[2022-02-24 11:17:54.873 +0000] INFO (32372 on C02YQC2LLVCG): pact@9.17.2: Setting up Pact with Consumer "qe-portal-ui" and Provider "qe-portal"
    using mock service on Port: "7000"
[2022-02-24 11:17:54.901 +0000] INFO (32372 on C02YQC2LLVCG): pact@9.17.2: Pact File Written
[2022-02-24 11:17:54.902 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Removing Pact process with PID: 32539
[2022-02-24 11:17:54.910 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Deleting Pact Server with options: 
{"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"INFO","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"}
and here’s the console output with debug log level
Copy code
/Users/athaper/.asdf/shims/node --require /Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-stdin-fix.js /Users/athaper/Repo/qe-portal-ui/node_modules/jest/bin/jest.js --colors --reporters /Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-reporter.js --verbose --testNamePattern=^SiteSpeed Details Service  --runTestsByPath /Users/athaper/Repo/qe-portal-ui/contract_tests/sitespeed_execution.spec.js
[2022-02-24 11:20:16.971 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Creating Pact Server with options: 
{"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"}
[2022-02-24 11:20:16.993 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: Starting pact binary '/Users/athaper/Repo/qe-portal-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.81/pact/bin/pact-mock-service', with arguments [service --consumer qe-portal-ui --cors false --pact_dir /Users/athaper/Repo/qe-portal-ui/pacts --host 127.0.0.1 --log /Users/athaper/Repo/qe-portal-ui/logs/pact.log --log-level DEBUG --provider qe-portal --pact_specification_version 2 --ssl false --port 7000 --pact-file-write-mode overwrite]
[2022-02-24 11:20:17.002 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: Created '/Users/athaper/Repo/qe-portal-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.81/pact/bin/pact-mock-service' process with PID: 32945
[2022-02-24 11:20:17.803 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO  WEBrick 1.3.1
INFO  ruby 2.2.2 (2015-04-13) [x86_64-darwin13]

[2022-02-24 11:20:17.803 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO  WEBrick::HTTPServer#start: pid=32945 port=7000

[2022-02-24 11:20:18.049 +0000] INFO (32777 on C02YQC2LLVCG): pact@9.17.2: Setting up Pact with Consumer "qe-portal-ui" and Provider "qe-portal"
    using mock service on Port: "7000"
[2022-02-24 11:20:18.078 +0000] INFO (32777 on C02YQC2LLVCG): pact@9.17.2: Pact File Written
[2022-02-24 11:20:18.078 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Removing Pact process with PID: 32945
[2022-02-24 11:20:18.083 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO  going to shutdown ...
INFO  WEBrick::HTTPServer#start done.

[2022-02-24 11:20:18.084 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Deleting Pact Server with options: 
{"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"}
m

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

02/24/2022, 11:38 AM
and
/Users/athaper/Repo/qe-portal-ui/pacts
is empty?
a

Ayush

02/24/2022, 11:39 AM
Yep!
m

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

02/24/2022, 11:40 AM
strange
definitely no Ruby processes hanging about
Copy code
ps -ef | grep ruby
a

Ayush

02/24/2022, 11:44 AM
only seeing this one
We’re using jest already for UTs and installed pact jest , is it possible that something might be conflicting ? Here are the dependencies in our package.json
Copy code
"@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^12.0.0",
    "autoprefixer": "^6.7.2",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^23.4.2",
    "babel-loader": "^8.0.0",
    "c3": "^0.4.23",
    "css-loader": "^0.26.1",
    "file-loader": "^0.10.1",
    "group-array": "^0.3.3",
    "history": "^5.0.0",
    "immutable": "^4.0.0-rc.12",
    "jest": "^27.0.6",
    "jest-pact": "^0.9.1",
3 Views