Skip to content

Commit

Permalink
chore(html): use api prefix to qualify public types (#34121)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Dec 20, 2024
1 parent c89e213 commit cce8e8e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions packages/playwright/src/reporters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import path from 'path';
import type { TransformCallback } from 'stream';
import { Transform } from 'stream';
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 { colors, formatError, formatResultFailure, stripAnsiEscapes } from './base';
import { resolveReporterOutputPath } from '../util';
Expand Down Expand Up @@ -56,16 +56,16 @@ type HtmlReporterOptions = {
};

class HtmlReporter implements ReporterV2 {
private config!: FullConfig;
private suite!: Suite;
private config!: api.FullConfig;
private suite!: api.Suite;
private _options: HtmlReporterOptions;
private _outputFolder!: string;
private _attachmentsBaseURL!: string;
private _open: string | undefined;
private _port: number | undefined;
private _host: string | undefined;
private _buildResult: { ok: boolean, singleTestId: string | undefined } | undefined;
private _topLevelErrors: TestError[] = [];
private _topLevelErrors: api.TestError[] = [];

constructor(options: HtmlReporterOptions) {
this._options = options;
Expand All @@ -79,11 +79,11 @@ class HtmlReporter implements ReporterV2 {
return false;
}

onConfigure(config: FullConfig) {
onConfigure(config: api.FullConfig) {
this.config = config;
}

onBegin(suite: Suite) {
onBegin(suite: api.Suite) {
const { outputFolder, open, attachmentsBaseURL, host, port } = this._resolveOptions();
this._outputFolder = outputFolder;
this._open = open;
Expand Down Expand Up @@ -125,11 +125,11 @@ class HtmlReporter implements ReporterV2 {
return !!relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
}

onError(error: TestError): void {
onError(error: api.TestError): void {
this._topLevelErrors.push(error);
}

async onEnd(result: FullResult) {
async onEnd(result: api.FullResult) {
const projectSuites = this.suite.suites;
await removeFolders([this._outputFolder]);
const builder = new HtmlBuilder(this.config, this._outputFolder, this._attachmentsBaseURL);
Expand Down Expand Up @@ -223,22 +223,22 @@ export function startHtmlReportServer(folder: string): HttpServer {
}

class HtmlBuilder {
private _config: FullConfig;
private _config: api.FullConfig;
private _reportFolder: string;
private _stepsInFile = new MultiMap<string, TestStep>();
private _dataZipFile: ZipFile;
private _hasTraces = false;
private _attachmentsBaseURL: string;

constructor(config: FullConfig, outputDir: string, attachmentsBaseURL: string) {
constructor(config: api.FullConfig, outputDir: string, attachmentsBaseURL: string) {
this._config = config;
this._reportFolder = outputDir;
fs.mkdirSync(this._reportFolder, { recursive: true });
this._dataZipFile = new yazl.ZipFile();
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 }>();
for (const projectSuite of projectSuites) {
for (const fileSuite of projectSuite.suites) {
Expand Down Expand Up @@ -378,7 +378,7 @@ class HtmlBuilder {
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];
suite.entries().forEach(e => {
if (e.type === 'test')
Expand All @@ -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 location = this._relativeLocation(test.location)!;
path = path.slice(1).filter(path => path.length > 0);
Expand Down Expand Up @@ -500,7 +500,7 @@ class HtmlBuilder {
}).filter(Boolean) as TestAttachment[];
}

private _createTestResult(test: TestCasePublic, result: TestResultPublic): TestResult {
private _createTestResult(test: api.TestCase, result: api.TestResult): TestResult {
return {
duration: result.duration,
startTime: result.startTime.toISOString(),
Expand Down Expand Up @@ -531,7 +531,7 @@ class HtmlBuilder {
return result;
}

private _relativeLocation(location: Location | undefined): Location | undefined {
private _relativeLocation(location: api.Location | undefined): api.Location | undefined {
if (!location)
return undefined;
const file = toPosixPath(path.relative(this._config.rootDir, location.file));
Expand Down Expand Up @@ -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[] = [];
let lastResult = undefined;
for (const step of steps) {
Expand Down

0 comments on commit cce8e8e

Please sign in to comment.