Skip to content
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
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';
import { REPO_ROOT } from '@kbn/utils';

const MINUTE = 1000 * 60;
const FIXTURE_DIR = resolve(__dirname, '__fixtures__');
const TARGET_DIR = resolve(FIXTURE_DIR, 'target');
const XML_PATH = makeJunitReportPath(FIXTURE_DIR, 'JUnit Reporter Integration Test');
const XML_PATH = getUniqueJunitReportPath(FIXTURE_DIR, 'JUnit Reporter Integration Test');

afterAll(async () => {
await del(TARGET_DIR);
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-test/src/jest/junit_reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { Config } from '@jest/types';
import { AggregatedResult, Test, BaseReporter } from '@jest/reporters';

import { escapeCdata } from '../mocha/xml';
import { makeJunitReportPath } from './report_path';
import { getUniqueJunitReportPath } from './report_path';

interface ReporterOptions {
reportName?: string;
Expand Down Expand Up @@ -115,7 +115,7 @@ export default class JestJUnitReporter extends BaseReporter {
});
});

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
18 changes: 14 additions & 4 deletions packages/kbn-test/src/jest/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;
}
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 packages/kbn-test/src/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 '../';
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