From fe0120eb58c186cb0bddaa4ce96c7c2f4b2b77ab Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 24 Aug 2022 16:37:57 -0700 Subject: [PATCH 01/16] [jest/helpers] add safeAct helper to try and debug act() --- packages/kbn-test-jest-helpers/src/index.ts | 4 +- .../kbn-test-jest-helpers/src/safe_act.ts | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 packages/kbn-test-jest-helpers/src/safe_act.ts diff --git a/packages/kbn-test-jest-helpers/src/index.ts b/packages/kbn-test-jest-helpers/src/index.ts index 5e794abdbbb78..129d48382ea44 100644 --- a/packages/kbn-test-jest-helpers/src/index.ts +++ b/packages/kbn-test-jest-helpers/src/index.ts @@ -28,6 +28,8 @@ export * from './testbed'; export * from './axe_helpers'; +export { safeAct } from './safe_act'; + export const nextTick = () => new Promise((res) => process.nextTick(res)); -export const delay = (time = 0) => new Promise((resolve) => setTimeout(resolve, time)); +export { setTimeout as delay } from 'timers/promises'; diff --git a/packages/kbn-test-jest-helpers/src/safe_act.ts b/packages/kbn-test-jest-helpers/src/safe_act.ts new file mode 100644 index 0000000000000..69092b17093a4 --- /dev/null +++ b/packages/kbn-test-jest-helpers/src/safe_act.ts @@ -0,0 +1,56 @@ +/* + * 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. + */ + +import { act } from 'react-dom/test-utils'; + +let current: symbol | undefined; + +if (typeof beforeEach === 'function') { + beforeEach(() => { + current = Symbol(); + }); +} + +if (typeof afterEach === 'function') { + afterEach(() => { + current = undefined; + }); +} + +export function safeAct(cb: () => Promise): Promise; +export function safeAct(cb: () => void): void; +export function safeAct(cb: () => Promise | void) { + const scheduled = current; + if (scheduled === undefined) { + throw new Error( + 'safeAct() should only be called in beforeAll/beforeEach hooks or in tests and must be imported at the root of the file' + ); + } + + const sourceStack = new Error().stack ?? ''; + + return act(() => { + if (scheduled === current) { + return cb() as never; + } + + const indentedStack = sourceStack + .split('\n') + .slice(1) + .map((l) => ` ${l}`) + .join('\n'); + + // console.log is the proper way to log in jest tests, but also nobody ever looks at them... + // eslint-disable-next-line no-console + console.log( + `act() cb triggered after test completed, act registration stacktrace:\n${indentedStack}` + ); + + return undefined as never; + }); +} From 8c3d9538ee53ce63c0802e1b4765703064749a0c Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 24 Aug 2022 16:49:39 -0700 Subject: [PATCH 02/16] use safeAct in ilm jest tests --- .../__jest__/client_integration/app/app.helpers.ts | 2 +- .../__jest__/client_integration/app/app.test.ts | 2 +- .../edit_policy/features/delete_phase.test.ts | 2 +- .../edit_policy/features/edit_warning.test.ts | 2 +- .../edit_policy/features/frozen_phase.test.ts | 2 +- .../features/node_allocation/cloud_aware_behavior.test.ts | 2 +- .../edit_policy/features/node_allocation/cold_phase.test.ts | 2 +- .../features/node_allocation/general_behavior.test.ts | 2 +- .../edit_policy/features/node_allocation/warm_phase.test.ts | 2 +- .../edit_policy/features/request_flyout.test.ts | 2 +- .../client_integration/edit_policy/features/rollover.test.ts | 2 +- .../edit_policy/features/searchable_snapshots.test.ts | 2 +- .../client_integration/edit_policy/features/timeline.test.ts | 2 +- .../client_integration/edit_policy/features/timing.test.ts | 2 +- .../edit_policy/form_validation/cold_phase_validation.test.ts | 2 +- .../edit_policy/form_validation/error_indicators.test.ts | 2 +- .../edit_policy/form_validation/hot_phase_validation.test.ts | 2 +- .../edit_policy/form_validation/policy_name_validation.test.ts | 2 +- .../edit_policy/form_validation/timing.test.ts | 2 +- .../edit_policy/form_validation/warm_phase_validation.test.ts | 2 +- .../edit_policy/serialization/policy_serialization.test.ts | 2 +- .../client_integration/helpers/actions/errors_actions.ts | 2 +- .../client_integration/helpers/actions/forcemerge_actions.ts | 2 +- .../client_integration/helpers/actions/form_set_value_action.ts | 2 +- .../client_integration/helpers/actions/form_toggle_action.ts | 2 +- .../helpers/actions/node_allocation_actions.ts | 2 +- .../helpers/actions/request_flyout_actions.ts | 2 +- .../client_integration/helpers/actions/rollover_actions.ts | 2 +- .../client_integration/helpers/actions/save_policy_action.ts | 2 +- .../helpers/actions/searchable_snapshot_actions.ts | 2 +- .../client_integration/helpers/actions/shrink_actions.ts | 2 +- .../helpers/actions/snapshot_policy_actions.ts | 2 +- .../client_integration/helpers/actions/toggle_phase_action.ts | 2 +- 33 files changed, 33 insertions(+), 33 deletions(-) diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.ts index df64fbce3fa1d..c3bfb5e1cc0b0 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { HttpSetup } from '@kbn/core/public'; import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test-jest-helpers'; import { App } from '../../../public/application/app'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts index 1aaec089724b6..21fb70163544d 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { getDefaultHotPhasePolicy } from '../edit_policy/constants'; import { setupEnvironment } from '../helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts index d877f05d06ae1..c97a42ad350cd 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { API_BASE_PATH } from '../../../../common/constants'; import { setupEnvironment } from '../../helpers'; import { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/edit_warning.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/edit_warning.test.ts index 98d6078da031c..88a3a183560e8 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/edit_warning.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/edit_warning.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../helpers'; import { initTestBed } from '../init_test_bed'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts index ffe11133be7fd..fe810e872b981 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts index 820f8a4f9100a..3e9c1aea8b0ec 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../../helpers'; import { CloudNodeAllocationTestBed, diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts index 63382de45f414..2bbbcb40cbb28 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../../helpers'; import { NodeAllocationTestBed, setupColdPhaseNodeAllocation } from './cold_phase.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.test.ts index 1eecd5207664f..b96fd0492fd10 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { HttpFetchOptionsWithPath } from '@kbn/core/public'; import { setupEnvironment } from '../../../helpers'; import { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts index 6f96aaf07da1b..7039a34ab910f 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../../helpers'; import { NodeAllocationTestBed, setupWarmPhaseNodeAllocation } from './warm_phase.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts index 61dda6fa65efb..a31e9194ef573 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../helpers'; import { setupRequestFlyoutTestBed, RequestFlyoutTestBed } from './request_flyout.helpers'; import { getDefaultHotPhasePolicy } from '../constants'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts index 1544390229595..aa9af63273b49 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../helpers'; import { RolloverTestBed, setupRolloverTestBed } from './rollover.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts index 09bb8b85082b6..5bfff36574394 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; import { HttpFetchOptionsWithPath } from '@kbn/core/public'; import { setupEnvironment } from '../../helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts index 760ede62606cb..9572e1b84e76c 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../helpers'; import { setupTimelineTestBed, TimelineTestBed } from './timeline.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts index 0aee8eb5f0be1..2549e2d93d7bb 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../helpers'; import { setupTimingTestBed, TimingTestBed } from './timing.helpers'; import { PhaseWithTiming } from '../../../../common/types'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts index 98891ea72928f..3fb47906dbad1 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts index bd4a2caec0be5..e743865ce5231 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../helpers'; import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts index 70a51cae4c71e..e309b8f05d038 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts index 9c14584bb2fcf..e72016976ed7c 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; import { getGeneratedPolicies } from '../constants'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts index 3e29bc5d76580..4355d6b7bde5a 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { PhaseWithTiming } from '../../../../common/types'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts index 9d326e9978519..31e5a5452df2a 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts index 14f1403ad536d..822ef26fca0bd 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; import { HttpFetchOptionsWithPath } from '@kbn/core/public'; import { setupEnvironment } from '../../helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts index 4b863071e191c..6e843a9da5167 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; import { Phase } from '../../../../common/types'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts index b6ed40de36ca9..ea8904f75925a 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; import { Phase } from '../../../../common/types'; import { createFormToggleAction } from './form_toggle_action'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts index 57a41831406f9..e7cc6150c2b8c 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; export function createFormSetValueAction( diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts index b2408583cc3aa..53d8b143dc0ed 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; export const createFormToggleAction = (testBed: TestBed, dataTestSubject: string) => async () => { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts index 2a680590654a8..f2add8022e06a 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; import { DataTierAllocationType } from '../../../../public/application/sections/edit_policy/types'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/request_flyout_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/request_flyout_actions.ts index ca79d52741595..4c142ef0360b7 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/request_flyout_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/request_flyout_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; const jsonSelector = 'policyRequestJson'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts index 43c296466dab4..57014828afa78 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; import { createFormToggleAction } from './form_toggle_action'; import { createFormSetValueAction } from './form_set_value_action'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts index 9c27e38d75e0d..0a831880b6835 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; export const createSavePolicyAction = (testBed: TestBed) => async () => { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts index 3efffcddbece6..a2957e0e6e5e1 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { TestBed } from '@kbn/test-jest-helpers'; import { Phase } from '../../../../common/types'; import { createFormToggleAction } from './form_toggle_action'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts index def20f73b82fe..119a6fc42e183 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts @@ -6,7 +6,7 @@ */ import { TestBed } from '@kbn/test-jest-helpers'; -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { Phase } from '../../../../common/types'; import { createFormSetValueAction } from './form_set_value_action'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts index 8aaf968560a1d..8865015556c07 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts @@ -6,7 +6,7 @@ */ import type { TestBed } from '@kbn/test-jest-helpers'; -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; const createSetWaitForSnapshotAction = (testBed: TestBed) => async (snapshotPolicyName: string) => { const { find, component } = testBed; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts index c22efae87d5ac..c810e5cc187e4 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts @@ -6,7 +6,7 @@ */ import { TestBed } from '@kbn/test-jest-helpers'; -import { act } from 'react-dom/test-utils'; +import { safeAct as act } from '@kbn/test-jest-helpers'; import { Phase } from '../../../../common/types'; From eadc8c205bfc9fb737c7dcf618a21817f6585dee Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 24 Aug 2022 16:59:49 -0700 Subject: [PATCH 03/16] remove invalid use of act() --- .../serialization/policy_serialization.test.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts index 822ef26fca0bd..9f89e027def35 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts @@ -33,16 +33,6 @@ describe(' serialization', () => { }); describe('top level form', () => { - afterAll(async () => { - await act(async () => { - testBed = await setupSerializationTestBed(httpSetup, { - appServicesContext: { - license: licensingMock.createLicense({ license: { type: 'enterprise' } }), - }, - }); - }); - }); - /** * We assume that policies that populate this form are loaded directly from ES and so * are valid according to ES. There may be settings in the policy created through the ILM From 899bf8274789f5f2554eb38bf707fe308b5736e3 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 24 Aug 2022 17:03:09 -0700 Subject: [PATCH 04/16] only run unit tests for now --- .buildkite/pipelines/pull_request/base.yml | 78 +++++++++++----------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/.buildkite/pipelines/pull_request/base.yml b/.buildkite/pipelines/pull_request/base.yml index 86c94dad7a667..27f6d4efe4962 100644 --- a/.buildkite/pipelines/pull_request/base.yml +++ b/.buildkite/pipelines/pull_request/base.yml @@ -51,49 +51,51 @@ steps: JEST_UNIT_SCRIPT: '.buildkite/scripts/steps/test/jest.sh' JEST_INTEGRATION_SCRIPT: '.buildkite/scripts/steps/test/jest_integration.sh' FTR_CONFIGS_SCRIPT: '.buildkite/scripts/steps/test/ftr_configs.sh' + LIMIT_CONFIG_TYPE: 'unit' + JEST_MAX_MINUTES: '20' retry: automatic: - exit_status: '*' limit: 1 - - command: .buildkite/scripts/steps/lint.sh - label: 'Linting' - agents: - queue: n2-8-spot - key: linting - timeout_in_minutes: 60 - retry: - automatic: - - exit_status: '-1' - limit: 3 + # - command: .buildkite/scripts/steps/lint.sh + # label: 'Linting' + # agents: + # queue: n2-8-spot + # key: linting + # timeout_in_minutes: 60 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 - - command: .buildkite/scripts/steps/lint_with_types.sh - label: 'Linting (with types)' - agents: - queue: n2-16-spot - key: linting_with_types - timeout_in_minutes: 90 - retry: - automatic: - - exit_status: '-1' - limit: 3 + # - command: .buildkite/scripts/steps/lint_with_types.sh + # label: 'Linting (with types)' + # agents: + # queue: n2-16-spot + # key: linting_with_types + # timeout_in_minutes: 90 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 - - command: .buildkite/scripts/steps/checks.sh - label: 'Checks' - agents: - queue: n2-2-spot - timeout_in_minutes: 60 - retry: - automatic: - - exit_status: '-1' - limit: 3 + # - command: .buildkite/scripts/steps/checks.sh + # label: 'Checks' + # agents: + # queue: n2-2-spot + # timeout_in_minutes: 60 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 - - command: .buildkite/scripts/steps/check_types.sh - label: 'Check Types' - agents: - queue: n2-16-spot - timeout_in_minutes: 60 - retry: - automatic: - - exit_status: '-1' - limit: 3 + # - command: .buildkite/scripts/steps/check_types.sh + # label: 'Check Types' + # agents: + # queue: n2-16-spot + # timeout_in_minutes: 60 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 From 8ee08c1b0968a3c65d9bc53efe8ab7efd160d4a3 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 24 Aug 2022 17:44:48 -0700 Subject: [PATCH 05/16] remove act in afterAll() --- .../serialization/policy_serialization.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts index 9f89e027def35..0af72d3e17ba0 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts @@ -166,6 +166,15 @@ describe(' serialization', () => { describe('hot phase', () => { beforeEach(async () => { + await act(async () => { + // this used to be in an afterAll hook in the previous suite... it seems to mutate something that is required for the following tests to work... + testBed = await setupSerializationTestBed(httpSetup, { + appServicesContext: { + license: licensingMock.createLicense({ license: { type: 'enterprise' } }), + }, + }); + }); + httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { From 01b76cbe71b1a0d14ef38c733a87dafc83f4ebc2 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 24 Aug 2022 18:05:58 -0700 Subject: [PATCH 06/16] fail safeAct more aggressively --- packages/kbn-test-jest-helpers/src/safe_act.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/kbn-test-jest-helpers/src/safe_act.ts b/packages/kbn-test-jest-helpers/src/safe_act.ts index 69092b17093a4..908ca5fe30cd3 100644 --- a/packages/kbn-test-jest-helpers/src/safe_act.ts +++ b/packages/kbn-test-jest-helpers/src/safe_act.ts @@ -50,7 +50,6 @@ export function safeAct(cb: () => Promise | void) { console.log( `act() cb triggered after test completed, act registration stacktrace:\n${indentedStack}` ); - - return undefined as never; + process.exit(1); }); } From e9a4335e3e787cbb9f459a197eb43ef684d1e321 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 24 Aug 2022 18:11:50 -0700 Subject: [PATCH 07/16] just run ILM tests over and over --- .../ci-stats/pick_test_group_run_order.ts | 462 ++---------------- 1 file changed, 34 insertions(+), 428 deletions(-) diff --git a/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts b/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts index 4044c4f1bebad..3f09e022f1451 100644 --- a/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts +++ b/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts @@ -8,14 +8,7 @@ import * as Fs from 'fs'; -import * as globby from 'globby'; -import minimatch from 'minimatch'; -import { load as loadYaml } from 'js-yaml'; - -import { BuildkiteClient, BuildkiteStep } from '../buildkite'; -import { CiStatsClient, TestGroupRunOrderResponse } from './client'; - -type RunGroup = TestGroupRunOrderResponse['types'][0]; +import { BuildkiteClient } from '../buildkite'; const getRequiredEnv = (name: string) => { const value = process.env[name]; @@ -25,438 +18,51 @@ const getRequiredEnv = (name: string) => { return value; }; -function getRunGroups(bk: BuildkiteClient, allTypes: RunGroup[], typeName: string): RunGroup[] { - const types = allTypes.filter((t) => t.type === typeName); - if (!types.length) { - throw new Error(`missing test group run order for group [${typeName}]`); - } - - const misses = types.flatMap((t) => t.namesWithoutDurations); - if (misses.length > 0) { - bk.setAnnotation( - `test-group-missing-durations:${typeName}`, - 'warning', - [ - misses.length === 1 - ? `The following "${typeName}" config doesn't have a recorded time in ci-stats so the automatically-determined test groups might be a little unbalanced.` - : `The following "${typeName}" configs don't have recorded times in ci-stats so the automatically-determined test groups might be a little unbalanced.`, - misses.length === 1 - ? `If this is a new config then this warning can be ignored as times will be reported soon.` - : `If these are new configs then this warning can be ignored as times will be reported soon.`, - misses.length === 1 - ? `The other possibility is that there aren't any tests in this config, so times are never reported.` - : `The other possibility is that there aren't any tests in these configs, so times are never reported.`, - 'Empty test configs should be removed', - '', - ...misses.map((n) => ` - ${n}`), - ].join('\n') - ); - } - - const tooLongs = types.flatMap((t) => t.tooLong ?? []); - if (tooLongs.length > 0) { - bk.setAnnotation( - `test-group-too-long:${typeName}`, - 'error', - [ - tooLongs.length === 1 - ? `The following "${typeName}" config has a duration that exceeds the maximum amount of time desired for a single CI job. Please split it up.` - : `The following "${typeName}" configs have durations that exceed the maximum amount of time desired for a single CI job. Please split them up.`, - '', - ...tooLongs.map(({ config, durationMin }) => ` - ${config}: ${durationMin} minutes`), - ].join('\n') - ); - } - - return types; -} - -function getRunGroup(bk: BuildkiteClient, allTypes: RunGroup[], typeName: string): RunGroup { - const groups = getRunGroups(bk, allTypes, typeName); - if (groups.length !== 1) { - throw new Error(`expected to find exactly 1 "${typeName}" run group`); - } - return groups[0]; -} - -function getTrackedBranch(): string { - let pkg; - try { - pkg = JSON.parse(Fs.readFileSync('package.json', 'utf8')); - } catch (_) { - const error = _ instanceof Error ? _ : new Error(`${_} thrown`); - throw new Error(`unable to read kibana's package.json file: ${error.message}`); - } - - const branch = pkg.branch; - if (typeof branch !== 'string') { - throw new Error('missing `branch` field from package.json file'); - } - - return branch; -} - -function isObj(x: unknown): x is Record { - return typeof x === 'object' && x !== null; -} - -function getEnabledFtrConfigs(patterns?: string[]) { - try { - const configs = loadYaml(Fs.readFileSync('.buildkite/ftr_configs.yml', 'utf8')); - if (!isObj(configs)) { - throw new Error('expected yaml file to parse to an object'); - } - if (!configs.enabled) { - throw new Error('expected yaml file to have an "enabled" key'); - } - if ( - !Array.isArray(configs.enabled) || - !configs.enabled.every( - (p): p is string | { [configPath: string]: { queue: string } } => - typeof p === 'string' || - (isObj(p) && Object.values(p).every((v) => isObj(v) && typeof v.queue === 'string')) - ) - ) { - throw new Error(`expected "enabled" value to be an array of strings or objects shaped as:\n - - {configPath}: - queue: {queueName}`); - } - if (typeof configs.defaultQueue !== 'string') { - throw new Error('expected yaml file to have a string "defaultQueue" key'); - } - - const defaultQueue = configs.defaultQueue; - const ftrConfigsByQueue = new Map(); - for (const enabled of configs.enabled) { - const path = typeof enabled === 'string' ? enabled : Object.keys(enabled)[0]; - const queue = isObj(enabled) ? enabled[path].queue : defaultQueue; - - if (patterns && !patterns.some((pattern) => minimatch(path, pattern))) { - continue; - } - - const group = ftrConfigsByQueue.get(queue); - if (group) { - group.push(path); - } else { - ftrConfigsByQueue.set(queue, [path]); - } - } - - return { defaultQueue, ftrConfigsByQueue }; - } catch (_) { - const error = _ instanceof Error ? _ : new Error(`${_} thrown`); - throw new Error(`unable to parse ftr_configs.yml file: ${error.message}`); - } -} - export async function pickTestGroupRunOrder() { const bk = new BuildkiteClient(); - const ciStats = new CiStatsClient(); - - // these keys are synchronized in a few placed by storing them in the env during builds - const UNIT_TYPE = getRequiredEnv('TEST_GROUP_TYPE_UNIT'); - const INTEGRATION_TYPE = getRequiredEnv('TEST_GROUP_TYPE_INTEGRATION'); - const FUNCTIONAL_TYPE = getRequiredEnv('TEST_GROUP_TYPE_FUNCTIONAL'); - - const JEST_MAX_MINUTES = process.env.JEST_MAX_MINUTES - ? parseFloat(process.env.JEST_MAX_MINUTES) - : 40; - if (Number.isNaN(JEST_MAX_MINUTES)) { - throw new Error(`invalid JEST_MAX_MINUTES: ${process.env.JEST_MAX_MINUTES}`); - } - - const FUNCTIONAL_MAX_MINUTES = process.env.FUNCTIONAL_MAX_MINUTES - ? parseFloat(process.env.FUNCTIONAL_MAX_MINUTES) - : 37; - if (Number.isNaN(FUNCTIONAL_MAX_MINUTES)) { - throw new Error(`invalid FUNCTIONAL_MAX_MINUTES: ${process.env.FUNCTIONAL_MAX_MINUTES}`); - } - - const LIMIT_CONFIG_TYPE = process.env.LIMIT_CONFIG_TYPE - ? process.env.LIMIT_CONFIG_TYPE.split(',') - .map((t) => t.trim()) - .filter(Boolean) - : ['unit', 'integration', 'functional']; - - const FTR_CONFIG_PATTERNS = process.env.FTR_CONFIG_PATTERNS - ? process.env.FTR_CONFIG_PATTERNS.split(',') - .map((t) => t.trim()) - .filter(Boolean) - : undefined; - - const FUNCTIONAL_MINIMUM_ISOLATION_MIN = process.env.FUNCTIONAL_MINIMUM_ISOLATION_MIN - ? parseFloat(process.env.FUNCTIONAL_MINIMUM_ISOLATION_MIN) - : undefined; - if ( - FUNCTIONAL_MINIMUM_ISOLATION_MIN !== undefined && - Number.isNaN(FUNCTIONAL_MINIMUM_ISOLATION_MIN) - ) { - throw new Error( - `invalid FUNCTIONAL_MINIMUM_ISOLATION_MIN: ${process.env.FUNCTIONAL_MINIMUM_ISOLATION_MIN}` - ); - } - - const FTR_CONFIGS_RETRY_COUNT = process.env.FTR_CONFIGS_RETRY_COUNT - ? parseInt(process.env.FTR_CONFIGS_RETRY_COUNT, 10) - : 1; - if (Number.isNaN(FTR_CONFIGS_RETRY_COUNT)) { - throw new Error(`invalid FTR_CONFIGS_RETRY_COUNT: ${process.env.FTR_CONFIGS_RETRY_COUNT}`); - } - - const FTR_CONFIGS_DEPS = - process.env.FTR_CONFIGS_DEPS !== undefined - ? process.env.FTR_CONFIGS_DEPS.split(',') - .map((t) => t.trim()) - .filter(Boolean) - : ['build']; - const { defaultQueue, ftrConfigsByQueue } = getEnabledFtrConfigs(FTR_CONFIG_PATTERNS); - if (!LIMIT_CONFIG_TYPE.includes('functional')) { - ftrConfigsByQueue.clear(); - } - - const jestUnitConfigs = LIMIT_CONFIG_TYPE.includes('unit') - ? globby.sync(['**/jest.config.js', '!**/__fixtures__/**'], { - cwd: process.cwd(), - absolute: false, - }) - : []; - - const jestIntegrationConfigs = LIMIT_CONFIG_TYPE.includes('integration') - ? globby.sync(['**/jest.integration.config.js', '!**/__fixtures__/**'], { - cwd: process.cwd(), - absolute: false, - }) - : []; - - if (!ftrConfigsByQueue.size && !jestUnitConfigs.length && !jestIntegrationConfigs.length) { - throw new Error('unable to find any unit, integration, or FTR configs'); - } - - const trackedBranch = getTrackedBranch(); - const ownBranch = process.env.BUILDKITE_BRANCH as string; - const pipelineSlug = process.env.BUILDKITE_PIPELINE_SLUG as string; - const prNumber = process.env.GITHUB_PR_NUMBER as string | undefined; - - const { sources, types } = await ciStats.pickTestGroupRunOrder({ - sources: [ - // try to get times from a recent successful job on this PR - ...(prNumber - ? [ - { - prId: prNumber, - jobName: 'kibana-pull-request', - }, - ] - : []), - // if we are running on a external job, like kibana-code-coverage-main, try finding times that are specific to that job - ...(!prNumber && pipelineSlug !== 'kibana-on-merge' - ? [ - { - branch: ownBranch, - jobName: pipelineSlug, - }, - { - branch: trackedBranch, - jobName: pipelineSlug, - }, - ] - : []), - // try to get times from the mergeBase commit - ...(process.env.GITHUB_PR_MERGE_BASE - ? [ - { - commit: process.env.GITHUB_PR_MERGE_BASE, - jobName: 'kibana-on-merge', - }, - ] - : []), - // fallback to the latest times from the tracked branch - { - branch: trackedBranch, - jobName: 'kibana-on-merge', - }, - // finally fallback to the latest times from the main branch in case this branch is brand new - { - branch: 'main', - jobName: 'kibana-on-merge', - }, - ], - groups: [ - { - type: UNIT_TYPE, - defaultMin: 3, - maxMin: JEST_MAX_MINUTES, - overheadMin: 0.2, - names: jestUnitConfigs, - }, + // write the config for each step to an artifact that can be used by the individual jest jobs + Fs.writeFileSync( + 'jest_run_order.json', + JSON.stringify( { - type: INTEGRATION_TYPE, - defaultMin: 10, - maxMin: JEST_MAX_MINUTES, - overheadMin: 0.2, - names: jestIntegrationConfigs, + unit: { + groups: new Array(50).fill(null).map(() => ({ + names: new Array(10).fill('x-pack/plugins/index_lifecycle_management/jest.config.js'), + })), + }, }, - ...Array.from(ftrConfigsByQueue).map(([queue, names]) => ({ - type: FUNCTIONAL_TYPE, - defaultMin: 60, - queue, - maxMin: FUNCTIONAL_MAX_MINUTES, - minimumIsolationMin: FUNCTIONAL_MINIMUM_ISOLATION_MIN, - overheadMin: 1.5, - names, - })), - ], - }); - - console.log('test run order is determined by builds:'); - console.dir(sources, { depth: Infinity, maxArrayLength: Infinity }); - - const unit = getRunGroup(bk, types, UNIT_TYPE); - const integration = getRunGroup(bk, types, INTEGRATION_TYPE); - - let configCounter = 0; - let groupCounter = 0; - - // the relevant data we will use to define the pipeline steps - const functionalGroups: Array<{ - title: string; - key: string; - sortBy: number | string; - queue: string; - }> = []; - // the map that we will write to the artifacts for informing ftr config jobs of what they should do - const ftrRunOrder: Record< - string, - { title: string; expectedDurationMin: number; names: string[] } - > = {}; - - if (ftrConfigsByQueue.size) { - for (const { groups, queue } of getRunGroups(bk, types, FUNCTIONAL_TYPE)) { - for (const group of groups) { - if (!group.names.length) { - continue; - } - - const key = `ftr_configs_${configCounter++}`; - let sortBy; - let title; - if (group.names.length === 1) { - title = group.names[0]; - sortBy = title; - } else { - sortBy = ++groupCounter; - title = `FTR Configs #${sortBy}`; - } - - functionalGroups.push({ - title, - key, - sortBy, - queue: queue ?? defaultQueue, - }); - ftrRunOrder[key] = { - title, - expectedDurationMin: group.durationMin, - names: group.names, - }; - } - } - } - - // write the config for each step to an artifact that can be used by the individual jest jobs - Fs.writeFileSync('jest_run_order.json', JSON.stringify({ unit, integration }, null, 2)); + null, + 2 + ) + ); bk.uploadArtifacts('jest_run_order.json'); - // write the config for functional steps to an artifact that can be used by the individual functional jobs - Fs.writeFileSync('ftr_run_order.json', JSON.stringify(ftrRunOrder, null, 2)); - bk.uploadArtifacts('ftr_run_order.json'); + // // write the config for functional steps to an artifact that can be used by the individual functional jobs + // Fs.writeFileSync('ftr_run_order.json', JSON.stringify(ftrRunOrder, null, 2)); + // bk.uploadArtifacts('ftr_run_order.json'); // upload the step definitions to Buildkite bk.uploadSteps( [ - unit.count > 0 - ? { - label: 'Jest Tests', - command: getRequiredEnv('JEST_UNIT_SCRIPT'), - parallelism: unit.count, - timeout_in_minutes: 90, - key: 'jest', - agents: { - queue: 'n2-4-spot', - }, - retry: { - automatic: [ - { - exit_status: '-1', - limit: 3, - }, - ], - }, - } - : [], - integration.count > 0 - ? { - label: 'Jest Integration Tests', - command: getRequiredEnv('JEST_INTEGRATION_SCRIPT'), - parallelism: integration.count, - timeout_in_minutes: 120, - key: 'jest-integration', - agents: { - queue: 'n2-4-spot', - }, - retry: { - automatic: [ - { - exit_status: '-1', - limit: 3, - }, - ], + { + label: 'Jest Tests', + command: getRequiredEnv('JEST_UNIT_SCRIPT'), + parallelism: 50, + timeout_in_minutes: 90, + key: 'jest', + agents: { + queue: 'n2-4-spot', + }, + retry: { + automatic: [ + { + exit_status: '-1', + limit: 3, }, - } - : [], - functionalGroups.length - ? { - group: 'FTR Configs', - key: 'ftr-configs', - depends_on: FTR_CONFIGS_DEPS, - steps: functionalGroups - .sort((a, b) => - // if both groups are sorted by number then sort by that - typeof a.sortBy === 'number' && typeof b.sortBy === 'number' - ? a.sortBy - b.sortBy - : // if both groups are sorted by string, sort by that - typeof a.sortBy === 'string' && typeof b.sortBy === 'string' - ? a.sortBy.localeCompare(b.sortBy) - : // if a is sorted by number then order it later than b - typeof a.sortBy === 'number' - ? 1 - : -1 - ) - .map( - ({ title, key, queue = defaultQueue }): BuildkiteStep => ({ - label: title, - command: getRequiredEnv('FTR_CONFIGS_SCRIPT'), - timeout_in_minutes: 150, - agents: { - queue, - }, - env: { - FTR_CONFIG_GROUP_KEY: key, - }, - retry: { - automatic: [ - { exit_status: '-1', limit: 3 }, - ...(FTR_CONFIGS_RETRY_COUNT > 0 - ? [{ exit_status: '*', limit: FTR_CONFIGS_RETRY_COUNT }] - : []), - ], - }, - }) - ), - } - : [], + ], + }, + }, ].flat() ); } From 3e1e26e64c5b6164153ad877dfcab64dd5c37f23 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 24 Aug 2022 18:21:09 -0700 Subject: [PATCH 08/16] disable build too --- .buildkite/pipelines/pull_request/base.yml | 66 +++++++++++----------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/.buildkite/pipelines/pull_request/base.yml b/.buildkite/pipelines/pull_request/base.yml index 27f6d4efe4962..0a3ea0b32175d 100644 --- a/.buildkite/pipelines/pull_request/base.yml +++ b/.buildkite/pipelines/pull_request/base.yml @@ -7,41 +7,41 @@ steps: - wait - - command: .buildkite/scripts/steps/build_kibana.sh - label: Build Kibana Distribution and Plugins - agents: - queue: n2-16-spot - key: build - if: "build.env('KIBANA_BUILD_ID') == null || build.env('KIBANA_BUILD_ID') == ''" - timeout_in_minutes: 60 - retry: - automatic: - - exit_status: '-1' - limit: 3 + # - command: .buildkite/scripts/steps/build_kibana.sh + # label: Build Kibana Distribution and Plugins + # agents: + # queue: n2-16-spot + # key: build + # if: "build.env('KIBANA_BUILD_ID') == null || build.env('KIBANA_BUILD_ID') == ''" + # timeout_in_minutes: 60 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 - - command: .buildkite/scripts/steps/build_api_docs.sh - label: 'Build API Docs' - agents: - queue: n2-4-spot - key: build_api_docs - timeout_in_minutes: 60 - retry: - automatic: - - exit_status: '-1' - limit: 3 + # - command: .buildkite/scripts/steps/build_api_docs.sh + # label: 'Build API Docs' + # agents: + # queue: n2-4-spot + # key: build_api_docs + # timeout_in_minutes: 60 + # retry: + # automatic: + # - exit_status: '-1' + # limit: 3 - - command: .buildkite/scripts/steps/ci_stats_ready.sh - label: Mark CI Stats as ready - agents: - queue: kibana-default - timeout_in_minutes: 10 - depends_on: - - build - - build_api_docs - retry: - automatic: - - exit_status: '*' - limit: 1 + # - command: .buildkite/scripts/steps/ci_stats_ready.sh + # label: Mark CI Stats as ready + # agents: + # queue: kibana-default + # timeout_in_minutes: 10 + # depends_on: + # - build + # - build_api_docs + # retry: + # automatic: + # - exit_status: '*' + # limit: 1 - command: .buildkite/scripts/steps/test/pick_test_group_run_order.sh label: 'Pick Test Group Run Order' From 637b09edc1e615bc69edd98ba68e2dfc26152b7e Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 25 Aug 2022 07:11:34 -0700 Subject: [PATCH 09/16] remove metric failure reporting --- .../pipeline-utils/ci-stats/on_complete.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.buildkite/pipeline-utils/ci-stats/on_complete.ts b/.buildkite/pipeline-utils/ci-stats/on_complete.ts index 0b93fd6b0673f..005cbd1817df9 100644 --- a/.buildkite/pipeline-utils/ci-stats/on_complete.ts +++ b/.buildkite/pipeline-utils/ci-stats/on_complete.ts @@ -21,22 +21,4 @@ export async function onComplete() { const status = result.success ? 'SUCCESS' : 'FAILURE'; console.log('Job Status:', result); await ciStats.completeBuild(status, process.env.CI_STATS_BUILD_ID); - - if (!process.env.GITHUB_PR_NUMBER) { - return; - } - - const report = await ciStats.getPrReport(process.env.CI_STATS_BUILD_ID); - if (report?.md) { - buildkite.setMetadata('pr_comment:ci_stats_report:body', report.md); - - const annotationType = report?.success ? 'info' : 'error'; - buildkite.setAnnotation('ci-stats-report', annotationType, report.md); - } - - if (report && !report.success) { - console.log('+++ CI Stats Report'); - console.error('Failing build due to CI Stats report. See annotation at top of build.'); - process.exit(1); - } } From 51dd25b69e6b3ce77fac6689f76fcc53cfb8c398 Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 25 Aug 2022 09:05:53 -0700 Subject: [PATCH 10/16] run jest a lot more times in a single build --- .buildkite/pipeline-utils/buildkite/client.ts | 2 + .../ci-stats/pick_test_group_run_order.ts | 42 +++++++++---------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.buildkite/pipeline-utils/buildkite/client.ts b/.buildkite/pipeline-utils/buildkite/client.ts index fe3f2041646e0..dc32113224c3c 100644 --- a/.buildkite/pipeline-utils/buildkite/client.ts +++ b/.buildkite/pipeline-utils/buildkite/client.ts @@ -28,6 +28,8 @@ export interface BuildkiteStep { command: string; label: string; parallelism?: number; + concurrency?: number; + concurrency_group?: string; agents: { queue: string; }; diff --git a/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts b/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts index 3f09e022f1451..3c3ec9f01f634 100644 --- a/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts +++ b/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts @@ -43,26 +43,26 @@ export async function pickTestGroupRunOrder() { // bk.uploadArtifacts('ftr_run_order.json'); // upload the step definitions to Buildkite - bk.uploadSteps( - [ - { - label: 'Jest Tests', - command: getRequiredEnv('JEST_UNIT_SCRIPT'), - parallelism: 50, - timeout_in_minutes: 90, - key: 'jest', - agents: { - queue: 'n2-4-spot', - }, - retry: { - automatic: [ - { - exit_status: '-1', - limit: 3, - }, - ], - }, + bk.uploadSteps([ + { + label: 'Jest Tests', + command: getRequiredEnv('JEST_UNIT_SCRIPT'), + parallelism: 500, + concurrency: 50, + concurrency_group: 'jest-safe-act-flaky-testing', + timeout_in_minutes: 90, + key: 'jest', + agents: { + queue: 'n2-4-spot', }, - ].flat() - ); + retry: { + automatic: [ + { + exit_status: '-1', + limit: 3, + }, + ], + }, + }, + ]); } From cebe5a5372e6ba52501df0c92f00b855508723f7 Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 25 Aug 2022 09:54:22 -0700 Subject: [PATCH 11/16] hard-code jest configs --- .../ci-stats/pick_test_group_run_order.ts | 28 +------------------ .../scripts/steps/test/jest_parallel.sh | 13 +++++++-- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts b/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts index 3c3ec9f01f634..6d80444607f31 100644 --- a/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts +++ b/.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts @@ -6,8 +6,6 @@ * Side Public License, v 1. */ -import * as Fs from 'fs'; - import { BuildkiteClient } from '../buildkite'; const getRequiredEnv = (name: string) => { @@ -19,31 +17,7 @@ const getRequiredEnv = (name: string) => { }; export async function pickTestGroupRunOrder() { - const bk = new BuildkiteClient(); - - // write the config for each step to an artifact that can be used by the individual jest jobs - Fs.writeFileSync( - 'jest_run_order.json', - JSON.stringify( - { - unit: { - groups: new Array(50).fill(null).map(() => ({ - names: new Array(10).fill('x-pack/plugins/index_lifecycle_management/jest.config.js'), - })), - }, - }, - null, - 2 - ) - ); - bk.uploadArtifacts('jest_run_order.json'); - - // // write the config for functional steps to an artifact that can be used by the individual functional jobs - // Fs.writeFileSync('ftr_run_order.json', JSON.stringify(ftrRunOrder, null, 2)); - // bk.uploadArtifacts('ftr_run_order.json'); - - // upload the step definitions to Buildkite - bk.uploadSteps([ + new BuildkiteClient().uploadSteps([ { label: 'Jest Tests', command: getRequiredEnv('JEST_UNIT_SCRIPT'), diff --git a/.buildkite/scripts/steps/test/jest_parallel.sh b/.buildkite/scripts/steps/test/jest_parallel.sh index 2c4474abe0b05..3490f13580cbc 100755 --- a/.buildkite/scripts/steps/test/jest_parallel.sh +++ b/.buildkite/scripts/steps/test/jest_parallel.sh @@ -20,9 +20,16 @@ else fi export TEST_TYPE -echo "--- downloading jest test run order" -download_artifact jest_run_order.json . -configs=$(jq -r 'getpath([env.TEST_TYPE]) | .groups[env.JOB | tonumber].names | .[]' jest_run_order.json) +configs="x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js +x-pack/plugins/index_lifecycle_management/jest.config.js" while read -r config; do echo "--- $ node scripts/jest --config $config" From 3d6b9b125eaa3e07ab4b7679cdb36219f9f9d423 Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 25 Aug 2022 10:41:49 -0700 Subject: [PATCH 12/16] ensure that safeAct() violations are actually logged --- packages/kbn-test-jest-helpers/BUILD.bazel | 1 + packages/kbn-test-jest-helpers/src/safe_act.ts | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/kbn-test-jest-helpers/BUILD.bazel b/packages/kbn-test-jest-helpers/BUILD.bazel index 3ac64fc5d52f0..cc07e89682c6a 100644 --- a/packages/kbn-test-jest-helpers/BUILD.bazel +++ b/packages/kbn-test-jest-helpers/BUILD.bazel @@ -82,6 +82,7 @@ TYPES_DEPS = [ "@npm//@elastic/elasticsearch", "@npm//axios", "@npm//axe-core", + "@npm//chalk", "@npm//elastic-apm-node", "@npm//del", "@npm//exit-hook", diff --git a/packages/kbn-test-jest-helpers/src/safe_act.ts b/packages/kbn-test-jest-helpers/src/safe_act.ts index 908ca5fe30cd3..521b996ce0c3b 100644 --- a/packages/kbn-test-jest-helpers/src/safe_act.ts +++ b/packages/kbn-test-jest-helpers/src/safe_act.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import Chalk from 'chalk'; import { act } from 'react-dom/test-utils'; let current: symbol | undefined; @@ -39,17 +40,21 @@ export function safeAct(cb: () => Promise | void) { return cb() as never; } + const title = Chalk.red.bold('safeAct() violation:'); + const desc = 'act() cb triggered after test completed'; const indentedStack = sourceStack .split('\n') .slice(1) .map((l) => ` ${l}`) .join('\n'); - // console.log is the proper way to log in jest tests, but also nobody ever looks at them... - // eslint-disable-next-line no-console - console.log( - `act() cb triggered after test completed, act registration stacktrace:\n${indentedStack}` + process.stderr.write( + `\n\n${title}\n${desc}, registration stacktrace:\n${indentedStack}\n`, + () => { + process.exit(1); + } ); - process.exit(1); + + return new Promise(() => {}) as never; }); } From 35f634c89c01331db6d019928f711aa09a4470d4 Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 30 Aug 2022 15:14:12 -0500 Subject: [PATCH 13/16] patch react-dom/test-utils for better debugging --- .buildkite/scripts/steps/test/jest.sh | 4 +++ scripts/patch_react_test_utils.js | 28 ++++++++++++++++ scripts/patch_react_test_utils.patch | 47 +++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 scripts/patch_react_test_utils.js create mode 100644 scripts/patch_react_test_utils.patch diff --git a/.buildkite/scripts/steps/test/jest.sh b/.buildkite/scripts/steps/test/jest.sh index 7b09c3f0d788a..58160a2ae665b 100755 --- a/.buildkite/scripts/steps/test/jest.sh +++ b/.buildkite/scripts/steps/test/jest.sh @@ -8,6 +8,10 @@ is_test_execution_step .buildkite/scripts/bootstrap.sh +echo "--- patch react-dom/test-utils" +node scripts/patch_react_test_utils.js +echo "✅" + JOB=${BUILDKITE_PARALLEL_JOB:-0} echo '--- Jest' diff --git a/scripts/patch_react_test_utils.js b/scripts/patch_react_test_utils.js new file mode 100644 index 0000000000000..c4e155bd0b520 --- /dev/null +++ b/scripts/patch_react_test_utils.js @@ -0,0 +1,28 @@ +/* + * 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. + */ + +var ChildProcess = require('child_process'); +var Fs = require('fs'); + +try { + ChildProcess.execFileSync( + 'patch', + ['node_modules/react-dom/cjs/react-dom-test-utils.development.js'], + { + input: Fs.readFileSync(require.resolve('./patch_react_test_utils.patch')), + } + ); +} catch (error) { + console.log( + `patch failed: ${error.output + .map(function (o) { + return !!o ? o.toString() : ''; + }) + .join('\n\n')}` + ); +} diff --git a/scripts/patch_react_test_utils.patch b/scripts/patch_react_test_utils.patch new file mode 100644 index 0000000000000..582b8291757dc --- /dev/null +++ b/scripts/patch_react_test_utils.patch @@ -0,0 +1,47 @@ +diff --git a/react-dom-test-utils.development.js b/react-dom-test-utils.development.js +index a3adf21..a2ebf49 100644 +--- a/react-dom-test-utils.development.js ++++ b/react-dom-test-utils.development.js +@@ -996,14 +996,18 @@ var flushWork = Scheduler.unstable_flushAllWithoutAsserting || function () { + return didFlushWork; + }; + +-function flushWorkAndMicroTasks(onDone) { ++function flushWorkAndMicroTasks(onDone, ex) { + try { + flushWork(); + enqueueTask(function () { +- if (flushWork()) { +- flushWorkAndMicroTasks(onDone); +- } else { +- onDone(); ++ try { ++ if (flushWork()) { ++ flushWorkAndMicroTasks(onDone); ++ } else { ++ onDone(); ++ } ++ } catch (error) { ++ throw ex || error; + } + }); + } catch (err) { +@@ -1064,6 +1068,9 @@ function act(callback) { + // effects and microtasks in a loop until flushPassiveEffects() === false, + // and cleans up + ++ const {testPath, currentTestName} = expect.getState(); ++ const ex = new Error(`${testPath}::${currentTestName}`); ++ ex.name = 'Test Failed'; + + return { + then: function (resolve, reject) { +@@ -1085,7 +1092,7 @@ function act(callback) { + } else { + resolve(); + } +- }); ++ }, ex); + }, function (err) { + onDone(); + reject(err); From 0447cecaebcc84525233e460e2a25d5e89947d3f Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 30 Aug 2022 15:23:38 -0500 Subject: [PATCH 14/16] fix import --- packages/kbn-test-jest-helpers/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-test-jest-helpers/index.ts b/packages/kbn-test-jest-helpers/index.ts index e60657ddd9534..363c4d6af379c 100644 --- a/packages/kbn-test-jest-helpers/index.ts +++ b/packages/kbn-test-jest-helpers/index.ts @@ -28,7 +28,7 @@ export * from './src/testbed'; export * from './src/axe_helpers'; -export { safeAct } from './safe_act'; +export { safeAct } from './src/safe_act'; export const nextTick = () => new Promise((res) => process.nextTick(res)); From fc84968a2a50cf3ec5e30cfdaea18258fe32925d Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 30 Aug 2022 15:33:29 -0500 Subject: [PATCH 15/16] exit early on failure --- .buildkite/scripts/steps/test/jest_parallel.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.buildkite/scripts/steps/test/jest_parallel.sh b/.buildkite/scripts/steps/test/jest_parallel.sh index 3490f13580cbc..e98c1b191ff6c 100755 --- a/.buildkite/scripts/steps/test/jest_parallel.sh +++ b/.buildkite/scripts/steps/test/jest_parallel.sh @@ -58,6 +58,7 @@ while read -r config; do exitCode=10 echo "Jest exited with code $lastCode" echo "^^^ +++" + exit $exitCode fi done <<< "$configs" From 0de0f07d7bd175b5d62c087793653dcd1243fcce Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 31 Aug 2022 14:47:24 -0500 Subject: [PATCH 16/16] switch back to default act helper --- packages/kbn-test-jest-helpers/BUILD.bazel | 1 - packages/kbn-test-jest-helpers/index.ts | 4 +- .../kbn-test-jest-helpers/src/safe_act.ts | 60 ------------------- .../client_integration/app/app.helpers.ts | 2 +- .../client_integration/app/app.test.ts | 2 +- .../edit_policy/features/delete_phase.test.ts | 2 +- .../edit_policy/features/edit_warning.test.ts | 2 +- .../edit_policy/features/frozen_phase.test.ts | 2 +- .../cloud_aware_behavior.test.ts | 2 +- .../node_allocation/cold_phase.test.ts | 2 +- .../node_allocation/general_behavior.test.ts | 2 +- .../node_allocation/warm_phase.test.ts | 2 +- .../features/request_flyout.test.ts | 2 +- .../edit_policy/features/rollover.test.ts | 2 +- .../features/searchable_snapshots.test.ts | 2 +- .../edit_policy/features/timeline.test.ts | 2 +- .../edit_policy/features/timing.test.ts | 2 +- .../cold_phase_validation.test.ts | 2 +- .../form_validation/error_indicators.test.ts | 2 +- .../hot_phase_validation.test.ts | 2 +- .../policy_name_validation.test.ts | 2 +- .../form_validation/timing.test.ts | 4 +- .../warm_phase_validation.test.ts | 2 +- .../policy_serialization.test.ts | 21 +++---- .../helpers/actions/errors_actions.ts | 2 +- .../helpers/actions/forcemerge_actions.ts | 2 +- .../helpers/actions/form_set_value_action.ts | 2 +- .../helpers/actions/form_toggle_action.ts | 2 +- .../actions/node_allocation_actions.ts | 2 +- .../helpers/actions/request_flyout_actions.ts | 2 +- .../helpers/actions/rollover_actions.ts | 2 +- .../helpers/actions/save_policy_action.ts | 2 +- .../actions/searchable_snapshot_actions.ts | 2 +- .../helpers/actions/shrink_actions.ts | 2 +- .../actions/snapshot_policy_actions.ts | 2 +- .../helpers/actions/toggle_phase_action.ts | 2 +- 36 files changed, 45 insertions(+), 107 deletions(-) delete mode 100644 packages/kbn-test-jest-helpers/src/safe_act.ts diff --git a/packages/kbn-test-jest-helpers/BUILD.bazel b/packages/kbn-test-jest-helpers/BUILD.bazel index 0be0a61ce23a6..d31f9184cf2ac 100644 --- a/packages/kbn-test-jest-helpers/BUILD.bazel +++ b/packages/kbn-test-jest-helpers/BUILD.bazel @@ -89,7 +89,6 @@ TYPES_DEPS = [ "@npm//@elastic/elasticsearch", "@npm//axios", "@npm//axe-core", - "@npm//chalk", "@npm//elastic-apm-node", "@npm//del", "@npm//exit-hook", diff --git a/packages/kbn-test-jest-helpers/index.ts b/packages/kbn-test-jest-helpers/index.ts index 363c4d6af379c..1bb9875776ad1 100644 --- a/packages/kbn-test-jest-helpers/index.ts +++ b/packages/kbn-test-jest-helpers/index.ts @@ -28,8 +28,6 @@ export * from './src/testbed'; export * from './src/axe_helpers'; -export { safeAct } from './src/safe_act'; - export const nextTick = () => new Promise((res) => process.nextTick(res)); -export { setTimeout as delay } from 'timers/promises'; +export const delay = (time = 0) => new Promise((resolve) => setTimeout(resolve, time)); diff --git a/packages/kbn-test-jest-helpers/src/safe_act.ts b/packages/kbn-test-jest-helpers/src/safe_act.ts deleted file mode 100644 index 521b996ce0c3b..0000000000000 --- a/packages/kbn-test-jest-helpers/src/safe_act.ts +++ /dev/null @@ -1,60 +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. - */ - -import Chalk from 'chalk'; -import { act } from 'react-dom/test-utils'; - -let current: symbol | undefined; - -if (typeof beforeEach === 'function') { - beforeEach(() => { - current = Symbol(); - }); -} - -if (typeof afterEach === 'function') { - afterEach(() => { - current = undefined; - }); -} - -export function safeAct(cb: () => Promise): Promise; -export function safeAct(cb: () => void): void; -export function safeAct(cb: () => Promise | void) { - const scheduled = current; - if (scheduled === undefined) { - throw new Error( - 'safeAct() should only be called in beforeAll/beforeEach hooks or in tests and must be imported at the root of the file' - ); - } - - const sourceStack = new Error().stack ?? ''; - - return act(() => { - if (scheduled === current) { - return cb() as never; - } - - const title = Chalk.red.bold('safeAct() violation:'); - const desc = 'act() cb triggered after test completed'; - const indentedStack = sourceStack - .split('\n') - .slice(1) - .map((l) => ` ${l}`) - .join('\n'); - - process.stderr.write( - `\n\n${title}\n${desc}, registration stacktrace:\n${indentedStack}\n`, - () => { - process.exit(1); - } - ); - - return new Promise(() => {}) as never; - }); -} diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.ts index c3bfb5e1cc0b0..df64fbce3fa1d 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { HttpSetup } from '@kbn/core/public'; import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test-jest-helpers'; import { App } from '../../../public/application/app'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts index 21fb70163544d..1aaec089724b6 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { getDefaultHotPhasePolicy } from '../edit_policy/constants'; import { setupEnvironment } from '../helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts index c97a42ad350cd..d877f05d06ae1 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/delete_phase.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { API_BASE_PATH } from '../../../../common/constants'; import { setupEnvironment } from '../../helpers'; import { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/edit_warning.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/edit_warning.test.ts index 88a3a183560e8..98d6078da031c 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/edit_warning.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/edit_warning.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; import { setupEnvironment } from '../../helpers'; import { initTestBed } from '../init_test_bed'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts index fe810e872b981..ffe11133be7fd 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/frozen_phase.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts index 3e9c1aea8b0ec..820f8a4f9100a 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cloud_aware_behavior.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../../helpers'; import { CloudNodeAllocationTestBed, diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts index 2bbbcb40cbb28..63382de45f414 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/cold_phase.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../../helpers'; import { NodeAllocationTestBed, setupColdPhaseNodeAllocation } from './cold_phase.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.test.ts index b96fd0492fd10..1eecd5207664f 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/general_behavior.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { HttpFetchOptionsWithPath } from '@kbn/core/public'; import { setupEnvironment } from '../../../helpers'; import { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts index 7039a34ab910f..6f96aaf07da1b 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/node_allocation/warm_phase.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../../helpers'; import { NodeAllocationTestBed, setupWarmPhaseNodeAllocation } from './warm_phase.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts index a31e9194ef573..61dda6fa65efb 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/request_flyout.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers'; import { setupRequestFlyoutTestBed, RequestFlyoutTestBed } from './request_flyout.helpers'; import { getDefaultHotPhasePolicy } from '../constants'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts index aa9af63273b49..1544390229595 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/rollover.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers'; import { RolloverTestBed, setupRolloverTestBed } from './rollover.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts index 5bfff36574394..09bb8b85082b6 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/searchable_snapshots.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; import { HttpFetchOptionsWithPath } from '@kbn/core/public'; import { setupEnvironment } from '../../helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts index 9572e1b84e76c..760ede62606cb 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timeline.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers'; import { setupTimelineTestBed, TimelineTestBed } from './timeline.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts index 2549e2d93d7bb..0aee8eb5f0be1 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/features/timing.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers'; import { setupTimingTestBed, TimingTestBed } from './timing.helpers'; import { PhaseWithTiming } from '../../../../common/types'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts index 3fb47906dbad1..98891ea72928f 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/cold_phase_validation.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts index e743865ce5231..bd4a2caec0be5 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/error_indicators.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { setupEnvironment } from '../../helpers'; import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts index e309b8f05d038..70a51cae4c71e 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/hot_phase_validation.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts index e72016976ed7c..9c14584bb2fcf 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/policy_name_validation.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; import { getGeneratedPolicies } from '../constants'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts index 4355d6b7bde5a..f65e18ba27da5 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/timing.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { PhaseWithTiming } from '../../../../common/types'; @@ -132,5 +132,5 @@ describe(' timing validation', () => { await actions.delete.setMinAgeValue('9'); // No more error for the delete phase actions.errors.expectMessages([], 'delete'); - }); + }, 30_000); }); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts index 31e5a5452df2a..9d326e9978519 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/form_validation/warm_phase_validation.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { i18nTexts } from '../../../../public/application/sections/edit_policy/i18n_texts'; import { setupEnvironment } from '../../helpers'; import { setupValidationTestBed, ValidationTestBed } from './validation.helpers'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts index 0af72d3e17ba0..14f1403ad536d 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/serialization/policy_serialization.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; import { HttpFetchOptionsWithPath } from '@kbn/core/public'; import { setupEnvironment } from '../../helpers'; @@ -33,6 +33,16 @@ describe(' serialization', () => { }); describe('top level form', () => { + afterAll(async () => { + await act(async () => { + testBed = await setupSerializationTestBed(httpSetup, { + appServicesContext: { + license: licensingMock.createLicense({ license: { type: 'enterprise' } }), + }, + }); + }); + }); + /** * We assume that policies that populate this form are loaded directly from ES and so * are valid according to ES. There may be settings in the policy created through the ILM @@ -166,15 +176,6 @@ describe(' serialization', () => { describe('hot phase', () => { beforeEach(async () => { - await act(async () => { - // this used to be in an afterAll hook in the previous suite... it seems to mutate something that is required for the following tests to work... - testBed = await setupSerializationTestBed(httpSetup, { - appServicesContext: { - license: licensingMock.createLicense({ license: { type: 'enterprise' } }), - }, - }); - }); - httpRequestsMockHelpers.setDefaultResponses(); await act(async () => { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts index 6e843a9da5167..4b863071e191c 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/errors_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; import { Phase } from '../../../../common/types'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts index ea8904f75925a..b6ed40de36ca9 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/forcemerge_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; import { Phase } from '../../../../common/types'; import { createFormToggleAction } from './form_toggle_action'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts index e7cc6150c2b8c..57a41831406f9 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_set_value_action.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; export function createFormSetValueAction( diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts index 53d8b143dc0ed..b2408583cc3aa 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/form_toggle_action.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; export const createFormToggleAction = (testBed: TestBed, dataTestSubject: string) => async () => { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts index f2add8022e06a..2a680590654a8 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/node_allocation_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; import { DataTierAllocationType } from '../../../../public/application/sections/edit_policy/types'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/request_flyout_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/request_flyout_actions.ts index 4c142ef0360b7..ca79d52741595 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/request_flyout_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/request_flyout_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; const jsonSelector = 'policyRequestJson'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts index 57014828afa78..43c296466dab4 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/rollover_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; import { createFormToggleAction } from './form_toggle_action'; import { createFormSetValueAction } from './form_set_value_action'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts index 0a831880b6835..9c27e38d75e0d 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/save_policy_action.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; export const createSavePolicyAction = (testBed: TestBed) => async () => { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts index a2957e0e6e5e1..3efffcddbece6 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/searchable_snapshot_actions.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { TestBed } from '@kbn/test-jest-helpers'; import { Phase } from '../../../../common/types'; import { createFormToggleAction } from './form_toggle_action'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts index 119a6fc42e183..def20f73b82fe 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/shrink_actions.ts @@ -6,7 +6,7 @@ */ import { TestBed } from '@kbn/test-jest-helpers'; -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { Phase } from '../../../../common/types'; import { createFormSetValueAction } from './form_set_value_action'; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts index 8865015556c07..8aaf968560a1d 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/snapshot_policy_actions.ts @@ -6,7 +6,7 @@ */ import type { TestBed } from '@kbn/test-jest-helpers'; -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; const createSetWaitForSnapshotAction = (testBed: TestBed) => async (snapshotPolicyName: string) => { const { find, component } = testBed; diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts index c810e5cc187e4..c22efae87d5ac 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/actions/toggle_phase_action.ts @@ -6,7 +6,7 @@ */ import { TestBed } from '@kbn/test-jest-helpers'; -import { safeAct as act } from '@kbn/test-jest-helpers'; +import { act } from 'react-dom/test-utils'; import { Phase } from '../../../../common/types';