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

IDM: Migrates kbn_server to a dev-only package #146248

Merged
merged 2 commits into from
Nov 24, 2022
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ packages/core/status/core-status-server-internal @elastic/kibana-core
packages/core/status/core-status-server-mocks @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-deprecations-getters @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-http-setup-browser @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-kbn-server @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-so-type-serializer @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-test-utils @elastic/kibana-core
packages/core/theme/core-theme-browser @elastic/kibana-core
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@
"@kbn/ci-stats-performance-metrics": "link:bazel-bin/packages/kbn-ci-stats-performance-metrics",
"@kbn/ci-stats-reporter": "link:bazel-bin/packages/kbn-ci-stats-reporter",
"@kbn/cli-dev-mode": "link:bazel-bin/packages/kbn-cli-dev-mode",
"@kbn/core-test-helpers-kbn-server": "link:bazel-bin/packages/core/test-helpers/core-test-helpers-kbn-server",
"@kbn/dev-cli-errors": "link:bazel-bin/packages/kbn-dev-cli-errors",
"@kbn/dev-cli-runner": "link:bazel-bin/packages/kbn-dev-cli-runner",
"@kbn/dev-proc-runner": "link:bazel-bin/packages/kbn-dev-proc-runner",
Expand Down
2 changes: 2 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ filegroup(
"//packages/core/status/core-status-server-mocks:build",
"//packages/core/test-helpers/core-test-helpers-deprecations-getters:build",
"//packages/core/test-helpers/core-test-helpers-http-setup-browser:build",
"//packages/core/test-helpers/core-test-helpers-kbn-server:build",
"//packages/core/test-helpers/core-test-helpers-so-type-serializer:build",
"//packages/core/test-helpers/core-test-helpers-test-utils:build",
"//packages/core/theme/core-theme-browser:build",
Expand Down Expand Up @@ -538,6 +539,7 @@ filegroup(
"//packages/core/status/core-status-server-mocks:build_types",
"//packages/core/test-helpers/core-test-helpers-deprecations-getters:build_types",
"//packages/core/test-helpers/core-test-helpers-http-setup-browser:build_types",
"//packages/core/test-helpers/core-test-helpers-kbn-server:build_types",
"//packages/core/test-helpers/core-test-helpers-so-type-serializer:build_types",
"//packages/core/test-helpers/core-test-helpers-test-utils:build_types",
"//packages/core/theme/core-theme-browser:build_types",
Expand Down
121 changes: 121 additions & 0 deletions packages/core/test-helpers/core-test-helpers-kbn-server/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")

PKG_DIRNAME = "core-test-helpers-kbn-server"
PKG_REQUIRE_NAME = "@kbn/core-test-helpers-kbn-server"

SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

RUNTIME_DEPS = [
"@npm//lodash",
"@npm//rxjs",
"@npm//supertest",
"//packages/kbn-tooling-log",
"//packages/kbn-utils",
"//packages/kbn-test",
"//packages/kbn-config",
"//packages/core/lifecycle/core-lifecycle-server-internal",
"//packages/core/root/core-root-server-internal",
]

TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//lodash",
"@npm//rxjs",
"@npm//supertest",
"//packages/kbn-tooling-log:npm_module_types",
"//packages/kbn-utils:npm_module_types",
"//packages/kbn-test:npm_module_types",
"//packages/kbn-config:npm_module_types",
"//packages/core/lifecycle/core-lifecycle-server-internal:npm_module_types",
"//packages/core/root/core-root-server-internal:npm_module_types",
]

jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)

ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

js_library(
name = "npm_module_types",
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":tsc_types"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)

filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)

filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @kbn/core-test-helpers-kbn-server

This package contains Core's server side kbn_server test helpers including:
- createRootWithSettings
- getSupertest
- createRoot
- createRootWithCorePlugins
- createTestServers
- request

and types:
- HttpMethod
- TestElasticsearchUtils
- TestKibanaUtils
- TestUtils
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export {
createRootWithSettings,
getSupertest,
createRoot,
createRootWithCorePlugins,
createTestServers,
request,
} from './src';

export type { HttpMethod, TestElasticsearchUtils, TestKibanaUtils, TestUtils } from './src';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/core/test-helpers/core-test-helpers-kbn-server'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "shared-common",
"id": "@kbn/core-test-helpers-kbn-server",
"owner": "@elastic/kibana-core",
"devOnly": true,
"runtimeDeps": [],
"typeDeps": [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kbn/core-test-helpers-kbn-server",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"types": "./target_types/index.d.ts",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export {
createRootWithSettings,
getSupertest,
createRoot,
createRootWithCorePlugins,
createTestServers,
request,
} from './create_root';

export type { HttpMethod, TestElasticsearchUtils, TestKibanaUtils, TestUtils } from './create_root';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
import { mockLoggingSystem } from './config_deprecation.test.mocks';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot } from '@kbn/core-test-helpers-kbn-server';

describe('configuration deprecations', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
let root: ReturnType<typeof createRoot>;

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -24,7 +24,7 @@ describe('configuration deprecations', () => {
});

it('should not log deprecation warnings for default configuration', async () => {
root = kbnTestServer.createRoot();
root = createRoot();

await root.preboot();
await root.setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/

import { Root } from '@kbn/core-root-server-internal';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
import { createRoot, request } from '@kbn/core-test-helpers-kbn-server';

describe('Core app routes', () => {
let root: Root;

beforeAll(async function () {
root = kbnTestServer.createRoot({
root = createRoot({
plugins: { initialize: false },
elasticsearch: { skipStartupConnectionCheck: true },
server: {
Expand All @@ -32,32 +32,32 @@ describe('Core app routes', () => {

describe('`/{path*}` route', () => {
it('redirects requests to include the basePath', async () => {
const response = await kbnTestServer.request.get(root, '/some-path/').expect(302);
const response = await request.get(root, '/some-path/').expect(302);
expect(response.get('location')).toEqual('/base-path/some-path');
});

it('includes the query in the redirect', async () => {
const response = await kbnTestServer.request.get(root, '/some-path/?foo=bar').expect(302);
const response = await request.get(root, '/some-path/?foo=bar').expect(302);
expect(response.get('location')).toEqual('/base-path/some-path?foo=bar');
});

it('does not redirect if the path starts with `//`', async () => {
await kbnTestServer.request.get(root, '//some-path/').expect(404);
await request.get(root, '//some-path/').expect(404);
});

it('does not redirect if the path does not end with `/`', async () => {
await kbnTestServer.request.get(root, '/some-path').expect(404);
await request.get(root, '/some-path').expect(404);
});

it('does not add the basePath if the path already contains it', async () => {
const response = await kbnTestServer.request.get(root, '/base-path/foo/').expect(302);
const response = await request.get(root, '/base-path/foo/').expect(302);
expect(response.get('location')).toEqual('/base-path/foo');
});
});

describe('`/` route', () => {
it('prevails on the `/{path*}` route', async () => {
const response = await kbnTestServer.request.get(root, '/').expect(302);
const response = await request.get(root, '/').expect(302);
expect(response.get('location')).toEqual('/base-path/app/home');
});
});
Expand Down
Loading