From e0a930b73898ae5340f60583d37a44f64aa58720 Mon Sep 17 00:00:00 2001 From: Myrotvorets Date: Sat, 27 Jan 2024 04:41:21 +0200 Subject: [PATCH] Remove chai-as-promised --- mocha.setup.mjs | 4 - package-lock.json | 139 +++++++++++++------------------- package.json | 4 +- test/functional/lib/db.test.mts | 4 +- test/unit/lib/utils.test.mts | 7 +- test/unit/lib/wpapi.test.mts | 17 ++-- 6 files changed, 74 insertions(+), 101 deletions(-) diff --git a/mocha.setup.mjs b/mocha.setup.mjs index d130b38f..765421c1 100644 --- a/mocha.setup.mjs +++ b/mocha.setup.mjs @@ -1,9 +1,5 @@ -import { use } from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import { reset } from 'testdouble'; -use(chaiAsPromised); - const env = { ...process.env }; process.env = { NODE_ENV: 'test', diff --git a/package-lock.json b/package-lock.json index a7aa2e02..b040c4e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,6 @@ "devDependencies": { "@myrotvorets/eslint-config-myrotvorets-ts": "^2.24.0", "@types/chai": "^4.3.11", - "@types/chai-as-promised": "^7.1.8", "@types/debug": "^4.1.12", "@types/localtunnel": "^2.0.4", "@types/mocha": "^10.0.6", @@ -35,9 +34,8 @@ "@types/node-fetch": "^2.6.11", "@types/supertest": "^6.0.2", "better-sqlite3": "^9.3.0", - "c8": "^8.0.1", - "chai": "^4.4.1", - "chai-as-promised": "^7.1.1", + "c8": "^9.1.0", + "chai": "^5.0.3", "eslint-formatter-gha": "^1.4.3", "eslint-plugin-mocha": "^10.2.0", "husky": "^9.0.6", @@ -1216,15 +1214,6 @@ "integrity": "sha512-qQR1dr2rGIHYlJulmr8Ioq3De0Le9E4MJ5AiaeAETJJpndT1uUNHsGFK3L/UIu+rbkQSdj8J/w2bCsBZc/Y5fQ==", "dev": true }, - "node_modules/@types/chai-as-promised": { - "version": "7.1.8", - "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz", - "integrity": "sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw==", - "dev": true, - "dependencies": { - "@types/chai": "*" - } - }, "node_modules/@types/cookiejar": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz", @@ -1832,12 +1821,12 @@ "dev": true }, "node_modules/assertion-error": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", "dev": true, "engines": { - "node": "*" + "node": ">=12" } }, "node_modules/asynckit": { @@ -1994,19 +1983,18 @@ } }, "node_modules/c8": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/c8/-/c8-8.0.1.tgz", - "integrity": "sha512-EINpopxZNH1mETuI0DzRA4MZpAUH+IFiRhnmFD3vFr3vdrgxqi3VfE3KL0AIL+zDq8rC9bZqwM/VDmmoe04y7w==", + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/c8/-/c8-9.1.0.tgz", + "integrity": "sha512-mBWcT5iqNir1zIkzSPyI3NCR9EZCVI3WUD+AVO17MVWTSFNyUueXE82qTeampNtTr+ilN/5Ua3j24LgbCKjDVg==", "dev": true, "dependencies": { "@bcoe/v8-coverage": "^0.2.3", "@istanbuljs/schema": "^0.1.3", "find-up": "^5.0.0", - "foreground-child": "^2.0.0", + "foreground-child": "^3.1.1", "istanbul-lib-coverage": "^3.2.0", "istanbul-lib-report": "^3.0.1", "istanbul-reports": "^3.1.6", - "rimraf": "^3.0.2", "test-exclude": "^6.0.0", "v8-to-istanbul": "^9.0.0", "yargs": "^17.7.2", @@ -2016,7 +2004,7 @@ "c8": "bin/c8.js" }, "engines": { - "node": ">=12" + "node": ">=14.14.0" } }, "node_modules/call-bind": { @@ -2056,33 +2044,28 @@ } }, "node_modules/chai": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.4.1.tgz", - "integrity": "sha512-13sOfMv2+DWduEU+/xbun3LScLoqN17nBeTLUsmDfKdoiC1fr0n9PU4guu4AhRcOVFk/sW8LyZWHuhWtQZiF+g==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/chai/-/chai-5.0.3.tgz", + "integrity": "sha512-wKGCtYv2kVY5WEjKqQ3fSIZWtTFveZCtzinhTZbx3/trVkxefiwovhpU9kRVCwxvKKCEjTWXPdM1/T7zPoDgow==", "dev": true, "dependencies": { - "assertion-error": "^1.1.0", - "check-error": "^1.0.3", - "deep-eql": "^4.1.3", - "get-func-name": "^2.0.2", - "loupe": "^2.3.6", - "pathval": "^1.1.1", - "type-detect": "^4.0.8" + "assertion-error": "^2.0.1", + "check-error": "^2.0.0", + "deep-eql": "^5.0.1", + "loupe": "^3.1.0", + "pathval": "^2.0.0" }, "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/chai-as-promised": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz", - "integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==", + "node_modules/chai/node_modules/check-error": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.0.0.tgz", + "integrity": "sha512-tjLAOBHKVxtPoHe/SA7kNOMvhCRdCJ3vETdeY0RuAc9popf+hyaSV6ZEg9hr4cpWF7jmo/JSWEnLDrnijS9Tog==", "dev": true, - "dependencies": { - "check-error": "^1.0.2" - }, - "peerDependencies": { - "chai": ">= 2.1.2 < 5" + "engines": { + "node": ">= 16" } }, "node_modules/chalk": { @@ -2101,18 +2084,6 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/check-error": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", - "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", - "dev": true, - "dependencies": { - "get-func-name": "^2.0.2" - }, - "engines": { - "node": "*" - } - }, "node_modules/chokidar": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", @@ -2389,13 +2360,10 @@ } }, "node_modules/deep-eql": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", - "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.1.tgz", + "integrity": "sha512-nwQCf6ne2gez3o1MxWifqkciwt0zhl0LO1/UwVu4uMBuPmflWM4oQ70XMqHqnBJA+nhzncaqL9HVL6KkHJ28lw==", "dev": true, - "dependencies": { - "type-detect": "^4.0.0" - }, "engines": { "node": ">=6" } @@ -3434,16 +3402,31 @@ } }, "node_modules/foreground-child": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", - "integrity": "sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", "dev": true, "dependencies": { "cross-spawn": "^7.0.0", - "signal-exit": "^3.0.2" + "signal-exit": "^4.0.1" }, "engines": { - "node": ">=8.0.0" + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/foreground-child/node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/form-data": { @@ -4937,9 +4920,9 @@ "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" }, "node_modules/loupe": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", - "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.1.0.tgz", + "integrity": "sha512-qKl+FrLXUhFuHUoDJG7f8P8gEMHq9NFS0c6ghXG1J0rldmZFQZoNVv/vyirE9qwCIhWZDsvEFd1sbFu3GvRQFg==", "dev": true, "dependencies": { "get-func-name": "^2.0.1" @@ -5773,12 +5756,12 @@ } }, "node_modules/pathval": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", - "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.0.tgz", + "integrity": "sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==", "dev": true, "engines": { - "node": "*" + "node": ">= 14.16" } }, "node_modules/pg-connection-string": { @@ -6183,6 +6166,7 @@ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "dev": true, + "peer": true, "dependencies": { "glob": "^7.1.3" }, @@ -7013,15 +6997,6 @@ "node": ">= 0.8.0" } }, - "node_modules/type-detect": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true, - "engines": { - "node": ">=4" - } - }, "node_modules/type-fest": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", diff --git a/package.json b/package.json index 91afe390..49284bf2 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "test": "mocha", "test:coverage": "c8 mocha", "preversion": "npm test", - "postinstall": "husky install || true" + "postinstall": "husky || true" }, "author": "Myrotvorets (https://myrotvorets.center/)", "license": "MIT", @@ -37,7 +37,6 @@ "devDependencies": { "@myrotvorets/eslint-config-myrotvorets-ts": "^2.24.0", "@types/chai": "^4.3.11", - "@types/chai-as-promised": "^7.1.8", "@types/debug": "^4.1.12", "@types/localtunnel": "^2.0.4", "@types/mocha": "^10.0.6", @@ -47,7 +46,6 @@ "better-sqlite3": "^9.3.0", "c8": "^9.1.0", "chai": "^5.0.3", - "chai-as-promised": "^7.1.1", "eslint-formatter-gha": "^1.4.3", "eslint-plugin-mocha": "^10.2.0", "husky": "^9.0.6", diff --git a/test/functional/lib/db.test.mts b/test/functional/lib/db.test.mts index 08a7978f..3fe5a076 100644 --- a/test/functional/lib/db.test.mts +++ b/test/functional/lib/db.test.mts @@ -29,8 +29,8 @@ describe('Database', function () { it('should insert a new row', async function () { await addPost(trx, 1); - return expect(trx.select('post_id').from('posts').where('post_id', 1).first()).to.eventually.not.be - .undefined; + const post = await trx.select('post_id').from('posts').where('post_id', 1).first(); + return expect(post).not.be.undefined; }); it('should return an array with the new post ID', async function () { diff --git a/test/unit/lib/utils.test.mts b/test/unit/lib/utils.test.mts index e27a9ebd..74e16aa1 100644 --- a/test/unit/lib/utils.test.mts +++ b/test/unit/lib/utils.test.mts @@ -102,12 +102,15 @@ describe('Utils', function () { it('should throw when the file cannot be located', function () { when(statMock(matchers.isA(String) as string)).thenReject(new Error()); - return expect(findFile('package.json')).to.be.rejectedWith(Error); + return findFile('package.json').then( + () => expect.fail('Should have thrown'), + (err) => expect(err).to.be.an('Error'), + ); }); it('should retrieve name and version from package.json', function () { when(statMock(matchers.isA(String) as string)).thenResolve({ isFile: () => true }); - return expect(findFile('package.json')).to.be.fulfilled; + return findFile('package.json').then((result) => expect(result).to.be.a('string')); }); }); }); diff --git a/test/unit/lib/wpapi.test.mts b/test/unit/lib/wpapi.test.mts index d97e8525..1afcde4b 100644 --- a/test/unit/lib/wpapi.test.mts +++ b/test/unit/lib/wpapi.test.mts @@ -21,7 +21,7 @@ describe('wpapi', function () { }); describe('getPosts', function () { - it('should properly extract data', function () { + it('should properly extract data', async function () { when(fetchMock(matchers.isA(String) as string)).thenResolve(new Response(JSON.stringify(getPostsResponse))); const expected: PostData[] = [ @@ -41,27 +41,28 @@ describe('wpapi', function () { }, ]; - return expect(getPosts('https://example.test')).to.become(expected); + const post = await getPosts('https://example.test'); + return expect(post).to.deep.equal(expected); }); }); describe('getFeaturedImageURL', function () { - it('should return image URL', function () { + it('should return image URL', async function () { when(fetchMock(matchers.isA(String) as string)).thenResolve( new Response(JSON.stringify(getFeaturedImageResponse)), ); - return expect(getFeaturedImageUrl('https://example.test', 43762)).to.become( - 'https://myrotvorets.news/wp-content/uploads/2019/10/Screenshot_5-3.png', - ); + const url = await getFeaturedImageUrl('https://example.test', 43762); + return expect(url).to.equal('https://myrotvorets.news/wp-content/uploads/2019/10/Screenshot_5-3.png'); }); - it('should return empty URL if the original image URL is malformed', function () { + it('should return empty URL if the original image URL is malformed', async function () { when(fetchMock(matchers.isA(String) as string)).thenResolve( new Response(JSON.stringify(getFeaturedImageResponseBadURL)), ); - return expect(getFeaturedImageUrl('https://example.test', 43762)).to.become(''); + const url = await getFeaturedImageUrl('https://example.test', 43762); + return expect(url).to.equal(''); }); }); });