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

chore(NA): splits types from code on @kbn/test #124469

Merged
merged 10 commits into from
Feb 4, 2022
Merged
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@
"@kbn/storybook": "link:bazel-bin/packages/kbn-storybook",
"@kbn/telemetry-tools": "link:bazel-bin/packages/kbn-telemetry-tools",
"@kbn/test": "link:bazel-bin/packages/kbn-test",
"@kbn/test-jest-helpers": "link:bazel-bin/packages/kbn-test-jest-helpers",
"@kbn/test-subj-selector": "link:bazel-bin/packages/kbn-test-subj-selector",
"@loaders.gl/polyfills": "^2.3.5",
"@mapbox/vector-tile": "1.3.1",
Expand Down Expand Up @@ -610,6 +611,8 @@
"@types/kbn__std": "link:bazel-bin/packages/kbn-std/npm_module_types",
"@types/kbn__storybook": "link:bazel-bin/packages/kbn-storybook/npm_module_types",
"@types/kbn__telemetry-tools": "link:bazel-bin/packages/kbn-telemetry-tools/npm_module_types",
"@types/kbn__test": "link:bazel-bin/packages/kbn-test/npm_module_types",
"@types/kbn__test-jest-helpers": "link:bazel-bin/packages/kbn-test-jest-helpers/npm_module_types",
"@types/kbn__ui-shared-deps-npm": "link:bazel-bin/packages/kbn-ui-shared-deps-npm/npm_module_types",
"@types/kbn__ui-shared-deps-src": "link:bazel-bin/packages/kbn-ui-shared-deps-src/npm_module_types",
"@types/kbn__ui-theme": "link:bazel-bin/packages/kbn-ui-theme/npm_module_types",
Expand Down
3 changes: 3 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ filegroup(
"//packages/kbn-storybook:build",
"//packages/kbn-telemetry-tools:build",
"//packages/kbn-test:build",
"//packages/kbn-test-jest-helpers:build",
"//packages/kbn-test-subj-selector:build",
"//packages/kbn-timelion-grammar:build",
"//packages/kbn-tinymath:build",
Expand Down Expand Up @@ -126,6 +127,8 @@ filegroup(
"//packages/kbn-std:build_types",
"//packages/kbn-storybook:build_types",
"//packages/kbn-telemetry-tools:build_types",
"//packages/kbn-test:build_types",
"//packages/kbn-test-jest-helpers:build_types",
"//packages/kbn-ui-shared-deps-npm:build_types",
"//packages/kbn-ui-shared-deps-src:build_types",
"//packages/kbn-ui-theme:build_types",
Expand Down
5 changes: 5 additions & 0 deletions packages/elastic-eslint-config-kibana/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ module.exports = {
to: false,
disallowedMessage: `Use "@kbn/ui-theme" to access theme vars.`
})),
{
from: '@kbn/test/jest',
to: '@kbn/test-jest-helpers',
disallowedMessage: `import from @kbn/test-jest-helpers instead`
},
],
],

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-archiver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RUNTIME_DEPS = [

TYPES_DEPS = [
"//packages/kbn-dev-utils:npm_module_types",
"//packages/kbn-test",
"//packages/kbn-test:npm_module_types",
"//packages/kbn-utils:npm_module_types",
"@npm//@elastic/elasticsearch",
"@npm//aggregate-error",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-i18n/GUIDELINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ Testing React component that uses the `injectI18n` higher-order component is mor

With shallow rendering only top level component is rendered, that is a wrapper itself, not the original component. Since we want to test the rendering of the original component, we need to access it via the wrapper's `WrappedComponent` property. Its value will be the component we passed into `injectI18n()`.

When testing such component, use the `shallowWithIntl` helper function defined in `@kbn/test/jest` and pass the component's `WrappedComponent` property to render the wrapped component. This will shallow render the component with Enzyme and inject the necessary context and props to use the `intl` mock defined in `test_utils/mocks/intl`.
When testing such component, use the `shallowWithIntl` helper function defined in `@kbn/test-jest-helpers` and pass the component's `WrappedComponent` property to render the wrapped component. This will shallow render the component with Enzyme and inject the necessary context and props to use the `intl` mock defined in `test_utils/mocks/intl`.

Use the `mountWithIntl` helper function to mount render the component.

Expand Down
182 changes: 182 additions & 0 deletions packages/kbn-test-jest-helpers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@npm//@babel/cli:index.bzl", "babel")
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_BASE_NAME = "kbn-test-jest-helpers"
PKG_REQUIRE_NAME = "@kbn/test-jest-helpers"
TYPES_PKG_REQUIRE_NAME = "@types/kbn__test-jest-helpers"

SOURCE_FILES = glob(
[
"src/**/*"
],
exclude = [
"**/*.test.*",
"**/*.snap",
"**/__fixture__/**",
"**/__fixtures__/**",
"**/__snapshots__/**",
]
)

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"jest.config.js",
"package.json",
]

RUNTIME_DEPS = [
"//packages/kbn-dev-utils",
"//packages/kbn-i18n-react",
"//packages/kbn-std",
"//packages/kbn-utils",
"@npm//@elastic/elasticsearch",
"@npm//axios",
"@npm//@babel/traverse",
"@npm//chance",
"@npm//dedent",
"@npm//del",
"@npm//enzyme",
"@npm//execa",
"@npm//exit-hook",
"@npm//form-data",
"@npm//getopts",
"@npm//globby",
"@npm//he",
"@npm//history",
"@npm//jest",
"@npm//jest-cli",
"@npm//jest-snapshot",
"@npm//jest-styled-components",
"@npm//@jest/reporters",
"@npm//joi",
"@npm//mustache",
"@npm//normalize-path",
"@npm//parse-link-header",
"@npm//prettier",
"@npm//react",
"@npm//react-dom",
"@npm//react-redux",
"@npm//react-router-dom",
"@npm//redux",
"@npm//rxjs",
"@npm//semver",
"@npm//strip-ansi",
"@npm//xmlbuilder",
"@npm//xml2js",
]

TYPES_DEPS = [
"//packages/kbn-dev-utils:npm_module_types",
"//packages/kbn-i18n-react:npm_module_types",
"//packages/kbn-std:npm_module_types",
"//packages/kbn-utils:npm_module_types",
"@npm//@elastic/elasticsearch",
"@npm//axios",
"@npm//elastic-apm-node",
"@npm//del",
"@npm//exit-hook",
"@npm//form-data",
"@npm//getopts",
"@npm//jest",
"@npm//jest-cli",
"@npm//jest-snapshot",
"@npm//redux",
"@npm//rxjs",
"@npm//xmlbuilder",
"@npm//@types/chance",
"@npm//@types/dedent",
"@npm//@types/enzyme",
"@npm//@types/he",
"@npm//@types/history",
"@npm//@types/jest",
"@npm//@types/joi",
"@npm//@types/lodash",
"@npm//@types/mustache",
"@npm//@types/normalize-path",
"@npm//@types/node",
"@npm//@types/parse-link-header",
"@npm//@types/prettier",
"@npm//@types/react",
"@npm//@types/react-dom",
"@npm//@types/react-redux",
"@npm//@types/react-router-dom",
"@npm//@types/semver",
"@npm//@types/xml2js",
]

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,
declaration_map = True,
emit_declaration_only = True,
out_dir = "target_types",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)

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

