Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] chore(NA): move console out of __tests__ folder (#87368) #87525

Merged
merged 2 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
import '../legacy_core_editor.test.mocks';
import RowParser from '../../../../lib/row_parser';
import { createTokenIterator } from '../../../factories';
import './legacy_core_editor.test.mocks';
import RowParser from '../../../lib/row_parser';
import { createTokenIterator } from '../../factories';
import $ from 'jquery';
import { create } from '../create';
import { create } from './create';

describe('Input', () => {
let coreEditor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
import '../legacy_core_editor.test.mocks';
import './legacy_core_editor.test.mocks';
import $ from 'jquery';
import RowParser from '../../../../lib/row_parser';
import RowParser from '../../../lib/row_parser';
import ace from 'brace';
import { createReadOnlyAceEditor } from '../create_readonly';
import { createReadOnlyAceEditor } from './create_readonly';
let output;
const tokenIterator = ace.acequire('ace/token_iterator');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import '../sense_editor.test.mocks';
import { create } from '../create';
import './sense_editor.test.mocks';
import { create } from './create';
import _ from 'lodash';
import $ from 'jquery';

import * as kb from '../../../../lib/kb/kb';
import * as mappings from '../../../../lib/mappings/mappings';
import * as kb from '../../../lib/kb/kb';
import * as mappings from '../../../lib/mappings/mappings';

describe('Integration', () => {
let senseEditor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
import '../sense_editor.test.mocks';
import './sense_editor.test.mocks';

import $ from 'jquery';
import _ from 'lodash';

import { create } from '../create';
import { XJson } from '../../../../../../es_ui_shared/public';
import editorInput1 from './editor_input1.txt';
import { create } from './create';
import { XJson } from '../../../../../es_ui_shared/public';
import editorInput1 from './__fixtures__/editor_input1.txt';

const { collapseLiteralStrings } = XJson;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@
*/

import _ from 'lodash';
import {
URL_PATH_END_MARKER,
UrlPatternMatcher,
ListComponent,
} from '../../autocomplete/components';

import { populateContext } from '../../autocomplete/engine';
import { URL_PATH_END_MARKER, UrlPatternMatcher, ListComponent } from './components';
import { populateContext } from './engine';

describe('Url autocomplete', () => {
function patternsTest(name, endpoints, tokenPath, expectedContext, globalUrlComponentFactories) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/
import _ from 'lodash';
import { UrlParams } from '../../autocomplete/url_params';
import { populateContext } from '../../autocomplete/engine';
import { UrlParams } from './url_params';
import { populateContext } from './engine';

describe('Url params', () => {
function paramTest(name, description, tokenPath, expectedContext, globalParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

import _ from 'lodash';
import { detectCURL, parseCURL } from '../curl';
import curlTests from './curl_parsing.txt';
import { detectCURL, parseCURL } from './curl';
import curlTests from './__fixtures__/curl_parsing.txt';

describe('CURL', () => {
const notCURLS = ['sldhfsljfhs', 's;kdjfsldkfj curl -XDELETE ""', '{ "hello": 1 }'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { getContentType } from '../es';
import { getContentType } from './es';

const APPLICATION_JSON = 'application/json';
describe('Content type', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/

import _ from 'lodash';
import { populateContext } from '../../autocomplete/engine';
import { populateContext } from '../autocomplete/engine';

import '../../../application/models/sense_editor/sense_editor.test.mocks';
import * as kb from '../../kb';
import * as mappings from '../../mappings/mappings';
import '../../application/models/sense_editor/sense_editor.test.mocks';
import * as kb from '../kb';
import * as mappings from '../mappings/mappings';

describe('Knowledge base', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import '../../../application/models/sense_editor/sense_editor.test.mocks';
import * as mappings from '../mappings';
import '../../application/models/sense_editor/sense_editor.test.mocks';
import * as mappings from './mappings';

describe('Mappings', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import * as utils from '../';
import * as utils from '.';

describe('Utils class', () => {
test('extract deprecation messages', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
*/
import { getProxyRouteHandlerDeps } from './mocks';

import expect from '@kbn/expect';
import { Readable } from 'stream';

import { kibanaResponseFactory } from '../../../../../../../../core/server';
import { createHandler } from '../create_handler';
import * as requestModule from '../../../../../lib/proxy_request';
import { kibanaResponseFactory } from '../../../../../../../core/server';
import { createHandler } from './create_handler';
import * as requestModule from '../../../../lib/proxy_request';
import { createResponseStub } from './stubs';

describe('Console Proxy Route', () => {
Expand Down Expand Up @@ -62,38 +61,38 @@ describe('Console Proxy Route', () => {
describe('GET request', () => {
it('returns the exact body', async () => {
const { payload } = await request('GET', '/', 'foobar');
expect(await readStream(payload)).to.be('foobar');
expect(await readStream(payload)).toBe('foobar');
});
});
describe('POST request', () => {
it('returns the exact body', async () => {
const { payload } = await request('POST', '/', 'foobar');
expect(await readStream(payload)).to.be('foobar');
expect(await readStream(payload)).toBe('foobar');
});
});
describe('PUT request', () => {
it('returns the exact body', async () => {
const { payload } = await request('PUT', '/', 'foobar');
expect(await readStream(payload)).to.be('foobar');
expect(await readStream(payload)).toBe('foobar');
});
});
describe('DELETE request', () => {
it('returns the exact body', async () => {
const { payload } = await request('DELETE', '/', 'foobar');
expect(await readStream(payload)).to.be('foobar');
expect(await readStream(payload)).toBe('foobar');
});
});
describe('HEAD request', () => {
it('returns the status code and text', async () => {
const { payload } = await request('HEAD', '/');
expect(typeof payload).to.be('string');
expect(payload).to.be('200 - OK');
expect(typeof payload).toBe('string');
expect(payload).toBe('200 - OK');
});
describe('mixed casing', () => {
it('returns the status code and text', async () => {
const { payload } = await request('HeAd', '/');
expect(typeof payload).to.be('string');
expect(payload).to.be('200 - OK');
expect(typeof payload).toBe('string');
expect(payload).toBe('200 - OK');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
jest.mock('../../../../../../../../core/server/http/router/request', () => ({
jest.mock('../../../../../../../core/server/http/router/request', () => ({
ensureRawRequest: jest.fn(),
}));

import { kibanaResponseFactory } from '../../../../../../../../core/server';
import { kibanaResponseFactory } from '../../../../../../../core/server';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ensureRawRequest } from '../../../../../../../../core/server/http/router/request';
import { ensureRawRequest } from '../../../../../../../core/server/http/router/request';

import { getProxyRouteHandlerDeps } from './mocks';

import expect from '@kbn/expect';
import * as requestModule from '../../../../../lib/proxy_request';
import * as requestModule from '../../../../lib/proxy_request';

import { createHandler } from '../create_handler';
import { createHandler } from './create_handler';

import { createResponseStub } from './stubs';

Expand Down Expand Up @@ -74,16 +73,16 @@ describe('Console Proxy Route', () => {
kibanaResponseFactory
);

expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).to.be(1);
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
const [[{ headers }]] = (requestModule.proxyRequest as jest.Mock).mock.calls;
expect(headers).to.have.property('x-forwarded-for');
expect(headers['x-forwarded-for']).to.be('0.0.0.0');
expect(headers).to.have.property('x-forwarded-port');
expect(headers['x-forwarded-port']).to.be('1234');
expect(headers).to.have.property('x-forwarded-proto');
expect(headers['x-forwarded-proto']).to.be('http');
expect(headers).to.have.property('x-forwarded-host');
expect(headers['x-forwarded-host']).to.be('test');
expect(headers).toHaveProperty('x-forwarded-for');
expect(headers['x-forwarded-for']).toBe('0.0.0.0');
expect(headers).toHaveProperty('x-forwarded-port');
expect(headers['x-forwarded-port']).toBe('1234');
expect(headers).toHaveProperty('x-forwarded-proto');
expect(headers['x-forwarded-proto']).toBe('http');
expect(headers).toHaveProperty('x-forwarded-host');
expect(headers['x-forwarded-host']).toBe('test');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* under the License.
*/

jest.mock('../../../../../lib/proxy_request', () => ({
jest.mock('../../../../lib/proxy_request', () => ({
proxyRequest: jest.fn(),
}));

import { duration } from 'moment';
import { ProxyConfigCollection } from '../../../../../lib';
import { RouteDependencies, ProxyDependencies } from '../../../../../routes';
import { EsLegacyConfigService, SpecDefinitionsService } from '../../../../../services';
import { coreMock, httpServiceMock } from '../../../../../../../../core/server/mocks';
import { ProxyConfigCollection } from '../../../../lib';
import { RouteDependencies, ProxyDependencies } from '../../../../routes';
import { EsLegacyConfigService, SpecDefinitionsService } from '../../../../services';
import { coreMock, httpServiceMock } from '../../../../../../../core/server/mocks';

const defaultProxyValue = Object.freeze({
readLegacyESConfig: async () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
import { kibanaResponseFactory } from '../../../../../../../../core/server';
import { kibanaResponseFactory } from '../../../../../../../core/server';
import { getProxyRouteHandlerDeps } from './mocks';
import { createResponseStub } from './stubs';
import * as requestModule from '../../../../../lib/proxy_request';
import expect from '@kbn/expect';
import * as requestModule from '../../../../lib/proxy_request';

import { createHandler } from '../create_handler';
import { createHandler } from './create_handler';

describe('Console Proxy Route', () => {
let handler: ReturnType<typeof createHandler>;
Expand All @@ -45,7 +44,7 @@ describe('Console Proxy Route', () => {
kibanaResponseFactory
);

expect(status).to.be(403);
expect(status).toBe(403);
});
});
describe('one match', () => {
Expand All @@ -62,8 +61,8 @@ describe('Console Proxy Route', () => {
kibanaResponseFactory
);

expect(status).to.be(200);
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).to.be(1);
expect(status).toBe(200);
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
});
});
describe('all match', () => {
Expand All @@ -80,8 +79,8 @@ describe('Console Proxy Route', () => {
kibanaResponseFactory
);

expect(status).to.be(200);
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).to.be(1);
expect(status).toBe(200);
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import { duration } from 'moment';
import { getProxyRouteHandlerDeps } from './mocks';

import { kibanaResponseFactory } from '../../../../../../../../core/server';
import * as requestModule from '../../../../../lib/proxy_request';
import { createHandler } from '../create_handler';
import { kibanaResponseFactory } from '../../../../../../../core/server';
import * as requestModule from '../../../../lib/proxy_request';
import { createHandler } from './create_handler';

describe('Console Proxy Route', () => {
afterEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
import { kibanaResponseFactory } from '../../../../../../../../core/server';
import { kibanaResponseFactory } from '../../../../../../../core/server';
import { getProxyRouteHandlerDeps } from './mocks';
import { createResponseStub } from './stubs';
import * as requestModule from '../../../../../lib/proxy_request';
import * as requestModule from '../../../../lib/proxy_request';

import expect from '@kbn/expect';

import { createHandler } from '../create_handler';
import { createHandler } from './create_handler';

describe('Console Proxy Route', () => {
let request: any;
Expand All @@ -50,25 +48,25 @@ describe('Console Proxy Route', () => {
describe('contains full url', () => {
it('treats the url as a path', async () => {
await request('GET', 'http://evil.com/test');
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).to.be(1);
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
const [[args]] = (requestModule.proxyRequest as jest.Mock).mock.calls;
expect(args.uri.href).to.be('http://localhost:9200/http://evil.com/test?pretty=true');
expect(args.uri.href).toBe('http://localhost:9200/http://evil.com/test?pretty=true');
});
});
describe('starts with a slash', () => {
it('combines well with the base url', async () => {
await request('GET', '/index/id');
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).to.be(1);
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
const [[args]] = (requestModule.proxyRequest as jest.Mock).mock.calls;
expect(args.uri.href).to.be('http://localhost:9200/index/id?pretty=true');
expect(args.uri.href).toBe('http://localhost:9200/index/id?pretty=true');
});
});
describe(`doesn't start with a slash`, () => {
it('combines well with the base url', async () => {
await request('GET', 'index/id');
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).to.be(1);
expect((requestModule.proxyRequest as jest.Mock).mock.calls.length).toBe(1);
const [[args]] = (requestModule.proxyRequest as jest.Mock).mock.calls;
expect(args.uri.href).to.be('http://localhost:9200/index/id?pretty=true');
expect(args.uri.href).toBe('http://localhost:9200/index/id?pretty=true');
});
});
});
Expand Down
Loading