diff --git a/package.json b/package.json index 6e8809063ca57..a7ba7e75d797c 100644 --- a/package.json +++ b/package.json @@ -354,7 +354,7 @@ "@elastic/maki": "6.3.0", "@elastic/ui-ace": "0.2.3", "@istanbuljs/schema": "^0.1.2", - "@jest/reporters": "^26.5.2", + "@jest/reporters": "^26.6.2", "@kbn/babel-code-parser": "link:packages/kbn-babel-code-parser", "@kbn/babel-preset": "link:packages/kbn-babel-preset", "@kbn/dev-utils": "link:packages/kbn-dev-utils", @@ -580,7 +580,7 @@ "autoprefixer": "^9.7.4", "axe-core": "^4.0.2", "babel-eslint": "^10.0.3", - "babel-jest": "^26.3.0", + "babel-jest": "^26.6.3", "babel-loader": "^8.0.6", "babel-plugin-add-module-exports": "^1.0.2", "babel-plugin-istanbul": "^6.0.0", diff --git a/src/core/jest.config.js b/src/core/jest.config.js index bdb65b3817507..8e1f228d43cef 100644 --- a/src/core/jest.config.js +++ b/src/core/jest.config.js @@ -21,5 +21,4 @@ module.exports = { preset: '@kbn/test', rootDir: '../..', roots: ['/src/core'], - testRunner: 'jasmine2', }; diff --git a/src/core/server/elasticsearch/client/cluster_client.test.ts b/src/core/server/elasticsearch/client/cluster_client.test.ts index 1127619040fff..dc72f44b02bdb 100644 --- a/src/core/server/elasticsearch/client/cluster_client.test.ts +++ b/src/core/server/elasticsearch/client/cluster_client.test.ts @@ -406,7 +406,7 @@ describe('ClusterClient', () => { expect(scopedClient.close).toHaveBeenCalledTimes(1); }); - it('waits for both clients to close', async (done) => { + it('waits for both clients to close', (done) => { expect.assertions(4); const clusterClient = new ClusterClient(createConfig(), logger, getAuthHeaders); diff --git a/src/core/server/elasticsearch/elasticsearch_service.test.ts b/src/core/server/elasticsearch/elasticsearch_service.test.ts index 7be3a31624df2..3609bbcd1d37a 100644 --- a/src/core/server/elasticsearch/elasticsearch_service.test.ts +++ b/src/core/server/elasticsearch/elasticsearch_service.test.ts @@ -221,7 +221,7 @@ describe('#setup', () => { }); }); - it('esNodeVersionCompatibility$ only starts polling when subscribed to', async (done) => { + it('esNodeVersionCompatibility$ only starts polling when subscribed to', async () => { const mockedClient = mockClusterClientInstance.asInternalUser; mockedClient.nodes.info.mockImplementation(() => elasticsearchClientMock.createErrorTransportRequestPromise(new Error()) @@ -231,13 +231,13 @@ describe('#setup', () => { await delay(10); expect(mockedClient.nodes.info).toHaveBeenCalledTimes(0); - setupContract.esNodesCompatibility$.subscribe(() => { - expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); - done(); - }); + + await setupContract.esNodesCompatibility$.pipe(first()).toPromise(); + + expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); }); - it('esNodeVersionCompatibility$ stops polling when unsubscribed from', async (done) => { + it('esNodeVersionCompatibility$ stops polling when unsubscribed from', async () => { const mockedClient = mockClusterClientInstance.asInternalUser; mockedClient.nodes.info.mockImplementation(() => elasticsearchClientMock.createErrorTransportRequestPromise(new Error()) @@ -246,12 +246,11 @@ describe('#setup', () => { const setupContract = await elasticsearchService.setup(setupDeps); expect(mockedClient.nodes.info).toHaveBeenCalledTimes(0); - const sub = setupContract.esNodesCompatibility$.subscribe(async () => { - sub.unsubscribe(); - await delay(100); - expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); - done(); - }); + + await setupContract.esNodesCompatibility$.pipe(first()).toPromise(); + + await delay(100); + expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); }); }); @@ -351,7 +350,7 @@ describe('#stop', () => { expect(mockClusterClientInstance.close).toHaveBeenCalledTimes(1); }); - it('stops pollEsNodeVersions even if there are active subscriptions', async (done) => { + it('stops pollEsNodeVersions even if there are active subscriptions', async () => { expect.assertions(2); const mockedClient = mockClusterClientInstance.asInternalUser; @@ -361,13 +360,12 @@ describe('#stop', () => { const setupContract = await elasticsearchService.setup(setupDeps); - setupContract.esNodesCompatibility$.subscribe(async () => { - expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); + await setupContract.esNodesCompatibility$.pipe(first()).toPromise(); - await elasticsearchService.stop(); - await delay(100); - expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); - done(); - }); + expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); + + await elasticsearchService.stop(); + await delay(100); + expect(mockedClient.nodes.info).toHaveBeenCalledTimes(1); }); }); diff --git a/src/core/server/http/integration_tests/request.test.ts b/src/core/server/http/integration_tests/request.test.ts index 710d7915c60a1..6b2c489d835f3 100644 --- a/src/core/server/http/integration_tests/request.test.ts +++ b/src/core/server/http/integration_tests/request.test.ts @@ -174,7 +174,7 @@ describe('KibanaRequest', () => { describe('events', () => { describe('aborted$', () => { - it('emits once and completes when request aborted', async (done) => { + it('emits once and completes when request aborted', async () => { expect.assertions(1); const { server: innerServer, createRouter } = await server.setup(setupDeps); const router = createRouter('/'); @@ -185,7 +185,6 @@ describe('KibanaRequest', () => { next: nextSpy, complete: () => { expect(nextSpy).toHaveBeenCalledTimes(1); - done(); }, }); @@ -202,6 +201,7 @@ describe('KibanaRequest', () => { .end(); setTimeout(() => incomingRequest.abort(), 50); + await delay(100); }); it('completes & does not emit when request handled', async () => { @@ -310,7 +310,7 @@ describe('KibanaRequest', () => { expect(completeSpy).toHaveBeenCalledTimes(1); }); - it('emits once and completes when response is aborted', async (done) => { + it('emits once and completes when response is aborted', async () => { expect.assertions(2); const { server: innerServer, createRouter } = await server.setup(setupDeps); const router = createRouter('/'); @@ -322,7 +322,6 @@ describe('KibanaRequest', () => { next: nextSpy, complete: () => { expect(nextSpy).toHaveBeenCalledTimes(1); - done(); }, }); @@ -338,6 +337,7 @@ describe('KibanaRequest', () => { // end required to send request .end(); setTimeout(() => incomingRequest.abort(), 50); + await delay(100); }); }); }); diff --git a/src/core/server/saved_objects/saved_objects_service.test.ts b/src/core/server/saved_objects/saved_objects_service.test.ts index 1eba61c7876d1..47191727dae47 100644 --- a/src/core/server/saved_objects/saved_objects_service.test.ts +++ b/src/core/server/saved_objects/saved_objects_service.test.ts @@ -177,7 +177,7 @@ describe('SavedObjectsService', () => { expect(migratorInstanceMock.runMigrations).not.toHaveBeenCalled(); }); - it('waits for all es nodes to be compatible before running migrations', async (done) => { + it('waits for all es nodes to be compatible before running migrations', async () => { expect.assertions(2); const coreContext = createCoreContext({ skipMigration: false }); const soService = new SavedObjectsService(coreContext); @@ -191,7 +191,7 @@ describe('SavedObjectsService', () => { kibanaVersion: '8.0.0', }); await soService.setup(setupDeps); - soService.start(createStartDeps()); + const promise = soService.start(createStartDeps()); expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(0); ((setupDeps.elasticsearch .esNodesCompatibility$ as any) as BehaviorSubject).next({ @@ -200,10 +200,8 @@ describe('SavedObjectsService', () => { warningNodes: [], kibanaVersion: '8.0.0', }); - setImmediate(() => { - expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(1); - done(); - }); + await promise; + expect(migratorInstanceMock.runMigrations).toHaveBeenCalledTimes(1); }); it('resolves with KibanaMigrator after waiting for migrations to complete', async () => { diff --git a/src/plugins/console/jest.config.js b/src/plugins/console/jest.config.js index f08613f91e1f1..ba455f7a14a38 100644 --- a/src/plugins/console/jest.config.js +++ b/src/plugins/console/jest.config.js @@ -21,5 +21,4 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/console'], - testRunner: 'jasmine2', }; diff --git a/src/plugins/console/public/application/models/legacy_core_editor/__tests__/output_tokenization.test.js b/src/plugins/console/public/application/models/legacy_core_editor/__tests__/output_tokenization.test.js index ea7530bd21387..fe53402bae0c1 100644 --- a/src/plugins/console/public/application/models/legacy_core_editor/__tests__/output_tokenization.test.js +++ b/src/plugins/console/public/application/models/legacy_core_editor/__tests__/output_tokenization.test.js @@ -57,7 +57,7 @@ describe('Output Tokenization', () => { data = JSON.stringify(data, null, 3); } - test('Token test ' + testCount++, async function (done) { + test('Token test ' + testCount++, function (done) { output.update(data, function () { const tokens = tokensAsList(); const normTokenList = []; diff --git a/src/plugins/console/public/application/models/sense_editor/__tests__/integration.test.js b/src/plugins/console/public/application/models/sense_editor/__tests__/integration.test.js index 89880528943e5..abe6458773a2e 100644 --- a/src/plugins/console/public/application/models/sense_editor/__tests__/integration.test.js +++ b/src/plugins/console/public/application/models/sense_editor/__tests__/integration.test.js @@ -41,7 +41,7 @@ describe('Integration', () => { }); function processContextTest(data, mapping, kbSchemes, requestLine, testToRun) { - test(testToRun.name, async function (done) { + test(testToRun.name, function (done) { let lineOffset = 0; // add one for the extra method line let editorValue = data; if (requestLine != null) { @@ -74,103 +74,105 @@ describe('Integration', () => { } kb.setActiveApi(testApi); const { cursor } = testToRun; - await senseEditor.update(editorValue, true); - senseEditor.getCoreEditor().moveCursorToPosition(cursor); - // allow ace rendering to move cursor so it will be seen during test - handy for debugging. - //setTimeout(function () { - senseEditor.completer = { - base: {}, - changeListener: function () {}, - }; // mimic auto complete + senseEditor.update(editorValue, true).then(() => { + senseEditor.getCoreEditor().moveCursorToPosition(cursor); - senseEditor.autocomplete._test.getCompletions( - senseEditor, - null, - cursor, - '', - function (err, terms) { - if (testToRun.assertThrows) { - done(); - return; - } - - if (err) { - throw err; - } + // allow ace rendering to move cursor so it will be seen during test - handy for debugging. + //setTimeout(function () { + senseEditor.completer = { + base: {}, + changeListener: function () {}, + }; // mimic auto complete - if (testToRun.no_context) { - expect(!terms || terms.length === 0).toBeTruthy(); - } else { - expect(terms).not.toBeNull(); - expect(terms.length).toBeGreaterThan(0); - } + senseEditor.autocomplete._test.getCompletions( + senseEditor, + null, + cursor, + '', + function (err, terms) { + if (testToRun.assertThrows) { + done(); + return; + } - if (!terms || terms.length === 0) { - done(); - return; - } + if (err) { + throw err; + } - if (testToRun.autoCompleteSet) { - const expectedTerms = _.map(testToRun.autoCompleteSet, function (t) { - if (typeof t !== 'object') { - t = { name: t }; - } - return t; - }); - if (terms.length !== expectedTerms.length) { - expect(_.map(terms, 'name')).toEqual(_.map(expectedTerms, 'name')); + if (testToRun.no_context) { + expect(!terms || terms.length === 0).toBeTruthy(); } else { - const filteredActualTerms = _.map(terms, function (actualTerm, i) { - const expectedTerm = expectedTerms[i]; - const filteredTerm = {}; - _.each(expectedTerm, function (v, p) { - filteredTerm[p] = actualTerm[p]; - }); - return filteredTerm; - }); - expect(filteredActualTerms).toEqual(expectedTerms); + expect(terms).not.toBeNull(); + expect(terms.length).toBeGreaterThan(0); } - } - const context = terms[0].context; - const { - cursor: { lineNumber, column }, - } = testToRun; - senseEditor.autocomplete._test.addReplacementInfoToContext( - context, - { lineNumber, column }, - terms[0].value - ); + if (!terms || terms.length === 0) { + done(); + return; + } - function ac(prop, propTest) { - if (typeof testToRun[prop] !== 'undefined') { - if (propTest) { - propTest(context[prop], testToRun[prop], prop); + if (testToRun.autoCompleteSet) { + const expectedTerms = _.map(testToRun.autoCompleteSet, function (t) { + if (typeof t !== 'object') { + t = { name: t }; + } + return t; + }); + if (terms.length !== expectedTerms.length) { + expect(_.map(terms, 'name')).toEqual(_.map(expectedTerms, 'name')); } else { - expect(context[prop]).toEqual(testToRun[prop]); + const filteredActualTerms = _.map(terms, function (actualTerm, i) { + const expectedTerm = expectedTerms[i]; + const filteredTerm = {}; + _.each(expectedTerm, function (v, p) { + filteredTerm[p] = actualTerm[p]; + }); + return filteredTerm; + }); + expect(filteredActualTerms).toEqual(expectedTerms); } } - } - function posCompare(actual, expected) { - expect(actual.lineNumber).toEqual(expected.lineNumber + lineOffset); - expect(actual.column).toEqual(expected.column); - } + const context = terms[0].context; + const { + cursor: { lineNumber, column }, + } = testToRun; + senseEditor.autocomplete._test.addReplacementInfoToContext( + context, + { lineNumber, column }, + terms[0].value + ); - function rangeCompare(actual, expected, name) { - posCompare(actual.start, expected.start, name + '.start'); - posCompare(actual.end, expected.end, name + '.end'); - } + function ac(prop, propTest) { + if (typeof testToRun[prop] !== 'undefined') { + if (propTest) { + propTest(context[prop], testToRun[prop], prop); + } else { + expect(context[prop]).toEqual(testToRun[prop]); + } + } + } - ac('prefixToAdd'); - ac('suffixToAdd'); - ac('addTemplate'); - ac('textBoxPosition', posCompare); - ac('rangeToReplace', rangeCompare); - done(); - } - ); + function posCompare(actual, expected) { + expect(actual.lineNumber).toEqual(expected.lineNumber + lineOffset); + expect(actual.column).toEqual(expected.column); + } + + function rangeCompare(actual, expected, name) { + posCompare(actual.start, expected.start, name + '.start'); + posCompare(actual.end, expected.end, name + '.end'); + } + + ac('prefixToAdd'); + ac('suffixToAdd'); + ac('addTemplate'); + ac('textBoxPosition', posCompare); + ac('rangeToReplace', rangeCompare); + done(); + } + ); + }); }); } diff --git a/src/plugins/console/public/application/models/sense_editor/__tests__/sense_editor.test.js b/src/plugins/console/public/application/models/sense_editor/__tests__/sense_editor.test.js index 04d3cd1a724e1..d8008fcd68dea 100644 --- a/src/plugins/console/public/application/models/sense_editor/__tests__/sense_editor.test.js +++ b/src/plugins/console/public/application/models/sense_editor/__tests__/sense_editor.test.js @@ -49,9 +49,9 @@ describe('Editor', () => { let testCount = 0; - const callWithEditorMethod = (editorMethod, fn) => async (done) => { + const callWithEditorMethod = (editorMethod, fn) => async () => { const results = await input[editorMethod](); - fn(results, done); + fn(results); }; function utilsTest(name, prefix, data, testToRun) { @@ -71,9 +71,9 @@ describe('Editor', () => { data = prefix; } - test('Utils test ' + id + ' : ' + name, async function (done) { + test('Utils test ' + id + ' : ' + name, async function () { await input.update(data, true); - testToRun(done); + testToRun(); }); } @@ -113,12 +113,11 @@ describe('Editor', () => { 'simple request range', simpleRequest.prefix, simpleRequest.data, - callWithEditorMethod('getRequestRange', (range, done) => { + callWithEditorMethod('getRequestRange', (range) => { compareRequest(range, { start: { lineNumber: 1, column: 1 }, end: { lineNumber: 4, column: 2 }, }); - done(); }) ); @@ -126,14 +125,13 @@ describe('Editor', () => { 'simple request data', simpleRequest.prefix, simpleRequest.data, - callWithEditorMethod('getRequest', (request, done) => { + callWithEditorMethod('getRequest', (request) => { const expected = { method: 'POST', url: '_search', data: [simpleRequest.data], }; compareRequest(request, expected); - done(); }) ); @@ -141,12 +139,11 @@ describe('Editor', () => { 'simple request range, prefixed with spaces', ' ' + simpleRequest.prefix, simpleRequest.data, - callWithEditorMethod('getRequestRange', (range, done) => { + callWithEditorMethod('getRequestRange', (range) => { expect(range).toEqual({ start: { lineNumber: 1, column: 1 }, end: { lineNumber: 4, column: 2 }, }); - done(); }) ); @@ -154,7 +151,7 @@ describe('Editor', () => { 'simple request data, prefixed with spaces', ' ' + simpleRequest.prefix, simpleRequest.data, - callWithEditorMethod('getRequest', (request, done) => { + callWithEditorMethod('getRequest', (request) => { const expected = { method: 'POST', url: '_search', @@ -162,7 +159,6 @@ describe('Editor', () => { }; compareRequest(request, expected); - done(); }) ); @@ -170,12 +166,11 @@ describe('Editor', () => { 'simple request range, suffixed with spaces', simpleRequest.prefix + ' ', simpleRequest.data + ' ', - callWithEditorMethod('getRequestRange', (range, done) => { + callWithEditorMethod('getRequestRange', (range) => { compareRequest(range, { start: { lineNumber: 1, column: 1 }, end: { lineNumber: 4, column: 2 }, }); - done(); }) ); @@ -183,7 +178,7 @@ describe('Editor', () => { 'simple request data, suffixed with spaces', simpleRequest.prefix + ' ', simpleRequest.data + ' ', - callWithEditorMethod('getRequest', (request, done) => { + callWithEditorMethod('getRequest', (request) => { const expected = { method: 'POST', url: '_search', @@ -191,7 +186,6 @@ describe('Editor', () => { }; compareRequest(request, expected); - done(); }) ); @@ -199,12 +193,11 @@ describe('Editor', () => { 'single line request range', singleLineRequest.prefix, singleLineRequest.data, - callWithEditorMethod('getRequestRange', (range, done) => { + callWithEditorMethod('getRequestRange', (range) => { compareRequest(range, { start: { lineNumber: 1, column: 1 }, end: { lineNumber: 2, column: 33 }, }); - done(); }) ); @@ -212,14 +205,13 @@ describe('Editor', () => { 'full url: single line request data', 'POST https://somehost/_search', singleLineRequest.data, - callWithEditorMethod('getRequest', (request, done) => { + callWithEditorMethod('getRequest', (request) => { const expected = { method: 'POST', url: 'https://somehost/_search', data: [singleLineRequest.data], }; compareRequest(request, expected); - done(); }) ); @@ -227,12 +219,11 @@ describe('Editor', () => { 'request with no data followed by a new line', getRequestNoData.prefix, '\n', - callWithEditorMethod('getRequestRange', (range, done) => { + callWithEditorMethod('getRequestRange', (range) => { compareRequest(range, { start: { lineNumber: 1, column: 1 }, end: { lineNumber: 1, column: 11 }, }); - done(); }) ); @@ -240,14 +231,13 @@ describe('Editor', () => { 'request with no data followed by a new line (data)', getRequestNoData.prefix, '\n', - callWithEditorMethod('getRequest', (request, done) => { + callWithEditorMethod('getRequest', (request) => { const expected = { method: 'GET', url: '_stats', data: [], }; compareRequest(request, expected); - done(); }) ); @@ -255,12 +245,11 @@ describe('Editor', () => { 'request with no data', getRequestNoData.prefix, getRequestNoData.data, - callWithEditorMethod('getRequestRange', (range, done) => { + callWithEditorMethod('getRequestRange', (range) => { expect(range).toEqual({ start: { lineNumber: 1, column: 1 }, end: { lineNumber: 1, column: 11 }, }); - done(); }) ); @@ -268,14 +257,13 @@ describe('Editor', () => { 'request with no data (data)', getRequestNoData.prefix, getRequestNoData.data, - callWithEditorMethod('getRequest', (request, done) => { + callWithEditorMethod('getRequest', (request) => { const expected = { method: 'GET', url: '_stats', data: [], }; compareRequest(request, expected); - done(); }) ); @@ -283,12 +271,11 @@ describe('Editor', () => { 'multi doc request range', multiDocRequest.prefix, multiDocRequest.data, - callWithEditorMethod('getRequestRange', (range, done) => { + callWithEditorMethod('getRequestRange', (range) => { expect(range).toEqual({ start: { lineNumber: 1, column: 1 }, end: { lineNumber: 3, column: 15 }, }); - done(); }) ); @@ -296,14 +283,13 @@ describe('Editor', () => { 'multi doc request data', multiDocRequest.prefix, multiDocRequest.data, - callWithEditorMethod('getRequest', (request, done) => { + callWithEditorMethod('getRequest', (request) => { const expected = { method: 'POST', url: '_bulk', data: multiDocRequest.data_as_array, }; compareRequest(request, expected); - done(); }) ); @@ -316,12 +302,11 @@ describe('Editor', () => { 'script request range', scriptRequest.prefix, scriptRequest.data, - callWithEditorMethod('getRequestRange', (range, done) => { + callWithEditorMethod('getRequestRange', (range) => { compareRequest(range, { start: { lineNumber: 1, column: 1 }, end: { lineNumber: 6, column: 2 }, }); - done(); }) ); @@ -329,7 +314,7 @@ describe('Editor', () => { 'simple request data', simpleRequest.prefix, simpleRequest.data, - callWithEditorMethod('getRequest', (request, done) => { + callWithEditorMethod('getRequest', (request) => { const expected = { method: 'POST', url: '_search', @@ -337,12 +322,11 @@ describe('Editor', () => { }; compareRequest(request, expected); - done(); }) ); function multiReqTest(name, editorInput, range, expected) { - utilsTest('multi request select - ' + name, editorInput, async function (done) { + utilsTest('multi request select - ' + name, editorInput, async function () { const requests = await input.getRequestsInRange(range, false); // convert to format returned by request. _.each(expected, function (req) { @@ -350,7 +334,6 @@ describe('Editor', () => { }); compareRequest(requests, expected); - done(); }); } @@ -453,10 +436,9 @@ describe('Editor', () => { ); function multiReqCopyAsCurlTest(name, editorInput, range, expected) { - utilsTest('multi request copy as curl - ' + name, editorInput, async function (done) { + utilsTest('multi request copy as curl - ' + name, editorInput, async function () { const curl = await input.getRequestsAsCURL('http://localhost:9200', range); expect(curl).toEqual(expected); - done(); }); } diff --git a/src/plugins/dashboard/jest.config.js b/src/plugins/dashboard/jest.config.js index b9f6f66159b30..2a733ab4691d7 100644 --- a/src/plugins/dashboard/jest.config.js +++ b/src/plugins/dashboard/jest.config.js @@ -21,5 +21,4 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/dashboard'], - testRunner: 'jasmine2', }; diff --git a/src/plugins/dashboard/public/application/embeddable/dashboard_container.test.tsx b/src/plugins/dashboard/public/application/embeddable/dashboard_container.test.tsx index 2d892ac49e9d2..267fcc16aec51 100644 --- a/src/plugins/dashboard/public/application/embeddable/dashboard_container.test.tsx +++ b/src/plugins/dashboard/public/application/embeddable/dashboard_container.test.tsx @@ -73,7 +73,7 @@ beforeEach(() => { options.application = applicationServiceMock.createStartContract(); }); -test('DashboardContainer initializes embeddables', async (done) => { +test('DashboardContainer initializes embeddables', (done) => { const initialInput = getSampleDashboardInput({ panels: { '123': getSampleDashboardPanel({ @@ -123,7 +123,7 @@ test('DashboardContainer.addNewEmbeddable', async () => { expect(embeddableInContainer.id).toBe(embeddable.id); }); -test('DashboardContainer.replacePanel', async (done) => { +test('DashboardContainer.replacePanel', (done) => { const ID = '123'; const initialInput = getSampleDashboardInput({ panels: { diff --git a/src/plugins/dashboard/public/application/embeddable/grid/dashboard_grid.test.tsx b/src/plugins/dashboard/public/application/embeddable/grid/dashboard_grid.test.tsx index ef23c636ad482..6a8c8532d9e16 100644 --- a/src/plugins/dashboard/public/application/embeddable/grid/dashboard_grid.test.tsx +++ b/src/plugins/dashboard/public/application/embeddable/grid/dashboard_grid.test.tsx @@ -170,7 +170,7 @@ test('DashboardGrid renders expanded panel', () => { ).toBeUndefined(); }); -test('DashboardGrid unmount unsubscribes', async (done) => { +test('DashboardGrid unmount unsubscribes', (done) => { const { props, options } = prepare(); const component = mountWithIntl( diff --git a/src/plugins/dashboard/public/application/embeddable/viewport/dashboard_viewport.test.tsx b/src/plugins/dashboard/public/application/embeddable/viewport/dashboard_viewport.test.tsx index 925687a07bb42..058898dc7e676 100644 --- a/src/plugins/dashboard/public/application/embeddable/viewport/dashboard_viewport.test.tsx +++ b/src/plugins/dashboard/public/application/embeddable/viewport/dashboard_viewport.test.tsx @@ -196,7 +196,7 @@ test('renders exit full screen button when in full screen mode and empty screen' component.unmount(); }); -test('DashboardViewport unmount unsubscribes', async (done) => { +test('DashboardViewport unmount unsubscribes', (done) => { const { props, options } = getProps(); const component = mount( diff --git a/src/plugins/data/jest.config.js b/src/plugins/data/jest.config.js index 3c6e854a53d7b..a9268a8f5dca3 100644 --- a/src/plugins/data/jest.config.js +++ b/src/plugins/data/jest.config.js @@ -21,5 +21,4 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/data'], - testRunner: 'jasmine2', }; diff --git a/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.test.ts b/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.test.ts index 780db36426dc1..ae6e9eab41b18 100644 --- a/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/generate_mapping_chain.test.ts @@ -97,7 +97,7 @@ describe('filter manager utilities', () => { expect(result).toEqual({ key: 'test', value: 'example' }); }); - test('should throw an error if no functions match', async (done) => { + test('should throw an error if no functions match', (done) => { const filter = buildEmptyFilter(true); mapping.throws(filter); diff --git a/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts b/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts index 7b303ca4d5314..e12c0ca7ddba6 100644 --- a/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/map_filter.test.ts @@ -79,7 +79,7 @@ describe('filter manager utilities', () => { expect(after.meta).toHaveProperty('negate', false); }); - test('should finish with a catch', async (done) => { + test('should finish with a catch', (done) => { const before: any = { meta: { index: 'logstash-*' } }; try { @@ -87,7 +87,6 @@ describe('filter manager utilities', () => { } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.message).toBe('No mappings have been found for filter.'); - done(); } }); diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.test.ts index 0e7b12b6f5f58..2466e685e080f 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_exists.test.ts @@ -44,7 +44,7 @@ describe('filter manager utilities', () => { expect(result).toHaveProperty('value', 'exists'); }); - test('should return undefined for none matching', async (done) => { + test('should return undefined for none matching', (done) => { const filter = buildEmptyFilter(true); try { diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.test.ts index 035dadfd7432a..6aff574cc9d16 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_bounding_box.test.ts @@ -79,7 +79,7 @@ describe('filter manager utilities', () => { } }); - test('should return undefined for none matching', async (done) => { + test('should return undefined for none matching', (done) => { const filter = { meta: { index: 'logstash-*' }, query: { query_string: { query: 'foo:bar' } }, diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.test.ts index 8da98b3a329d6..1ed1b304a0d37 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_geo_polygon.test.ts @@ -70,7 +70,7 @@ describe('filter manager utilities', () => { } }); - test('should return undefined for none matching', async (done) => { + test('should return undefined for none matching', (done) => { const wrongFilter = { meta: { index: 'logstash-*' }, query: { query_string: { query: 'foo:bar' } }, diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.test.ts index 3d50b87bb32f8..dd263687aa05b 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_match_all.test.ts @@ -38,7 +38,7 @@ describe('filter_manager/lib', () => { }); describe('when given a filter that is not match_all', () => { - test('filter is rejected', async (done) => { + test('filter is rejected', (done) => { delete filter.match_all; try { diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.test.ts index d851e96ad6ac6..6ec9a583d57b5 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_missing.test.ts @@ -33,7 +33,7 @@ describe('filter manager utilities', () => { expect(result).toHaveProperty('value', 'missing'); }); - test('should return undefined for none matching', async (done) => { + test('should return undefined for none matching', (done) => { const filter = buildEmptyFilter(true); try { diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.test.ts index 8f4a8d1bb35a1..b554057318fa4 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_phrase.test.ts @@ -38,7 +38,7 @@ describe('filter manager utilities', () => { } }); - test('should return undefined for none matching', async (done) => { + test('should return undefined for none matching', (done) => { const filter = { meta: { index: 'logstash-*' }, query: { query_string: { query: 'foo:bar' } }, diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.test.ts index 9b75d5a769d3e..9d2410f31f080 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_query_string.test.ts @@ -30,7 +30,7 @@ describe('filter manager utilities', () => { expect(result).toHaveProperty('value', 'foo:bar'); }); - test('should return undefined for none matching', async (done) => { + test('should return undefined for none matching', (done) => { const filter = buildEmptyFilter(true); try { diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts index a6f587ddc7d32..a919292c44f31 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_range.test.ts @@ -37,7 +37,7 @@ describe('filter manager utilities', () => { } }); - test('should return undefined for none matching', async (done) => { + test('should return undefined for none matching', (done) => { const filter = { meta: { index: 'logstash-*' }, query: { query_string: { query: 'foo:bar' } }, diff --git a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts index 5e58b2c14c262..05a2cc4de3ea3 100644 --- a/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts +++ b/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.test.ts @@ -65,7 +65,7 @@ describe('mapSpatialFilter()', () => { expect(result).toHaveProperty('type', FILTERS.SPATIAL_FILTER); }); - test('should return undefined for none matching', async (done) => { + test('should return undefined for none matching', (done) => { const filter = { meta: { key: 'location', diff --git a/src/plugins/data/public/search/search_interceptor.test.ts b/src/plugins/data/public/search/search_interceptor.test.ts index 947dac1b32640..704e80e9a735c 100644 --- a/src/plugins/data/public/search/search_interceptor.test.ts +++ b/src/plugins/data/public/search/search_interceptor.test.ts @@ -347,7 +347,7 @@ describe('SearchInterceptor', () => { await flushPromises(); }); - test('Immediately aborts if passed an aborted abort signal', async (done) => { + test('Immediately aborts if passed an aborted abort signal', (done) => { const abort = new AbortController(); const mockRequest: IEsSearchRequest = { params: {}, diff --git a/src/plugins/data/server/search/es_search/es_search_strategy.test.ts b/src/plugins/data/server/search/es_search/es_search_strategy.test.ts index 4556bee94603f..8a335ba078537 100644 --- a/src/plugins/data/server/search/es_search/es_search_strategy.test.ts +++ b/src/plugins/data/server/search/es_search/es_search_strategy.test.ts @@ -17,6 +17,7 @@ * under the License. */ +import { first } from 'rxjs/operators'; import { pluginInitializerContextConfigMock } from '../../../../../core/server/mocks'; import { esSearchStrategyProvider } from './es_search_strategy'; import { SearchStrategyDependencies } from '../types'; @@ -55,39 +56,41 @@ describe('ES search strategy', () => { expect(typeof esSearch.search).toBe('function'); }); - it('calls the API caller with the params with defaults', async (done) => { + it('calls the API caller with the params with defaults', async () => { const params = { index: 'logstash-*' }; - await esSearchStrategyProvider(mockConfig$, mockLogger) + const promise = await esSearchStrategyProvider(mockConfig$, mockLogger) .search({ params }, {}, mockDeps) - .subscribe(() => { - expect(mockApiCaller).toBeCalled(); - expect(mockApiCaller.mock.calls[0][0]).toEqual({ - ...params, - ignore_unavailable: true, - track_total_hits: true, - }); - done(); - }); + .pipe(first()) + .toPromise(); + await promise; + + expect(mockApiCaller).toBeCalled(); + expect(mockApiCaller.mock.calls[0][0]).toEqual({ + ...params, + ignore_unavailable: true, + track_total_hits: true, + }); }); - it('calls the API caller with overridden defaults', async (done) => { + it('calls the API caller with overridden defaults', async () => { const params = { index: 'logstash-*', ignore_unavailable: false, timeout: '1000ms' }; - await esSearchStrategyProvider(mockConfig$, mockLogger) + const promise = await esSearchStrategyProvider(mockConfig$, mockLogger) .search({ params }, {}, mockDeps) - .subscribe(() => { - expect(mockApiCaller).toBeCalled(); - expect(mockApiCaller.mock.calls[0][0]).toEqual({ - ...params, - track_total_hits: true, - }); - done(); - }); + .pipe(first()) + .toPromise(); + await promise; + + expect(mockApiCaller).toBeCalled(); + expect(mockApiCaller.mock.calls[0][0]).toEqual({ + ...params, + track_total_hits: true, + }); }); - it('has all response parameters', async (done) => - await esSearchStrategyProvider(mockConfig$, mockLogger) + it('has all response parameters', async () => { + const promise = await esSearchStrategyProvider(mockConfig$, mockLogger) .search( { params: { index: 'logstash-*' }, @@ -95,11 +98,13 @@ describe('ES search strategy', () => { {}, mockDeps ) - .subscribe((data) => { - expect(data.isRunning).toBe(false); - expect(data.isPartial).toBe(false); - expect(data).toHaveProperty('loaded'); - expect(data).toHaveProperty('rawResponse'); - done(); - })); + .pipe(first()) + .toPromise(); + await promise; + + expect(promise.isRunning).toBe(false); + expect(promise.isPartial).toBe(false); + expect(promise).toHaveProperty('loaded'); + expect(promise).toHaveProperty('rawResponse'); + }); }); diff --git a/src/plugins/embeddable/jest.config.js b/src/plugins/embeddable/jest.config.js index a079791092549..3f02b6deb3f27 100644 --- a/src/plugins/embeddable/jest.config.js +++ b/src/plugins/embeddable/jest.config.js @@ -21,5 +21,4 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/embeddable'], - testRunner: 'jasmine2', }; diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable.test.tsx b/src/plugins/embeddable/public/lib/embeddables/embeddable.test.tsx index c0e13a84066ca..c11e7d2417fea 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable.test.tsx +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable.test.tsx @@ -54,7 +54,7 @@ class OutputTestEmbeddable extends Embeddable { reload() {} } -test('Embeddable calls input subscribers when changed', async (done) => { +test('Embeddable calls input subscribers when changed', (done) => { const hello = new ContactCardEmbeddable( { id: '123', firstName: 'Brienne', lastName: 'Tarth' }, { execAction: (() => null) as any } diff --git a/src/plugins/embeddable/public/lib/panel/embeddable_panel.test.tsx b/src/plugins/embeddable/public/lib/panel/embeddable_panel.test.tsx index 2104d93da9ad8..53af90ffe45c9 100644 --- a/src/plugins/embeddable/public/lib/panel/embeddable_panel.test.tsx +++ b/src/plugins/embeddable/public/lib/panel/embeddable_panel.test.tsx @@ -20,6 +20,7 @@ import React from 'react'; import { mount } from 'enzyme'; import { mountWithIntl, nextTick } from '@kbn/test/jest'; +import { first } from 'rxjs/operators'; import { findTestSubject } from '@elastic/eui/lib/test'; import { I18nProvider } from '@kbn/i18n/react'; @@ -62,7 +63,7 @@ setup.registerEmbeddableFactory(embeddableFactory.type, embeddableFactory); const start = doStart(); const getEmbeddableFactory = start.getEmbeddableFactory; -test('HelloWorldContainer initializes embeddables', async (done) => { +test('HelloWorldContainer initializes embeddables', async () => { const container = new HelloWorldContainer( { id: '123', @@ -76,22 +77,12 @@ test('HelloWorldContainer initializes embeddables', async (done) => { { getEmbeddableFactory } as any ); - const subscription = container.getOutput$().subscribe(() => { - if (container.getOutput().embeddableLoaded['123']) { - const embeddable = container.getChild('123'); - expect(embeddable).toBeDefined(); - expect(embeddable.id).toBe('123'); - done(); - } - }); + await container.getOutput$().pipe(first()).toPromise(); - if (container.getOutput().embeddableLoaded['123']) { - const embeddable = container.getChild('123'); - expect(embeddable).toBeDefined(); - expect(embeddable.id).toBe('123'); - subscription.unsubscribe(); - done(); - } + expect(container.getOutput().embeddableLoaded['123']).toBeTruthy(); + const embeddable = container.getChild('123'); + expect(embeddable).toBeDefined(); + expect(embeddable.id).toBe('123'); }); test('HelloWorldContainer.addNewEmbeddable', async () => { diff --git a/src/plugins/embeddable/public/lib/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts b/src/plugins/embeddable/public/lib/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts index 1ca62d2170b71..cd65858cf33bd 100644 --- a/src/plugins/embeddable/public/lib/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts +++ b/src/plugins/embeddable/public/lib/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts @@ -17,6 +17,7 @@ * under the License. */ +import { first } from 'rxjs/operators'; import { Container, isErrorEmbeddable } from '../../../..'; import { nextTick } from '@kbn/test/jest'; import { CustomizePanelTitleAction } from './customize_panel_action'; @@ -64,7 +65,7 @@ beforeEach(async () => { } }); -test('Updates the embeddable title when given', async (done) => { +test('Updates the embeddable title when given', async () => { const getUserData = () => Promise.resolve({ title: 'What is up?' }); const customizePanelAction = new CustomizePanelTitleAction(getUserData); expect(embeddable.getInput().title).toBeUndefined(); @@ -77,13 +78,10 @@ test('Updates the embeddable title when given', async (done) => { // Recreating the container should preserve the custom title. const containerClone = createHelloWorldContainer(container.getInput()); // Need to wait for the container to tell us the embeddable has been loaded. - const subscription = containerClone.getOutput$().subscribe(() => { - if (containerClone.getOutput().embeddableLoaded[embeddable.id]) { - expect(embeddable.getInput().title).toBe('What is up?'); - subscription.unsubscribe(); - done(); - } - }); + await containerClone.getOutput$().pipe(first()).toPromise(); + + expect(containerClone.getOutput().embeddableLoaded[embeddable.id]).toBeTruthy(); + expect(embeddable.getInput().title).toBe('What is up?'); }); test('Empty string results in an empty title', async () => { diff --git a/src/plugins/embeddable/public/tests/container.test.ts b/src/plugins/embeddable/public/tests/container.test.ts index bb3e35c949666..0d392304a8df5 100644 --- a/src/plugins/embeddable/public/tests/container.test.ts +++ b/src/plugins/embeddable/public/tests/container.test.ts @@ -18,7 +18,7 @@ */ import * as Rx from 'rxjs'; -import { skip } from 'rxjs/operators'; +import { first, skip } from 'rxjs/operators'; import { isErrorEmbeddable, EmbeddableOutput, @@ -101,7 +101,7 @@ async function creatHelloWorldContainerAndEmbeddable( return { container, embeddable, coreSetup, coreStart, setup, start, uiActions, testPanel }; } -test('Container initializes embeddables', async (done) => { +test('Container initializes embeddables', async () => { const { container } = await creatHelloWorldContainerAndEmbeddable({ id: 'hello', panels: { @@ -112,12 +112,10 @@ test('Container initializes embeddables', async (done) => { }, }); - if (container.getOutput().embeddableLoaded['123']) { - const embeddable = container.getChild('123'); - expect(embeddable).toBeDefined(); - expect(embeddable.id).toBe('123'); - done(); - } + expect(container.getOutput().embeddableLoaded['123']).toBeTruthy(); + const embeddable = container.getChild('123'); + expect(embeddable).toBeDefined(); + expect(embeddable.id).toBe('123'); }); test('Container.addNewEmbeddable', async () => { @@ -140,7 +138,7 @@ test('Container.addNewEmbeddable', async () => { expect(embeddableInContainer.id).toBe(embeddable.id); }); -test('Container.removeEmbeddable removes and cleans up', async (done) => { +test('Container.removeEmbeddable removes and cleans up', async () => { const { start, testPanel } = await creatHelloWorldContainerAndEmbeddable(); const container = new HelloWorldContainer( @@ -174,25 +172,19 @@ test('Container.removeEmbeddable removes and cleans up', async (done) => { embeddable.updateInput({ lastName: 'Z' }); - container - .getOutput$() - .pipe(skip(1)) - .subscribe(() => { - const noFind = container.getChild(embeddable.id); - expect(noFind).toBeUndefined(); + container.removeEmbeddable(embeddable.id); + await container.getOutput$().pipe(first()).toPromise(); - expect(container.getInput().panels[embeddable.id]).toBeUndefined(); - if (isErrorEmbeddable(embeddable)) { - expect(false).toBe(true); - done(); - } + const noFind = container.getChild(embeddable.id); + expect(noFind).toBeUndefined(); - expect(() => embeddable.updateInput({ nameTitle: 'Sir' })).toThrowError(); - expect(container.getOutput().embeddableLoaded[embeddable.id]).toBeUndefined(); - done(); - }); + expect(container.getInput().panels[embeddable.id]).toBeUndefined(); + if (isErrorEmbeddable(embeddable)) { + expect(false).toBe(true); + } - container.removeEmbeddable(embeddable.id); + expect(() => embeddable.updateInput({ nameTitle: 'Sir' })).toThrowError(); + expect(container.getOutput().embeddableLoaded[embeddable.id]).toBeUndefined(); }); test('Container.input$ is notified when child embeddable input is updated', async () => { @@ -299,7 +291,7 @@ test('Container view mode change propagates to children', async () => { expect(embeddable.getInput().viewMode).toBe(ViewMode.EDIT); }); -test(`Container updates its state when a child's input is updated`, async (done) => { +test(`Container updates its state when a child's input is updated`, async () => { const { container, embeddable, @@ -351,7 +343,6 @@ test(`Container updates its state when a child's input is updated`, async (done) childClone.getInput().nameTitle === 'Dr.' ) { cloneSubscription.unsubscribe(); - done(); } }); } @@ -388,7 +379,7 @@ test(`Derived container state passed to children`, async () => { subscription.unsubscribe(); }); -test(`Can subscribe to children embeddable updates`, async (done) => { +test(`Can subscribe to children embeddable updates`, async () => { const { embeddable } = await creatHelloWorldContainerAndEmbeddable( { id: 'hello container', @@ -402,16 +393,14 @@ test(`Can subscribe to children embeddable updates`, async (done) => { expect(isErrorEmbeddable(embeddable)).toBe(false); - const subscription = embeddable.getInput$().subscribe((input: ContactCardEmbeddableInput) => { - if (input.nameTitle === 'Dr.') { - subscription.unsubscribe(); - done(); - } - }); embeddable.updateInput({ nameTitle: 'Dr.' }); + + await embeddable.getInput$().pipe(first()).toPromise(); + + expect(embeddable.getInput().nameTitle).toEqual('Dr.'); }); -test('Test nested reactions', async (done) => { +test('Test nested reactions', async () => { const { container, embeddable } = await creatHelloWorldContainerAndEmbeddable( { id: 'hello', panels: {}, viewMode: ViewMode.VIEW }, { @@ -421,30 +410,25 @@ test('Test nested reactions', async (done) => { expect(isErrorEmbeddable(embeddable)).toBe(false); - const containerSubscription = container.getInput$().subscribe((input: any) => { - const embeddableNameTitle = embeddable.getInput().nameTitle; - const viewMode = input.viewMode; - const nameTitleFromContainer = container.getInputForChild( - embeddable.id - ).nameTitle; - if ( - embeddableNameTitle === 'Dr.' && - nameTitleFromContainer === 'Dr.' && - viewMode === ViewMode.EDIT - ) { - containerSubscription.unsubscribe(); - embeddableSubscription.unsubscribe(); - done(); - } - }); + embeddable.updateInput({ nameTitle: 'Dr.' }); - const embeddableSubscription = embeddable.getInput$().subscribe(() => { - if (embeddable.getInput().nameTitle === 'Dr.') { - container.updateInput({ viewMode: ViewMode.EDIT }); - } - }); + await embeddable.getInput$().pipe(first()).toPromise(); - embeddable.updateInput({ nameTitle: 'Dr.' }); + expect(embeddable.getInput().nameTitle).toEqual('Dr.'); + + container.updateInput({ viewMode: ViewMode.EDIT }); + + await container.getInput$().pipe(first()).toPromise(); + + const embeddableNameTitle = embeddable.getInput().nameTitle; + const viewMode = container.getInput().viewMode; + const nameTitleFromContainer = container.getInputForChild( + embeddable.id + ).nameTitle; + + expect(embeddableNameTitle).toEqual('Dr.'); + expect(nameTitleFromContainer).toEqual('Dr.'); + expect(viewMode).toEqual(ViewMode.EDIT); }); test('Explicit embeddable input mapped to undefined will default to inherited', async () => { @@ -479,7 +463,7 @@ test('Explicit embeddable input mapped to undefined will default to inherited', ]); }); -test('Explicit embeddable input mapped to undefined with no inherited value will get passed to embeddable', async (done) => { +test('Explicit embeddable input mapped to undefined with no inherited value will get passed to embeddable', async () => { const { container } = await creatHelloWorldContainerAndEmbeddable({ id: 'hello', panels: {} }); const embeddable = await container.addNewEmbeddable< @@ -496,17 +480,11 @@ test('Explicit embeddable input mapped to undefined with no inherited value will expect(container.getInputForChild(embeddable.id).filters).toEqual([]); - const subscription = embeddable - .getInput$() - .pipe(skip(1)) - .subscribe(() => { - if (embeddable.getInput().filters === undefined) { - subscription.unsubscribe(); - done(); - } - }); - embeddable.updateInput({ filters: undefined }); + + expect(container.getInputForChild(embeddable.id).filters).toEqual( + undefined + ); }); test('Panel removed from input state', async () => { @@ -569,7 +547,7 @@ test('Panel added to input state', async () => { expect(container.getOutput().embeddableLoaded[embeddable2.id]).toBe(true); }); -test('Container changes made directly after adding a new embeddable are propagated', async (done) => { +test('Container changes made directly after adding a new embeddable are propagated', (done) => { const coreSetup = coreMock.createSetup(); const coreStart = coreMock.createStart(); const { setup, doStart, uiActions } = testPlugin(coreSetup, coreStart); @@ -627,7 +605,7 @@ test('Container changes made directly after adding a new embeddable are propagat container.updateInput({ viewMode: ViewMode.VIEW }); }); -test('container stores ErrorEmbeddables when a factory for a child cannot be found (so the panel can be removed)', async (done) => { +test('container stores ErrorEmbeddables when a factory for a child cannot be found (so the panel can be removed)', async () => { const { container } = await creatHelloWorldContainerAndEmbeddable({ id: 'hello', panels: { @@ -639,16 +617,14 @@ test('container stores ErrorEmbeddables when a factory for a child cannot be fou viewMode: ViewMode.EDIT, }); - container.getOutput$().subscribe(() => { - if (container.getOutput().embeddableLoaded['123']) { - const child = container.getChild('123'); - expect(child.type).toBe(ERROR_EMBEDDABLE_TYPE); - done(); - } - }); + await container.getOutput$().pipe(first()).toPromise(); + + expect(container.getOutput().embeddableLoaded['123']).toBeTruthy(); + const child = container.getChild('123'); + expect(child.type).toBe(ERROR_EMBEDDABLE_TYPE); }); -test('container stores ErrorEmbeddables when a saved object cannot be found', async (done) => { +test('container stores ErrorEmbeddables when a saved object cannot be found', async () => { const { container } = await creatHelloWorldContainerAndEmbeddable({ id: 'hello', panels: { @@ -660,16 +636,14 @@ test('container stores ErrorEmbeddables when a saved object cannot be found', as viewMode: ViewMode.EDIT, }); - container.getOutput$().subscribe(() => { - if (container.getOutput().embeddableLoaded['123']) { - const child = container.getChild('123'); - expect(child.type).toBe(ERROR_EMBEDDABLE_TYPE); - done(); - } - }); + await container.getOutput$().pipe(first()).toPromise(); + + expect(container.getOutput().embeddableLoaded['123']).toBeTruthy(); + const child = container.getChild('123'); + expect(child.type).toBe(ERROR_EMBEDDABLE_TYPE); }); -test('ErrorEmbeddables get updated when parent does', async (done) => { +test('ErrorEmbeddables get updated when parent does', async () => { const { container } = await creatHelloWorldContainerAndEmbeddable({ id: 'hello', panels: { @@ -681,18 +655,17 @@ test('ErrorEmbeddables get updated when parent does', async (done) => { viewMode: ViewMode.EDIT, }); - container.getOutput$().subscribe(() => { - if (container.getOutput().embeddableLoaded['123']) { - const embeddable = container.getChild('123'); + await container.getOutput$().pipe(first()).toPromise(); - expect(embeddable.getInput().viewMode).toBe(ViewMode.EDIT); + expect(container.getOutput().embeddableLoaded['123']).toBeTruthy(); - container.updateInput({ viewMode: ViewMode.VIEW }); + const embeddable = container.getChild('123'); - expect(embeddable.getInput().viewMode).toBe(ViewMode.VIEW); - done(); - } - }); + expect(embeddable.getInput().viewMode).toBe(ViewMode.EDIT); + + container.updateInput({ viewMode: ViewMode.VIEW }); + + expect(embeddable.getInput().viewMode).toBe(ViewMode.VIEW); }); test('untilEmbeddableLoaded() throws an error if there is no such child panel in the container', async () => { @@ -734,7 +707,7 @@ test('untilEmbeddableLoaded() throws an error if there is no such child panel in expect(error.message).toMatchInlineSnapshot(`"Panel not found"`); }); -test('untilEmbeddableLoaded() resolves if child is loaded in the container', async (done) => { +test('untilEmbeddableLoaded() resolves if child is loaded in the container', async () => { const { setup, doStart, coreStart, uiActions } = testPlugin( coreMock.createSetup(), coreMock.createStart() @@ -769,10 +742,9 @@ test('untilEmbeddableLoaded() resolves if child is loaded in the container', asy const child = await container.untilEmbeddableLoaded('123'); expect(child).toBeDefined(); expect(child.type).toBe(HELLO_WORLD_EMBEDDABLE); - done(); }); -test('untilEmbeddableLoaded resolves with undefined if child is subsequently removed', async (done) => { +test('untilEmbeddableLoaded resolves with undefined if child is subsequently removed', (done) => { const { doStart, setup, coreStart, uiActions } = testPlugin( coreMock.createSetup(), coreMock.createStart() @@ -816,7 +788,7 @@ test('untilEmbeddableLoaded resolves with undefined if child is subsequently rem container.updateInput({ panels: {} }); }); -test('adding a panel then subsequently removing it before its loaded removes the panel', async (done) => { +test('adding a panel then subsequently removing it before its loaded removes the panel', (done) => { const { doStart, coreStart, uiActions, setup } = testPlugin( coreMock.createSetup(), coreMock.createStart() diff --git a/src/plugins/embeddable/public/tests/explicit_input.test.ts b/src/plugins/embeddable/public/tests/explicit_input.test.ts index 531fbcee94db6..9eafd63475e93 100644 --- a/src/plugins/embeddable/public/tests/explicit_input.test.ts +++ b/src/plugins/embeddable/public/tests/explicit_input.test.ts @@ -17,7 +17,6 @@ * under the License. */ -import { skip } from 'rxjs/operators'; import { testPlugin } from './test_plugin'; import { MockFilter, @@ -82,7 +81,7 @@ test('Explicit embeddable input mapped to undefined will default to inherited', ]); }); -test('Explicit embeddable input mapped to undefined with no inherited value will get passed to embeddable', async (done) => { +test('Explicit embeddable input mapped to undefined with no inherited value will get passed to embeddable', async () => { const testPanel = createEmbeddablePanelMock({ getActions: uiActions.getTriggerCompatibleActions, getEmbeddableFactory: start.getEmbeddableFactory, @@ -109,17 +108,11 @@ test('Explicit embeddable input mapped to undefined with no inherited value will expect(container.getInputForChild(embeddable.id).filters).toEqual([]); - const subscription = embeddable - .getInput$() - .pipe(skip(1)) - .subscribe(() => { - if (embeddable.getInput().filters === undefined) { - subscription.unsubscribe(); - done(); - } - }); - embeddable.updateInput({ filters: undefined }); + + expect(container.getInputForChild(embeddable.id).filters).toEqual( + undefined + ); }); // The goal is to make sure that if the container input changes after `onPanelAdded` is called diff --git a/src/plugins/index_pattern_management/jest.config.js b/src/plugins/index_pattern_management/jest.config.js index 8a499406080fd..b5ff28714cbeb 100644 --- a/src/plugins/index_pattern_management/jest.config.js +++ b/src/plugins/index_pattern_management/jest.config.js @@ -21,5 +21,4 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/index_pattern_management'], - testRunner: 'jasmine2', }; diff --git a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/ensure_minimum_time.test.ts b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/ensure_minimum_time.test.ts index 5a202bff53b64..26df9e2b39b23 100644 --- a/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/ensure_minimum_time.test.ts +++ b/src/plugins/index_pattern_management/public/components/create_index_pattern_wizard/lib/ensure_minimum_time.test.ts @@ -20,28 +20,25 @@ import { ensureMinimumTime } from './ensure_minimum_time'; describe('ensureMinimumTime', () => { - it('resolves single promise', async (done) => { + it('resolves single promise', async () => { const promiseA = new Promise((resolve) => resolve('a')); const a = await ensureMinimumTime(promiseA, 0); expect(a).toBe('a'); - done(); }); - it('resolves multiple promises', async (done) => { + it('resolves multiple promises', async () => { const promiseA = new Promise((resolve) => resolve('a')); const promiseB = new Promise((resolve) => resolve('b')); const [a, b] = await ensureMinimumTime([promiseA, promiseB], 0); expect(a).toBe('a'); expect(b).toBe('b'); - done(); }); - it('resolves in the amount of time provided, at minimum', async (done) => { + it('resolves in the amount of time provided, at minimum', async () => { const startTime = new Date().getTime(); const promise = new Promise((resolve) => resolve()); await ensureMinimumTime(promise, 100); const endTime = new Date().getTime(); expect(endTime - startTime).toBeGreaterThanOrEqual(100); - done(); }); }); diff --git a/src/plugins/vis_type_tagcloud/jest.config.js b/src/plugins/vis_type_tagcloud/jest.config.js index 5419ca05cca84..8fc749229b430 100644 --- a/src/plugins/vis_type_tagcloud/jest.config.js +++ b/src/plugins/vis_type_tagcloud/jest.config.js @@ -21,5 +21,4 @@ module.exports = { preset: '@kbn/test', rootDir: '../../..', roots: ['/src/plugins/vis_type_tagcloud'], - testRunner: 'jasmine2', }; diff --git a/src/plugins/vis_type_tagcloud/public/components/tag_cloud_visualization.test.js b/src/plugins/vis_type_tagcloud/public/components/tag_cloud_visualization.test.js index 597aafea0d162..0bd1db9ef9eb7 100644 --- a/src/plugins/vis_type_tagcloud/public/components/tag_cloud_visualization.test.js +++ b/src/plugins/vis_type_tagcloud/public/components/tag_cloud_visualization.test.js @@ -58,11 +58,12 @@ describe('TagCloudVisualizationTest', () => { setFormatService(dataPluginMock.createStartContract().fieldFormats); Object.defineProperties(window.SVGElement.prototype, { transform: { - get: () => ({ + value: { baseVal: { consolidate: () => {}, }, - }), + }, + writable: true, configurable: true, }, }); diff --git a/yarn.lock b/yarn.lock index 6e4df2f5b197a..f2fa60dc15dd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2118,7 +2118,7 @@ chalk "^2.0.1" slash "^2.0.0" -"@jest/console@^26.5.2", "@jest/console@^26.6.2": +"@jest/console@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/console/-/console-26.6.2.tgz#4e04bc464014358b03ab4937805ee36a0aeb98f2" integrity sha512-IY1R2i2aLsLr7Id3S6p2BA82GNWryt4oSvEXLAKc+L2zdi89dSkE8xC1C+0kpATG4JhBJREnQOH7/zmccM2B0g== @@ -2204,38 +2204,6 @@ "@jest/types" "^26.6.2" expect "^26.6.2" -"@jest/reporters@^26.5.2": - version "26.5.3" - resolved "https://registry.yarnpkg.com/@jest/reporters/-/reporters-26.5.3.tgz#e810e9c2b670f33f1c09e9975749260ca12f1c17" - integrity sha512-X+vR0CpfMQzYcYmMFKNY9n4jklcb14Kffffp7+H/MqitWnb0440bW2L76NGWKAa+bnXhNoZr+lCVtdtPmfJVOQ== - dependencies: - "@bcoe/v8-coverage" "^0.2.3" - "@jest/console" "^26.5.2" - "@jest/test-result" "^26.5.2" - "@jest/transform" "^26.5.2" - "@jest/types" "^26.5.2" - chalk "^4.0.0" - collect-v8-coverage "^1.0.0" - exit "^0.1.2" - glob "^7.1.2" - graceful-fs "^4.2.4" - istanbul-lib-coverage "^3.0.0" - istanbul-lib-instrument "^4.0.3" - istanbul-lib-report "^3.0.0" - istanbul-lib-source-maps "^4.0.0" - istanbul-reports "^3.0.2" - jest-haste-map "^26.5.2" - jest-resolve "^26.5.2" - jest-util "^26.5.2" - jest-worker "^26.5.0" - slash "^3.0.0" - source-map "^0.6.0" - string-length "^4.0.1" - terminal-link "^2.0.0" - v8-to-istanbul "^6.0.1" - optionalDependencies: - node-notifier "^8.0.0" - "@jest/reporters@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/reporters/-/reporters-26.6.2.tgz#1f518b99637a5f18307bd3ecf9275f6882a667f6" @@ -2295,7 +2263,7 @@ "@jest/types" "^24.9.0" "@types/istanbul-lib-coverage" "^2.0.0" -"@jest/test-result@^26.5.2", "@jest/test-result@^26.6.2": +"@jest/test-result@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/test-result/-/test-result-26.6.2.tgz#55da58b62df134576cc95476efa5f7949e3f5f18" integrity sha512-5O7H5c/7YlojphYNrK02LlDIV2GNPYisKwHm2QTKjNZeEzezCbwYs9swJySv2UfPMyZ0VdsmMv7jIlD/IKYQpQ== @@ -2316,7 +2284,7 @@ jest-runner "^26.6.3" jest-runtime "^26.6.3" -"@jest/transform@^26.0.0", "@jest/transform@^26.5.2", "@jest/transform@^26.6.2": +"@jest/transform@^26.0.0", "@jest/transform@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/transform/-/transform-26.6.2.tgz#5ac57c5fa1ad17b2aae83e73e45813894dcf2e4b" integrity sha512-E9JjhUgNzvuQ+vVAL21vlyfy12gP0GhazGgJC4h6qUt1jSdUXGWJ1wfu/X7Sd8etSgxV4ovT1pb9v5D6QW4XgA== @@ -2356,7 +2324,7 @@ "@types/yargs" "^15.0.0" chalk "^3.0.0" -"@jest/types@^26.5.2", "@jest/types@^26.6.2": +"@jest/types@^26.6.2": version "26.6.2" resolved "https://registry.yarnpkg.com/@jest/types/-/types-26.6.2.tgz#bef5a532030e1d88a2f5a6d933f84e97226ed48e" integrity sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ== @@ -7672,7 +7640,7 @@ babel-helper-to-multiple-sequence-expressions@^0.5.0: resolved "https://registry.yarnpkg.com/babel-helper-to-multiple-sequence-expressions/-/babel-helper-to-multiple-sequence-expressions-0.5.0.tgz#a3f924e3561882d42fcf48907aa98f7979a4588d" integrity sha512-m2CvfDW4+1qfDdsrtf4dwOslQC3yhbgyBFptncp4wvtdrDHqueW7slsYv4gArie056phvQFhT2nRcGS4bnm6mA== -babel-jest@^26.3.0, babel-jest@^26.6.3: +babel-jest@^26.6.3: version "26.6.3" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-26.6.3.tgz#d87d25cb0037577a0c89f82e5755c5d293c01056" integrity sha512-pl4Q+GAVOHwvjrck6jKjvmGhnO3jHX/xuB9d27f+EJZ/6k+6nMuPjorrYp7s++bKKdANwzElBWnLWaObvTnaZA== @@ -17433,7 +17401,7 @@ jest-get-type@^26.3.0: resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-26.3.0.tgz#e97dc3c3f53c2b406ca7afaed4493b1d099199e0" integrity sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig== -jest-haste-map@^26.5.2, jest-haste-map@^26.6.2: +jest-haste-map@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-26.6.2.tgz#dd7e60fe7dc0e9f911a23d79c5ff7fb5c2cafeaa" integrity sha512-easWIJXIw71B2RdR8kgqpjQrbMRWQBgiBwXYEhtGUTaX+doCjBheluShdDMeR8IMfJiTqH4+zfhtg29apJf/8w== @@ -17590,7 +17558,7 @@ jest-resolve@^24.9.0: jest-pnp-resolver "^1.2.1" realpath-native "^1.1.0" -jest-resolve@^26.5.2, jest-resolve@^26.6.2: +jest-resolve@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-resolve/-/jest-resolve-26.6.2.tgz#a3ab1517217f469b504f1b56603c5bb541fbb507" integrity sha512-sOxsZOq25mT1wRsfHcbtkInS+Ek7Q8jCHUB0ZUTP0tc/c41QHriU/NunqMfCUWsL4H3MHpvQD4QR9kSYhS7UvQ== @@ -17759,7 +17727,7 @@ jest-util@^24.0.0: slash "^2.0.0" source-map "^0.6.0" -jest-util@^26.5.2, jest-util@^26.6.2: +jest-util@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-26.6.2.tgz#907535dbe4d5a6cb4c47ac9b926f6af29576cbc1" integrity sha512-MDW0fKfsn0OI7MS7Euz6h8HNDXVQ0gaM9uW6RjfDmd1DAFcaxX9OqIakHIqhbnmF08Cf2DLDG+ulq8YQQ0Lp0Q== @@ -17812,7 +17780,7 @@ jest-worker@^25.4.0: merge-stream "^2.0.0" supports-color "^7.0.0" -jest-worker@^26.2.1, jest-worker@^26.5.0, jest-worker@^26.6.2: +jest-worker@^26.2.1, jest-worker@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-26.6.2.tgz#7f72cbc4d643c365e27b9fd775f9d0eaa9c7a8ed" integrity sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ== @@ -28222,15 +28190,6 @@ v8-compile-cache@^2.0.3, v8-compile-cache@^2.1.1: resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz#9471efa3ef9128d2f7c6a7ca39c4dd6b5055b132" integrity sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q== -v8-to-istanbul@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-6.0.1.tgz#7ef0e32faa10f841fe4c1b0f8de96ed067c0be1e" - integrity sha512-PzM1WlqquhBvsV+Gco6WSFeg1AGdD53ccMRkFeyHRE/KRZaVacPOmQYP3EeVgDBtKD2BJ8kgynBQ5OtKiHCH+w== - dependencies: - "@types/istanbul-lib-coverage" "^2.0.1" - convert-source-map "^1.6.0" - source-map "^0.7.3" - v8-to-istanbul@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-7.0.0.tgz#b4fe00e35649ef7785a9b7fcebcea05f37c332fc"