@@ -22,20 +22,31 @@ import { writeFileSync, mkdirSync } from 'fs';
2222
2323import xmlBuilder from 'xmlbuilder' ;
2424
25- import { escapeCdata , makeJunitReportPath } from '@kbn/test' ;
25+ import type { Config } from '@jest/types' ;
26+ import { AggregatedResult , Test , BaseReporter } from '@jest/reporters' ;
2627
27- const ROOT_DIR = dirname ( require . resolve ( '../../../package.json' ) ) ;
28+ import { escapeCdata } from '../mocha/xml' ;
29+ import { makeJunitReportPath } from './report_path' ;
30+
31+ interface ReporterOptions {
32+ reportName ?: string ;
33+ rootDirectory ?: string ;
34+ }
2835
2936/**
3037 * Jest reporter that produces JUnit report when running on CI
3138 * @class JestJUnitReporter
3239 */
33- export default class JestJUnitReporter {
34- constructor ( globalConfig , options = { } ) {
35- const { reportName = 'Jest Tests' , rootDirectory = ROOT_DIR } = options ;
3640
37- this . _reportName = reportName ;
38- this . _rootDirectory = resolve ( rootDirectory ) ;
41+ // eslint-disable-next-line import/no-default-export
42+ export default class JestJUnitReporter extends BaseReporter {
43+ private _reportName : string ;
44+ private _rootDirectory : string ;
45+
46+ constructor ( globalConfig : Config . GlobalConfig , { rootDirectory, reportName } : ReporterOptions ) {
47+ super ( ) ;
48+ this . _reportName = reportName || 'Jest Tests' ;
49+ this . _rootDirectory = rootDirectory ? resolve ( rootDirectory ) : resolve ( __dirname , '../..' ) ;
3950 }
4051
4152 /**
@@ -44,7 +55,7 @@ export default class JestJUnitReporter {
4455 * @param {JestResults } results see https://facebook.github.io/jest/docs/en/configuration.html#testresultsprocessor-string
4556 * @return {undefined }
4657 */
47- onRunComplete ( contexts , results ) {
58+ onRunComplete ( contexts : Set < Test [ 'context' ] > , results : AggregatedResult ) : void {
4859 if ( ! process . env . CI || process . env . DISABLE_JUNIT_REPORTER || ! results . testResults . length ) {
4960 return ;
5061 }
@@ -55,18 +66,19 @@ export default class JestJUnitReporter {
5566 'testsuites' ,
5667 { encoding : 'utf-8' } ,
5768 { } ,
58- { skipNullAttributes : true }
69+ { keepNullAttributes : false }
5970 ) ;
6071
61- const msToIso = ( ms ) => ( ms ? new Date ( ms ) . toISOString ( ) . slice ( 0 , - 5 ) : undefined ) ;
62- const msToSec = ( ms ) => ( ms ? ( ms / 1000 ) . toFixed ( 3 ) : undefined ) ;
72+ const msToIso = ( ms : number | null | undefined ) =>
73+ ms ? new Date ( ms ) . toISOString ( ) . slice ( 0 , - 5 ) : undefined ;
74+ const msToSec = ( ms : number | null | undefined ) => ( ms ? ( ms / 1000 ) . toFixed ( 3 ) : undefined ) ;
6375
6476 root . att ( {
6577 name : 'jest' ,
6678 timestamp : msToIso ( results . startTime ) ,
6779 time : msToSec ( Date . now ( ) - results . startTime ) ,
6880 tests : results . numTotalTests ,
69- failures : results . numFailingTests ,
81+ failures : results . numFailedTests ,
7082 skipped : results . numPendingTests ,
7183 } ) ;
7284
0 commit comments