Skip to content

Commit

Permalink
Update supertest and superagent to latest version (#183587)
Browse files Browse the repository at this point in the history
## Summary

Related to #7104

Update supertest, superagent, and the corresponding type package, to
their latest version.

(of course, types had some signature changes and we're massively using
supertest in all our FTR suites so the whole Kibana multiverse has to
review it)

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
pgayvallet and kibanamachine authored May 17, 2024
1 parent 4b7d014 commit 148eeec
Show file tree
Hide file tree
Showing 153 changed files with 439 additions and 431 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@
"@types/source-map-support": "^0.5.3",
"@types/stats-lite": "^2.2.0",
"@types/styled-components": "^5.1.0",
"@types/supertest": "^2.0.12",
"@types/supertest": "^6.0.2",
"@types/tapable": "^1.0.6",
"@types/tar": "^6.1.11",
"@types/testing-library__jest-dom": "^5.14.7",
Expand Down Expand Up @@ -1697,8 +1697,8 @@
"style-loader": "^1.1.3",
"stylelint": "^14.9.1",
"stylelint-scss": "^4.3.0",
"superagent": "^8.1.2",
"supertest": "^6.3.3",
"superagent": "^9.0.2",
"supertest": "^7.0.0",
"svgo": "^2.8.0",
"table": "^6.8.1",
"tape": "^5.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ describe('setup contract', () => {
.get('/static/some_json.json')
.expect(200);

const etag = response.get('etag');
const etag = response.get('etag')!;
expect(etag).not.toBeUndefined();

await supertest(innerServer.listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('BasePathProxyServer', () => {
let logger: TestLog;
let config: IHttpConfig;
let basePath: string;
let proxySupertest: supertest.SuperTest<supertest.Test>;
let proxySupertest: supertest.Agent;

beforeEach(async () => {
logger = new TestLog();
Expand Down Expand Up @@ -330,7 +330,7 @@ describe('BasePathProxyServer', () => {

describe('shouldRedirect', () => {
let proxyServerWithoutShouldRedirect: BasePathProxyServer;
let proxyWithoutShouldRedirectSupertest: supertest.SuperTest<supertest.Test>;
let proxyWithoutShouldRedirectSupertest: supertest.Agent;

beforeEach(async () => {
// setup and start a proxy server which does not use "shouldRedirectFromOldBasePath"
Expand Down Expand Up @@ -373,7 +373,7 @@ describe('BasePathProxyServer', () => {

describe('constructor option for sending in a custom basePath', () => {
let proxyServerWithFooBasePath: BasePathProxyServer;
let proxyWithFooBasePath: supertest.SuperTest<supertest.Test>;
let proxyWithFooBasePath: supertest.Agent;

beforeEach(async () => {
// setup and start a proxy server which uses a basePath of "foo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('Cookie based SessionStorage', () => {

const response = await supertest(innerServer.listener).get('/').expect(200);

const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();
expect(cookies).toHaveLength(1);

Expand Down Expand Up @@ -172,7 +172,7 @@ describe('Cookie based SessionStorage', () => {

const response = await supertest(innerServer.listener).get('/').expect(200);

const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();
expect(cookies).toHaveLength(1);

Expand Down Expand Up @@ -204,7 +204,7 @@ describe('Cookie based SessionStorage', () => {

const response = await supertest(innerServer.listener).get('/').expect(200, { value: null });

const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).not.toBeDefined();
});

Expand Down Expand Up @@ -237,7 +237,7 @@ describe('Cookie based SessionStorage', () => {
.get('/')
.expect(200, { value: userData });

const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();

await delay(sessionDurationMs);
Expand Down Expand Up @@ -283,7 +283,7 @@ describe('Cookie based SessionStorage', () => {
.get('/')
.expect(200, { value: userData });

const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();

const sessionCookie = retrieveSessionCookie(cookies[0]);
Expand Down Expand Up @@ -418,7 +418,7 @@ describe('Cookie based SessionStorage', () => {

const response = await supertest(innerServer.listener).get('/').expect(200);

const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
const sessionCookie = retrieveSessionCookie(cookies[0]);

const response2 = await supertest(innerServer.listener)
Expand Down Expand Up @@ -475,7 +475,7 @@ describe('Cookie based SessionStorage', () => {

const response = await supertest(innerServer.listener).get('/').expect(200);

const cookies = response.get('set-cookie');
const cookies = response.get('set-cookie')!;
expect(cookies).toBeDefined();
expect(cookies).toHaveLength(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface AdditionalOptions {

describe('Routing versioned requests', () => {
let router: IRouter;
let supertest: Supertest.SuperTest<Supertest.Test>;
let supertest: Supertest.Agent;

async function setupServer(cliArgs: Partial<CliArgs> = {}, options: AdditionalOptions = {}) {
logger = loggingSystemMock.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('ServerMetricsCollector', () => {
// Subscribe to the aborted$ event
const waitFor1stAbort = disconnectAborted$.pipe(take(1)).toPromise();

discoReq1.abort();
void discoReq1.abort();

// Wait for the aborted$ event
await waitFor1stAbort;
Expand All @@ -132,7 +132,7 @@ describe('ServerMetricsCollector', () => {
// Subscribe to the aborted$ event
const waitFor2ndAbort = disconnectAborted$.pipe(take(1)).toPromise();

discoReq2.abort();
void discoReq2.abort();

// Wait for the aborted$ event
await waitFor2ndAbort;
Expand Down
2 changes: 1 addition & 1 deletion test/api_integration/apis/data_views/fields_route/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function ({ getService }: FtrProviderContext) {

await supertest
.get(FIELDS_PATH)
.set('If-None-Match', response.get('etag'))
.set('If-None-Match', response.get('etag')!)
.query({
pattern: '*',
include_unmapped: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
* Side Public License, v 1.
*/

import { SuperTest, Test } from 'supertest';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

const apiUrl = '/api/kibana/management/saved_objects/scroll/counts';
const defaultTypes = ['visualization', 'index-pattern', 'search', 'dashboard'];

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest') as SuperTest<Test>;
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
const esArchiver = getService('esArchiver');

Expand Down
2 changes: 1 addition & 1 deletion test/api_integration/apis/telemetry/opt_in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function optInTest({ getService }: FtrProviderContext) {
}

async function postTelemetryV2OptIn(
supertest: SuperTest.SuperTest<SuperTest.Test>,
supertest: SuperTest.Agent,
value: unknown,
statusCode: number
): Promise<any> {
Expand Down
6 changes: 4 additions & 2 deletions test/api_integration/services/supertest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import { format as formatUrl } from 'url';
import supertest from 'supertest';
import { FtrProviderContext } from '../../functional/ftr_provider_context';

export function KibanaSupertestProvider({ getService }: FtrProviderContext) {
export function KibanaSupertestProvider({ getService }: FtrProviderContext): supertest.Agent {
const config = getService('config');
const kibanaServerUrl = formatUrl(config.get('servers.kibana'));
return supertest(kibanaServerUrl);
}

export function ElasticsearchSupertestProvider({ getService }: FtrProviderContext) {
export function ElasticsearchSupertestProvider({
getService,
}: FtrProviderContext): supertest.Agent {
const config = getService('config');
const esServerConfig = config.get('servers.elasticsearch');

Expand Down
2 changes: 1 addition & 1 deletion test/common/services/bsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getSpaceUrlPrefix = (spaceId?: string): string => {
* Options for the send method
*/
interface SendOptions {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
options: object;
strategy: string;
space?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('APMEventClient', () => {
resolve(undefined);
}, 100);
});
incomingRequest.abort();
void incomingRequest.abort();
}, 100);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function delay(millis: number): Promise<void> {
}

export function createWaitForExecutionCount(
st: supertest.SuperTest<supertest.Test>,
st: supertest.Agent,
spaceId?: string,
delayMs: number = 3000
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { Client } from '@elastic/elasticsearch';
import type { SuperTest, Test } from 'supertest';
import type { Agent as SuperTestAgent } from 'supertest';
import { ToolingLog } from '@kbn/tooling-log';
import { ThresholdParams } from '@kbn/observability-plugin/common/custom_threshold_rule/types';
import { refreshSavedObjectIndices } from './refresh_index';
Expand All @@ -17,7 +17,7 @@ export async function createIndexConnector({
indexName,
logger,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
name: string;
indexName: string;
logger: ToolingLog;
Expand Down Expand Up @@ -51,7 +51,7 @@ export async function createRule<Params = ThresholdParams>({
logger,
esClient,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
ruleTypeId: string;
name: string;
params: Params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function waitForRuleStatus({
}: {
id: string;
expectedStatus: string;
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
retryService: RetryService;
logger: ToolingLog;
}): Promise<Record<string, any>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { ToolingLog } from '@kbn/tooling-log';

export const createDataView = async ({
Expand All @@ -15,7 +15,7 @@ export const createDataView = async ({
title,
logger,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
id: string;
name: string;
title: string;
Expand Down Expand Up @@ -50,7 +50,7 @@ export const deleteDataView = async ({
id,
logger,
}: {
supertest: SuperTest<Test>;
supertest: SuperTestAgent;
id: string;
logger: ToolingLog;
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { chunk, omit } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { SuperuserAtSpace1, UserAtSpaceScenarios } from '../../../scenarios';
Expand All @@ -16,7 +16,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
const findTestUtils = (
describeType: 'internal' | 'public',
objectRemover: ObjectRemover,
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
supertestWithoutAuth: any
) => {
describe.skip(describeType, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { chunk, omit } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { UserAtSpaceScenarios } from '../../../scenarios';
Expand All @@ -16,7 +16,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
const findTestUtils = (
describeType: 'internal' | 'public',
objectRemover: ObjectRemover,
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
supertestWithoutAuth: any
) => {
// FLAKY: https://github.com/elastic/kibana/issues/182314
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import expect from '@kbn/expect';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import { SuperuserAtSpace1, UserAtSpaceScenarios } from '../../../scenarios';
import {
getUrlPrefix,
Expand All @@ -19,7 +19,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
const getTestUtils = (
describeType: 'internal' | 'public',
objectRemover: ObjectRemover,
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
supertestWithoutAuth: any
) => {
describe(describeType, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default function createCrowdstrikeTests({ getService }: FtrProviderContex
password = 'changeme',
errorLogger = logErrorDetails,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
subAction: string;
subActionParams: Record<string, unknown>;
expectedHttpCode?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default function createSentinelOneTests({ getService }: FtrProviderContex
password = 'changeme',
errorLogger = logErrorDetails,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
subAction: string;
subActionParams: Record<string, unknown>;
expectedHttpCode?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const createSubActionConnector = async ({
connectorTypeId = 'test.sub-action-connector',
expectedHttpCode = 200,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
config?: Record<string, unknown>;
secrets?: Record<string, unknown>;
connectorTypeId?: string;
Expand Down Expand Up @@ -56,7 +56,7 @@ const executeSubAction = async ({
subActionParams,
expectedHttpCode = 200,
}: {
supertest: SuperTest.SuperTest<SuperTest.Test>;
supertest: SuperTest.Agent;
connectorId: string;
subAction: string;
subActionParams: Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import http from 'http';
import https from 'https';
import getPort from 'get-port';
import { SuperTest, Test } from 'supertest';
import { Agent as SuperTestAgent } from 'supertest';
import expect from '@kbn/expect';
import { URL, format as formatUrl } from 'url';
import {
Expand Down Expand Up @@ -177,7 +177,7 @@ export default function webhookTest({ getService }: FtrProviderContext) {
}

export async function createWebhookAction(
supertest: SuperTest<Test>,
supertest: SuperTestAgent,
webhookSimulatorURL: string,
config: Record<string, string | Record<string, string>> = {}
): Promise<string> {
Expand Down
Loading

0 comments on commit 148eeec

Please sign in to comment.