Skip to content

Commit

Permalink
Removes supertest-as-promised dependency (#100486)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Smalley <[email protected]>
  • Loading branch information
Tyler Smalley authored Aug 17, 2021
1 parent e6d446a commit 689d974
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 134 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@
"@types/strong-log-transformer": "^1.0.0",
"@types/styled-components": "^5.1.0",
"@types/supertest": "^2.0.5",
"@types/supertest-as-promised": "^2.0.38",
"@types/tapable": "^1.0.6",
"@types/tar": "^4.0.3",
"@types/tar-fs": "^1.16.1",
Expand Down Expand Up @@ -824,7 +823,6 @@
"stylelint-scss": "^3.18.0",
"superagent": "^3.8.2",
"supertest": "^3.1.0",
"supertest-as-promised": "^4.0.2",
"supports-color": "^7.0.0",
"tape": "^5.0.1",
"tar-fs": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export default function () {
To consume the test server, use can use something like supertest to send request. Just make sure that you disable your test suite if the user doesn't choose to enable your docker server:

```ts
import makeSupertest from 'supertest-as-promised';
import supertest from 'supertest';
import { FtrProviderContext } from '../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const dockerServers = getService('dockerServers');
const log = getService('log');

const server = dockerServers.get('helloWorld');
const supertest = makeSupertest(server.url);
const request = supertest(server.url);

describe('test suite name', function () {
if (!server.enabled) {
Expand All @@ -72,7 +72,7 @@ export default function ({ getService }: FtrProviderContext) {
}

it('test name', async () => {
await supertest.get('/foo/bar').expect(200);
await request.get('/foo/bar').expect(200);
});
});
}
Expand Down
7 changes: 3 additions & 4 deletions test/api_integration/services/supertest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import { FtrProviderContext } from 'test/functional/ftr_provider_context';
import { format as formatUrl } from 'url';

import supertestAsPromised from 'supertest-as-promised';
import supertest from 'supertest';

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

export function ElasticsearchSupertestProvider({ getService }: FtrProviderContext) {
Expand All @@ -27,6 +27,5 @@ export function ElasticsearchSupertestProvider({ getService }: FtrProviderContex
agentOptions = { ca: esServerConfig!.certificateAuthorities };
}

// @ts-ignore - supertestAsPromised doesn't like the agentOptions, but still passes it correctly to supertest
return supertestAsPromised.agent(elasticSearchServerUrl, agentOptions);
return supertest.agent(elasticSearchServerUrl, agentOptions);
}
4 changes: 2 additions & 2 deletions test/common/services/security/test_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { format as formatUrl } from 'url';
import supertestAsPromised from 'supertest-as-promised';
import supertest from 'supertest';

import { Role } from './role';
import { User } from './user';
Expand Down Expand Up @@ -110,7 +110,7 @@ export function TestUserSupertestProvider({ getService }: FtrProviderContext) {
const config = getService('config');
const kibanaServerConfig = config.get('servers.kibana');

return supertestAsPromised(
return supertest(
formatUrl({
...kibanaServerConfig,
auth: `${TEST_USER_NAME}:${TEST_USER_PASSWORD}`,
Expand Down
4 changes: 2 additions & 2 deletions test/functional/services/supertest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import { FtrProviderContext } from 'test/functional/ftr_provider_context';
import { format as formatUrl } from 'url';

import supertestAsPromised from 'supertest-as-promised';
import supertest from 'supertest';

export function KibanaSupertestProvider({ getService }: FtrProviderContext) {
const config = getService('config');
const kibanaServerUrl = formatUrl(config.get('servers.kibana'));
return supertestAsPromised(kibanaServerUrl);
return supertest(kibanaServerUrl);
}
10 changes: 5 additions & 5 deletions test/server_integration/services/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@

import { format as formatUrl } from 'url';

import supertestAsPromised from 'supertest-as-promised';
import supertest from 'supertest';

export function createKibanaSupertestProvider({ certificateAuthorities, kibanaUrl } = {}) {
return function ({ getService }) {
const config = getService('config');
kibanaUrl = kibanaUrl ?? formatUrl(config.get('servers.kibana'));

return certificateAuthorities
? supertestAsPromised.agent(kibanaUrl, { ca: certificateAuthorities })
: supertestAsPromised(kibanaUrl);
? supertest.agent(kibanaUrl, { ca: certificateAuthorities })
: supertest(kibanaUrl);
};
}

export function KibanaSupertestWithoutAuthProvider({ getService }) {
const config = getService('config');
const kibanaServerConfig = config.get('servers.kibana');

return supertestAsPromised(
return supertest(
formatUrl({
...kibanaServerConfig,
auth: false,
Expand All @@ -36,5 +36,5 @@ export function KibanaSupertestWithoutAuthProvider({ getService }) {
export function ElasticsearchSupertestProvider({ getService }) {
const config = getService('config');
const elasticSearchServerUrl = formatUrl(config.get('servers.elasticsearch'));
return supertestAsPromised(elasticSearchServerUrl);
return supertest(elasticSearchServerUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* 2.0.
*/

import Supertest from 'supertest';
import supertestAsPromised from 'supertest-as-promised';
import type SuperTest from 'supertest';
import uuid from 'uuid';
import { TimelineType } from '../../../../../plugins/security_solution/common/types/timeline';

export const createBasicTimeline = async (
supertest: Supertest.SuperTest<supertestAsPromised.Test>,
supertest: SuperTest.SuperTest<SuperTest.Test>,
titleToSaved: string
) =>
await supertest
Expand All @@ -26,7 +25,7 @@ export const createBasicTimeline = async (
});

export const createBasicTimelineTemplate = async (
supertest: Supertest.SuperTest<supertestAsPromised.Test>,
supertest: SuperTest.SuperTest<SuperTest.Test>,
titleToSaved: string
) =>
await supertest
Expand Down
5 changes: 2 additions & 3 deletions x-pack/test/api_integration/apis/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import expect from '@kbn/expect';
import moment from 'moment';
import type { SuperTest } from 'supertest';
import type supertestAsPromised from 'supertest-as-promised';
import type SuperTest from 'supertest';
import deepmerge from 'deepmerge';
import type { FtrProviderContext } from '../../ftr_provider_context';

Expand All @@ -29,7 +28,7 @@ import { assertTelemetryPayload } from '../../../../../test/api_integration/apis
* @param timestamp The new timestamp to be set
*/
function updateMonitoringDates(
esSupertest: SuperTest<supertestAsPromised.Test>,
esSupertest: SuperTest.SuperTest<SuperTest.Test>,
fromTimestamp: string,
toTimestamp: string,
timestamp: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { format as formatUrl } from 'url';

import supertestAsPromised from 'supertest-as-promised';
import supertest from 'supertest';

/**
* Supertest provider that doesn't include user credentials into base URL that is passed
Expand All @@ -17,7 +17,7 @@ export function EsSupertestWithoutAuthProvider({ getService }) {
const config = getService('config');
const elasticsearchServerConfig = config.get('servers.elasticsearch');

return supertestAsPromised(
return supertest(
formatUrl({
...elasticsearchServerConfig,
auth: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

import { format as formatUrl } from 'url';

import supertestAsPromised from 'supertest-as-promised';
import supertest from 'supertest';

/**
* Supertest provider that doesn't include user credentials into base URL that is passed
* supertest provider that doesn't include user credentials into base URL that is passed
* to the supertest. It's used to test API behaviour for not yet authenticated user.
*/
export function SupertestWithoutAuthProvider({ getService }) {
const config = getService('config');
const kibanaServerConfig = config.get('servers.kibana');

return supertestAsPromised(
return supertest(
formatUrl({
...kibanaServerConfig,
auth: false,
Expand Down
Loading

0 comments on commit 689d974

Please sign in to comment.