diff --git a/packages/kbn-test/src/failed_tests_reporter/__fixtures__/ftr_report.xml b/packages/kbn-test/src/failed_tests_reporter/__fixtures__/ftr_report.xml index 9da63234e03d4..3bfc686f9e845 100644 --- a/packages/kbn-test/src/failed_tests_reporter/__fixtures__/ftr_report.xml +++ b/packages/kbn-test/src/failed_tests_reporter/__fixtures__/ftr_report.xml @@ -18,7 +18,7 @@ Wait timed out after 10055ms at onFailure (/var/lib/jenkins/workspace/elastic+kibana+master/JOB/x-pack-ciGroup7/node/immutable/kibana/test/common/services/retry/retry_for_success.ts:68:13)]]> - + { + at onFailure (/var/lib/jenkins/workspace/elastic+kibana+master/JOB/x-pack-ciGroup7/node/immutable/kibana/test/common/services/retry/retry_for_success.ts:68:13) ‹/failure› ‹/testcase› - ‹testcase name="maps app "after all" hook" classname="Chrome X-Pack UI Functional Tests.x-pack/test/functional/apps/maps" time="0.179"› + ‹testcase name="maps app "after all" hook" classname="Chrome X-Pack UI Functional Tests.x-pack/test/functional/apps/maps" time="0.179" metadata-json="{"messages":["foo"],"screenshots":[{"name":"failure[dashboard app using current data dashboard snapshots compare TSVB snapshot]","url":"https://storage.googleapis.com/kibana-ci-artifacts/jobs/elastic+kibana+7.x/1632/kibana-oss-tests/test/functional/screenshots/failure/dashboard%20app%20using%20current%20data%20dashboard%20snapshots%20compare%20TSVB%20snapshot.png"}]}"› ‹system-out› - ‹![CDATA[[00:00:00] │ + [00:00:00] │ diff --git a/packages/kbn-test/src/failed_tests_reporter/get_failures.test.ts b/packages/kbn-test/src/failed_tests_reporter/get_failures.test.ts index fe6e0bbc796ee..23d9805727f32 100644 --- a/packages/kbn-test/src/failed_tests_reporter/get_failures.test.ts +++ b/packages/kbn-test/src/failed_tests_reporter/get_failures.test.ts @@ -48,6 +48,7 @@ it('discovers failures in ftr report', async () => { at process._tickCallback (internal/process/next_tick.js:68:7) name: 'NoSuchSessionError', remoteStacktrace: '' } ", "likelyIrrelevant": true, + "metadata-json": "{\\"messages\\":[\\"foo\\"],\\"screenshots\\":[{\\"name\\":\\"failure[dashboard app using current data dashboard snapshots compare TSVB snapshot]\\",\\"url\\":\\"https://storage.googleapis.com/kibana-ci-artifacts/jobs/elastic+kibana+7.x/1632/kibana-oss-tests/test/functional/screenshots/failure/dashboard%20app%20using%20current%20data%20dashboard%20snapshots%20compare%20TSVB%20snapshot.png\\"}]}", "name": "maps app \\"after all\\" hook", "time": "0.179", }, diff --git a/packages/kbn-test/src/failed_tests_reporter/report_metadata.test.ts b/packages/kbn-test/src/failed_tests_reporter/report_metadata.test.ts new file mode 100644 index 0000000000000..729d80ddfcb44 --- /dev/null +++ b/packages/kbn-test/src/failed_tests_reporter/report_metadata.test.ts @@ -0,0 +1,49 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { getReportMessageIter } from './report_metadata'; +import { parseTestReport } from './test_report'; +import { FTR_REPORT, JEST_REPORT, KARMA_REPORT, MOCHA_REPORT } from './__fixtures__'; + +it('reads messages and screenshots from metadata-json properties', async () => { + const ftrReport = await parseTestReport(FTR_REPORT); + expect(Array.from(getReportMessageIter(ftrReport))).toMatchInlineSnapshot(` + Array [ + Object { + "classname": "Chrome X-Pack UI Functional Tests.x-pack/test/functional/apps/maps", + "message": "foo", + "name": "maps app \\"after all\\" hook", + }, + Object { + "classname": "Chrome X-Pack UI Functional Tests.x-pack/test/functional/apps/maps", + "message": "Screenshot: failure[dashboard app using current data dashboard snapshots compare TSVB snapshot] https://storage.googleapis.com/kibana-ci-artifacts/jobs/elastic+kibana+7.x/1632/kibana-oss-tests/test/functional/screenshots/failure/dashboard%20app%20using%20current%20data%20dashboard%20snapshots%20compare%20TSVB%20snapshot.png", + "name": "maps app \\"after all\\" hook", + }, + ] + `); + + const jestReport = await parseTestReport(JEST_REPORT); + expect(Array.from(getReportMessageIter(jestReport))).toMatchInlineSnapshot(`Array []`); + + const mochaReport = await parseTestReport(MOCHA_REPORT); + expect(Array.from(getReportMessageIter(mochaReport))).toMatchInlineSnapshot(`Array []`); + + const karmaReport = await parseTestReport(KARMA_REPORT); + expect(Array.from(getReportMessageIter(karmaReport))).toMatchInlineSnapshot(`Array []`); +}); diff --git a/packages/kbn-test/src/failed_tests_reporter/report_metadata.ts b/packages/kbn-test/src/failed_tests_reporter/report_metadata.ts index aad4c5d3c30c0..5484948e59976 100644 --- a/packages/kbn-test/src/failed_tests_reporter/report_metadata.ts +++ b/packages/kbn-test/src/failed_tests_reporter/report_metadata.ts @@ -18,36 +18,25 @@ */ import { TestReport, makeTestCaseIter } from './test_report'; -import { Message } from './add_messages_to_report'; -export function* getMetadataIter(report: TestReport) { +export function* getReportMessageIter(report: TestReport) { for (const testCase of makeTestCaseIter(report)) { - if (!testCase.$['metadata-json']) { - yield [{}, testCase]; - } else { - yield [{}, JSON.parse(testCase.$['metadata-json'])]; - } - } -} + const metadata = testCase.$['metadata-json'] ? JSON.parse(testCase.$['metadata-json']) : {}; -export function getReportMessages(report: TestReport) { - const messages: Message[] = []; - for (const [metadata, testCase] of getMetadataIter(report)) { for (const message of metadata.messages || []) { - messages.push({ + yield { classname: testCase.$.classname, name: testCase.$.name, - message, - }); + message: String(message), + }; } for (const screenshot of metadata.screenshots || []) { - messages.push({ + yield { classname: testCase.$.classname, name: testCase.$.name, message: `Screenshot: ${screenshot.name} ${screenshot.url}`, - }); + }; } } - return messages; } diff --git a/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts b/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts index fd7976d6e87e1..fc52fa6cbf9e7 100644 --- a/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts +++ b/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts @@ -26,7 +26,7 @@ import { updateFailureIssue, createFailureIssue } from './report_failure'; import { getIssueMetadata } from './issue_metadata'; import { readTestReport } from './test_report'; import { addMessagesToReport } from './add_messages_to_report'; -import { getReportMessages } from './report_metadata'; +import { getReportMessageIter } from './report_metadata'; export function runFailedTestsReporterCli() { run( @@ -75,7 +75,7 @@ export function runFailedTestsReporterCli() { for (const reportPath of reportPaths) { const report = await readTestReport(reportPath); - const messages = getReportMessages(report); + const messages = Array.from(getReportMessageIter(report)); for (const failure of await getFailures(report)) { const pushMessage = (msg: string) => {