Skip to content

Commit

Permalink
TS Incremental build exclude test files (elastic#95610)
Browse files Browse the repository at this point in the history
* add base config for all the TS projects

* all the project use new tsconfig.project.json

* compile test files in the high-level tsconfig.json

* fix TS error in maps plugin

* fix TS error in infra plugin

* exclude mote test and test until folders

* uptime. do not import test code within prod code

* expressions. do not import test code within prod code

* data: export mocks from high level folder

* task_manager: comply with es client typings

* infra: remove unused enzyme_helpers

* check_ts_project requires "include" key

* ts_check should handle parent configs

* all ts configs should extend base one

* exclude test folders from plugins

* update patterns to fix ts_check errors

* Apply suggestions from code review

Co-authored-by: Constance <constancecchen@users.noreply.github.com>

* uptime: MountWithReduxProvider to test helpers

Co-authored-by: Constance <constancecchen@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 1, 2021
1 parent a1c36e7 commit b6e582c
Show file tree
Hide file tree
Showing 172 changed files with 351 additions and 282 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"incremental": false,
"outDir": "target",
Expand Down
2 changes: 1 addition & 1 deletion src/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
37 changes: 32 additions & 5 deletions src/dev/typescript/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { basename, dirname, relative, resolve } from 'path';

import { memoize } from 'lodash';
import { IMinimatch, Minimatch } from 'minimatch';
import { REPO_ROOT } from '@kbn/utils';

Expand All @@ -26,6 +26,10 @@ function testMatchers(matchers: IMinimatch[], path: string) {
return matchers.some((matcher) => matcher.match(path));
}

const parentProjectFactory = memoize(function (parentConfigPath: string) {
return new Project(parentConfigPath);
});

export class Project {
public directory: string;
public name: string;
Expand All @@ -34,22 +38,24 @@ export class Project {

private readonly include: IMinimatch[];
private readonly exclude: IMinimatch[];
private readonly parent?: Project;

constructor(
public tsConfigPath: string,
options: { name?: string; disableTypeCheck?: boolean } = {}
) {
this.config = parseTsConfig(tsConfigPath);

const { files, include, exclude = [] } = this.config as {
const { files, include, exclude = [], extends: extendsPath } = this.config as {
files?: string[];
include?: string[];
exclude?: string[];
extends?: string;
};

if (files || !include) {
throw new Error(
'tsconfig.json files in the Kibana repo must use "include" keys and not "files"'
`[${tsConfigPath}]: tsconfig.json files in the Kibana repo must use "include" keys and not "files"`
);
}

Expand All @@ -58,9 +64,30 @@ export class Project {
this.name = options.name || relative(REPO_ROOT, this.directory) || basename(this.directory);
this.include = makeMatchers(this.directory, include);
this.exclude = makeMatchers(this.directory, exclude);

if (extendsPath !== undefined) {
const parentConfigPath = resolve(this.directory, extendsPath);
this.parent = parentProjectFactory(parentConfigPath);
}
}

public isAbsolutePathSelected(path: string): boolean {
return this.isExcluded(path) ? false : this.isIncluded(path);
}

public isAbsolutePathSelected(path: string) {
return testMatchers(this.exclude, path) ? false : testMatchers(this.include, path);
public isExcluded(path: string): boolean {
if (testMatchers(this.exclude, path)) return true;
if (this.parent) {
return this.parent.isExcluded(path);
}
return false;
}

public isIncluded(path: string): boolean {
if (testMatchers(this.include, path)) return true;
if (this.parent) {
return this.parent.isIncluded(path);
}
return false;
}
}
2 changes: 1 addition & 1 deletion src/plugins/advanced_settings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/apm_oss/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/bfetch/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/charts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/console/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dashboard/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { createMockContext } from '../../../../expressions/common';
import { createMockContext } from '../../../../expressions/common/mocks';
import { functionWrapper } from './utils';
import { existsFilterFunction } from './exists_filter';

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

import { createMockContext } from '../../../../expressions/common';
import { createMockContext } from '../../../../expressions/common/mocks';
import { functionWrapper } from './utils';
import { kibanaFilterFunction } from './kibana_filter';

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

import { createMockContext } from '../../../../expressions/common';
import { createMockContext } from '../../../../expressions/common/mocks';
import { functionWrapper } from './utils';
import { phraseFilterFunction } from './phrase_filter';

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

import { createMockContext } from '../../../../expressions/common';
import { createMockContext } from '../../../../expressions/common/mocks';
import { functionWrapper } from './utils';
import { rangeFilterFunction } from './range_filter';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dev_tools/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/discover/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/embeddable/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/es_ui_shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/expressions/common/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ export const createMockExecutionContext = <ExtraContext extends object = object>
...extraContext,
};
};

export { createMockContext } from './util/test_utils';
1 change: 0 additions & 1 deletion src/plugins/expressions/common/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ export * from './create_error';
export * from './get_by_alias';
export * from './tables_adapter';
export * from './expressions_inspector_adapter';
export * from './test_utils';
2 changes: 1 addition & 1 deletion src/plugins/expressions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/home/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/index_pattern_field_editor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/index_pattern_management/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/input_control_vis/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/inspector/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana_legacy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana_overview/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana_react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana_usage_collection/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana_utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/legacy_export/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/management/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/maps_ems/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/maps_legacy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/navigation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/newsfeed/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/presentation_util/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/region_map/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/saved_objects/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/saved_objects_management/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/saved_objects_tagging_oss/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/security_oss/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/share/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/spaces_oss/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/telemetry/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.project.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
Expand Down
Loading

0 comments on commit b6e582c

Please sign in to comment.