added PLAYWRIGHT_JUNIT_PROPERTIES
This commit is contained in:
parent
b3a82bef46
commit
a15ca44b45
|
|
@ -17,7 +17,7 @@
|
||||||
export function getFromENV(name: string): string | undefined {
|
export function getFromENV(name: string): string | undefined {
|
||||||
let value = process.env[name];
|
let value = process.env[name];
|
||||||
value = value === undefined ? process.env[`npm_config_${name.toLowerCase()}`] : value;
|
value = value === undefined ? process.env[`npm_config_${name.toLowerCase()}`] : value;
|
||||||
value = value === undefined ? process.env[`npm_package_config_${name.toLowerCase()}`] : value;
|
value = value === undefined ? process.env[`npm_package_config_${name.toLowerCase()}`] : value;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,3 +47,27 @@ export function getPackageManagerExecCommand() {
|
||||||
return 'pnpm exec';
|
return 'pnpm exec';
|
||||||
return 'npx';
|
return 'npx';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getParsedFromEnv(key: string): Array<{name: string, value: string}> {
|
||||||
|
const envValue = getFromENV(key);
|
||||||
|
if (envValue) {
|
||||||
|
const commaSplittedValuesInEnv = [...new Set(envValue.split(','))].map(prop => {
|
||||||
|
let property = prop.split('=');
|
||||||
|
if (property.length === 2 && property[0] && property[1])
|
||||||
|
return {name: property[0].trim(), value: property[1].trim()};
|
||||||
|
}).filter(item => !!item)
|
||||||
|
const uniqueItems = [];
|
||||||
|
const mapWithUniqueName = new Map();
|
||||||
|
for (const value of commaSplittedValuesInEnv) {
|
||||||
|
const key = Object.values(value)[0];
|
||||||
|
if (!mapWithUniqueName.has(key)) {
|
||||||
|
mapWithUniqueName.set(key, true);
|
||||||
|
uniqueItems.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return uniqueItems;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import type { FullConfig, FullResult, Suite, TestCase } from '../../types/testReporter';
|
import type { FullConfig, FullResult, Suite, TestCase } from '../../types/testReporter';
|
||||||
import { formatFailure, resolveOutputFile, stripAnsiEscapes } from './base';
|
import { formatFailure, resolveOutputFile, stripAnsiEscapes } from './base';
|
||||||
import { getAsBooleanFromENV } from 'playwright-core/lib/utils';
|
import { getAsBooleanFromENV, getParsedFromEnv } from 'playwright-core/lib/utils';
|
||||||
import type { ReporterV2 } from './reporterV2';
|
import type { ReporterV2 } from './reporterV2';
|
||||||
|
|
||||||
type JUnitOptions = {
|
type JUnitOptions = {
|
||||||
|
|
@ -40,12 +40,17 @@ class JUnitReporter implements ReporterV2 {
|
||||||
private resolvedOutputFile: string | undefined;
|
private resolvedOutputFile: string | undefined;
|
||||||
private stripANSIControlSequences = false;
|
private stripANSIControlSequences = false;
|
||||||
private includeProjectInTestName = false;
|
private includeProjectInTestName = false;
|
||||||
|
private propertiesFromEnv: Array<{
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
constructor(options: JUnitOptions) {
|
constructor(options: JUnitOptions) {
|
||||||
this.stripANSIControlSequences = getAsBooleanFromENV('PLAYWRIGHT_JUNIT_STRIP_ANSI', !!options.stripANSIControlSequences);
|
this.stripANSIControlSequences = getAsBooleanFromENV('PLAYWRIGHT_JUNIT_STRIP_ANSI', !!options.stripANSIControlSequences);
|
||||||
this.includeProjectInTestName = getAsBooleanFromENV('PLAYWRIGHT_JUNIT_INCLUDE_PROJECT_IN_TEST_NAME', !!options.includeProjectInTestName);
|
this.includeProjectInTestName = getAsBooleanFromENV('PLAYWRIGHT_JUNIT_INCLUDE_PROJECT_IN_TEST_NAME', !!options.includeProjectInTestName);
|
||||||
this.configDir = options.configDir;
|
this.configDir = options.configDir;
|
||||||
this.resolvedOutputFile = resolveOutputFile('JUNIT', options)?.outputFile;
|
this.resolvedOutputFile = resolveOutputFile('JUNIT', options)?.outputFile;
|
||||||
|
this.propertiesFromEnv = getParsedFromEnv('PLAYWRIGHT_JUNIT_PROPERTIES');
|
||||||
}
|
}
|
||||||
|
|
||||||
version(): 'v2' {
|
version(): 'v2' {
|
||||||
|
|
@ -173,6 +178,17 @@ class JUnitReporter implements ReporterV2 {
|
||||||
properties.children?.push(property);
|
properties.children?.push(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const propertyFromEnv of this.propertiesFromEnv) {
|
||||||
|
const property: XMLEntry = {
|
||||||
|
name: 'property',
|
||||||
|
attributes: {
|
||||||
|
name: propertyFromEnv.name,
|
||||||
|
value: propertyFromEnv.value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
properties.children?.push(property);
|
||||||
|
}
|
||||||
|
|
||||||
if (properties.children?.length)
|
if (properties.children?.length)
|
||||||
entry.children.push(properties);
|
entry.children.push(properties);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue