Agustin Gomes
03/22/2022, 5:23 PMdocker-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:
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)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Agustin Gomes
03/23/2022, 8:43 AMnew Pact
used in the graphQL example I linked, I used new PactWeb
and it worked nicely with the rest of the example.
Thank you for your feedback so far @Matt (pactflow.io / pact-js / pact-go)Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Agustin Gomes
03/23/2022, 2:01 PMit could even be a port conflictI think it's unlikely. The mock server is brought up outside the node ecosystem. From this part of the message I posted above:
Error: listen EADDRNOTAVAIL: address not available 172.28.0.4:1234
I get the feeling Node is trying to start the server without checking if the server is already reachable.Agustin Gomes
03/23/2022, 2:02 PMsetting log level to debug and sharinsg the output might be helpfulI'll try to recreate the situation further.
Agustin Gomes
03/23/2022, 2:04 PMyou shouldn’t need to use PactWeb, and we’re currently planning on decommissioning/stop support for it going forwardThe
PactWeb
I'm refering still part of the @pact-foundation/pact
package, not the @pact-foundation/pact-web
Matt (pactflow.io / pact-js / pact-go)
The mock server is brought up outside the node ecosystem.the port conflict has nothing to do with where the conflict happens - in or out or node
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
1234
? If so, you need to make sure you can a) bind to that port b) it’s free and c) the address you want to bind is corrrect.
172.28.0.4:1234
Looks like you’re not using dynamic port allocation (i.e. you’re hard coding 1234
as the port). Drop the hard coding and it should pick a random free one for youAgustin Gomes
03/28/2022, 3:51 PMservices:
app:
build:
context: /home/agustingomes/pact-project-poc
dockerfile: ./.docker/Dockerfile.node.alpine
container_name: contract-test
environment:
PACT_CONSUMER_NAME: instapro-client
PACT_MOCK_SERVER_HOST: 127.0.0.1
PACT_MOCK_SERVER_PORT: '1234'
PACT_PROVIDER_NAME: pocProvider
hostname: contract-test
network_mode: host
volumes:
- /home/agustingomes/pact-project-poc/contract-tests-poc:/var/www/html:rw
working_dir: /var/www/html
pact-mock-provider:
command: >
mock-service
--port 1234
--host 0.0.0.0
--pact-dir=/tmp/pacts
--consumer=pocConsumer
--provider=pocProvider
--log=/tmp/pacts/mock-provider.log
--log-level=debug
--pact-specification-version=2.0.0
--pact-file-write-mode=overwrite
container_name: pact-mock-provider
expose:
- '1234'
hostname: pact-mock-provider
image: pactfoundation/pact-cli:0.50.0.19
ports:
- published: 1234
target: 1234
volumes:
- /home/agustingomes/pact-project-poc/pacts:/tmp/pacts:rw
working_dir: /pact
version: '3.8'
I start the Mock provider with:
docker-compose up -d pact-mock-provider
And then, I run the test via the app
service I defined in my docker-compose:
docker-compose run --rm app npm run test:contract
And finally, this is how the provider in the test is set up:
import { PactWeb } from "@pact-foundation/pact/src/pact-web"
.
.
.
const provider = new PactWeb({
host: process.env.PACT_MOCK_SERVER_HOST || "",
port: parseInt(process.env.PACT_MOCK_SERVER_PORT || ""),
log: "stderr",
logLevel: "debug",
})
.
.
.
With this setup, I am able to generate the contract:
> mocha src/consumer.spec.ts
Setting up Pact using mock service on port: "1234"
(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 login
login via /graphql
✔ returns a valid token
1 passing (27ms)
Let me know if I can provide you more detailsMatt (pactflow.io / pact-js / pact-go)
PactWeb
interface going forward, and it’s a clumsy setup. I’d like to know why you need to manually run the mock service and you can’t just run the testsMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Agustin Gomes
03/29/2022, 8:06 AMif you could share a reproducible code base, I could run it to see why it doesn’t workI will put together the example I have. Will do it in 2 commits. the first one with
PactWeb
, and the second with Pact
.Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Agustin Gomes
03/29/2022, 1:03 PM