mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore(html): use api prefix to qualify public types (#34121)
This commit is contained in:
parent
c89e213eff
commit
cce8e8e0e5
@ -21,7 +21,7 @@ import path from 'path';
|
|||||||
import type { TransformCallback } from 'stream';
|
import type { TransformCallback } from 'stream';
|
||||||
import { Transform } from 'stream';
|
import { Transform } from 'stream';
|
||||||
import { codeFrameColumns } from '../transform/babelBundle';
|
import { codeFrameColumns } from '../transform/babelBundle';
|
||||||
import type { FullResult, FullConfig, Location, Suite, TestCase as TestCasePublic, TestResult as TestResultPublic, TestStep as TestStepPublic, TestError } from '../../types/testReporter';
|
import type * as api from '../../types/testReporter';
|
||||||
import { HttpServer, assert, calculateSha1, copyFileAndMakeWritable, gracefullyProcessExitDoNotHang, removeFolders, sanitizeForFilePath, toPosixPath } from 'playwright-core/lib/utils';
|
import { HttpServer, assert, calculateSha1, copyFileAndMakeWritable, gracefullyProcessExitDoNotHang, removeFolders, sanitizeForFilePath, toPosixPath } from 'playwright-core/lib/utils';
|
||||||
import { colors, formatError, formatResultFailure, stripAnsiEscapes } from './base';
|
import { colors, formatError, formatResultFailure, stripAnsiEscapes } from './base';
|
||||||
import { resolveReporterOutputPath } from '../util';
|
import { resolveReporterOutputPath } from '../util';
|
||||||
@ -56,8 +56,8 @@ type HtmlReporterOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class HtmlReporter implements ReporterV2 {
|
class HtmlReporter implements ReporterV2 {
|
||||||
private config!: FullConfig;
|
private config!: api.FullConfig;
|
||||||
private suite!: Suite;
|
private suite!: api.Suite;
|
||||||
private _options: HtmlReporterOptions;
|
private _options: HtmlReporterOptions;
|
||||||
private _outputFolder!: string;
|
private _outputFolder!: string;
|
||||||
private _attachmentsBaseURL!: string;
|
private _attachmentsBaseURL!: string;
|
||||||
@ -65,7 +65,7 @@ class HtmlReporter implements ReporterV2 {
|
|||||||
private _port: number | undefined;
|
private _port: number | undefined;
|
||||||
private _host: string | undefined;
|
private _host: string | undefined;
|
||||||
private _buildResult: { ok: boolean, singleTestId: string | undefined } | undefined;
|
private _buildResult: { ok: boolean, singleTestId: string | undefined } | undefined;
|
||||||
private _topLevelErrors: TestError[] = [];
|
private _topLevelErrors: api.TestError[] = [];
|
||||||
|
|
||||||
constructor(options: HtmlReporterOptions) {
|
constructor(options: HtmlReporterOptions) {
|
||||||
this._options = options;
|
this._options = options;
|
||||||
@ -79,11 +79,11 @@ class HtmlReporter implements ReporterV2 {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onConfigure(config: FullConfig) {
|
onConfigure(config: api.FullConfig) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
onBegin(suite: Suite) {
|
onBegin(suite: api.Suite) {
|
||||||
const { outputFolder, open, attachmentsBaseURL, host, port } = this._resolveOptions();
|
const { outputFolder, open, attachmentsBaseURL, host, port } = this._resolveOptions();
|
||||||
this._outputFolder = outputFolder;
|
this._outputFolder = outputFolder;
|
||||||
this._open = open;
|
this._open = open;
|
||||||
@ -125,11 +125,11 @@ class HtmlReporter implements ReporterV2 {
|
|||||||
return !!relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
|
return !!relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
onError(error: TestError): void {
|
onError(error: api.TestError): void {
|
||||||
this._topLevelErrors.push(error);
|
this._topLevelErrors.push(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onEnd(result: FullResult) {
|
async onEnd(result: api.FullResult) {
|
||||||
const projectSuites = this.suite.suites;
|
const projectSuites = this.suite.suites;
|
||||||
await removeFolders([this._outputFolder]);
|
await removeFolders([this._outputFolder]);
|
||||||
const builder = new HtmlBuilder(this.config, this._outputFolder, this._attachmentsBaseURL);
|
const builder = new HtmlBuilder(this.config, this._outputFolder, this._attachmentsBaseURL);
|
||||||
@ -223,14 +223,14 @@ export function startHtmlReportServer(folder: string): HttpServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class HtmlBuilder {
|
class HtmlBuilder {
|
||||||
private _config: FullConfig;
|
private _config: api.FullConfig;
|
||||||
private _reportFolder: string;
|
private _reportFolder: string;
|
||||||
private _stepsInFile = new MultiMap<string, TestStep>();
|
private _stepsInFile = new MultiMap<string, TestStep>();
|
||||||
private _dataZipFile: ZipFile;
|
private _dataZipFile: ZipFile;
|
||||||
private _hasTraces = false;
|
private _hasTraces = false;
|
||||||
private _attachmentsBaseURL: string;
|
private _attachmentsBaseURL: string;
|
||||||
|
|
||||||
constructor(config: FullConfig, outputDir: string, attachmentsBaseURL: string) {
|
constructor(config: api.FullConfig, outputDir: string, attachmentsBaseURL: string) {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
this._reportFolder = outputDir;
|
this._reportFolder = outputDir;
|
||||||
fs.mkdirSync(this._reportFolder, { recursive: true });
|
fs.mkdirSync(this._reportFolder, { recursive: true });
|
||||||
@ -238,7 +238,7 @@ class HtmlBuilder {
|
|||||||
this._attachmentsBaseURL = attachmentsBaseURL;
|
this._attachmentsBaseURL = attachmentsBaseURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
async build(metadata: Metadata, projectSuites: Suite[], result: FullResult, topLevelErrors: TestError[]): Promise<{ ok: boolean, singleTestId: string | undefined }> {
|
async build(metadata: Metadata, projectSuites: api.Suite[], result: api.FullResult, topLevelErrors: api.TestError[]): Promise<{ ok: boolean, singleTestId: string | undefined }> {
|
||||||
const data = new Map<string, { testFile: TestFile, testFileSummary: TestFileSummary }>();
|
const data = new Map<string, { testFile: TestFile, testFileSummary: TestFileSummary }>();
|
||||||
for (const projectSuite of projectSuites) {
|
for (const projectSuite of projectSuites) {
|
||||||
for (const fileSuite of projectSuite.suites) {
|
for (const fileSuite of projectSuite.suites) {
|
||||||
@ -378,7 +378,7 @@ class HtmlBuilder {
|
|||||||
this._dataZipFile.addBuffer(Buffer.from(JSON.stringify(data)), fileName);
|
this._dataZipFile.addBuffer(Buffer.from(JSON.stringify(data)), fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _processSuite(suite: Suite, projectName: string, path: string[], outTests: TestEntry[]) {
|
private _processSuite(suite: api.Suite, projectName: string, path: string[], outTests: TestEntry[]) {
|
||||||
const newPath = [...path, suite.title];
|
const newPath = [...path, suite.title];
|
||||||
suite.entries().forEach(e => {
|
suite.entries().forEach(e => {
|
||||||
if (e.type === 'test')
|
if (e.type === 'test')
|
||||||
@ -388,7 +388,7 @@ class HtmlBuilder {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createTestEntry(test: TestCasePublic, projectName: string, path: string[]): TestEntry {
|
private _createTestEntry(test: api.TestCase, projectName: string, path: string[]): TestEntry {
|
||||||
const duration = test.results.reduce((a, r) => a + r.duration, 0);
|
const duration = test.results.reduce((a, r) => a + r.duration, 0);
|
||||||
const location = this._relativeLocation(test.location)!;
|
const location = this._relativeLocation(test.location)!;
|
||||||
path = path.slice(1).filter(path => path.length > 0);
|
path = path.slice(1).filter(path => path.length > 0);
|
||||||
@ -500,7 +500,7 @@ class HtmlBuilder {
|
|||||||
}).filter(Boolean) as TestAttachment[];
|
}).filter(Boolean) as TestAttachment[];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createTestResult(test: TestCasePublic, result: TestResultPublic): TestResult {
|
private _createTestResult(test: api.TestCase, result: api.TestResult): TestResult {
|
||||||
return {
|
return {
|
||||||
duration: result.duration,
|
duration: result.duration,
|
||||||
startTime: result.startTime.toISOString(),
|
startTime: result.startTime.toISOString(),
|
||||||
@ -531,7 +531,7 @@ class HtmlBuilder {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _relativeLocation(location: Location | undefined): Location | undefined {
|
private _relativeLocation(location: api.Location | undefined): api.Location | undefined {
|
||||||
if (!location)
|
if (!location)
|
||||||
return undefined;
|
return undefined;
|
||||||
const file = toPosixPath(path.relative(this._config.rootDir, location.file));
|
const file = toPosixPath(path.relative(this._config.rootDir, location.file));
|
||||||
@ -609,9 +609,9 @@ function stdioAttachment(chunk: Buffer | string, type: 'stdout' | 'stderr'): Jso
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type DedupedStep = { step: TestStepPublic, count: number, duration: number };
|
type DedupedStep = { step: api.TestStep, count: number, duration: number };
|
||||||
|
|
||||||
function dedupeSteps(steps: TestStepPublic[]) {
|
function dedupeSteps(steps: api.TestStep[]) {
|
||||||
const result: DedupedStep[] = [];
|
const result: DedupedStep[] = [];
|
||||||
let lastResult = undefined;
|
let lastResult = undefined;
|
||||||
for (const step of steps) {
|
for (const step of steps) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user