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

[7.9] [junit] make sure that report paths are unique (#81255) #81395

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kbn-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export { runFtrCli } from './functional_test_runner/cli';

export { runFailedTestsReporterCli } from './failed_tests_reporter';

export { makeJunitReportPath } from './junit_report_path';
export { getUniqueJunitReportPath } from './junit_report_path';

export { CI_PARALLEL_PROCESS_PREFIX } from './ci_parallel_process_prefix';

Expand Down
18 changes: 14 additions & 4 deletions packages/kbn-test/src/junit_report_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@
* under the License.
*/

import { resolve } from 'path';
import Fs from 'fs';
import Path from 'path';

import { CI_PARALLEL_PROCESS_PREFIX } from './ci_parallel_process_prefix';

export function makeJunitReportPath(rootDirectory: string, reportName: string) {
return resolve(
export function getUniqueJunitReportPath(
rootDirectory: string,
reportName: string,
counter?: number
): string {
const path = Path.resolve(
rootDirectory,
'target/junit',
process.env.JOB || '.',
`TEST-${CI_PARALLEL_PROCESS_PREFIX}${reportName}.xml`
`TEST-${CI_PARALLEL_PROCESS_PREFIX}${reportName}${counter ? `-${counter}` : ''}.xml`
);

return Fs.existsSync(path)
? getUniqueJunitReportPath(rootDirectory, reportName, (counter ?? 0) + 1)
: path;
}
4 changes: 2 additions & 2 deletions src/dev/jest/integration_tests/junit_reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import { readFileSync } from 'fs';
import del from 'del';
import execa from 'execa';
import xml2js from 'xml2js';
import { makeJunitReportPath } from '@kbn/test';
import { getUniqueJunitReportPath } from '@kbn/test';

const MINUTE = 1000 * 60;
const ROOT_DIR = resolve(__dirname, '../../../../');
const FIXTURE_DIR = resolve(__dirname, '__fixtures__');
const TARGET_DIR = resolve(FIXTURE_DIR, 'target');
const XML_PATH = makeJunitReportPath(FIXTURE_DIR, 'Jest Tests');
const XML_PATH = getUniqueJunitReportPath(FIXTURE_DIR, 'Jest Tests');

afterAll(async () => {
await del(TARGET_DIR);
Expand Down
4 changes: 2 additions & 2 deletions src/dev/jest/junit_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { writeFileSync, mkdirSync } from 'fs';
import xmlBuilder from 'xmlbuilder';

import { escapeCdata } from '../xml';
import { makeJunitReportPath } from '@kbn/test';
import { getUniqueJunitReportPath } from '@kbn/test';

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

Expand Down Expand Up @@ -103,7 +103,7 @@ export default class JestJUnitReporter {
});
});

const reportPath = makeJunitReportPath(rootDirectory, reportName);
const reportPath = getUniqueJunitReportPath(rootDirectory, reportName);
const reportXML = root.end();
mkdirSync(dirname(reportPath), { recursive: true });
writeFileSync(reportPath, reportXML, 'utf8');
Expand Down
7 changes: 3 additions & 4 deletions src/dev/mocha/__tests__/junit_report_generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import { parseString } from 'xml2js';
import del from 'del';
import Mocha from 'mocha';
import expect from '@kbn/expect';
import { makeJunitReportPath } from '@kbn/test';
import { getUniqueJunitReportPath } from '@kbn/test';

import { setupJUnitReportGeneration } from '../junit_report_generation';

const PROJECT_DIR = resolve(__dirname, 'fixtures/project');
const DURATION_REGEX = /^\d+\.\d{3}$/;
const ISO_DATE_SEC_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
const XML_PATH = getUniqueJunitReportPath(PROJECT_DIR, 'test');

describe('dev/mocha/junit report generation', () => {
afterEach(() => {
Expand All @@ -50,9 +51,7 @@ describe('dev/mocha/junit report generation', () => {

mocha.addFile(resolve(PROJECT_DIR, 'test.js'));
await new Promise((resolve) => mocha.run(resolve));
const report = await fcb((cb) =>
parseString(readFileSync(makeJunitReportPath(PROJECT_DIR, 'test')), cb)
);
const report = await fcb((cb) => parseString(readFileSync(XML_PATH), cb));

// test case results are wrapped in <testsuites></testsuites>
expect(report).to.eql({
Expand Down
4 changes: 2 additions & 2 deletions src/dev/mocha/junit_report_generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { writeFileSync, mkdirSync } from 'fs';
import { inspect } from 'util';

import xmlBuilder from 'xmlbuilder';
import { makeJunitReportPath } from '@kbn/test';
import { getUniqueJunitReportPath } from '@kbn/test';

import { getSnapshotOfRunnableLogs } from './log_cache';
import { escapeCdata } from '../xml';
Expand Down Expand Up @@ -140,7 +140,7 @@ export function setupJUnitReportGeneration(runner, options = {}) {
}
});

const reportPath = makeJunitReportPath(rootDirectory, reportName);
const reportPath = getUniqueJunitReportPath(rootDirectory, reportName);
const reportXML = builder.end();
mkdirSync(dirname(reportPath), { recursive: true });
writeFileSync(reportPath, reportXML, 'utf8');
Expand Down
4 changes: 2 additions & 2 deletions tasks/config/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { dirname } from 'path';
import { times } from 'lodash';
import { makeJunitReportPath } from '@kbn/test';
import { getUniqueJunitReportPath } from '@kbn/test';
import * as UiSharedDeps from '@kbn/ui-shared-deps';
import { DllCompiler } from '../../src/optimize/dynamic_dll_plugin';

Expand Down Expand Up @@ -117,7 +117,7 @@ module.exports = function (grunt) {
reporters: pickReporters(),

junitReporter: {
outputFile: makeJunitReportPath(ROOT, 'karma'),
outputFile: getUniqueJunitReportPath(ROOT, 'karma'),
useBrowserName: false,
nameFormatter: (_, result) => [...result.suite, result.description].join(' '),
classNameFormatter: (_, result) => {
Expand Down