Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(playwrighttesting): use playwright OSS types #32319

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"typescript": "~5.7.2"
},
"peerDependencies": {
"@playwright/test": "^1.43.1"
"@playwright/test": "^1.47.0"
},
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
"//sampleConfiguration": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { TestResult } from '@playwright/test/reporter';

// @public
class MPTReporter implements Reporter {
constructor(config: Partial<MPTReporterConfig>);
constructor(config: Partial<ReporterConfiguration>);
onBegin(config: FullConfig, suite: Suite): void;
onEnd(result: FullResult): Promise<void>;
onTestEnd(test: TestCase, result: TestResult): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

```ts

import type { ConnectOptions } from '@playwright/test';
import type { PlaywrightTestConfig } from '@playwright/test';
import type { TokenCredential } from '@azure/identity';

Expand All @@ -15,16 +16,6 @@ export type BrowserConnectOptions = EndpointOptions & {
options: ConnectOptions;
};

// @public
export type ConnectOptions = {
headers?: {
[key: string]: string;
};
exposeNetwork?: string;
timeout?: number;
slowMo?: number;
};

// @public
export type EndpointOptions = {
wsEndpoint: string;
Expand All @@ -36,12 +27,6 @@ export const getConnectOptions: (options?: Omit<PlaywrightServiceAdditionalOptio
// @public
export const getServiceConfig: (config: PlaywrightTestConfig, options?: PlaywrightServiceAdditionalOptions) => PlaywrightTestConfig;

// @public
export interface MPTReporterConfig {
enableGitHubSummary?: boolean;
enableResultPublish?: boolean;
}

// @public
export type OsType = (typeof ServiceOS)[keyof typeof ServiceOS];

Expand All @@ -58,6 +43,12 @@ export type PlaywrightServiceAdditionalOptions = {
runName?: string;
};

// @public
export type ReporterConfiguration = {
enableGitHubSummary?: boolean;
enableResultPublish?: boolean;
};

// @public
export const ServiceAuth: {
readonly ENTRA_ID: "ENTRA_ID";
Expand All @@ -66,11 +57,8 @@ export const ServiceAuth: {

// @public
export const ServiceEnvironmentVariable: {
PLAYWRIGHT_SERVICE_OS: string;
PLAYWRIGHT_SERVICE_EXPOSE_NETWORK_ENVIRONMENT_VARIABLE: string;
PLAYWRIGHT_SERVICE_ACCESS_TOKEN: string;
PLAYWRIGHT_SERVICE_URL: string;
PLAYWRIGHT_SERVICE_REPORTING_URL: string;
};

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ export const ServiceAuth = {
* Environment variables used by Microsoft Playwright Testing
*/
export const ServiceEnvironmentVariable = {
PLAYWRIGHT_SERVICE_OS: "PLAYWRIGHT_SERVICE_OS",
PLAYWRIGHT_SERVICE_EXPOSE_NETWORK_ENVIRONMENT_VARIABLE: "PLAYWRIGHT_SERVICE_EXPOSE_NETWORK",
PLAYWRIGHT_SERVICE_ACCESS_TOKEN: "PLAYWRIGHT_SERVICE_ACCESS_TOKEN",
PLAYWRIGHT_SERVICE_URL: "PLAYWRIGHT_SERVICE_URL",
PLAYWRIGHT_SERVICE_REPORTING_URL: "PLAYWRIGHT_SERVICE_REPORTING_URL",
};

export const DefaultConnectOptionsConstants = {
Expand Down Expand Up @@ -240,6 +237,8 @@ export const InternalEnvironmentVariables = {
MPT_SERVICE_RUN_NAME: "_MPT_SERVICE_RUN_NAME",
MPT_SERVICE_RUN_ID: "_MPT_SERVICE_RUN_ID",
MPT_CLOUD_HOSTED_BROWSER_USED: "_MPT_CLOUD_HOSTED_BROWSER_USED",
MPT_SERVICE_OS: "_MPT_SERVICE_OS",
MPT_SERVICE_REPORTING_URL: "_MPT_SERVICE_REPORTING_URL",
};

export const MINIMUM_SUPPORTED_PLAYWRIGHT_VERSION = "1.47.0";
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import {
DefaultConnectOptionsConstants,
InternalEnvironmentVariables,
ServiceEnvironmentVariable,
} from "./constants";
import { DefaultConnectOptionsConstants, InternalEnvironmentVariables } from "./constants";
import type { PlaywrightServiceAdditionalOptions, OsType } from "./types";
import { getAndSetRunId } from "../utils/utils";

Expand All @@ -17,7 +13,7 @@ class PlaywrightServiceConfig {
public exposeNetwork: string;
public runName: string;
constructor() {
this.serviceOs = (process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_OS] ||
this.serviceOs = (process.env[InternalEnvironmentVariables.MPT_SERVICE_OS] ||
DefaultConnectOptionsConstants.DEFAULT_SERVICE_OS) as OsType;
this.runName = process.env[InternalEnvironmentVariables.MPT_SERVICE_RUN_NAME] || "";
this.runId = process.env[InternalEnvironmentVariables.MPT_SERVICE_RUN_ID] || "";
Expand All @@ -44,7 +40,7 @@ class PlaywrightServiceConfig {
}
if (options?.os) {
this.serviceOs = options.os;
process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_OS] = this.serviceOs;
process.env[InternalEnvironmentVariables.MPT_SERVICE_OS] = this.serviceOs;
}
if (options?.slowMo) {
this.slowMo = options.slowMo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@
// Licensed under the MIT License.

import type { Location, TestStep } from "@playwright/test/reporter";
import type { ConnectOptions } from "@playwright/test";
import type { ServiceAuth, ServiceOS } from "./constants";
import type { TokenCredential } from "@azure/identity";

export type JwtPayload = {
aid?: string;
iss?: string;
sub?: string;
aud?: string[] | string;
exp?: number;
nbf?: number;
iat?: number;
jti?: string;
};

export type AccessTokenClaims = JwtPayload & {
aid?: string;
accountId?: string;
};
// Public APIs

/**
* @public
Expand All @@ -35,47 +22,6 @@ export type EndpointOptions = {
wsEndpoint: string;
};

/**
* @public
*
* Connect options for the service.
*/
export type ConnectOptions = {
/**
* @public
*
* Additional HTTP headers to be sent with web socket connect request.
*/
headers?: { [key: string]: string };

/**
* @public
*
* Exposes network available on the connecting client to the browser being connected to.
*
* @defaultValue `<loopback>`
*/
exposeNetwork?: string;

/**
* @public
*
* Maximum time in milliseconds to wait for the connection to be established.
*
* @defaultValue `30000`
*/
timeout?: number;

/**
* @public
*
* Slows down Playwright operations by the specified amount of milliseconds.
*
* @defaultValue `0`
*/
slowMo?: number;
};

/**
* @public
*
Expand Down Expand Up @@ -206,15 +152,6 @@ export type OsType = (typeof ServiceOS)[keyof typeof ServiceOS];
*/
export type AuthenticationType = (typeof ServiceAuth)[keyof typeof ServiceAuth];

export type ErrorDetails = {
message: string;
location?: Location;
};
export type ApiErrorMessage = {
[key: string]: {
[key: number]: string;
};
};
/**
* @public
*
Expand All @@ -232,7 +169,7 @@ export type ApiErrorMessage = {
* });
* ```
*/
export interface MPTReporterConfig {
export type ReporterConfiguration = {
/**
* @public
*
Expand All @@ -250,7 +187,37 @@ export interface MPTReporterConfig {
* @defaultValue `true`
*/
enableResultPublish?: boolean;
}
};

// Internal APIs

export type JwtPayload = {
aid?: string;
iss?: string;
sub?: string;
aud?: string[] | string;
exp?: number;
nbf?: number;
iat?: number;
jti?: string;
};

export type AccessTokenClaims = JwtPayload & {
aid?: string;
accountId?: string;
};

export type ErrorDetails = {
message: string;
location?: Location;
};

export type ApiErrorMessage = {
[key: string]: {
[key: number]: string;
};
};

export type DedupedStep = { step: TestStep; count: number; duration: number };

export type RawTestStep = {
Expand Down Expand Up @@ -283,9 +250,3 @@ export type PackageManager = {
runCommand: (command: string, args: string) => string;
getVersionFromStdout: (stdout: string) => string;
};

// Playwright OSS Types

export interface FullConfig {
configFile?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { dirname } from "path";
import type { FullConfig } from "../../common/types";
import type { FullConfig } from "@playwright/test";
import playwrightServiceEntra from "../playwrightServiceEntra";
import { loadCustomerGlobalFunction } from "../../common/executor";
import customerConfig from "../../common/customerConfig";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { dirname } from "path";
import type { FullConfig } from "../../common/types";
import type { FullConfig } from "@playwright/test";
import playwrightServiceEntra from "../playwrightServiceEntra";
import { loadCustomerGlobalFunction } from "../../common/executor";
import customerConfig from "../../common/customerConfig";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import type {
OsType,
AuthenticationType,
BrowserConnectOptions,
MPTReporterConfig,
ReporterConfiguration,
EndpointOptions,
ConnectOptions,
PlaywrightServiceAdditionalOptions,
} from "./common/types";
import { getServiceConfig, getConnectOptions } from "./core/playwrightService";
Expand All @@ -29,7 +28,6 @@ export {
AuthenticationType,
BrowserConnectOptions,
EndpointOptions,
ConnectOptions,
MPTReporterConfig,
ReporterConfiguration,
PlaywrightServiceAdditionalOptions,
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { CIInfoProvider } from "../utils/cIInfoProvider";
import ReporterUtils from "../utils/reporterUtils";
import { ServiceClient } from "../utils/serviceClient";
import { StorageClient } from "../utils/storageClient";
import type { MPTReporterConfig } from "../common/types";
import type { ReporterConfiguration } from "../common/types";
import { ServiceErrorMessageConstants } from "../common/messages";
import { validateMptPAT, populateValuesFromServiceUrl } from "../utils/utils";

Expand Down Expand Up @@ -78,7 +78,7 @@ class MPTReporter implements Reporter {
private testRunUrl: string = "";
private enableResultPublish: boolean = true;

constructor(config: Partial<MPTReporterConfig>) {
constructor(config: Partial<ReporterConfiguration>) {
if (config?.enableGitHubSummary !== undefined) {
this.enableGitHubSummary = config.enableGitHubSummary;
}
Expand Down Expand Up @@ -377,12 +377,14 @@ class MPTReporter implements Reporter {
this.isTokenValid = false;
return;
}
if (!process.env["PLAYWRIGHT_SERVICE_REPORTING_URL"]) {
if (!process.env[InternalEnvironmentVariables.MPT_SERVICE_REPORTING_URL]) {
process.stdout.write("\nReporting service url not found.");
this.isTokenValid = false;
return;
}
reporterLogger.info(`Reporting url - ${process.env["PLAYWRIGHT_SERVICE_REPORTING_URL"]}`);
reporterLogger.info(
`Reporting url - ${process.env[InternalEnvironmentVariables.MPT_SERVICE_REPORTING_URL]}`,
);
if (this.envVariables.accessToken === undefined || this.envVariables.accessToken === "") {
process.stdout.write(`\n${ServiceErrorMessageConstants.NO_AUTH_ERROR.message}`);
this.isTokenValid = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import type { FullResult } from "@playwright/test/reporter";
import { Constants } from "../common/constants";
import { Constants, InternalEnvironmentVariables } from "../common/constants";
import type { EnvironmentVariables } from "../common/environmentVariables";
import { HttpService } from "../common/httpService";
import type { Shard, UploadMetadata } from "../model/shard";
Expand Down Expand Up @@ -170,7 +170,7 @@ export class ServiceClient {
}

private getServiceEndpoint(): string {
return process.env["PLAYWRIGHT_SERVICE_REPORTING_URL"]!;
return process.env[InternalEnvironmentVariables.MPT_SERVICE_REPORTING_URL]!;
}

private handleErrorResponse(response: PipelineResponse, action: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const emitReportingUrl = (): void => {
const match = url?.match(regex);
if (match && match.length >= 3) {
const [, region, domain] = match;
process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_REPORTING_URL] =
process.env[InternalEnvironmentVariables.MPT_SERVICE_REPORTING_URL] =
`https://${region}.reporting.api.${domain}`;
}
};
Expand Down
Loading
Loading