Skip to content

Commit

Permalink
[packages] Migrate @kbn/test to Bazel (#103122)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
jbudz and kibanamachine authored Jun 30, 2021
1 parent ff47516 commit bed5b6d
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 138 deletions.
1 change: 1 addition & 0 deletions docs/developer/getting-started/monorepo-packages.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ yarn kbn watch-bazel
- @kbn/std
- @kbn/storybook
- @kbn/telemetry-utils
- @kbn/test
- @kbn/test-subj-selector
- @kbn/tinymath
- @kbn/ui-framework
Expand Down
9 changes: 4 additions & 5 deletions jest.config.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ module.exports = {
testPathIgnorePatterns: preset.testPathIgnorePatterns.filter(
(pattern) => !pattern.includes('integration_tests')
),
setupFilesAfterEnv: ['<rootDir>/packages/kbn-test/target/jest/setup/after_env.integration.js'],
setupFilesAfterEnv: [
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/after_env.integration.js',
],
reporters: [
'default',
[
'<rootDir>/packages/kbn-test/target/jest/junit_reporter',
{ reportName: 'Jest Integration Tests' },
],
['@kbn/test/target_node/jest/junit_reporter', { reportName: 'Jest Integration Tests' }],
],
coverageReporters: !!process.env.CI
? [['json', { file: 'jest-integration.json' }]]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@
"@kbn/spec-to-console": "link:bazel-bin/packages/kbn-spec-to-console",
"@kbn/storybook": "link:bazel-bin/packages/kbn-storybook",
"@kbn/telemetry-tools": "link:bazel-bin/packages/kbn-telemetry-tools",
"@kbn/test": "link:packages/kbn-test",
"@kbn/test": "link:bazel-bin/packages/kbn-test",
"@kbn/test-subj-selector": "link:bazel-bin/packages/kbn-test-subj-selector",
"@loaders.gl/polyfills": "^2.3.5",
"@microsoft/api-documenter": "7.7.2",
Expand Down
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ filegroup(
"//packages/kbn-std:build",
"//packages/kbn-storybook:build",
"//packages/kbn-telemetry-tools:build",
"//packages/kbn-test:build",
"//packages/kbn-test-subj-selector:build",
"//packages/kbn-tinymath:build",
"//packages/kbn-ui-framework:build",
Expand Down
5 changes: 1 addition & 4 deletions packages/kbn-es-archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
"scripts": {
"kbn:bootstrap": "rm -rf target && ../../node_modules/.bin/tsc",
"kbn:watch": "rm -rf target && ../../node_modules/.bin/tsc --watch"
},
"dependencies": {
"@kbn/test": "link:../kbn-test"
}
}
}
153 changes: 153 additions & 0 deletions packages/kbn-test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@npm//@babel/cli:index.bzl", "babel")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")

PKG_BASE_NAME = "kbn-test"
PKG_REQUIRE_NAME = "@kbn/test"

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

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"jest/package.json",
"jest-preset.js",
"jest.config.js",
"README.md",
"package.json",
]

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

TYPES_DEPS = [
"@npm//@types/chance",
"@npm//@types/enzyme",
"@npm//@types/history",
"@npm//@types/jest",
"@npm//@types/joi",
"@npm//@types/lodash",
"@npm//@types/mustache",
"@npm//@types/node",
"@npm//@types/parse-link-header",
"@npm//@types/prettier",
"@npm//@types/react-dom",
"@npm//@types/react-redux",
"@npm//@types/react-router-dom",
"@npm//@types/xml2js",
]

DEPS = SRC_DEPS + TYPES_DEPS

babel(
name = "target_node",
data = DEPS + [
":srcs",
"babel.config.js",
],
output_dir = True,
# the following arg paths includes $(execpath) as babel runs on the sandbox root
args = [
"./%s/src" % package_name(),
"--config-file",
"./%s/babel.config.js" % package_name(),
"--out-dir",
"$(@D)",
"--extensions",
".ts,.js,.tsx",
"--quiet"
],
)

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

ts_project(
name = "tsc",
args = ['--pretty'],
srcs = SRCS,
deps = DEPS,
declaration = True,
declaration_map = True,
declaration_dir = "target_types",
emit_declaration_only = True,
incremental = True,
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = DEPS + [":target_node", ":tsc"],
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"],
)
35 changes: 18 additions & 17 deletions packages/kbn-test/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

const { resolve } = require('path');

