From f49831744f4cc572630cbbbc42a256df08c4208c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 20:14:22 +0000 Subject: [PATCH 1/6] chore(deps-dev): bump nock from 13.5.6 to 14.0.3 in /packages/web-api Bumps [nock](https://github.com/nock/nock) from 13.5.6 to 14.0.3. - [Release notes](https://github.com/nock/nock/releases) - [Changelog](https://github.com/nock/nock/blob/main/CHANGELOG.md) - [Commits](https://github.com/nock/nock/compare/v13.5.6...v14.0.3) --- updated-dependencies: - dependency-name: nock dependency-version: 14.0.3 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- packages/web-api/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-api/package.json b/packages/web-api/package.json index 8b4620228..1f9ff236b 100644 --- a/packages/web-api/package.json +++ b/packages/web-api/package.json @@ -61,7 +61,7 @@ "mocha": "^11", "mocha-junit-reporter": "^2.2.1", "mocha-multi-reporters": "^1.5.1", - "nock": "^13", + "nock": "^14", "shx": "^0.4.0", "sinon": "^20", "source-map-support": "^0.5.21", From c122f5ba669b6fbaee53d8e21230df0d722106a1 Mon Sep 17 00:00:00 2001 From: William Bergamin Date: Thu, 17 Apr 2025 09:55:45 -0400 Subject: [PATCH 2/6] Fix disallowed undefined header in test --- packages/web-api/src/WebClient.spec.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/web-api/src/WebClient.spec.ts b/packages/web-api/src/WebClient.spec.ts index bbade1d90..bad16cbf8 100644 --- a/packages/web-api/src/WebClient.spec.ts +++ b/packages/web-api/src/WebClient.spec.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import axios, { type InternalAxiosRequestConfig } from 'axios'; import { assert, expect } from 'chai'; -import nock from 'nock'; +import nock, { type ReplyHeaders } from 'nock'; import sinon from 'sinon'; import { type RequestConfig, @@ -1102,14 +1102,15 @@ describe('WebClient', () => { }); it('should throw an error if the response has no retry info', async () => { - // @ts-expect-error header values cannot be undefined - const scope = nock('https://slack.com').post(/api/).reply(429, {}, { 'retry-after': undefined }); + const emptyHeaders: ReplyHeaders = {}; + const scope = nock('https://slack.com').post(/api/).reply(429, {}, emptyHeaders); const client = new WebClient(token); try { await client.apiCall('method'); assert.fail('expected error to be thrown'); } catch (err) { assert.instanceOf(err, Error); + } finally { scope.done(); } }); From b1f6cfa64e97d41e455343b8ecd1a55b445e1750 Mon Sep 17 00:00:00 2001 From: William Bergamin Date: Thu, 17 Apr 2025 10:07:04 -0400 Subject: [PATCH 3/6] Use typing to our advantage --- packages/web-api/src/WebClient.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-api/src/WebClient.spec.ts b/packages/web-api/src/WebClient.spec.ts index bad16cbf8..2c1914c4f 100644 --- a/packages/web-api/src/WebClient.spec.ts +++ b/packages/web-api/src/WebClient.spec.ts @@ -1102,7 +1102,7 @@ describe('WebClient', () => { }); it('should throw an error if the response has no retry info', async () => { - const emptyHeaders: ReplyHeaders = {}; + const emptyHeaders: ReplyHeaders & { 'retry-after'?: never } = {}; // Ensure that 'retry-after' is not in the headers const scope = nock('https://slack.com').post(/api/).reply(429, {}, emptyHeaders); const client = new WebClient(token); try { From 186b76c0efc8f3b0a323b961354fcda1a7f385fe Mon Sep 17 00:00:00 2001 From: William Bergamin Date: Thu, 17 Apr 2025 11:03:32 -0400 Subject: [PATCH 4/6] Will this make the tests more stable? --- packages/web-api/src/WebClient.spec.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/web-api/src/WebClient.spec.ts b/packages/web-api/src/WebClient.spec.ts index 2c1914c4f..bff5e0e04 100644 --- a/packages/web-api/src/WebClient.spec.ts +++ b/packages/web-api/src/WebClient.spec.ts @@ -802,11 +802,9 @@ describe('WebClient', () => { describe('has an option to set request concurrency', () => { // TODO: factor out common logic into test helpers const responseDelay = 100; // ms - let testStart: number; let scope: nock.Scope; beforeEach(() => { - testStart = Date.now(); scope = nock('https://slack.com') .persist() .post(/api/) @@ -814,7 +812,10 @@ describe('WebClient', () => { .reply((_uri, _requestBody) => { // NOTE: the assumption is that this function gets called right away when the request body is available, // not after the delay - const diff = Date.now() - testStart; + const now = Date.now(); + const paths = _uri.split('/'); // "/api/99/1744901290437" -> "", "api", "99", "1744901290437" + const requestTimeSent = Number(paths[3]); + const diff = now - requestTimeSent; return [200, JSON.stringify({ ok: true, diff })]; }); }); @@ -825,9 +826,9 @@ describe('WebClient', () => { it('should have a default conncurrency of 100', async () => { const client = new WebClient(token); - const requests = []; + const requests: Promise[] = []; for (let i = 0; i < 101; i++) { - requests.push(client.apiCall(`${i}`)); + requests.push(client.apiCall(`${i}/${Date.now()}`)); } const responses = (await Promise.all(requests)) as (WebAPICallResult & { diff: number })[]; // verify all responses are present @@ -847,7 +848,7 @@ describe('WebClient', () => { it('should allow concurrency to be set', async () => { const client = new WebClient(token, { maxRequestConcurrency: 1 }); - const requests = [client.apiCall('1'), client.apiCall('2')]; + const requests = [client.apiCall(`1/${Date.now()}`), client.apiCall(`2/${Date.now()}`)]; const responses = (await Promise.all(requests)) as (WebAPICallResult & { diff: number })[]; // verify all responses are present assert.lengthOf(responses, 2); From 2de0c5b50ebcb5553b440a1084a13f7551c83373 Mon Sep 17 00:00:00 2001 From: William Bergamin Date: Thu, 17 Apr 2025 11:09:05 -0400 Subject: [PATCH 5/6] make things more stable --- packages/web-api/src/WebClient.spec.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/web-api/src/WebClient.spec.ts b/packages/web-api/src/WebClient.spec.ts index bff5e0e04..a613a5149 100644 --- a/packages/web-api/src/WebClient.spec.ts +++ b/packages/web-api/src/WebClient.spec.ts @@ -801,10 +801,12 @@ describe('WebClient', () => { describe('has an option to set request concurrency', () => { // TODO: factor out common logic into test helpers - const responseDelay = 100; // ms + const responseDelay = 500; // ms + let testStart: number; let scope: nock.Scope; beforeEach(() => { + testStart = Date.now(); scope = nock('https://slack.com') .persist() .post(/api/) @@ -812,10 +814,7 @@ describe('WebClient', () => { .reply((_uri, _requestBody) => { // NOTE: the assumption is that this function gets called right away when the request body is available, // not after the delay - const now = Date.now(); - const paths = _uri.split('/'); // "/api/99/1744901290437" -> "", "api", "99", "1744901290437" - const requestTimeSent = Number(paths[3]); - const diff = now - requestTimeSent; + const diff = Date.now() - testStart; return [200, JSON.stringify({ ok: true, diff })]; }); }); @@ -828,7 +827,7 @@ describe('WebClient', () => { const client = new WebClient(token); const requests: Promise[] = []; for (let i = 0; i < 101; i++) { - requests.push(client.apiCall(`${i}/${Date.now()}`)); + requests.push(client.apiCall(`${i}`)); } const responses = (await Promise.all(requests)) as (WebAPICallResult & { diff: number })[]; // verify all responses are present @@ -848,7 +847,7 @@ describe('WebClient', () => { it('should allow concurrency to be set', async () => { const client = new WebClient(token, { maxRequestConcurrency: 1 }); - const requests = [client.apiCall(`1/${Date.now()}`), client.apiCall(`2/${Date.now()}`)]; + const requests = [client.apiCall('1'), client.apiCall('2')]; const responses = (await Promise.all(requests)) as (WebAPICallResult & { diff: number })[]; // verify all responses are present assert.lengthOf(responses, 2); From ff37c5cb2a767efafb639b6fdee8fd4eb6ebe55f Mon Sep 17 00:00:00 2001 From: William Bergamin Date: Thu, 17 Apr 2025 11:12:30 -0400 Subject: [PATCH 6/6] clean up changes --- packages/web-api/src/WebClient.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-api/src/WebClient.spec.ts b/packages/web-api/src/WebClient.spec.ts index a613a5149..72ffbcdf0 100644 --- a/packages/web-api/src/WebClient.spec.ts +++ b/packages/web-api/src/WebClient.spec.ts @@ -825,7 +825,7 @@ describe('WebClient', () => { it('should have a default conncurrency of 100', async () => { const client = new WebClient(token); - const requests: Promise[] = []; + const requests = []; for (let i = 0; i < 101; i++) { requests.push(client.apiCall(`${i}`)); }