diff --git a/test-case-reporting/src/test_result_record.ts b/test-case-reporting/src/test_result_record.ts index 6099d6c46..292c3db41 100644 --- a/test-case-reporting/src/test_result_record.ts +++ b/test-case-reporting/src/test_result_record.ts @@ -18,6 +18,8 @@ import { Build, DB, Job, + KarmaReporter, + MochaReporter, PageInfo, TestCase, TestRun, @@ -29,6 +31,10 @@ import {QueryBuilder} from 'knex'; import md5 from 'md5'; type QueryFunction = (q: QueryBuilder) => QueryBuilder; +interface FormattedResult extends KarmaReporter.TestResult { + testCaseId: string; + testCaseName: string; +} /* eslint-disable @typescript-eslint/camelcase */ /** @@ -172,17 +178,24 @@ export class TestResultRecord { const buildId = await this.insertTravisBuild(build); const jobId = await this.insertTravisJob(job, buildId); - const formattedResults = results.browsers - .map(({results}) => results) - .reduce((flattenedArray, array) => flattenedArray.concat(array), []) - .map(result => { - const testCaseName = this.testCaseName(result); - return { - ...result, - testCaseId: md5(testCaseName), - testCaseName, - }; - }); + let resultList: Array; + + if (job.testSuiteType === 'e2e') { + resultList = (results as MochaReporter.TestResultReport).testResults; + } else { + resultList = (results as KarmaReporter.TestResultReport).browsers + .map(({results}) => results) + .reduce((flattenedArray, array) => flattenedArray.concat(array), []); + } + + const formattedResults: Array = resultList.map(result => { + const testCaseName = this.testCaseName(result); + return { + ...result, + testCaseId: md5(testCaseName), + testCaseName, + }; + }); const testCases: Array = formattedResults.map( ({testCaseId, testCaseName}) => ({ diff --git a/test-case-reporting/types/test-case-reporting.d.ts b/test-case-reporting/types/test-case-reporting.d.ts index 5c3e10504..192ea978c 100644 --- a/test-case-reporting/types/test-case-reporting.d.ts +++ b/test-case-reporting/types/test-case-reporting.d.ts @@ -18,7 +18,7 @@ declare module 'test-case-reporting' { /** * Travis job types for which test results may be reported. */ - export type TestSuiteType = 'unit' | 'integration'; + export type TestSuiteType = 'unit' | 'integration' | 'e2e'; export type TestStatus = 'PASS' | 'FAIL' | 'SKIP' | 'ERROR'; @@ -144,6 +144,7 @@ declare module 'test-case-reporting' { results: Array; } + // TODO(980): Move this to API namespace export interface TestResult { description: string; suite: Array; @@ -153,13 +154,21 @@ declare module 'test-case-reporting' { } } + // Types for the JSON reports generated by Mocha + // Supposed to match the reports exactly. + namespace MochaReporter { + export interface TestResultReport { + testResults: Array; + } + } + // Types for the JSON reports POSTed by Travis // Supposed to match the reports exactly. namespace Travis { export interface Report { job: Travis.Job; build: Travis.Build; - results: KarmaReporter.TestResultReport; + results: KarmaReporter.TestResultReport | MochaReporter.TestResultReport; } export interface Build { buildNumber: string;