module.exports = {
// The directory where Jest should output its coverage files
coverageDirectory: '<rootDir>/target/kibana-coverage/jest',
Expand All @@ -30,13 +28,16 @@ module.exports = {
moduleNameMapper: {
'@elastic/eui/lib/(.*)?': '<rootDir>/node_modules/@elastic/eui/test-env/$1',
'@elastic/eui$': '<rootDir>/node_modules/@elastic/eui/test-env',
'\\.module.(css|scss)$': '<rootDir>/packages/kbn-test/target/jest/mocks/css_module_mock.js',
'\\.(css|less|scss)$': '<rootDir>/packages/kbn-test/target/jest/mocks/style_mock.js',
'\\.module.(css|scss)$':
'<rootDir>/node_modules/@kbn/test/target_node/jest/mocks/css_module_mock.js',
'\\.(css|less|scss)$': '<rootDir>/node_modules/@kbn/test/target_node/jest/mocks/style_mock.js',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/packages/kbn-test/target/jest/mocks/file_mock.js',
'\\.ace\\.worker.js$': '<rootDir>/packages/kbn-test/target/jest/mocks/worker_module_mock.js',
'\\.editor\\.worker.js$': '<rootDir>/packages/kbn-test/target/jest/mocks/worker_module_mock.js',
'^(!!)?file-loader!': '<rootDir>/packages/kbn-test/target/jest/mocks/file_mock.js',
'<rootDir>/node_modules/@kbn/test/target_node/jest/mocks/file_mock.js',
'\\.ace\\.worker.js$':
'<rootDir>/node_modules/@kbn/test/target_node/jest/mocks/worker_module_mock.js',
'\\.editor\\.worker.js$':
'<rootDir>/node_modules/@kbn/test/target_node/jest/mocks/worker_module_mock.js',
'^(!!)?file-loader!': '<rootDir>/node_modules/@kbn/test/target_node/jest/mocks/file_mock.js',
'^src/core/(.*)': '<rootDir>/src/core/$1',
'^src/plugins/(.*)': '<rootDir>/src/plugins/$1',
},
Expand All @@ -45,20 +46,20 @@ module.exports = {
modulePathIgnorePatterns: ['__fixtures__/', 'target/'],

// Use this configuration option to add custom reporters to Jest
reporters: ['default', resolve(__dirname, './target/jest/junit_reporter')],
reporters: ['default', '@kbn/test/target_node/jest/junit_reporter'],

// The paths to modules that run some code to configure or set up the testing environment before each test
setupFiles: [
'<rootDir>/packages/kbn-test/target/jest/setup/babel_polyfill.js',
'<rootDir>/packages/kbn-test/target/jest/setup/polyfills.js',
'<rootDir>/packages/kbn-test/target/jest/setup/enzyme.js',
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/babel_polyfill.js',
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/polyfills.js',
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/enzyme.js',
],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
setupFilesAfterEnv: [
'<rootDir>/packages/kbn-test/target/jest/setup/setup_test.js',
'<rootDir>/packages/kbn-test/target/jest/setup/mocks.js',
'<rootDir>/packages/kbn-test/target/jest/setup/react_testing_library.js',
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/setup_test.js',
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/mocks.js',
'<rootDir>/node_modules/@kbn/test/target_node/jest/setup/react_testing_library.js',
],

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
Expand All @@ -85,7 +86,7 @@ module.exports = {

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.(js|tsx?)$': '<rootDir>/packages/kbn-test/target/jest/babel_transform.js',
'^.+\\.(js|tsx?)$': '<rootDir>/node_modules/@kbn/test/target_node/jest/babel_transform.js',
'^.+\\.txt?$': 'jest-raw-loader',
'^.+\\.html?$': 'jest-raw-loader',
},
Expand All @@ -109,5 +110,5 @@ module.exports = {
],

// A custom resolver to preserve symlinks by default
resolver: '<rootDir>/packages/kbn-test/target/jest/setup/preserve_symlinks_resolver.js',
resolver: '<rootDir>/node_modules/@kbn/test/target_node/jest/setup/preserve_symlinks_resolver.js',
};
4 changes: 2 additions & 2 deletions packages/kbn-test/jest/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"main": "../target/jest",
"types": "../target/types/jest/index.d.ts"
"main": "../target_node/jest",
"types": "../target_types/jest/index.d.ts"
}
11 changes: 3 additions & 8 deletions packages/kbn-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
"version": "1.0.0",
"private": true,
"license": "SSPL-1.0 OR Elastic License 2.0",
"main": "./target",
"types": "./target/types",
"scripts": {
"build": "node scripts/build",
"kbn:bootstrap": "node scripts/build --source-maps",
"kbn:watch": "node scripts/build --watch --source-maps"
},
"main": "./target_node",
"types": "./target_types",
"kibana": {
"devOnly": true
}
}
}
80 changes: 0 additions & 80 deletions packages/kbn-test/scripts/build.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/kbn-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
// @internal
export { runTestsCli, processRunTestsCliOptions, startServersCli, processStartServersCliOptions };

// @ts-expect-error not typed yet
// @ts-ignore not typed yet
// @internal
export { runTests, startServers } from './functional_tests/tasks';

Expand Down
Loading

0 comments on commit bed5b6d

Please sign in to comment.