Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: use utils via index export (1) (#13398)
Pavel Feldmandbafe3bb4e82
diff --git a/packages/playwright-core/package.json b/packages/playwright-core/package.jsonindex aa934e5334..79c2cf1faa 100644--- a/packages/playwright-core/package.json+++ b/packages/playwright-core/package.json@@ -22,10 +22,9 @@"./lib/grid/gridClient": "./lib/grid/gridClient.js","./lib/grid/dockerGridFactory": "./lib/grid/dockerGridFactory.js","./lib/outofprocess": "./lib/outofprocess.js",- "./lib/utils/async": "./lib/utils/async.js",+ "./lib/utils": "./lib/utils/index.js","./lib/utils/comparators": "./lib/utils/comparators.js","./lib/utils/httpServer": "./lib/utils/httpServer.js",- "./lib/utils/multimap": "./lib/utils/multimap.js","./lib/utils/processLauncher": "./lib/utils/processLauncher.js","./lib/utils/utils": "./lib/utils/utils.js","./lib/utils/stackTrace": "./lib/utils/stackTrace.js",diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.tsindex 1a1e6a6318..10dea84945 100644--- a/packages/playwright-core/src/client/browserType.ts+++ b/packages/playwright-core/src/client/browserType.ts@@ -26,7 +26,7 @@ import { envObjectToArray } from './clientHelper';import { assert, headersObjectToArray, monotonicTime } from '../utils/utils';import type * as api from '../../types/types';import { kBrowserClosedError } from '../utils/errors';-import { raceAgainstTimeout } from '../utils/async';+import { raceAgainstTimeout } from '../utils';import type { Playwright } from './playwright';export interface BrowserServerLauncher {diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.tsindex d5c96b4561..a565d5080c 100644--- a/packages/playwright-core/src/client/network.ts+++ b/packages/playwright-core/src/client/network.ts@@ -22,14 +22,14 @@ import type { Headers, RemoteAddr, SecurityDetails, WaitForEventOptions } from 'import fs from 'fs';import * as mime from 'mime';import { isString, headersObjectToArray } from '../utils/utils';-import { ManualPromise } from '../utils/async';+import { ManualPromise } from '../utils';import { Events } from './events';import type { Page } from './page';import { Waiter } from './waiter';import type * as api from '../../types/types';import type { HeadersArray, URLMatch } from '../common/types';import { urlMatches } from './clientHelper';-import { MultiMap } from '../utils/multimap';+import { MultiMap } from '../utils';import { APIResponse } from './fetch';export type NetworkCookie = {diff --git a/packages/playwright-core/src/outofprocess.ts b/packages/playwright-core/src/outofprocess.tsindex 68c5b31882..a3da11e2b0 100644--- a/packages/playwright-core/src/outofprocess.ts+++ b/packages/playwright-core/src/outofprocess.ts@@ -19,7 +19,7 @@ import { IpcTransport } from './protocol/transport';import type { Playwright } from './client/playwright';import * as childProcess from 'child_process';import * as path from 'path';-import { ManualPromise } from './utils/async';+import { ManualPromise } from './utils';export async function start(env: any = {}): Promise<{ playwright: Playwright, stop: () => Promise<void> }> {const client = new PlaywrightClient(env);diff --git a/packages/playwright-core/src/server/artifact.ts b/packages/playwright-core/src/server/artifact.tsindex 0868ef19a8..85aaff8a0c 100644--- a/packages/playwright-core/src/server/artifact.ts+++ b/packages/playwright-core/src/server/artifact.ts@@ -16,7 +16,7 @@import fs from 'fs';import { assert } from '../utils/utils';-import { ManualPromise } from '../utils/async';+import { ManualPromise } from '../utils';import { SdkObject } from './instrumentation';type SaveCallback = (localPath: string, error?: string) => Promise<void>;diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.tsindex 7dc95ad6c2..00ec9634db 100644--- a/packages/playwright-core/src/server/chromium/chromium.ts+++ b/packages/playwright-core/src/server/chromium/chromium.ts@@ -41,7 +41,7 @@ import type { CallMetadata } from '../instrumentation';import http from 'http';import https from 'https';import { registry } from '../registry';-import { ManualPromise } from '../../utils/async';+import { ManualPromise } from '../../utils';const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-');diff --git a/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts b/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.tsindex 48919b846b..748b406b34 100644--- a/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts@@ -20,7 +20,7 @@ import path from 'path';import yauzl from 'yauzl';import yazl from 'yazl';import type * as channels from '../../protocol/channels';-import { ManualPromise } from '../../utils/async';+import { ManualPromise } from '../../utils';import { assert, createGuid } from '../../utils/utils';import type { DispatcherScope } from './dispatcher';import { Dispatcher } from './dispatcher';diff --git a/packages/playwright-core/src/server/firefox/ffPage.ts b/packages/playwright-core/src/server/firefox/ffPage.tsindex 951d3ac807..b939c07ba0 100644--- a/packages/playwright-core/src/server/firefox/ffPage.ts+++ b/packages/playwright-core/src/server/firefox/ffPage.ts@@ -34,7 +34,7 @@ import type { Protocol } from './protocol';import type { Progress } from '../progress';import { splitErrorMessage } from '../../utils/stackTrace';import { debugLogger } from '../../utils/debugLogger';-import { ManualPromise } from '../../utils/async';+import { ManualPromise } from '../../utils';export const UTILITY_WORLD_NAME = '__playwright_utility_world__';diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.tsindex 93e372b29d..c80b6fff02 100644--- a/packages/playwright-core/src/server/frames.ts+++ b/packages/playwright-core/src/server/frames.ts@@ -30,7 +30,7 @@ import { BrowserContext } from './browserContext';import type { Progress } from './progress';import { ProgressController } from './progress';import { assert, constructURLBasedOnBaseURL, makeWaitForNextTask } from '../utils/utils';-import { ManualPromise } from '../utils/async';+import { ManualPromise } from '../utils';import { debugLogger } from '../utils/debugLogger';import type { CallMetadata } from './instrumentation';import { serverSideCallMetadata, SdkObject } from './instrumentation';diff --git a/packages/playwright-core/src/server/javascript.ts b/packages/playwright-core/src/server/javascript.tsindex 8d48cd615b..00168dacae 100644--- a/packages/playwright-core/src/server/javascript.ts+++ b/packages/playwright-core/src/server/javascript.ts@@ -19,7 +19,7 @@ import * as utilityScriptSource from '../generated/utilityScriptSource';import { serializeAsCallArgument } from './common/utilityScriptSerializers';import { type UtilityScript } from './injected/utilityScript';import { SdkObject } from './instrumentation';-import { ManualPromise } from '../utils/async';+import { ManualPromise } from '../utils';export type ObjectId = string;export type RemoteObject = {diff --git a/packages/playwright-core/src/server/network.ts b/packages/playwright-core/src/server/network.tsindex 2e173bab23..e85a743441 100644--- a/packages/playwright-core/src/server/network.ts+++ b/packages/playwright-core/src/server/network.ts@@ -18,7 +18,7 @@ import type * as frames from './frames';import type * as types from './types';import type * as channels from '../protocol/channels';import { assert } from '../utils/utils';-import { ManualPromise } from '../utils/async';+import { ManualPromise } from '../utils';import { SdkObject } from './instrumentation';import type { NameValue } from '../common/types';import { APIRequestContext } from './fetch';diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.tsindex cb7435ae5a..7ecff6cf5b 100644--- a/packages/playwright-core/src/server/page.ts+++ b/packages/playwright-core/src/server/page.ts@@ -31,7 +31,7 @@ import { FileChooser } from './fileChooser';import type { Progress } from './progress';import { ProgressController } from './progress';import { assert, isError } from '../utils/utils';-import { ManualPromise } from '../utils/async';+import { ManualPromise } from '../utils';import { debugLogger } from '../utils/debugLogger';import type { ImageComparatorOptions } from '../utils/comparators';import { getComparator } from '../utils/comparators';diff --git a/packages/playwright-core/src/server/progress.ts b/packages/playwright-core/src/server/progress.tsindex d2e312a196..1978c96d5c 100644--- a/packages/playwright-core/src/server/progress.ts+++ b/packages/playwright-core/src/server/progress.ts@@ -19,7 +19,7 @@ import { assert, monotonicTime } from '../utils/utils';import type { LogName } from '../utils/debugLogger';import type { CallMetadata, Instrumentation, SdkObject } from './instrumentation';import type { ElementHandle } from './dom';-import { ManualPromise } from '../utils/async';+import { ManualPromise } from '../utils';import type { LogEntry } from './injected/injectedScript';export interface Progress {diff --git a/packages/playwright-core/src/server/screenshotter.ts b/packages/playwright-core/src/server/screenshotter.tsindex 27b20f482d..3228a06448 100644--- a/packages/playwright-core/src/server/screenshotter.ts+++ b/packages/playwright-core/src/server/screenshotter.ts@@ -24,7 +24,7 @@ import type { ParsedSelector } from './common/selectorParser';import type * as types from './types';import type { Progress } from './progress';import { assert } from '../utils/utils';-import { MultiMap } from '../utils/multimap';+import { MultiMap } from '../utils';declare global {interface Window {diff --git a/packages/playwright-core/src/server/supplements/har/harTracer.ts b/packages/playwright-core/src/server/supplements/har/harTracer.tsindex ec289575b1..47b23d5394 100644--- a/packages/playwright-core/src/server/supplements/har/harTracer.ts+++ b/packages/playwright-core/src/server/supplements/har/harTracer.ts@@ -25,7 +25,7 @@ import { calculateSha1, monotonicTime } from '../../../utils/utils';import type { RegisteredListener } from '../../../utils/eventsHelper';import { eventsHelper } from '../../../utils/eventsHelper';import * as mime from 'mime';-import { ManualPromise } from '../../../utils/async';+import { ManualPromise } from '../../../utils';const FALLBACK_HTTP_VERSION = 'HTTP/1.1';diff --git a/packages/playwright-core/src/server/supplements/recorderSupplement.ts b/packages/playwright-core/src/server/supplements/recorderSupplement.tsindex 38a0198582..7e00a7007a 100644--- a/packages/playwright-core/src/server/supplements/recorderSupplement.ts+++ b/packages/playwright-core/src/server/supplements/recorderSupplement.ts@@ -38,7 +38,7 @@ import { createGuid, monotonicTime } from '../../utils/utils';import { metadataToCallLog } from './recorder/recorderUtils';import { Debugger } from './debugger';import { EventEmitter } from 'events';-import { raceAgainstTimeout } from '../../utils/async';+import { raceAgainstTimeout } from '../../utils';type BindingSource = { frame: Frame, page: Page };diff --git a/packages/playwright-core/src/server/trace/recorder/tracing.ts b/packages/playwright-core/src/server/trace/recorder/tracing.tsindex 98e218acc0..ac47e871e0 100644--- a/packages/playwright-core/src/server/trace/recorder/tracing.ts+++ b/packages/playwright-core/src/server/trace/recorder/tracing.ts@@ -22,7 +22,7 @@ import yazl from 'yazl';import type { NameValue } from '../../../common/types';import type { TracingTracingStopChunkParams } from '../../../protocol/channels';import { commandsWithTracingSnapshots } from '../../../protocol/channels';-import { ManualPromise } from '../../../utils/async';+import { ManualPromise } from '../../../utils';import type { RegisteredListener } from '../../../utils/eventsHelper';import { eventsHelper } from '../../../utils/eventsHelper';import { assert, calculateSha1, createGuid, mkdirIfNeeded, monotonicTime, removeFolders } from '../../../utils/utils';diff --git a/packages/playwright-core/src/server/webkit/wkInterceptableRequest.ts b/packages/playwright-core/src/server/webkit/wkInterceptableRequest.tsindex c8e9389438..de1eade0f8 100644--- a/packages/playwright-core/src/server/webkit/wkInterceptableRequest.ts+++ b/packages/playwright-core/src/server/webkit/wkInterceptableRequest.ts@@ -21,7 +21,7 @@ import type * as types from '../types';import type { Protocol } from './protocol';import type { WKSession } from './wkConnection';import { assert, headersObjectToArray, headersArrayToObject } from '../../utils/utils';-import { ManualPromise } from '../../utils/async';+import { ManualPromise } from '../../utils';const errorReasons: { [reason: string]: Protocol.Network.ResourceErrorType } = {'aborted': 'Cancellation',diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.tsindex caf9e58444..7f96f0be47 100644--- a/packages/playwright-core/src/server/webkit/wkPage.ts+++ b/packages/playwright-core/src/server/webkit/wkPage.ts@@ -43,7 +43,7 @@ import { WKInterceptableRequest, WKRouteImpl } from './wkInterceptableRequest';import { WKProvisionalPage } from './wkProvisionalPage';import { WKWorkers } from './wkWorkers';import { debugLogger } from '../../utils/debugLogger';-import { ManualPromise } from '../../utils/async';+import { ManualPromise } from '../../utils';const UTILITY_WORLD_NAME = '__playwright_utility_world__';const BINDING_CALL_MESSAGE = '__playwright_binding_call__';diff --git a/packages/playwright-core/src/utils/index.ts b/packages/playwright-core/src/utils/index.tsnew file mode 100644index 0000000000..7b6f1b2958--- /dev/null+++ b/packages/playwright-core/src/utils/index.ts@@ -0,0 +1,19 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++export { ManualPromise } from './manualPromise';+export { MultiMap } from './multimap';+export { raceAgainstTimeout, TimeoutRunner, TimeoutRunnerError } from './timeoutRunner';diff --git a/packages/playwright-core/src/utils/manualPromise.ts b/packages/playwright-core/src/utils/manualPromise.tsnew file mode 100644index 0000000000..18b0aaf910--- /dev/null+++ b/packages/playwright-core/src/utils/manualPromise.ts@@ -0,0 +1,55 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++export class ManualPromise<T> extends Promise<T> {+ private _resolve!: (t: T) => void;+ private _reject!: (e: Error) => void;+ private _isDone: boolean;++ constructor() {+ let resolve: (t: T) => void;+ let reject: (e: Error) => void;+ super((f, r) => {+ resolve = f;+ reject = r;+ });+ this._isDone = false;+ this._resolve = resolve!;+ this._reject = reject!;+ }++ isDone() {+ return this._isDone;+ }++ resolve(t: T) {+ this._isDone = true;+ this._resolve(t);+ }++ reject(e: Error) {+ this._isDone = true;+ this._reject(e);+ }++ static override get [Symbol.species]() {+ return Promise;+ }++ override get [Symbol.toStringTag]() {+ return 'ManualPromise';+ }+}diff --git a/packages/playwright-core/src/utils/async.ts b/packages/playwright-core/src/utils/timeoutRunner.tssimilarity index 80%rename from packages/playwright-core/src/utils/async.tsrename to packages/playwright-core/src/utils/timeoutRunner.tsindex 2648fcaac8..4da10e7c44 100644--- a/packages/playwright-core/src/utils/async.ts+++ b/packages/playwright-core/src/utils/timeoutRunner.ts@@ -14,6 +14,7 @@* limitations under the License.*/+import { ManualPromise } from './manualPromise';import { monotonicTime } from './utils';export class TimeoutRunnerError extends Error {}@@ -23,6 +24,7 @@ type TimeoutRunnerData = {timer: NodeJS.Timer | undefined,timeoutPromise: ManualPromise<any>,};+export class TimeoutRunner {private _running: TimeoutRunnerData | undefined;private _timeout: number;@@ -107,43 +109,3 @@ export async function raceAgainstTimeout<T>(cb: () => Promise<T>, timeout: numbethrow e;}}--export class ManualPromise<T> extends Promise<T> {- private _resolve!: (t: T) => void;- private _reject!: (e: Error) => void;- private _isDone: boolean;-- constructor() {- let resolve: (t: T) => void;- let reject: (e: Error) => void;- super((f, r) => {- resolve = f;- reject = r;- });- this._isDone = false;- this._resolve = resolve!;- this._reject = reject!;- }-- isDone() {- return this._isDone;- }-- resolve(t: T) {- this._isDone = true;- this._resolve(t);- }-- reject(e: Error) {- this._isDone = true;- this._reject(e);- }-- static override get [Symbol.species]() {- return Promise;- }-- override get [Symbol.toStringTag]() {- return 'ManualPromise';- }-}diff --git a/packages/playwright-test/src/dispatcher.ts b/packages/playwright-test/src/dispatcher.tsindex 8412206894..1ee2a4cf4c 100644--- a/packages/playwright-test/src/dispatcher.ts+++ b/packages/playwright-test/src/dispatcher.ts@@ -21,7 +21,7 @@ import type { RunPayload, TestBeginPayload, TestEndPayload, DonePayload, TestOutimport type { TestResult, Reporter, TestStep, TestError } from '../types/testReporter';import type { Suite, TestCase } from './test';import type { Loader } from './loader';-import { ManualPromise } from 'playwright-core/lib/utils/async';+import { ManualPromise } from 'playwright-core/lib/utils';export type TestGroup = {workerHash: string;diff --git a/packages/playwright-test/src/expect.ts b/packages/playwright-test/src/expect.tsindex 12c3697e9c..ff68fb9c06 100644--- a/packages/playwright-test/src/expect.ts+++ b/packages/playwright-test/src/expect.ts@@ -15,7 +15,7 @@*/import expectLibrary from 'expect';-import { raceAgainstTimeout } from 'playwright-core/lib/utils/async';+import { raceAgainstTimeout } from 'playwright-core/lib/utils';import path from 'path';import {INVERTED_COLOR,diff --git a/packages/playwright-test/src/fixtures.ts b/packages/playwright-test/src/fixtures.tsindex e592d1a5a6..60a21cd790 100644--- a/packages/playwright-test/src/fixtures.ts+++ b/packages/playwright-test/src/fixtures.ts@@ -17,7 +17,7 @@import { formatLocation, debugTest } from './util';import * as crypto from 'crypto';import type { FixturesWithLocation, Location, WorkerInfo } from './types';-import { ManualPromise } from 'playwright-core/lib/utils/async';+import { ManualPromise } from 'playwright-core/lib/utils';import type { TestInfoImpl } from './testInfo';import type { FixtureDescription, TimeoutManager } from './timeoutManager';diff --git a/packages/playwright-test/src/reporters/raw.ts b/packages/playwright-test/src/reporters/raw.tsindex 81974e900e..aa150bbf86 100644--- a/packages/playwright-test/src/reporters/raw.ts+++ b/packages/playwright-test/src/reporters/raw.ts@@ -21,7 +21,7 @@ import { assert, calculateSha1 } from 'playwright-core/lib/utils/utils';import { sanitizeForFilePath } from '../util';import { formatResultFailure } from './base';import { toPosixPath, serializePatterns } from './json';-import { MultiMap } from 'playwright-core/lib/utils/multimap';+import { MultiMap } from 'playwright-core/lib/utils';import { codeFrameColumns } from '@babel/code-frame';import type { FullConfigInternal } from '../types';diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.tsindex 369a6d59f2..aa08e79fa7 100644--- a/packages/playwright-test/src/runner.ts+++ b/packages/playwright-test/src/runner.ts@@ -42,7 +42,7 @@ import { Minimatch } from 'minimatch';import type { Config } from './types';import type { FullConfigInternal } from './types';import { WebServer } from './webServer';-import { raceAgainstTimeout } from 'playwright-core/lib/utils/async';+import { raceAgainstTimeout } from 'playwright-core/lib/utils';import { SigIntWatcher } from 'playwright-core/lib/utils/utils';const removeFolderAsync = promisify(rimraf);diff --git a/packages/playwright-test/src/timeoutManager.ts b/packages/playwright-test/src/timeoutManager.tsindex e6bad9e172..f2d92488e7 100644--- a/packages/playwright-test/src/timeoutManager.ts+++ b/packages/playwright-test/src/timeoutManager.ts@@ -15,7 +15,7 @@*/import colors from 'colors/safe';-import { TimeoutRunner, TimeoutRunnerError } from 'playwright-core/lib/utils/async';+import { TimeoutRunner, TimeoutRunnerError } from 'playwright-core/lib/utils';import type { TestError } from '../types/test';import type { Location } from './types';diff --git a/packages/playwright-test/src/webServer.ts b/packages/playwright-test/src/webServer.tsindex 3127347bc1..86dd4206ec 100644--- a/packages/playwright-test/src/webServer.ts+++ b/packages/playwright-test/src/webServer.ts@@ -18,7 +18,7 @@ import http from 'http';import https from 'https';import net from 'net';import debug from 'debug';-import { raceAgainstTimeout } from 'playwright-core/lib/utils/async';+import { raceAgainstTimeout } from 'playwright-core/lib/utils';import type { WebServerConfig } from './types';import { launchProcess } from 'playwright-core/lib/utils/processLauncher';import type { Reporter } from '../types/testReporter';diff --git a/packages/playwright-test/src/workerRunner.ts b/packages/playwright-test/src/workerRunner.tsindex c8db16c9c2..b1db516d44 100644--- a/packages/playwright-test/src/workerRunner.ts+++ b/packages/playwright-test/src/workerRunner.ts@@ -26,7 +26,7 @@ import type { Suite, TestCase } from './test';import type { Annotation, TestError, TestStepInternal } from './types';import type { ProjectImpl } from './project';import { FixtureRunner } from './fixtures';-import { ManualPromise } from 'playwright-core/lib/utils/async';+import { ManualPromise } from 'playwright-core/lib/utils';import { TestInfoImpl } from './testInfo';import type { TimeSlot } from './timeoutManager';import { TimeoutManager } from './timeoutManager';