From 2d1386137a0dead98ab035cf09c6a5a55ad7be9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=88zu=CC=88m=20Eldog=CC=86an?= Date: Tue, 7 Dec 2021 13:36:23 +0300 Subject: [PATCH] test: make test compatible with CI --- package-lock.json | 42 ++++++++++++++++++++++++++++++--------- package.json | 2 +- src/util/helper.ts | 1 + test/pg-structure.test.ts | 3 ++- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6143435..6bb9ca7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "@types/json5": "^2.2.0", "@types/lodash.get": "^4.4.6", "@types/node": "^14.14.31", - "@types/pg": "^7.14.3", + "@types/pg": "^8.6.1", "@types/pg-connection-string": "^2.0.0", "@typescript-eslint/eslint-plugin": "^4.15.1", "@typescript-eslint/parser": "^4.15.1", @@ -2893,13 +2893,13 @@ "dev": true }, "node_modules/@types/pg": { - "version": "7.14.11", - "resolved": "https://registry.npmjs.org/@types/pg/-/pg-7.14.11.tgz", - "integrity": "sha512-EnZkZ1OMw9DvNfQkn2MTJrwKmhJYDEs5ujWrPfvseWNoI95N8B4HzU/Ltrq5ZfYxDX/Zg8mTzwr6UAyTjjFvXA==", + "version": "8.6.1", + "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.6.1.tgz", + "integrity": "sha512-1Kc4oAGzAl7uqUStZCDvaLFqZrW9qWSjXOmBfdgyBP5La7Us6Mg4GBvRlSoaZMhQF/zSj1C8CtKMBkoiT8eL8w==", "dev": true, "dependencies": { "@types/node": "*", - "pg-protocol": "^1.2.0", + "pg-protocol": "*", "pg-types": "^2.2.0" } }, @@ -22043,6 +22043,17 @@ "node": ">=10.8.0" } }, + "node_modules/pg-test-util/node_modules/@types/pg": { + "version": "7.14.11", + "resolved": "https://registry.npmjs.org/@types/pg/-/pg-7.14.11.tgz", + "integrity": "sha512-EnZkZ1OMw9DvNfQkn2MTJrwKmhJYDEs5ujWrPfvseWNoI95N8B4HzU/Ltrq5ZfYxDX/Zg8mTzwr6UAyTjjFvXA==", + "dev": true, + "dependencies": { + "@types/node": "*", + "pg-protocol": "^1.2.0", + "pg-types": "^2.2.0" + } + }, "node_modules/pg-types": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", @@ -32974,13 +32985,13 @@ "dev": true }, "@types/pg": { - "version": "7.14.11", - "resolved": "https://registry.npmjs.org/@types/pg/-/pg-7.14.11.tgz", - "integrity": "sha512-EnZkZ1OMw9DvNfQkn2MTJrwKmhJYDEs5ujWrPfvseWNoI95N8B4HzU/Ltrq5ZfYxDX/Zg8mTzwr6UAyTjjFvXA==", + "version": "8.6.1", + "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.6.1.tgz", + "integrity": "sha512-1Kc4oAGzAl7uqUStZCDvaLFqZrW9qWSjXOmBfdgyBP5La7Us6Mg4GBvRlSoaZMhQF/zSj1C8CtKMBkoiT8eL8w==", "dev": true, "requires": { "@types/node": "*", - "pg-protocol": "^1.2.0", + "pg-protocol": "*", "pg-types": "^2.2.0" } }, @@ -48079,6 +48090,19 @@ "pg-connection-string": "^2.2.3", "pg-escape": "^0.2.0", "verror": "^1.10.0" + }, + "dependencies": { + "@types/pg": { + "version": "7.14.11", + "resolved": "https://registry.npmjs.org/@types/pg/-/pg-7.14.11.tgz", + "integrity": "sha512-EnZkZ1OMw9DvNfQkn2MTJrwKmhJYDEs5ujWrPfvseWNoI95N8B4HzU/Ltrq5ZfYxDX/Zg8mTzwr6UAyTjjFvXA==", + "dev": true, + "requires": { + "@types/node": "*", + "pg-protocol": "^1.2.0", + "pg-types": "^2.2.0" + } + } } }, "pg-types": { diff --git a/package.json b/package.json index 2e98b7f..087d58f 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@types/json5": "^2.2.0", "@types/lodash.get": "^4.4.6", "@types/node": "^14.14.31", - "@types/pg": "^7.14.3", + "@types/pg": "^8.6.1", "@types/pg-connection-string": "^2.0.0", "@typescript-eslint/eslint-plugin": "^4.15.1", "@typescript-eslint/parser": "^4.15.1", diff --git a/src/util/helper.ts b/src/util/helper.ts index e5e19da..2ff4c8d 100644 --- a/src/util/helper.ts +++ b/src/util/helper.ts @@ -201,6 +201,7 @@ export async function getConnectedPgClient( return { client, shouldCloseConnection: true }; } catch (error: any) { if (error.message.includes("Client has already been connected")) return { client, shouldCloseConnection: false }; + /* istanbul ignore next */ throw new Error(`pg-structure cannot connect to the database: ${error.message}`); } } diff --git a/test/pg-structure.test.ts b/test/pg-structure.test.ts index 7afe36a..e095c86 100644 --- a/test/pg-structure.test.ts +++ b/test/pg-structure.test.ts @@ -84,11 +84,12 @@ describe("pgStructure()", () => { }); it("should throw if it cannot connect.", async () => { - await expect(pgStructure()).rejects.toThrow("cannot connect to the database"); + await expect(pgStructure()).rejects.toThrow(); }); it("should accept options as first argument and reads client config from environment variables.", async () => { process.env.DBPX_USER = "xyz-user"; + process.env.DBPX_PASSWORD = "wrong-password"; await expect(pgStructure({ envPrefix: "DBPX", name: "deneme" })).rejects.toThrow('password authentication failed for user "xyz-user"'); }); });