pkg_npm(
name = "npm_module",
deps = [
":%s" % PKG_BASE_NAME,
]
)

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

pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = TYPES_PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)

filegroup(
name = "build_types",
srcs = [
":npm_module_types",
],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
* Side Public License, v 1.
*/

export * from './utils';
module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-test-jest-helpers'],
};
10 changes: 10 additions & 0 deletions packages/kbn-test-jest-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@kbn/test-jest-helpers",
"version": "1.0.0",
"private": true,
"license": "SSPL-1.0 OR Elastic License 2.0",
"main": "./target_node",
"kibana": {
"devOnly": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import { I18nProvider, InjectedIntl, intlShape, __IntlProvider } from '@kbn/i18n-react';
// eslint-disable-next-line import/no-extraneous-dependencies
import { mount, ReactWrapper, render, shallow } from 'enzyme';
import React, { ReactElement, ValidationMap } from 'react';
import { act as reactAct } from 'react-dom/test-utils';
Expand Down Expand Up @@ -118,7 +119,7 @@ export function renderWithIntl<T>(
context?: any;
childContextTypes?: ValidationMap<any>;
} = {}
) {
): any {
const options = getOptions(context, childContextTypes, props);

return render(nodeWithIntlProp(node), options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import { ReactWrapper } from 'enzyme';

type Matcher = '=' | '~=' | '|=' | '^=' | '$=' | '*=';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

export * from './enzyme_helpers';

export * from './get_url';

export * from './find_test_subject';

export * from './jsdom_svg_mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import Chance from 'chance';

const chance = new Chance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export type {
SetupFunc,
SyncSetupFunc,
AsyncSetupFunc,
EuiTableMetaData,
} from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React, { ComponentType } from 'react';
import { Store } from 'redux';
// eslint-disable-next-line import/no-extraneous-dependencies
import { ReactWrapper } from 'enzyme';
import { act } from 'react-dom/test-utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { Component as ReactComponent } from 'react';
// eslint-disable-next-line import/no-extraneous-dependencies
import { ComponentType, HTMLAttributes, ReactWrapper } from 'enzyme';

import { findTestSubject } from '../find_test_subject';
Expand Down Expand Up @@ -41,7 +42,7 @@ const defaultConfig: TestBedConfig = {
*
* @example
```typescript
import { registerTestBed } from '@kbn/test/jest';
import { registerTestBed } from '@kbn/test-jest-helpers';
import { RemoteClusterList } from '../../app/sections/remote_cluster_list';
import { remoteClustersStore } from '../../app/store';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { Store } from 'redux';
// eslint-disable-next-line import/no-extraneous-dependencies
import { ReactWrapper as GenericReactWrapper } from 'enzyme';
import { LocationDescriptor } from 'history';

Expand Down
16 changes: 16 additions & 0 deletions packages/kbn-test-jest-helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "./target_types",
"stripInternal": true,
"rootDir": "src",
"sourceMap": true,
"sourceRoot": "../../../../../../packages/kbn-test-jest-helpers/src",
"types": ["jest", "node"]
},
"include": ["src/**/*"],
"exclude": ["**/__fixtures__/**/*"]
}
Loading