diff --git a/package.json b/package.json index 4c08d1f9ec..f67d2ae4d2 100644 --- a/package.json +++ b/package.json @@ -172,7 +172,7 @@ "@types/pg": "8.10.9", "@types/semver": "7.5.6", "@types/stoppable": "1.1.3", - "@types/supertest": "2.0.16", + "@types/supertest": "6.0.2", "@types/type-is": "1.6.6", "@types/uuid": "9.0.7", "concurrently": "^8.0.1", diff --git a/src/lib/features/client-feature-toggles/tests/client-feature-toggle.e2e.test.ts b/src/lib/features/client-feature-toggles/tests/client-feature-toggle.e2e.test.ts index 68df2cd6af..7f21a2d8e1 100644 --- a/src/lib/features/client-feature-toggles/tests/client-feature-toggle.e2e.test.ts +++ b/src/lib/features/client-feature-toggles/tests/client-feature-toggle.e2e.test.ts @@ -1,4 +1,4 @@ -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import createStores from '../../../../test/fixtures/store'; import getLogger from '../../../../test/fixtures/no-logger'; import getApp from '../../../app'; @@ -9,6 +9,7 @@ import { secondsToMilliseconds } from 'date-fns'; import { ClientSpecService } from '../../../services/client-spec-service'; import { Application } from 'express'; import { IFlagResolver } from '../../../types'; +import TestAgent from 'supertest/lib/agent'; let app: Application; @@ -41,7 +42,7 @@ const callGetAll = async (controller: FeatureController) => { }; let base: string; -let request: supertest.SuperTest; +let request: TestAgent; let flagResolver: Partial; diff --git a/src/lib/features/metrics/instance/metrics.test.ts b/src/lib/features/metrics/instance/metrics.test.ts index 29c4cbca05..ad86000788 100644 --- a/src/lib/features/metrics/instance/metrics.test.ts +++ b/src/lib/features/metrics/instance/metrics.test.ts @@ -1,4 +1,4 @@ -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import getApp from '../../../app'; import { createTestConfig } from '../../../../test/config/test-config'; import { clientMetricsSchema } from '../shared/schema'; @@ -12,6 +12,7 @@ import { import dbInit, { ITestDb } from '../../../../test/e2e/helpers/database-init'; import { subMinutes } from 'date-fns'; import { ApiTokenType } from '../../../types/models/api-token'; +import TestAgent from 'supertest/lib/agent'; let db: ITestDb; @@ -30,7 +31,7 @@ async function getSetup(opts?: IUnleashOptions) { }; } -let request: supertest.SuperTest; +let request: TestAgent; let stores: IUnleashStores; let services: IUnleashServices; let destroy: () => Promise; diff --git a/src/lib/features/metrics/instance/register.test.ts b/src/lib/features/metrics/instance/register.test.ts index d11865b77a..fcdb620ea3 100644 --- a/src/lib/features/metrics/instance/register.test.ts +++ b/src/lib/features/metrics/instance/register.test.ts @@ -1,9 +1,10 @@ -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import { createTestConfig } from '../../../../test/config/test-config'; import createStores from '../../../../test/fixtures/store'; import getLogger from '../../../../test/fixtures/no-logger'; import getApp from '../../../app'; import { createServices } from '../../../services'; +import TestAgent from 'supertest/lib/agent'; async function getSetup() { const stores = createStores(); @@ -16,7 +17,7 @@ async function getSetup() { stores, }; } -let request: supertest.SuperTest; +let request: TestAgent; beforeEach(async () => { const setup = await getSetup(); request = setup.request; diff --git a/src/lib/routes/admin-api/config.test.ts b/src/lib/routes/admin-api/config.test.ts index 9a3395194f..562de5eba1 100644 --- a/src/lib/routes/admin-api/config.test.ts +++ b/src/lib/routes/admin-api/config.test.ts @@ -1,4 +1,4 @@ -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import { createTestConfig } from '../../../test/config/test-config'; import createStores from '../../../test/fixtures/store'; @@ -8,6 +8,7 @@ import { DEFAULT_SEGMENT_VALUES_LIMIT, DEFAULT_STRATEGY_SEGMENTS_LIMIT, } from '../../util/segments'; +import TestAgent from 'supertest/lib/agent'; const uiConfig = { headerBackground: 'red', @@ -31,7 +32,7 @@ async function getSetup() { }; } -let request: supertest.SuperTest; +let request: TestAgent; let base: string; beforeEach(async () => { diff --git a/src/lib/routes/admin-api/context.test.ts b/src/lib/routes/admin-api/context.test.ts index 58baeb2fc9..2a017ea7b4 100644 --- a/src/lib/routes/admin-api/context.test.ts +++ b/src/lib/routes/admin-api/context.test.ts @@ -1,9 +1,10 @@ -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import { createTestConfig } from '../../../test/config/test-config'; import createStores from '../../../test/fixtures/store'; import { createServices } from '../../services'; import permissions from '../../../test/fixtures/permissions'; import getApp from '../../app'; +import TestAgent from 'supertest/lib/agent'; async function getSetup() { const base = `/random${Math.round(Math.random() * 1000)}`; @@ -24,7 +25,7 @@ async function getSetup() { } let base: string; -let request: supertest.SuperTest; +let request: TestAgent; beforeEach(async () => { const setup = await getSetup(); diff --git a/src/lib/routes/admin-api/metrics.test.ts b/src/lib/routes/admin-api/metrics.test.ts index 562ff2f041..adb1f6a57f 100644 --- a/src/lib/routes/admin-api/metrics.test.ts +++ b/src/lib/routes/admin-api/metrics.test.ts @@ -1,10 +1,11 @@ -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import createStores from '../../../test/fixtures/store'; import permissions from '../../../test/fixtures/permissions'; import getApp from '../../app'; import { createTestConfig } from '../../../test/config/test-config'; import { createServices } from '../../services'; import { IUnleashStores } from '../../types'; +import TestAgent from 'supertest/lib/agent'; async function getSetup() { const stores = createStores(); @@ -24,7 +25,7 @@ async function getSetup() { } let stores: IUnleashStores; -let request: supertest.SuperTest; +let request: TestAgent; beforeEach(async () => { const setup = await getSetup(); diff --git a/src/lib/routes/admin-api/public-signup.test.ts b/src/lib/routes/admin-api/public-signup.test.ts index 7980d4abac..bc2d9156ec 100644 --- a/src/lib/routes/admin-api/public-signup.test.ts +++ b/src/lib/routes/admin-api/public-signup.test.ts @@ -2,10 +2,11 @@ import createStores from '../../../test/fixtures/store'; import { createTestConfig } from '../../../test/config/test-config'; import { createServices } from '../../services'; import getApp from '../../app'; -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import permissions from '../../../test/fixtures/permissions'; import { RoleName, RoleType } from '../../types/model'; import { IUnleashStores } from '../../types'; +import TestAgent from 'supertest/lib/agent'; describe('Public Signup API', () => { async function getSetup() { @@ -38,7 +39,7 @@ describe('Public Signup API', () => { } let stores: IUnleashStores; - let request: supertest.SuperTest; + let request: TestAgent; const user = { username: 'some-username', diff --git a/src/lib/routes/admin-api/tag.test.ts b/src/lib/routes/admin-api/tag.test.ts index a375752374..e12b713096 100644 --- a/src/lib/routes/admin-api/tag.test.ts +++ b/src/lib/routes/admin-api/tag.test.ts @@ -1,10 +1,11 @@ -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import createStores from '../../../test/fixtures/store'; import permissions from '../../../test/fixtures/permissions'; import getApp from '../../app'; import { createTestConfig } from '../../../test/config/test-config'; import { createServices } from '../../services'; import { ITagStore } from '../../types'; +import TestAgent from 'supertest/lib/agent'; async function getSetup() { const base = `/random${Math.round(Math.random() * 1000)}`; @@ -27,7 +28,7 @@ async function getSetup() { let base: string; let tagStore: ITagStore; -let request: supertest.SuperTest; +let request: TestAgent; beforeEach(async () => { const setup = await getSetup(); diff --git a/src/lib/routes/health-check.test.ts b/src/lib/routes/health-check.test.ts index a7d26d65d2..b2fb3e0d9d 100644 --- a/src/lib/routes/health-check.test.ts +++ b/src/lib/routes/health-check.test.ts @@ -1,10 +1,11 @@ -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import { createServices } from '../services'; import { createTestConfig } from '../../test/config/test-config'; import createStores from '../../test/fixtures/store'; import getLogger from '../../test/fixtures/no-logger'; import getApp from '../app'; +import TestAgent from 'supertest/lib/agent'; async function getSetup() { const stores = createStores(); @@ -17,7 +18,7 @@ async function getSetup() { stores, }; } -let request: supertest.SuperTest; +let request: TestAgent; beforeEach(async () => { const setup = await getSetup(); request = setup.request; diff --git a/src/lib/routes/public-invite.test.ts b/src/lib/routes/public-invite.test.ts index 99507e2fe8..bf6c112647 100644 --- a/src/lib/routes/public-invite.test.ts +++ b/src/lib/routes/public-invite.test.ts @@ -2,10 +2,11 @@ import createStores from '../../test/fixtures/store'; import { createTestConfig } from '../../test/config/test-config'; import { createServices } from '../services'; import getApp from '../app'; -import supertest from 'supertest'; +import supertest, { Test } from 'supertest'; import permissions from '../../test/fixtures/permissions'; import { RoleName, RoleType } from '../types/model'; import { IUnleashStores } from 'lib/types'; +import TestAgent from 'supertest/lib/agent'; describe('Public Signup API', () => { async function getSetup() { @@ -51,7 +52,7 @@ describe('Public Signup API', () => { } let stores: IUnleashStores; - let request: supertest.SuperTest; + let request: TestAgent; const user = { username: 'some-username', diff --git a/src/test/e2e/helpers/test-helper.ts b/src/test/e2e/helpers/test-helper.ts index 8b0da3c515..e56ff1da23 100644 --- a/src/test/e2e/helpers/test-helper.ts +++ b/src/test/e2e/helpers/test-helper.ts @@ -21,11 +21,13 @@ import { ImportTogglesSchema, } from '../../../lib/openapi'; import { Knex } from 'knex'; +import TestAgent from 'supertest/lib/agent'; +import Test from 'supertest/lib/test'; process.env.NODE_ENV = 'test'; export interface IUnleashTest extends IUnleashHttpAPI { - request: supertest.SuperAgentTest; + request: TestAgent; destroy: () => Promise; services: IUnleashServices; config: IUnleashConfig; @@ -108,7 +110,7 @@ export interface IUnleashHttpAPI { } function httpApis( - request: supertest.SuperAgentTest, + request: TestAgent, config: IUnleashConfig, ): IUnleashHttpAPI { const base = config.server.baseUriPath || ''; diff --git a/yarn.lock b/yarn.lock index 4b859f5932..9381a054ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1339,10 +1339,10 @@ dependencies: "@types/node" "*" -"@types/cookiejar@*": - version "2.1.2" - resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.2.tgz#66ad9331f63fe8a3d3d9d8c6e3906dd10f6446e8" - integrity sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog== +"@types/cookiejar@^2.1.5": + version "2.1.5" + resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.5.tgz#14a3e83fa641beb169a2dd8422d91c3c345a9a78" + integrity sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q== "@types/cors@2.8.17": version "2.8.17" @@ -1488,6 +1488,11 @@ resolved "https://registry.yarnpkg.com/@types/memoizee/-/memoizee-0.4.11.tgz#da8897f0064bff3e845b5185e2a323bbd5c8d0a3" integrity sha512-2gyorIBZu8GoDr9pYjROkxWWcFtHCquF7TVbN2I+/OvgZhnIGQS0vX5KJz4lXNKb8XOSfxFOSG5OLru1ESqLUg== +"@types/methods@^1.1.4": + version "1.1.4" + resolved "https://registry.yarnpkg.com/@types/methods/-/methods-1.1.4.tgz#d3b7ac30ac47c91054ea951ce9eed07b1051e547" + integrity sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ== + "@types/mime@*": version "3.0.1" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10" @@ -1608,20 +1613,22 @@ dependencies: "@types/node" "*" -"@types/superagent@*": - version "4.1.16" - resolved "https://registry.yarnpkg.com/@types/superagent/-/superagent-4.1.16.tgz#12c9c16f232f9d89beab91d69368f96ce8e2d881" - integrity sha512-tLfnlJf6A5mB6ddqF159GqcDizfzbMUB1/DeT59/wBNqzRTNNKsaw79A/1TZ84X+f/EwWH8FeuSkjlCLyqS/zQ== +"@types/superagent@^8.1.0": + version "8.1.1" + resolved "https://registry.yarnpkg.com/@types/superagent/-/superagent-8.1.1.tgz#dbc620c5df3770b0c3092f947d6d5e808adae2bc" + integrity sha512-YQyEXA4PgCl7EVOoSAS3o0fyPFU6erv5mMixztQYe1bqbWmmn8c+IrqoxjQeZe4MgwXikgcaZPiI/DsbmOVlzA== dependencies: - "@types/cookiejar" "*" + "@types/cookiejar" "^2.1.5" + "@types/methods" "^1.1.4" "@types/node" "*" -"@types/supertest@2.0.16": - version "2.0.16" - resolved "https://registry.yarnpkg.com/@types/supertest/-/supertest-2.0.16.tgz#7a1294edebecb960d957bbe9b26002a2b7f21cd7" - integrity sha512-6c2ogktZ06tr2ENoZivgm7YnprnhYE4ZoXGMY+oA7IuAf17M8FWvujXZGmxLv8y0PTyts4x5A+erSwVUFA8XSg== +"@types/supertest@6.0.2": + version "6.0.2" + resolved "https://registry.yarnpkg.com/@types/supertest/-/supertest-6.0.2.tgz#2af1c466456aaf82c7c6106c6b5cbd73a5e86588" + integrity sha512-137ypx2lk/wTQbW6An6safu9hXmajAifU/s7szAHLN/FeIm5w7yR0Wkl9fdJMRSHwOn4HLAI0DaB2TOORuhPDg== dependencies: - "@types/superagent" "*" + "@types/methods" "^1.1.4" + "@types/superagent" "^8.1.0" "@types/type-is@1.6.6": version "1.6.6"