mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[packages] Migrate @kbn/test to Bazel (#103122)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
ff475164ed
commit
bed5b6d8f2
18 changed files with 198 additions and 138 deletions
|
@ -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
|
||||
|
|
|
@ -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' }]]
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
packages/kbn-test/BUILD.bazel
Normal file
153
packages/kbn-test/BUILD.bazel
Normal file
|
@ -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"],
|
||||
)
|
|
@ -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',
|
||||
|
@ -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',
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -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',
|
||||
},
|
||||
|
@ -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',
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
const { resolve } = require('path');
|
||||
|
||||
const del = require('del');
|
||||
const supportsColor = require('supports-color');
|
||||
const { run, withProcRunner } = require('@kbn/dev-utils');
|
||||
|
||||
const ROOT_DIR = resolve(__dirname, '..');
|
||||
const BUILD_DIR = resolve(ROOT_DIR, 'target');
|
||||
|
||||
const padRight = (width, str) =>
|
||||
str.length >= width ? str : `${str}${' '.repeat(width - str.length)}`;
|
||||
|
||||
run(
|
||||
async ({ log, flags }) => {
|
||||
await withProcRunner(log, async (proc) => {
|
||||
log.info('Deleting old output');
|
||||
await del(BUILD_DIR);
|
||||
|
||||
const cwd = ROOT_DIR;
|
||||
const env = { ...process.env };
|
||||
if (supportsColor.stdout) {
|
||||
env.FORCE_COLOR = 'true';
|
||||
}
|
||||
|
||||
log.info(`Starting babel and typescript${flags.watch ? ' in watch mode' : ''}`);
|
||||
await Promise.all([
|
||||
proc.run(padRight(10, `babel`), {
|
||||
cmd: 'babel',
|
||||
args: [
|
||||
'src',
|
||||
'--config-file',
|
||||
require.resolve('../babel.config.js'),
|
||||
'--out-dir',
|
||||
BUILD_DIR,
|
||||
'--extensions',
|
||||
'.ts,.js,.tsx',
|
||||
...(flags.watch ? ['--watch'] : ['--quiet']),
|
||||
...(!flags['source-maps'] || !!process.env.CODE_COVERAGE
|
||||
? []
|
||||
: ['--source-maps', 'inline']),
|
||||
],
|
||||
wait: true,
|
||||
env,
|
||||
cwd,
|
||||
}),
|
||||
|
||||
proc.run(padRight(10, 'tsc'), {
|
||||
cmd: 'tsc',
|
||||
args: [
|
||||
...(flags.watch ? ['--watch', '--preserveWatchOutput', 'true'] : []),
|
||||
...(flags['source-maps'] ? ['--declarationMap', 'true'] : []),
|
||||
],
|
||||
wait: true,
|
||||
env,
|
||||
cwd,
|
||||
}),
|
||||
]);
|
||||
|
||||
log.success('Complete');
|
||||
});
|
||||
},
|
||||
{
|
||||
description: 'Simple build tool for @kbn/i18n package',
|
||||
flags: {
|
||||
boolean: ['watch', 'source-maps'],
|
||||
help: `
|
||||
--watch Run in watch mode
|
||||
--source-maps Include sourcemaps
|
||||
`,
|
||||
},
|
||||
}
|
||||
);
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
reporters: [
|
||||
'default',
|
||||
[
|
||||
`${REPO_ROOT}/packages/kbn-test/target/jest/junit_reporter`,
|
||||
`${REPO_ROOT}/node_modules/@kbn/test/target_node/jest/junit_reporter`,
|
||||
{
|
||||
reportName: 'JUnit Reporter Integration Test',
|
||||
rootDirectory: resolve(
|
||||
|
|
|
@ -1,24 +1,17 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "./target/types",
|
||||
"incremental": true,
|
||||
"outDir": "./target_types",
|
||||
"stripInternal": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"rootDir": "src",
|
||||
"sourceMap": true,
|
||||
"sourceRoot": "../../../../../../packages/kbn-test/src",
|
||||
"types": [
|
||||
"jest",
|
||||
"node"
|
||||
],
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"index.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**/__fixtures__/**/*"
|
||||
]
|
||||
"include": ["src/**/*", "index.d.ts"],
|
||||
"exclude": ["**/__fixtures__/**/*"]
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { TestBed } from '@kbn/test/target/types/jest';
|
||||
import { TestBed } from '@kbn/test/target_types/jest';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
|
||||
const createSetWaitForSnapshotAction = (testBed: TestBed) => async (snapshotPolicyName: string) => {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// brace/ace uses the Worker class, which is not currently provided by JSDOM.
|
||||
// This is not required for the tests to pass, but it rather suppresses lengthy
|
||||
// warnings in the console which adds unnecessary noise to the test output.
|
||||
import '@kbn/test/target/jest/utils/stub_web_worker';
|
||||
import '@kbn/test/target_node/jest/utils/stub_web_worker';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import 'brace/mode/json';
|
|||
// brace/ace uses the Worker class, which is not currently provided by JSDOM.
|
||||
// This is not required for the tests to pass, but it rather suppresses lengthy
|
||||
// warnings in the console which adds unnecessary noise to the test output.
|
||||
import '@kbn/test/target/jest/utils/stub_web_worker';
|
||||
import '@kbn/test/target_node/jest/utils/stub_web_worker';
|
||||
|
||||
import { EuiCodeEditor } from '@elastic/eui';
|
||||
import React from 'react';
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// brace/ace uses the Worker class, which is not currently provided by JSDOM.
|
||||
// This is not required for the tests to pass, but it rather suppresses lengthy
|
||||
// warnings in the console which adds unnecessary noise to the test output.
|
||||
import '@kbn/test/target/jest/utils/stub_web_worker';
|
||||
import '@kbn/test/target_node/jest/utils/stub_web_worker';
|
||||
|
||||
import { EuiErrorBoundary } from '@elastic/eui';
|
||||
import React from 'react';
|
||||
|
|
|
@ -2789,7 +2789,7 @@
|
|||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/test@link:packages/kbn-test":
|
||||
"@kbn/test@link:bazel-bin/packages/kbn-test":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue