From 6ff1b1d98731043d93e486b88fe2a101ddd9ab7c Mon Sep 17 00:00:00 2001 From: Isaac Au Date: Tue, 14 Jan 2025 09:54:37 +0000 Subject: [PATCH] ATO-1237: fix test running in github - Due to a a difference in node version from the lambda and Github (18,20) this has caused a know issue where node uses ipv4 or ipv6 by default depending on node version. Setting the localhost to a default ipv4 has not worked. This has caused some de synced behaviour when running the pact tests and due to the code setting the httpAgent in axios is a bigger change than we would like at this moment. Solution is to seperate out the running of the pact tests for now. More information on: https://github.com/pact-foundation/pact-js/issues/1066 --- backend/api/tests/contract-tests/package.json | 2 +- .../tests/testClientRegistryContract.spec.ts | 30 +++++++++++-------- package.json | 4 +-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/backend/api/tests/contract-tests/package.json b/backend/api/tests/contract-tests/package.json index 91647008d..9deb1e67e 100644 --- a/backend/api/tests/contract-tests/package.json +++ b/backend/api/tests/contract-tests/package.json @@ -9,7 +9,7 @@ "build": "npm run buildts && npm run buildjs", "publish": "node dist/provider/publish.js", "test": "npm run publish && jest", - "test:pact": "jest" + "test:pact": "jest --detectOpenHandles -runInBand" }, "author": "", "license": "ISC", diff --git a/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts b/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts index f0d5f9930..f24645b44 100644 --- a/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts +++ b/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts @@ -8,22 +8,19 @@ import {clientRegistryResponse} from "../../../src/handlers/types/client-registr import {mockLambdaContext} from "../../handlers/utils"; import {updateClientInRegistryHandler, UpdateClientPayload} from "../../../src/handlers/auth/update-client"; -beforeAll((): void => { - jest.setTimeout(200000); -}); - describe("ClientRegistryProvider", () => { const {like} = MatchersV3; - const provider = new PactV3({ - dir: path.resolve(process.cwd(), "pacts"), - logLevel: "debug", - port: 8080, - consumer: "SSEAdminAPIClient", - provider: "ClientRegistryProvider" - }); - describe("When a POST request is made to create a client", () => { + const provider = new PactV3({ + dir: path.resolve(process.cwd(), "pacts"), + logLevel: "debug", + port: 8080, + host: "127.0.0.1", + consumer: "SSEAdminAPIClient", + provider: "ClientRegistryProvider" + }); + const postEvent: RegisterClientPayload = { contactEmail: "pacttest.account@digital.cabinet-office.gov.uk", service: { @@ -88,6 +85,15 @@ describe("ClientRegistryProvider", () => { }); describe("When a PUT request is made to update a client", () => { + const provider = new PactV3({ + dir: path.resolve(process.cwd(), "pacts"), + logLevel: "debug", + port: 8081, + host: "127.0.0.1", + consumer: "SSEAdminAPIClient", + provider: "ClientRegistryProvider" + }); + const updatesForClient = { contacts: ["new.email@digital.cabinet-office.gov.uk"], subject_type: "pairwise" diff --git a/package.json b/package.json index 462c50985..cd7ae2557 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "list": "infrastructure/dev/deploy.sh list", "open": "infrastructure/dev/deploy.sh open", "creds": "infrastructure/aws.sh", - "test": "jest --silent", - "test:cov": "jest --silent --coverage", + "test": "jest --runInBand", + "test:cov": "jest --coverage", "lint": "prettier . --check ; eslint '*.ts' --quiet --fix", "lint:fix": "prettier . --write ; eslint . --fix", "pii-scan": "infrastructure/dev/pii_scan.sh -p *template*.yml -i infrastructure/config/pii_scan_ignore.txt -s infrastructure/config/pii_scan_skip.txt"