chore: remove usage of configFile from junit reporter (#30273)
Reference https://github.com/microsoft/playwright/issues/29768
This commit is contained in:
parent
adc645d3cb
commit
9e89f292bf
|
|
@ -19,31 +19,41 @@ import path from 'path';
|
||||||
import type { FullConfig, FullResult, Suite, TestCase } from '../../types/testReporter';
|
import type { FullConfig, FullResult, Suite, TestCase } from '../../types/testReporter';
|
||||||
import { monotonicTime } from 'playwright-core/lib/utils';
|
import { monotonicTime } from 'playwright-core/lib/utils';
|
||||||
import { formatFailure, stripAnsiEscapes } from './base';
|
import { formatFailure, stripAnsiEscapes } from './base';
|
||||||
import { assert } from 'playwright-core/lib/utils';
|
|
||||||
import EmptyReporter from './empty';
|
import EmptyReporter from './empty';
|
||||||
|
|
||||||
|
type JUnitOptions = {
|
||||||
|
outputFile?: string,
|
||||||
|
stripANSIControlSequences?: boolean,
|
||||||
|
includeProjectInTestName?: boolean,
|
||||||
|
|
||||||
|
configDir?: string,
|
||||||
|
};
|
||||||
|
|
||||||
class JUnitReporter extends EmptyReporter {
|
class JUnitReporter extends EmptyReporter {
|
||||||
private config!: FullConfig;
|
private config!: FullConfig;
|
||||||
|
private configDir: string;
|
||||||
private suite!: Suite;
|
private suite!: Suite;
|
||||||
private timestamp!: Date;
|
private timestamp!: Date;
|
||||||
private startTime!: number;
|
private startTime!: number;
|
||||||
private totalTests = 0;
|
private totalTests = 0;
|
||||||
private totalFailures = 0;
|
private totalFailures = 0;
|
||||||
private totalSkipped = 0;
|
private totalSkipped = 0;
|
||||||
private outputFile: string | undefined;
|
|
||||||
private resolvedOutputFile: string | undefined;
|
private resolvedOutputFile: string | undefined;
|
||||||
private stripANSIControlSequences = false;
|
private stripANSIControlSequences = false;
|
||||||
private includeProjectInTestName = false;
|
private includeProjectInTestName = false;
|
||||||
|
|
||||||
constructor(options: { outputFile?: string, stripANSIControlSequences?: boolean, includeProjectInTestName?: boolean } = {}) {
|
constructor(options: JUnitOptions = {}) {
|
||||||
super();
|
super();
|
||||||
this.outputFile = options.outputFile || reportOutputNameFromEnv();
|
|
||||||
this.stripANSIControlSequences = options.stripANSIControlSequences || false;
|
this.stripANSIControlSequences = options.stripANSIControlSequences || false;
|
||||||
this.includeProjectInTestName = options.includeProjectInTestName || false;
|
this.includeProjectInTestName = options.includeProjectInTestName || false;
|
||||||
|
this.configDir = options.configDir || '';
|
||||||
|
const outputFile = options.outputFile || reportOutputNameFromEnv();
|
||||||
|
if (outputFile)
|
||||||
|
this.resolvedOutputFile = path.resolve(this.configDir, outputFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
override printsToStdio() {
|
override printsToStdio() {
|
||||||
return !this.outputFile;
|
return !this.resolvedOutputFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
override onConfigure(config: FullConfig) {
|
override onConfigure(config: FullConfig) {
|
||||||
|
|
@ -54,10 +64,6 @@ class JUnitReporter extends EmptyReporter {
|
||||||
this.suite = suite;
|
this.suite = suite;
|
||||||
this.timestamp = new Date();
|
this.timestamp = new Date();
|
||||||
this.startTime = monotonicTime();
|
this.startTime = monotonicTime();
|
||||||
if (this.outputFile) {
|
|
||||||
assert(this.config.configFile || path.isAbsolute(this.outputFile), 'Expected fully resolved path if not using config file.');
|
|
||||||
this.resolvedOutputFile = this.config.configFile ? path.resolve(path.dirname(this.config.configFile), this.outputFile) : this.outputFile;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override async onEnd(result: FullResult) {
|
override async onEnd(result: FullResult) {
|
||||||
|
|
@ -197,12 +203,12 @@ class JUnitReporter extends EmptyReporter {
|
||||||
if (!attachment.path)
|
if (!attachment.path)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
let attachmentPath = path.relative(this.config.rootDir, attachment.path);
|
let attachmentPath = path.relative(this.configDir, attachment.path);
|
||||||
try {
|
try {
|
||||||
if (this.resolvedOutputFile)
|
if (this.resolvedOutputFile)
|
||||||
attachmentPath = path.relative(path.dirname(this.resolvedOutputFile), attachment.path);
|
attachmentPath = path.relative(path.dirname(this.resolvedOutputFile), attachment.path);
|
||||||
} catch {
|
} catch {
|
||||||
systemOut.push(`\nWarning: Unable to make attachment path ${attachment.path} relative to report output file ${this.outputFile}`);
|
systemOut.push(`\nWarning: Unable to make attachment path ${attachment.path} relative to report output file ${this.resolvedOutputFile}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue