-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CI] Produce junit test reports #15281
Conversation
a6eb638
to
82678a1
Compare
11d2eb5
to
4cef043
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for working on this!
src/dev/mocha/junit_reporter.js
Outdated
suite.startTime = Date.now(); | ||
}); | ||
|
||
runner.on('test', (suite) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: suite
--> test
?
src/dev/mocha/junit_reporter.js
Outdated
suite.startTime = Date.now(); | ||
}); | ||
|
||
runner.on('test end', (suite) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: suite
--> test
?
src/dev/mocha/junit_reporter.js
Outdated
const segments = [...directory.split(pathSep), filenameWithoutExt]; | ||
|
||
return segments | ||
.filter(seg => seg && !PATH_SEGMENTS_TO_IGNORE.includes(seg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: it's probably a matter of personal taste, but having "raw" core_plugins/kibana/common/field_formats/types/__tests__/truncate.js
instead of
CorePlugins/Kibana/Common/FieldFormats/Types/Truncate
seems to be easier to understand and map to actual test file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, the issue I primarily had with using paths was that they can't include .
characters as Jenkins treats everything to the left of the last .
as the top level package, and everything following the .
as the classname. To work around this I was replacing .
with ∙
, so the path looked similar but they weren't really paths anymore... Do you think you'd prefer the paths with .
replaced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, the issue I primarily had with using paths was that they can't include
.
characters as Jenkins treats everything to the left of the last.
as the top level package, and everything following the.
as the classname. To work around this I was replacing.
with∙
, so the path looked similar but they weren't really paths anymore...
Hmm, I see, thanks for the details. Even though both options work for me, I still would prefer to be as close to real paths as possible. I'm going to defer that to you and @kjbekkelund as I don't have a strong opinion on that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and updated the jest and mocha reporters to use relative file paths for the test "classname", will post comparisons when they're done running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the screenshots, I still prefer the latter one personally, not a big deal though :)
@@ -24,6 +26,16 @@ export function ConsoleReporterProvider({ getService }) { | |||
runner.on('test end', this.onTestEnd); | |||
runner.on('suite end', this.onSuiteEnd); | |||
runner.on('end', this.onEnd); | |||
|
|||
if (config.get('junit.enabled') && config.get('junit.reportName')) { | |||
new MochaJunitReporter(runner, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can't MochaJunitReporter
be just a function like setupMochaJunitReporter
? Is there any reason why it should be a constructor function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally added this as a standard mocha reporter, which is instantiated with new
, but no reason for it anymore
src/dev/mocha/junit_reporter.js
Outdated
.dat(inspect(test.err)); | ||
} | ||
|
||
if (isTestPending(test)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: else if
maybe?
@@ -2,17 +2,19 @@ import { format } from 'util'; | |||
|
|||
import Mocha from 'mocha'; | |||
|
|||
import { MochaJunitReporter } from '../../../../dev/mocha/junit_reporter'; | |||
import * as colors from './colors'; | |||
import * as symbols from './symbols'; | |||
import { ms } from './ms'; | |||
import { writeEpilogue } from './write_epilogue'; | |||
|
|||
export function ConsoleReporterProvider({ getService }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional nit: it isn't just a console
reporter anymore, maybe we can have a better name for this reporter, it's not a big deal though.
tasks/config/simplemocha.js
Outdated
}, | ||
all: { | ||
src: [ | ||
'test/mocha_setup.js', | ||
require.resolve('../../src/babel-register'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: just for my understanding, do we need require.resolve('../../src/babel-register')
here? I thought it's either loaded from mocha.opts
, mocha.js
script or from main Gruntfile....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grunt-simplemocha
imports mocha and interacts with it directly, so neither mocha.opts
or scripts/mocha.js
would be called. Now that I typed that out I realize the Gruntfile is loading babel-register already so this is unnecessary.
tasks/config/karma.js
Outdated
].join(' '), | ||
classNameFormatter: (browser, result) => { | ||
const rootSuite = result.suite[0] || result.description; | ||
return `Browser Unit Tests.${rootSuite.split('.').join('·')}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: .split('.').join('·')
---> .replace(/\./gi, '·')
maybe (just to make intention clearer)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I got in this habit when reading about the efficiency of replace... but readability > micro-performance-improvements
src/dev/jest/junit_reporter.js
Outdated
const ROOT_DIR = dirname(require.resolve('../../../package.json')); | ||
|
||
/** | ||
* Jest reporter that that produces JUnit report when running on CI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: redundant that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! LGTM
* [mocha] use custom reporter for legible results in jenkins * [jest] use custom result processor for legible results in jenkins * [karma] enable junit output on CI * [mocha/junitReporter] accept rootDirectory as configuration * [jest/reporter] use reporters option added in jest 20 * [toolingLog] remove black/white specific colors * [dev/mocha/junit] no reason for junit to be a "reporter" * typos * [dev/mocha/junit] use else if * [karma/junit] use string#replace for explicitness * [junit] use test file path as "classname" * [ftr/mocha] no longer a "console" specific reporter
* [mocha] use custom reporter for legible results in jenkins * [jest] use custom result processor for legible results in jenkins * [karma] enable junit output on CI * [mocha/junitReporter] accept rootDirectory as configuration * [jest/reporter] use reporters option added in jest 20 * [toolingLog] remove black/white specific colors * [dev/mocha/junit] no reason for junit to be a "reporter" * typos * [dev/mocha/junit] use else if * [karma/junit] use string#replace for explicitness * [junit] use test file path as "classname" * [ftr/mocha] no longer a "console" specific reporter
* [mocha] use custom reporter for legible results in jenkins * [jest] use custom result processor for legible results in jenkins * [karma] enable junit output on CI * [mocha/junitReporter] accept rootDirectory as configuration * [jest/reporter] use reporters option added in jest 20 * [toolingLog] remove black/white specific colors * [dev/mocha/junit] no reason for junit to be a "reporter" * typos * [dev/mocha/junit] use else if * [karma/junit] use string#replace for explicitness * [junit] use test file path as "classname" * [ftr/mocha] no longer a "console" specific reporter
* [mocha] use custom reporter for legible results in jenkins * [jest] use custom result processor for legible results in jenkins * [karma] enable junit output on CI * [mocha/junitReporter] accept rootDirectory as configuration * [jest/reporter] use reporters option added in jest 20 * [toolingLog] remove black/white specific colors * [dev/mocha/junit] no reason for junit to be a "reporter" * typos * [dev/mocha/junit] use else if * [karma/junit] use string#replace for explicitness * [junit] use test file path as "classname" * [ftr/mocha] no longer a "console" specific reporter
* [mocha] use custom reporter for legible results in jenkins * [jest] use custom result processor for legible results in jenkins * [karma] enable junit output on CI * [mocha/junitReporter] accept rootDirectory as configuration * [jest/reporter] use reporters option added in jest 20 * [toolingLog] remove black/white specific colors * [dev/mocha/junit] no reason for junit to be a "reporter" * typos * [dev/mocha/junit] use else if * [karma/junit] use string#replace for explicitness * [junit] use test file path as "classname" * [ftr/mocha] no longer a "console" specific reporter
* [mocha] use custom reporter for legible results in jenkins * [jest] use custom result processor for legible results in jenkins * [karma] enable junit output on CI * [mocha/junitReporter] accept rootDirectory as configuration * [jest/reporter] use reporters option added in jest 20 * [toolingLog] remove black/white specific colors * [dev/mocha/junit] no reason for junit to be a "reporter" * typos * [dev/mocha/junit] use else if * [karma/junit] use string#replace for explicitness * [junit] use test file path as "classname" * [ftr/mocha] no longer a "console" specific reporter
* [mocha] use custom reporter for legible results in jenkins * [jest] use custom result processor for legible results in jenkins * [karma] enable junit output on CI * [mocha/junitReporter] accept rootDirectory as configuration * [jest/reporter] use reporters option added in jest 20 * [toolingLog] remove black/white specific colors * [dev/mocha/junit] no reason for junit to be a "reporter" * typos * [dev/mocha/junit] use else if * [karma/junit] use string#replace for explicitness * [junit] use test file path as "classname" * [ftr/mocha] no longer a "console" specific reporter
* [CI] Produce junit test reports (#15281) * [mocha] use custom reporter for legible results in jenkins * [jest] use custom result processor for legible results in jenkins * [karma] enable junit output on CI * [mocha/junitReporter] accept rootDirectory as configuration * [jest/reporter] use reporters option added in jest 20 * [toolingLog] remove black/white specific colors * [dev/mocha/junit] no reason for junit to be a "reporter" * typos * [dev/mocha/junit] use else if * [karma/junit] use string#replace for explicitness * [junit] use test file path as "classname" * [ftr/mocha] no longer a "console" specific reporter * [dev/jest] fix relative path to babel options
This PR extends the mocha, jest, and functional test runner implementations to produce JUnit test reports. These reports allow Jenkins to track the results of individual tests and should help us understand which tests fail regularly, and which are being flaky.
To view the test results, navigate to the console output for the specific job like always, but to get a test-by-test breakdown click the new "Test Result" link in the left hand nav