Skip to content
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

Merged
merged 12 commits into from
Dec 6, 2017

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Nov 30, 2017

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

image

@spalger spalger added the WIP Work in progress label Nov 30, 2017
@spalger spalger force-pushed the implement/junit-test-reports branch 27 times, most recently from a6eb638 to 82678a1 Compare December 1, 2017 07:33
@spalger spalger force-pushed the implement/junit-test-reports branch from 11d2eb5 to 4cef043 Compare December 2, 2017 01:50
Copy link
Member

@azasypkin azasypkin left a 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!

suite.startTime = Date.now();
});

runner.on('test', (suite) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: suite --> test?

suite.startTime = Date.now();
});

runner.on('test end', (suite) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: suite --> test?

const segments = [...directory.split(pathSep), filenameWithoutExt];

return segments
.filter(seg => seg && !PATH_SEGMENTS_TO_IGNORE.includes(seg))
Copy link
Member

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.

Copy link
Contributor Author

@spalger spalger Dec 4, 2017

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?

Copy link
Member

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 :)

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class named derived from the file path:
image

file path with '.' replaced with '·':
image

Copy link
Member

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, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can't MochaJunitReporterbe just a function like setupMochaJunitReporter? Is there any reason why it should be a constructor function?

Copy link
Contributor Author

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

.dat(inspect(test.err));
}

if (isTestPending(test)) {
Copy link
Member

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 }) {
Copy link
Member

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 consolereporter anymore, maybe we can have a better name for this reporter, it's not a big deal though.

},
all: {
src: [
'test/mocha_setup.js',
require.resolve('../../src/babel-register'),
Copy link
Member

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....

Copy link
Contributor Author

@spalger spalger Dec 4, 2017

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.

].join(' '),
classNameFormatter: (browser, result) => {
const rootSuite = result.suite[0] || result.description;
return `Browser Unit Tests.${rootSuite.split('.').join('·')}`;
Copy link
Member

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)?

Copy link
Contributor Author

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

const ROOT_DIR = dirname(require.resolve('../../../package.json'));

/**
* Jest reporter that that produces JUnit report when running on CI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: redundant that

Copy link
Contributor

@kimjoar kimjoar left a 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

@spalger spalger merged commit f71ec29 into elastic:master Dec 6, 2017
spalger added a commit to spalger/kibana that referenced this pull request Dec 6, 2017
* [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
spalger added a commit to spalger/kibana that referenced this pull request Dec 6, 2017
* [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
spalger added a commit to spalger/kibana that referenced this pull request Dec 6, 2017
* [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
spalger added a commit to spalger/kibana that referenced this pull request Dec 6, 2017
* [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
spalger added a commit that referenced this pull request Dec 6, 2017
* [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
spalger added a commit that referenced this pull request Dec 6, 2017
* [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
spalger added a commit that referenced this pull request Dec 6, 2017
* [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
spalger added a commit that referenced this pull request Dec 6, 2017
* [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
@spalger
Copy link
Contributor Author

spalger commented Dec 6, 2017

5.6: 5c5e03a
6.0: d16ff7a
6.1: 0969d3d
6.2/6.x: b4bd640

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v5.6.5 v6.0.1 v6.1.0 v6.2.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants