diff --git a/packages/playwright-core/package.json b/packages/playwright-core/package.json index 79c2cf1faa..a144aa7639 100644 --- a/packages/playwright-core/package.json +++ b/packages/playwright-core/package.json @@ -26,7 +26,6 @@ "./lib/utils/comparators": "./lib/utils/comparators.js", "./lib/utils/httpServer": "./lib/utils/httpServer.js", "./lib/utils/processLauncher": "./lib/utils/processLauncher.js", - "./lib/utils/utils": "./lib/utils/utils.js", "./lib/utils/stackTrace": "./lib/utils/stackTrace.js", "./lib/remote/playwrightServer": "./lib/remote/playwrightServer.js", "./lib/remote/playwrightClient": "./lib/remote/playwrightClient.js", diff --git a/packages/playwright-core/src/browserServerImpl.ts b/packages/playwright-core/src/browserServerImpl.ts index 957393317a..fae7812921 100644 --- a/packages/playwright-core/src/browserServerImpl.ts +++ b/packages/playwright-core/src/browserServerImpl.ts @@ -18,7 +18,7 @@ import type { LaunchServerOptions, Logger } from './client/types'; import { EventEmitter } from 'ws'; import type { BrowserServerLauncher, BrowserServer } from './client/browserType'; import { envObjectToArray } from './client/clientHelper'; -import { createGuid } from './utils/utils'; +import { createGuid } from './utils'; import type { ProtocolLogger } from './server/types'; import { serverSideCallMetadata } from './server/instrumentation'; import { createPlaywright } from './server/playwright'; diff --git a/packages/playwright-core/src/cli/cli.ts b/packages/playwright-core/src/cli/cli.ts index 489c73e881..91adf285c7 100755 --- a/packages/playwright-core/src/cli/cli.ts +++ b/packages/playwright-core/src/cli/cli.ts @@ -32,7 +32,7 @@ import type { Page } from '../client/page'; import type { BrowserType } from '../client/browserType'; import type { BrowserContextOptions, LaunchOptions } from '../client/types'; import { spawn } from 'child_process'; -import { spawnAsync, getPlaywrightVersion, wrapInASCIIBox } from '../utils/utils'; +import { spawnAsync, getPlaywrightVersion, wrapInASCIIBox } from '../utils'; import { launchGridAgent } from '../grid/gridAgent'; import type { GridFactory } from '../grid/gridServer'; import { GridServer } from '../grid/gridServer'; diff --git a/packages/playwright-core/src/client/android.ts b/packages/playwright-core/src/client/android.ts index 3ac818c1e2..ebc644c56d 100644 --- a/packages/playwright-core/src/client/android.ts +++ b/packages/playwright-core/src/client/android.ts @@ -15,7 +15,7 @@ */ import fs from 'fs'; -import { isString, isRegExp } from '../utils/utils'; +import { isString, isRegExp } from '../utils'; import type * as channels from '../protocol/channels'; import { Events } from './events'; import { BrowserContext, prepareBrowserContextParams } from './browserContext'; diff --git a/packages/playwright-core/src/client/artifact.ts b/packages/playwright-core/src/client/artifact.ts index 21cfa01afc..7a211fb5b0 100644 --- a/packages/playwright-core/src/client/artifact.ts +++ b/packages/playwright-core/src/client/artifact.ts @@ -17,7 +17,7 @@ import type * as channels from '../protocol/channels'; import * as fs from 'fs'; import { Stream } from './stream'; -import { mkdirIfNeeded } from '../utils/utils'; +import { mkdirIfNeeded } from '../utils'; import { ChannelOwner } from './channelOwner'; import type { Readable } from 'stream'; diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index daca2b4f44..3fcb72b24f 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -28,7 +28,7 @@ import { Events } from './events'; import { TimeoutSettings } from '../utils/timeoutSettings'; import { Waiter } from './waiter'; import type { URLMatch, Headers, WaitForEventOptions, BrowserContextOptions, StorageState, LaunchOptions } from './types'; -import { headersObjectToArray, mkdirIfNeeded } from '../utils/utils'; +import { headersObjectToArray, mkdirIfNeeded } from '../utils'; import { isSafeCloseError } from '../utils/errors'; import type * as api from '../../types/types'; import type * as structs from '../../types/structs'; diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts index 10dea84945..9007dbccb6 100644 --- a/packages/playwright-core/src/client/browserType.ts +++ b/packages/playwright-core/src/client/browserType.ts @@ -23,7 +23,7 @@ import { Connection } from './connection'; import { Events } from './events'; import type { ChildProcess } from 'child_process'; import { envObjectToArray } from './clientHelper'; -import { assert, headersObjectToArray, monotonicTime } from '../utils/utils'; +import { assert, headersObjectToArray, monotonicTime } from '../utils'; import type * as api from '../../types/types'; import { kBrowserClosedError } from '../utils/errors'; import { raceAgainstTimeout } from '../utils'; diff --git a/packages/playwright-core/src/client/channelOwner.ts b/packages/playwright-core/src/client/channelOwner.ts index bc2fb4a92a..29411c234b 100644 --- a/packages/playwright-core/src/client/channelOwner.ts +++ b/packages/playwright-core/src/client/channelOwner.ts @@ -21,7 +21,7 @@ import { createScheme, ValidationError } from '../protocol/validator'; import { debugLogger } from '../utils/debugLogger'; import type { ParsedStackTrace } from '../utils/stackTrace'; import { captureRawStack, captureStackTrace } from '../utils/stackTrace'; -import { isUnderTest } from '../utils/utils'; +import { isUnderTest } from '../utils'; import { zones } from '../utils/zones'; import type { ClientInstrumentation } from './clientInstrumentation'; import type { Connection } from './connection'; diff --git a/packages/playwright-core/src/client/clientHelper.ts b/packages/playwright-core/src/client/clientHelper.ts index befe5ec502..3b28794b81 100644 --- a/packages/playwright-core/src/client/clientHelper.ts +++ b/packages/playwright-core/src/client/clientHelper.ts @@ -17,7 +17,7 @@ import type * as types from './types'; import fs from 'fs'; -import { isString, isRegExp, constructURLBasedOnBaseURL } from '../utils/utils'; +import { isString, isRegExp, constructURLBasedOnBaseURL } from '../utils'; export function envObjectToArray(env: types.Env): { name: string, value: string }[] { const result: { name: string, value: string }[] = []; diff --git a/packages/playwright-core/src/client/electron.ts b/packages/playwright-core/src/client/electron.ts index 983e360740..f7d996621e 100644 --- a/packages/playwright-core/src/client/electron.ts +++ b/packages/playwright-core/src/client/electron.ts @@ -20,7 +20,7 @@ import type * as structs from '../../types/structs'; import type * as api from '../../types/types'; import type * as channels from '../protocol/channels'; import { TimeoutSettings } from '../utils/timeoutSettings'; -import { headersObjectToArray } from '../utils/utils'; +import { headersObjectToArray } from '../utils'; import { BrowserContext } from './browserContext'; import { ChannelOwner } from './channelOwner'; import { envObjectToArray } from './clientHelper'; diff --git a/packages/playwright-core/src/client/elementHandle.ts b/packages/playwright-core/src/client/elementHandle.ts index de0c439b0e..a5dfdd2e1f 100644 --- a/packages/playwright-core/src/client/elementHandle.ts +++ b/packages/playwright-core/src/client/elementHandle.ts @@ -23,7 +23,7 @@ import type { SelectOption, FilePayload, Rect, SelectOptionOptions } from './typ import fs from 'fs'; import * as mime from 'mime'; import path from 'path'; -import { assert, isString, mkdirIfNeeded } from '../utils/utils'; +import { assert, isString, mkdirIfNeeded } from '../utils'; import type * as api from '../../types/types'; import type * as structs from '../../types/structs'; import type { BrowserContext } from './browserContext'; diff --git a/packages/playwright-core/src/client/fetch.ts b/packages/playwright-core/src/client/fetch.ts index 040a795b41..d202eccc94 100644 --- a/packages/playwright-core/src/client/fetch.ts +++ b/packages/playwright-core/src/client/fetch.ts @@ -22,7 +22,7 @@ import type * as api from '../../types/types'; import type { HeadersArray } from '../common/types'; import type * as channels from '../protocol/channels'; import { kBrowserOrContextClosedError } from '../utils/errors'; -import { assert, headersObjectToArray, isFilePayload, isString, mkdirIfNeeded, objectToArray } from '../utils/utils'; +import { assert, headersObjectToArray, isFilePayload, isString, mkdirIfNeeded, objectToArray } from '../utils'; import { ChannelOwner } from './channelOwner'; import * as network from './network'; import { RawHeaders } from './network'; diff --git a/packages/playwright-core/src/client/frame.ts b/packages/playwright-core/src/client/frame.ts index 1be9d27f02..b7ff0fab7e 100644 --- a/packages/playwright-core/src/client/frame.ts +++ b/packages/playwright-core/src/client/frame.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { assert } from '../utils/utils'; +import { assert } from '../utils'; import type * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; import { FrameLocator, Locator } from './locator'; diff --git a/packages/playwright-core/src/client/locator.ts b/packages/playwright-core/src/client/locator.ts index 5ba66ad80a..d9e9f98a47 100644 --- a/packages/playwright-core/src/client/locator.ts +++ b/packages/playwright-core/src/client/locator.ts @@ -19,7 +19,7 @@ import type * as api from '../../types/types'; import type * as channels from '../protocol/channels'; import type { ParsedStackTrace } from '../utils/stackTrace'; import * as util from 'util'; -import { isRegExp, monotonicTime } from '../utils/utils'; +import { isRegExp, monotonicTime } from '../utils'; import { ElementHandle } from './elementHandle'; import type { Frame } from './frame'; import type { FilePayload, FrameExpectOptions, Rect, SelectOption, SelectOptionOptions, TimeoutOptions } from './types'; diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.ts index a565d5080c..0d4b2ef594 100644 --- a/packages/playwright-core/src/client/network.ts +++ b/packages/playwright-core/src/client/network.ts @@ -21,7 +21,7 @@ import { Frame } from './frame'; import type { Headers, RemoteAddr, SecurityDetails, WaitForEventOptions } from './types'; import fs from 'fs'; import * as mime from 'mime'; -import { isString, headersObjectToArray } from '../utils/utils'; +import { isString, headersObjectToArray } from '../utils'; import { ManualPromise } from '../utils'; import { Events } from './events'; import type { Page } from './page'; diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts index 8df4adc533..94d4f414ea 100644 --- a/packages/playwright-core/src/client/page.ts +++ b/packages/playwright-core/src/client/page.ts @@ -16,7 +16,7 @@ */ import { Events } from './events'; -import { assert } from '../utils/utils'; +import { assert } from '../utils'; import { TimeoutSettings } from '../utils/timeoutSettings'; import type { ParsedStackTrace } from '../utils/stackTrace'; import type * as channels from '../protocol/channels'; @@ -46,7 +46,7 @@ import fs from 'fs'; import path from 'path'; import type { Size, URLMatch, Headers, LifecycleEvent, WaitForEventOptions, SelectOption, SelectOptionOptions, FilePayload, WaitForFunctionOptions } from './types'; import { evaluationScript, urlMatches } from './clientHelper'; -import { isString, isRegExp, isObject, mkdirIfNeeded, headersObjectToArray } from '../utils/utils'; +import { isString, isRegExp, isObject, mkdirIfNeeded, headersObjectToArray } from '../utils'; import { isSafeCloseError } from '../utils/errors'; import { Video } from './video'; import { Artifact } from './artifact'; diff --git a/packages/playwright-core/src/client/waiter.ts b/packages/playwright-core/src/client/waiter.ts index 2e60baf78e..2a04df7d91 100644 --- a/packages/playwright-core/src/client/waiter.ts +++ b/packages/playwright-core/src/client/waiter.ts @@ -17,7 +17,7 @@ import type { EventEmitter } from 'events'; import { rewriteErrorMessage } from '../utils/stackTrace'; import { TimeoutError } from '../utils/errors'; -import { createGuid } from '../utils/utils'; +import { createGuid } from '../utils'; import type * as channels from '../protocol/channels'; import type { ChannelOwner } from './channelOwner'; diff --git a/packages/playwright-core/src/grid/dockerGridFactory.ts b/packages/playwright-core/src/grid/dockerGridFactory.ts index 62ddf08b59..7926d38db1 100644 --- a/packages/playwright-core/src/grid/dockerGridFactory.ts +++ b/packages/playwright-core/src/grid/dockerGridFactory.ts @@ -17,7 +17,7 @@ import http from 'http'; import os from 'os'; import type { GridAgentLaunchOptions, GridFactory } from './gridServer'; -import * as utils from '../utils/utils'; +import * as utils from '../utils'; const dockerFactory: GridFactory = { name: 'Agents launched inside Docker container', diff --git a/packages/playwright-core/src/grid/gridAgent.ts b/packages/playwright-core/src/grid/gridAgent.ts index 62774ce5f6..1787f51897 100644 --- a/packages/playwright-core/src/grid/gridAgent.ts +++ b/packages/playwright-core/src/grid/gridAgent.ts @@ -17,7 +17,7 @@ import debug from 'debug'; import WebSocket from 'ws'; import { fork } from 'child_process'; -import { getPlaywrightVersion } from '../utils/utils'; +import { getPlaywrightVersion } from '../utils'; export function launchGridAgent(agentId: string, gridURL: string) { const log = debug(`pw:grid:agent:${agentId}`); diff --git a/packages/playwright-core/src/grid/gridClient.ts b/packages/playwright-core/src/grid/gridClient.ts index a5c535ca01..0383a5ef17 100644 --- a/packages/playwright-core/src/grid/gridClient.ts +++ b/packages/playwright-core/src/grid/gridClient.ts @@ -17,7 +17,7 @@ import WebSocket from 'ws'; import { Connection } from '../client/connection'; import type { Playwright } from '../client/playwright'; -import { getPlaywrightVersion } from '../utils/utils'; +import { getPlaywrightVersion } from '../utils'; export class GridClient { private _ws: WebSocket; diff --git a/packages/playwright-core/src/grid/gridServer.ts b/packages/playwright-core/src/grid/gridServer.ts index 4b6ed294f7..7cb4620f01 100644 --- a/packages/playwright-core/src/grid/gridServer.ts +++ b/packages/playwright-core/src/grid/gridServer.ts @@ -20,7 +20,7 @@ import { URL } from 'url'; import type { Server as WebSocketServer } from 'ws'; import type WebSocket from 'ws'; import { HttpServer } from '../utils/httpServer'; -import { assert, createGuid, getPlaywrightVersion } from '../utils/utils'; +import { assert, createGuid, getPlaywrightVersion } from '../utils'; export type GridAgentLaunchOptions = { agentId: string, diff --git a/packages/playwright-core/src/protocol/transport.ts b/packages/playwright-core/src/protocol/transport.ts index 63f09ce4e5..8026f00c21 100644 --- a/packages/playwright-core/src/protocol/transport.ts +++ b/packages/playwright-core/src/protocol/transport.ts @@ -15,7 +15,7 @@ */ import type { ChildProcess } from 'child_process'; -import { makeWaitForNextTask } from '../utils/utils'; +import { makeWaitForNextTask } from '../utils'; export interface WritableStream { write(data: Buffer): void; diff --git a/packages/playwright-core/src/protocol/validatorPrimitives.ts b/packages/playwright-core/src/protocol/validatorPrimitives.ts index ac996b078d..86c1b54d54 100644 --- a/packages/playwright-core/src/protocol/validatorPrimitives.ts +++ b/packages/playwright-core/src/protocol/validatorPrimitives.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { isUnderTest } from '../utils/utils'; +import { isUnderTest } from '../utils'; export class ValidationError extends Error {} export type Validator = (arg: any, path: string) => any; diff --git a/packages/playwright-core/src/remote/playwrightClient.ts b/packages/playwright-core/src/remote/playwrightClient.ts index 0dbc914a58..571ed28fcd 100644 --- a/packages/playwright-core/src/remote/playwrightClient.ts +++ b/packages/playwright-core/src/remote/playwrightClient.ts @@ -17,7 +17,7 @@ import WebSocket from 'ws'; import { Connection } from '../client/connection'; import type { Playwright } from '../client/playwright'; -import { makeWaitForNextTask } from '../utils/utils'; +import { makeWaitForNextTask } from '../utils'; // TODO: this file should be removed because it uses the old protocol. diff --git a/packages/playwright-core/src/server/android/android.ts b/packages/playwright-core/src/server/android/android.ts index 71b8c6ab56..0428b5df22 100644 --- a/packages/playwright-core/src/server/android/android.ts +++ b/packages/playwright-core/src/server/android/android.ts @@ -22,7 +22,7 @@ import os from 'os'; import path from 'path'; import type * as stream from 'stream'; import * as ws from 'ws'; -import { createGuid, makeWaitForNextTask, removeFolders } from '../../utils/utils'; +import { createGuid, makeWaitForNextTask, removeFolders } from '../../utils'; import type { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser'; import type { BrowserContext } from '../browserContext'; import { validateBrowserContextOptions } from '../browserContext'; diff --git a/packages/playwright-core/src/server/android/backendAdb.ts b/packages/playwright-core/src/server/android/backendAdb.ts index 2e2918d902..32e98f6a44 100644 --- a/packages/playwright-core/src/server/android/backendAdb.ts +++ b/packages/playwright-core/src/server/android/backendAdb.ts @@ -19,7 +19,7 @@ import type * as types from '../types'; import * as net from 'net'; import { EventEmitter } from 'events'; import type { Backend, DeviceBackend, SocketBackend } from './android'; -import { assert, createGuid } from '../../utils/utils'; +import { assert, createGuid } from '../../utils'; export class AdbBackend implements Backend { async devices(options: types.AndroidDeviceOptions = {}): Promise { diff --git a/packages/playwright-core/src/server/artifact.ts b/packages/playwright-core/src/server/artifact.ts index 85aaff8a0c..44a28383fe 100644 --- a/packages/playwright-core/src/server/artifact.ts +++ b/packages/playwright-core/src/server/artifact.ts @@ -15,7 +15,7 @@ */ import fs from 'fs'; -import { assert } from '../utils/utils'; +import { assert } from '../utils'; import { ManualPromise } from '../utils'; import { SdkObject } from './instrumentation'; diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts index 9cc5872633..82ee981489 100644 --- a/packages/playwright-core/src/server/browserContext.ts +++ b/packages/playwright-core/src/server/browserContext.ts @@ -17,7 +17,7 @@ import * as os from 'os'; import { TimeoutSettings } from '../utils/timeoutSettings'; -import { debugMode, mkdirIfNeeded, createGuid } from '../utils/utils'; +import { debugMode, mkdirIfNeeded, createGuid } from '../utils'; import type { Browser, BrowserOptions } from './browser'; import type { Download } from './download'; import type * as frames from './frames'; diff --git a/packages/playwright-core/src/server/browserType.ts b/packages/playwright-core/src/server/browserType.ts index 70417bf3e2..f68cffe12c 100644 --- a/packages/playwright-core/src/server/browserType.ts +++ b/packages/playwright-core/src/server/browserType.ts @@ -31,7 +31,7 @@ import type { Progress } from './progress'; import { ProgressController } from './progress'; import type * as types from './types'; import { DEFAULT_TIMEOUT, TimeoutSettings } from '../utils/timeoutSettings'; -import { debugMode, existsAsync } from '../utils/utils'; +import { debugMode, existsAsync } from '../utils'; import { helper } from './helper'; import { RecentLogsCollector } from '../utils/debugLogger'; import type { CallMetadata } from './instrumentation'; diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.ts index 99422328ac..d113b99746 100644 --- a/packages/playwright-core/src/server/chromium/chromium.ts +++ b/packages/playwright-core/src/server/chromium/chromium.ts @@ -32,7 +32,7 @@ import { Browser } from '../browser'; import type * as types from '../types'; import type { HTTPRequestParams } from '../../utils'; import { fetchData } from '../../utils'; -import { debugMode, getUserAgent, headersArrayToObject, removeFolders, streamToString, wrapInASCIIBox } from '../../utils/utils'; +import { debugMode, getUserAgent, headersArrayToObject, removeFolders, streamToString, wrapInASCIIBox } from '../../utils'; import { RecentLogsCollector } from '../../utils/debugLogger'; import type { Progress } from '../progress'; import { ProgressController } from '../progress'; diff --git a/packages/playwright-core/src/server/chromium/crBrowser.ts b/packages/playwright-core/src/server/chromium/crBrowser.ts index 2f85948a88..2cd01d22e0 100644 --- a/packages/playwright-core/src/server/chromium/crBrowser.ts +++ b/packages/playwright-core/src/server/chromium/crBrowser.ts @@ -18,7 +18,7 @@ import type { BrowserOptions } from '../browser'; import { Browser } from '../browser'; import { assertBrowserContextIsNotOwned, BrowserContext, verifyGeolocation } from '../browserContext'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import * as network from '../network'; import type { PageBinding, PageDelegate } from '../page'; import { Page, Worker } from '../page'; diff --git a/packages/playwright-core/src/server/chromium/crConnection.ts b/packages/playwright-core/src/server/chromium/crConnection.ts index 2138051353..bdbed342d9 100644 --- a/packages/playwright-core/src/server/chromium/crConnection.ts +++ b/packages/playwright-core/src/server/chromium/crConnection.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport'; import type { Protocol } from './protocol'; import { EventEmitter } from 'events'; diff --git a/packages/playwright-core/src/server/chromium/crCoverage.ts b/packages/playwright-core/src/server/chromium/crCoverage.ts index 022c6bf666..9f91e11ac0 100644 --- a/packages/playwright-core/src/server/chromium/crCoverage.ts +++ b/packages/playwright-core/src/server/chromium/crCoverage.ts @@ -20,7 +20,7 @@ import type { RegisteredListener } from '../../utils/eventsHelper'; import { eventsHelper } from '../../utils/eventsHelper'; import type { Protocol } from './protocol'; import type * as types from '../types'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; export class CRCoverage { private _jsCoverage: JSCoverage; diff --git a/packages/playwright-core/src/server/chromium/crDragDrop.ts b/packages/playwright-core/src/server/chromium/crDragDrop.ts index ca1b3ea2dd..39d10ee542 100644 --- a/packages/playwright-core/src/server/chromium/crDragDrop.ts +++ b/packages/playwright-core/src/server/chromium/crDragDrop.ts @@ -15,7 +15,7 @@ */ import type { CRPage } from './crPage'; import type * as types from '../types'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import type { Protocol } from './protocol'; import { toModifiersMask } from './crProtocolHelper'; diff --git a/packages/playwright-core/src/server/chromium/crInput.ts b/packages/playwright-core/src/server/chromium/crInput.ts index 6c27025be5..bbfd973d10 100644 --- a/packages/playwright-core/src/server/chromium/crInput.ts +++ b/packages/playwright-core/src/server/chromium/crInput.ts @@ -19,7 +19,7 @@ import * as input from '../input'; import type * as types from '../types'; import type { CRSession } from './crConnection'; import { macEditingCommands } from '../macEditingCommands'; -import { isString } from '../../utils/utils'; +import { isString } from '../../utils'; import type { DragManager } from './crDragDrop'; import type { CRPage } from './crPage'; import { toButtonsMask, toModifiersMask } from './crProtocolHelper'; diff --git a/packages/playwright-core/src/server/chromium/crNetworkManager.ts b/packages/playwright-core/src/server/chromium/crNetworkManager.ts index 98b5de3642..e517c0b89b 100644 --- a/packages/playwright-core/src/server/chromium/crNetworkManager.ts +++ b/packages/playwright-core/src/server/chromium/crNetworkManager.ts @@ -25,7 +25,7 @@ import * as network from '../network'; import type * as frames from '../frames'; import type * as types from '../types'; import type { CRPage } from './crPage'; -import { assert, headersObjectToArray } from '../../utils/utils'; +import { assert, headersObjectToArray } from '../../utils'; export class CRNetworkManager { private _client: CRSession; diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts index 6c917229a5..73fe02568f 100644 --- a/packages/playwright-core/src/server/chromium/crPage.ts +++ b/packages/playwright-core/src/server/chromium/crPage.ts @@ -20,7 +20,7 @@ import type { RegisteredListener } from '../../utils/eventsHelper'; import { eventsHelper } from '../../utils/eventsHelper'; import { registry } from '../registry'; import { rewriteErrorMessage } from '../../utils/stackTrace'; -import { assert, createGuid, headersArrayToObject } from '../../utils/utils'; +import { assert, createGuid, headersArrayToObject } from '../../utils'; import * as dialog from '../dialog'; import * as dom from '../dom'; import type * as frames from '../frames'; diff --git a/packages/playwright-core/src/server/chromium/crPdf.ts b/packages/playwright-core/src/server/chromium/crPdf.ts index 9f541687f4..390ea65bf0 100644 --- a/packages/playwright-core/src/server/chromium/crPdf.ts +++ b/packages/playwright-core/src/server/chromium/crPdf.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import type * as types from '../types'; import type { CRSession } from './crConnection'; import { readProtocolStream } from './crProtocolHelper'; diff --git a/packages/playwright-core/src/server/chromium/crProtocolHelper.ts b/packages/playwright-core/src/server/chromium/crProtocolHelper.ts index 94b9277e7f..10d1c9c54b 100644 --- a/packages/playwright-core/src/server/chromium/crProtocolHelper.ts +++ b/packages/playwright-core/src/server/chromium/crProtocolHelper.ts @@ -19,7 +19,7 @@ import type { CRSession } from './crConnection'; import type { Protocol } from './protocol'; import fs from 'fs'; import type * as types from '../types'; -import { mkdirIfNeeded } from '../../utils/utils'; +import { mkdirIfNeeded } from '../../utils'; import { splitErrorMessage } from '../../utils/stackTrace'; export function getExceptionMessage(exceptionDetails: Protocol.Runtime.ExceptionDetails): string { diff --git a/packages/playwright-core/src/server/chromium/videoRecorder.ts b/packages/playwright-core/src/server/chromium/videoRecorder.ts index d1cc9c5544..889978be24 100644 --- a/packages/playwright-core/src/server/chromium/videoRecorder.ts +++ b/packages/playwright-core/src/server/chromium/videoRecorder.ts @@ -15,7 +15,7 @@ */ import type { ChildProcess } from 'child_process'; -import { assert, monotonicTime } from '../../utils/utils'; +import { assert, monotonicTime } from '../../utils'; import { Page } from '../page'; import { launchProcess } from '../../utils/processLauncher'; import type { Progress } from '../progress'; diff --git a/packages/playwright-core/src/server/dialog.ts b/packages/playwright-core/src/server/dialog.ts index e90e1e8a67..8d863fa9cb 100644 --- a/packages/playwright-core/src/server/dialog.ts +++ b/packages/playwright-core/src/server/dialog.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { assert } from '../utils/utils'; +import { assert } from '../utils'; import type { Page } from './page'; import { SdkObject } from './instrumentation'; diff --git a/packages/playwright-core/src/server/dispatchers/artifactDispatcher.ts b/packages/playwright-core/src/server/dispatchers/artifactDispatcher.ts index f855558484..95046d4465 100644 --- a/packages/playwright-core/src/server/dispatchers/artifactDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/artifactDispatcher.ts @@ -19,7 +19,7 @@ import type { DispatcherScope } from './dispatcher'; import { Dispatcher } from './dispatcher'; import { StreamDispatcher } from './streamDispatcher'; import fs from 'fs'; -import { mkdirIfNeeded } from '../../utils/utils'; +import { mkdirIfNeeded } from '../../utils'; import type { Artifact } from '../artifact'; export class ArtifactDispatcher extends Dispatcher implements channels.ArtifactChannel { diff --git a/packages/playwright-core/src/server/dispatchers/browserContextDispatcher.ts b/packages/playwright-core/src/server/dispatchers/browserContextDispatcher.ts index 9b0fa52be8..a32c4e921d 100644 --- a/packages/playwright-core/src/server/dispatchers/browserContextDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/browserContextDispatcher.ts @@ -31,7 +31,7 @@ import type { Request, Response } from '../network'; import { TracingDispatcher } from './tracingDispatcher'; import * as fs from 'fs'; import * as path from 'path'; -import { createGuid } from '../../utils/utils'; +import { createGuid } from '../../utils'; import { WritableStreamDispatcher } from './writableStreamDispatcher'; export class BrowserContextDispatcher extends Dispatcher implements channels.BrowserContextChannel { diff --git a/packages/playwright-core/src/server/dispatchers/browserTypeDispatcher.ts b/packages/playwright-core/src/server/dispatchers/browserTypeDispatcher.ts index cc45328c08..cd6c321921 100644 --- a/packages/playwright-core/src/server/dispatchers/browserTypeDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/browserTypeDispatcher.ts @@ -22,7 +22,7 @@ import { Dispatcher } from './dispatcher'; import { BrowserContextDispatcher } from './browserContextDispatcher'; import type { CallMetadata } from '../instrumentation'; import { JsonPipeDispatcher } from '../dispatchers/jsonPipeDispatcher'; -import { getUserAgent } from '../../utils/utils'; +import { getUserAgent } from '../../utils'; import * as socks from '../../utils/socksProxy'; import EventEmitter from 'events'; import { ProgressController } from '../progress'; diff --git a/packages/playwright-core/src/server/dispatchers/dispatcher.ts b/packages/playwright-core/src/server/dispatchers/dispatcher.ts index ca7943dc7b..9451407986 100644 --- a/packages/playwright-core/src/server/dispatchers/dispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/dispatcher.ts @@ -19,7 +19,7 @@ import type * as channels from '../../protocol/channels'; import { serializeError } from '../../protocol/serializers'; import type { Validator } from '../../protocol/validator'; import { createScheme, ValidationError } from '../../protocol/validator'; -import { assert, debugAssert, isUnderTest, monotonicTime } from '../../utils/utils'; +import { assert, debugAssert, isUnderTest, monotonicTime } from '../../utils'; import { tOptional } from '../../protocol/validatorPrimitives'; import { kBrowserOrContextClosedError } from '../../utils/errors'; import type { CallMetadata } from '../instrumentation'; diff --git a/packages/playwright-core/src/server/dispatchers/jsonPipeDispatcher.ts b/packages/playwright-core/src/server/dispatchers/jsonPipeDispatcher.ts index 57fee7896b..719bd01105 100644 --- a/packages/playwright-core/src/server/dispatchers/jsonPipeDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/jsonPipeDispatcher.ts @@ -17,7 +17,7 @@ import type * as channels from '../../protocol/channels'; import type { DispatcherScope } from './dispatcher'; import { Dispatcher } from './dispatcher'; -import { createGuid } from '../../utils/utils'; +import { createGuid } from '../../utils'; import { serializeError } from '../../protocol/serializers'; export class JsonPipeDispatcher extends Dispatcher<{ guid: string }, channels.JsonPipeChannel> implements channels.JsonPipeChannel { diff --git a/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts b/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts index 748b406b34..2fd53f9f4b 100644 --- a/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts @@ -21,7 +21,7 @@ import yauzl from 'yauzl'; import yazl from 'yazl'; import type * as channels from '../../protocol/channels'; import { ManualPromise } from '../../utils'; -import { assert, createGuid } from '../../utils/utils'; +import { assert, createGuid } from '../../utils'; import type { DispatcherScope } from './dispatcher'; import { Dispatcher } from './dispatcher'; diff --git a/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts b/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts index 41430cedf2..a34d326133 100644 --- a/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts @@ -35,7 +35,7 @@ import type { CallMetadata } from '../instrumentation'; import type { Artifact } from '../artifact'; import { ArtifactDispatcher } from './artifactDispatcher'; import type { Download } from '../download'; -import { createGuid } from '../../utils/utils'; +import { createGuid } from '../../utils'; export class PageDispatcher extends Dispatcher implements channels.PageChannel { _type_EventTarget = true; diff --git a/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts b/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts index 2e64c6bbe5..1859e44339 100644 --- a/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts @@ -30,7 +30,7 @@ import { LocalUtilsDispatcher } from './localUtilsDispatcher'; import { APIRequestContextDispatcher } from './networkDispatchers'; import { SelectorsDispatcher } from './selectorsDispatcher'; import { ConnectedBrowserDispatcher } from './browserDispatcher'; -import { createGuid } from '../../utils/utils'; +import { createGuid } from '../../utils'; export class PlaywrightDispatcher extends Dispatcher implements channels.PlaywrightChannel { _type_Playwright; diff --git a/packages/playwright-core/src/server/dispatchers/streamDispatcher.ts b/packages/playwright-core/src/server/dispatchers/streamDispatcher.ts index 4ceeba8bbc..25eb9ff732 100644 --- a/packages/playwright-core/src/server/dispatchers/streamDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/streamDispatcher.ts @@ -18,7 +18,7 @@ import type * as channels from '../../protocol/channels'; import type { DispatcherScope } from './dispatcher'; import { Dispatcher } from './dispatcher'; import type * as stream from 'stream'; -import { createGuid } from '../../utils/utils'; +import { createGuid } from '../../utils'; export class StreamDispatcher extends Dispatcher<{ guid: string, stream: stream.Readable }, channels.StreamChannel> implements channels.StreamChannel { _type_Stream = true; diff --git a/packages/playwright-core/src/server/dispatchers/writableStreamDispatcher.ts b/packages/playwright-core/src/server/dispatchers/writableStreamDispatcher.ts index e1b281fb52..5569c13d27 100644 --- a/packages/playwright-core/src/server/dispatchers/writableStreamDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/writableStreamDispatcher.ts @@ -18,7 +18,7 @@ import type * as channels from '../../protocol/channels'; import type { DispatcherScope } from './dispatcher'; import { Dispatcher } from './dispatcher'; import type * as fs from 'fs'; -import { createGuid } from '../../utils/utils'; +import { createGuid } from '../../utils'; export class WritableStreamDispatcher extends Dispatcher<{ guid: string, stream: fs.WriteStream }, channels.WritableStreamChannel> implements channels.WritableStreamChannel { _type_WritableStream = true; diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.ts index 7407de72c8..2e46e3cea8 100644 --- a/packages/playwright-core/src/server/dom.ts +++ b/packages/playwright-core/src/server/dom.ts @@ -29,7 +29,7 @@ import { ProgressController } from './progress'; import type { SelectorInfo } from './selectors'; import type * as types from './types'; import type { TimeoutOptions } from '../common/types'; -import { experimentalFeaturesEnabled, isUnderTest } from '../utils/utils'; +import { experimentalFeaturesEnabled, isUnderTest } from '../utils'; type SetInputFilesFiles = channels.ElementHandleSetInputFilesParams['files']; export type InputFilesItems = { files?: SetInputFilesFiles, localPaths?: string[] }; diff --git a/packages/playwright-core/src/server/download.ts b/packages/playwright-core/src/server/download.ts index f6fda002af..1e33c65e8b 100644 --- a/packages/playwright-core/src/server/download.ts +++ b/packages/playwright-core/src/server/download.ts @@ -16,7 +16,7 @@ import path from 'path'; import { Page } from './page'; -import { assert } from '../utils/utils'; +import { assert } from '../utils'; import { Artifact } from './artifact'; export class Download { diff --git a/packages/playwright-core/src/server/electron/electron.ts b/packages/playwright-core/src/server/electron/electron.ts index 195315deef..20a74671b9 100644 --- a/packages/playwright-core/src/server/electron/electron.ts +++ b/packages/playwright-core/src/server/electron/electron.ts @@ -26,7 +26,7 @@ import { CRExecutionContext } from '../chromium/crExecutionContext'; import * as js from '../javascript'; import type { Page } from '../page'; import { TimeoutSettings } from '../../utils/timeoutSettings'; -import { wrapInASCIIBox } from '../../utils/utils'; +import { wrapInASCIIBox } from '../../utils'; import { WebSocketTransport } from '../transport'; import { launchProcess, envArrayToObject } from '../../utils/processLauncher'; import { BrowserContext, validateBrowserContextOptions } from '../browserContext'; diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.ts index abc05af34a..873d5e041d 100644 --- a/packages/playwright-core/src/server/fetch.ts +++ b/packages/playwright-core/src/server/fetch.ts @@ -25,7 +25,7 @@ import zlib from 'zlib'; import type { HTTPCredentials } from '../../types/types'; import type * as channels from '../protocol/channels'; import { TimeoutSettings } from '../utils/timeoutSettings'; -import { assert, createGuid, getUserAgent, monotonicTime } from '../utils/utils'; +import { assert, createGuid, getUserAgent, monotonicTime } from '../utils'; import { BrowserContext } from './browserContext'; import { CookieStore, domainMatches } from './cookieStore'; import { MultipartFormData } from './formData'; diff --git a/packages/playwright-core/src/server/firefox/ffBrowser.ts b/packages/playwright-core/src/server/firefox/ffBrowser.ts index 91d3116c87..6d898f8afb 100644 --- a/packages/playwright-core/src/server/firefox/ffBrowser.ts +++ b/packages/playwright-core/src/server/firefox/ffBrowser.ts @@ -16,7 +16,7 @@ */ import { kBrowserClosedError } from '../../utils/errors'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import type { BrowserOptions } from '../browser'; import { Browser } from '../browser'; import { assertBrowserContextIsNotOwned, BrowserContext, verifyGeolocation } from '../browserContext'; diff --git a/packages/playwright-core/src/server/firefox/ffConnection.ts b/packages/playwright-core/src/server/firefox/ffConnection.ts index aa2108eb68..d39ca17b1e 100644 --- a/packages/playwright-core/src/server/firefox/ffConnection.ts +++ b/packages/playwright-core/src/server/firefox/ffConnection.ts @@ -16,7 +16,7 @@ */ import { EventEmitter } from 'events'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport'; import type { Protocol } from './protocol'; import { rewriteErrorMessage } from '../../utils/stackTrace'; diff --git a/packages/playwright-core/src/server/firefox/ffPage.ts b/packages/playwright-core/src/server/firefox/ffPage.ts index b939c07ba0..e2df66f5bc 100644 --- a/packages/playwright-core/src/server/firefox/ffPage.ts +++ b/packages/playwright-core/src/server/firefox/ffPage.ts @@ -20,7 +20,7 @@ import * as dom from '../dom'; import type * as frames from '../frames'; import type { RegisteredListener } from '../../utils/eventsHelper'; import { eventsHelper } from '../../utils/eventsHelper'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import type { PageBinding, PageDelegate } from '../page'; import { Page, Worker } from '../page'; import type * as types from '../types'; diff --git a/packages/playwright-core/src/server/firefox/firefox.ts b/packages/playwright-core/src/server/firefox/firefox.ts index 361ede064a..a55d28750b 100644 --- a/packages/playwright-core/src/server/firefox/firefox.ts +++ b/packages/playwright-core/src/server/firefox/firefox.ts @@ -26,7 +26,7 @@ import type { ConnectionTransport } from '../transport'; import type { BrowserOptions, PlaywrightOptions } from '../browser'; import type * as types from '../types'; import { rewriteErrorMessage } from '../../utils/stackTrace'; -import { wrapInASCIIBox } from '../../utils/utils'; +import { wrapInASCIIBox } from '../../utils'; export class Firefox extends BrowserType { constructor(playwrightOptions: PlaywrightOptions) { diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.ts index c80b6fff02..ba8758c65b 100644 --- a/packages/playwright-core/src/server/frames.ts +++ b/packages/playwright-core/src/server/frames.ts @@ -29,7 +29,7 @@ import * as types from './types'; import { BrowserContext } from './browserContext'; import type { Progress } from './progress'; import { ProgressController } from './progress'; -import { assert, constructURLBasedOnBaseURL, makeWaitForNextTask } from '../utils/utils'; +import { assert, constructURLBasedOnBaseURL, makeWaitForNextTask } from '../utils'; import { ManualPromise } from '../utils'; import { debugLogger } from '../utils/debugLogger'; import type { CallMetadata } from './instrumentation'; diff --git a/packages/playwright-core/src/server/input.ts b/packages/playwright-core/src/server/input.ts index 422d723faf..d049099b00 100644 --- a/packages/playwright-core/src/server/input.ts +++ b/packages/playwright-core/src/server/input.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { assert } from '../utils/utils'; +import { assert } from '../utils'; import * as keyboardLayout from './usKeyboardLayout'; import type * as types from './types'; import type { Page } from './page'; diff --git a/packages/playwright-core/src/server/instrumentation.ts b/packages/playwright-core/src/server/instrumentation.ts index f2186696b6..b9d696f750 100644 --- a/packages/playwright-core/src/server/instrumentation.ts +++ b/packages/playwright-core/src/server/instrumentation.ts @@ -15,7 +15,7 @@ */ import { EventEmitter } from 'events'; -import { createGuid } from '../utils/utils'; +import { createGuid } from '../utils'; import type { APIRequestContext } from './fetch'; import type { Browser } from './browser'; import type { BrowserContext } from './browserContext'; diff --git a/packages/playwright-core/src/server/network.ts b/packages/playwright-core/src/server/network.ts index e85a743441..9d843f3ef6 100644 --- a/packages/playwright-core/src/server/network.ts +++ b/packages/playwright-core/src/server/network.ts @@ -17,7 +17,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 { assert } from '../utils'; import { ManualPromise } from '../utils'; import { SdkObject } from './instrumentation'; import type { NameValue } from '../common/types'; diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.ts index 7ecff6cf5b..3971f79a68 100644 --- a/packages/playwright-core/src/server/page.ts +++ b/packages/playwright-core/src/server/page.ts @@ -30,7 +30,7 @@ import * as accessibility from './accessibility'; import { FileChooser } from './fileChooser'; import type { Progress } from './progress'; import { ProgressController } from './progress'; -import { assert, isError } from '../utils/utils'; +import { assert, isError } from '../utils'; import { ManualPromise } from '../utils'; import { debugLogger } from '../utils/debugLogger'; import type { ImageComparatorOptions } from '../utils/comparators'; diff --git a/packages/playwright-core/src/server/pipeTransport.ts b/packages/playwright-core/src/server/pipeTransport.ts index a3e0384d06..55a4de057a 100644 --- a/packages/playwright-core/src/server/pipeTransport.ts +++ b/packages/playwright-core/src/server/pipeTransport.ts @@ -16,7 +16,7 @@ */ import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from './transport'; -import { makeWaitForNextTask } from '../utils/utils'; +import { makeWaitForNextTask } from '../utils'; import { debugLogger } from '../utils/debugLogger'; export class PipeTransport implements ConnectionTransport { diff --git a/packages/playwright-core/src/server/progress.ts b/packages/playwright-core/src/server/progress.ts index 1978c96d5c..1697ca7e21 100644 --- a/packages/playwright-core/src/server/progress.ts +++ b/packages/playwright-core/src/server/progress.ts @@ -15,7 +15,7 @@ */ import { TimeoutError } from '../utils/errors'; -import { assert, monotonicTime } from '../utils/utils'; +import { assert, monotonicTime } from '../utils'; import type { LogName } from '../utils/debugLogger'; import type { CallMetadata, Instrumentation, SdkObject } from './instrumentation'; import type { ElementHandle } from './dom'; diff --git a/packages/playwright-core/src/server/registry/browserFetcher.ts b/packages/playwright-core/src/server/registry/browserFetcher.ts index 8abce769e1..b2bdfbe0ba 100644 --- a/packages/playwright-core/src/server/registry/browserFetcher.ts +++ b/packages/playwright-core/src/server/registry/browserFetcher.ts @@ -19,7 +19,7 @@ import extract from 'extract-zip'; import fs from 'fs'; import os from 'os'; import path from 'path'; -import { existsAsync, getUserAgent } from '../../utils/utils'; +import { existsAsync, getUserAgent } from '../../utils'; import { debugLogger } from '../../utils/debugLogger'; import { download } from './download'; diff --git a/packages/playwright-core/src/server/registry/dependencies.ts b/packages/playwright-core/src/server/registry/dependencies.ts index 3ccaa79077..45585a9377 100644 --- a/packages/playwright-core/src/server/registry/dependencies.ts +++ b/packages/playwright-core/src/server/registry/dependencies.ts @@ -18,7 +18,7 @@ import fs from 'fs'; import path from 'path'; import * as os from 'os'; import childProcess from 'child_process'; -import * as utils from '../../utils/utils'; +import * as utils from '../../utils'; import { buildPlaywrightCLICommand } from '.'; import { deps } from './nativeDeps'; import { getUbuntuVersion } from '../../utils/ubuntuVersion'; diff --git a/packages/playwright-core/src/server/registry/index.ts b/packages/playwright-core/src/server/registry/index.ts index a7e91890f2..5bb1e4d79c 100644 --- a/packages/playwright-core/src/server/registry/index.ts +++ b/packages/playwright-core/src/server/registry/index.ts @@ -22,7 +22,7 @@ import * as fs from 'fs'; import lockfile from 'proper-lockfile'; import { getUbuntuVersion } from '../../utils/ubuntuVersion'; import { fetchData } from '../../utils'; -import { getFromENV, getAsBooleanFromENV, getClientLanguage, calculateSha1, removeFolders, existsAsync, hostPlatform, canAccessFile, spawnAsync, wrapInASCIIBox, transformCommandsForRoot } from '../../utils/utils'; +import { getFromENV, getAsBooleanFromENV, getClientLanguage, calculateSha1, removeFolders, existsAsync, hostPlatform, canAccessFile, spawnAsync, wrapInASCIIBox, transformCommandsForRoot } from '../../utils'; import type { DependencyGroup } from './dependencies'; import { installDependenciesLinux, installDependenciesWindows, validateDependenciesLinux, validateDependenciesWindows } from './dependencies'; import { downloadBrowserWithProgressBar, logPolitely } from './browserFetcher'; diff --git a/packages/playwright-core/src/server/screenshotter.ts b/packages/playwright-core/src/server/screenshotter.ts index 3228a06448..65f1993efe 100644 --- a/packages/playwright-core/src/server/screenshotter.ts +++ b/packages/playwright-core/src/server/screenshotter.ts @@ -23,7 +23,7 @@ import type { Frame } from './frames'; import type { ParsedSelector } from './common/selectorParser'; import type * as types from './types'; import type { Progress } from './progress'; -import { assert } from '../utils/utils'; +import { assert } from '../utils'; import { MultiMap } from '../utils'; declare global { diff --git a/packages/playwright-core/src/server/selectors.ts b/packages/playwright-core/src/server/selectors.ts index dbcfde373a..90c4f4d4b7 100644 --- a/packages/playwright-core/src/server/selectors.ts +++ b/packages/playwright-core/src/server/selectors.ts @@ -20,7 +20,7 @@ import type * as js from './javascript'; import type * as types from './types'; import type { ParsedSelector } from './common/selectorParser'; import { allEngineNames, InvalidSelectorError, parseSelector, stringifySelector } from './common/selectorParser'; -import { createGuid, experimentalFeaturesEnabled } from '../utils/utils'; +import { createGuid, experimentalFeaturesEnabled } from '../utils'; export type SelectorInfo = { parsed: ParsedSelector, diff --git a/packages/playwright-core/src/server/supplements/debugger.ts b/packages/playwright-core/src/server/supplements/debugger.ts index d56fa5d1fd..ce6eef4b3e 100644 --- a/packages/playwright-core/src/server/supplements/debugger.ts +++ b/packages/playwright-core/src/server/supplements/debugger.ts @@ -15,7 +15,7 @@ */ import { EventEmitter } from 'events'; -import { debugMode, isUnderTest, monotonicTime } from '../../utils/utils'; +import { debugMode, isUnderTest, monotonicTime } from '../../utils'; import type { BrowserContext } from '../browserContext'; import type { CallMetadata, InstrumentationListener, SdkObject } from '../instrumentation'; import { commandsWithTracingSnapshots, pausesBeforeInputActions } from '../../protocol/channels'; diff --git a/packages/playwright-core/src/server/supplements/har/harTracer.ts b/packages/playwright-core/src/server/supplements/har/harTracer.ts index 47b23d5394..08dc65b997 100644 --- a/packages/playwright-core/src/server/supplements/har/harTracer.ts +++ b/packages/playwright-core/src/server/supplements/har/harTracer.ts @@ -21,7 +21,7 @@ import { helper } from '../../helper'; import * as network from '../../network'; import { Page } from '../../page'; import type * as har from './har'; -import { calculateSha1, monotonicTime } from '../../../utils/utils'; +import { calculateSha1, monotonicTime } from '../../../utils'; import type { RegisteredListener } from '../../../utils/eventsHelper'; import { eventsHelper } from '../../../utils/eventsHelper'; import * as mime from 'mime'; diff --git a/packages/playwright-core/src/server/supplements/recorder/recorderApp.ts b/packages/playwright-core/src/server/supplements/recorder/recorderApp.ts index 41c70e3d60..7a22cb7a7e 100644 --- a/packages/playwright-core/src/server/supplements/recorder/recorderApp.ts +++ b/packages/playwright-core/src/server/supplements/recorder/recorderApp.ts @@ -21,7 +21,7 @@ import { ProgressController } from '../../progress'; import { EventEmitter } from 'events'; import { serverSideCallMetadata } from '../../instrumentation'; import type { CallLog, EventData, Mode, Source } from './recorderTypes'; -import { isUnderTest } from '../../../utils/utils'; +import { isUnderTest } from '../../../utils'; import * as mime from 'mime'; import { installAppIcon } from '../../chromium/crApp'; import { findChromiumChannel } from '../../registry'; diff --git a/packages/playwright-core/src/server/supplements/recorderSupplement.ts b/packages/playwright-core/src/server/supplements/recorderSupplement.ts index 7e00a7007a..a8988444b6 100644 --- a/packages/playwright-core/src/server/supplements/recorderSupplement.ts +++ b/packages/playwright-core/src/server/supplements/recorderSupplement.ts @@ -34,7 +34,7 @@ import { RecorderApp } from './recorder/recorderApp'; import type { CallMetadata, InstrumentationListener, SdkObject } from '../instrumentation'; import type { Point } from '../../common/types'; import type { CallLog, CallLogStatus, EventData, Mode, Source, UIState } from './recorder/recorderTypes'; -import { createGuid, monotonicTime } from '../../utils/utils'; +import { createGuid, monotonicTime } from '../../utils'; import { metadataToCallLog } from './recorder/recorderUtils'; import { Debugger } from './debugger'; import { EventEmitter } from 'events'; diff --git a/packages/playwright-core/src/server/trace/recorder/snapshotter.ts b/packages/playwright-core/src/server/trace/recorder/snapshotter.ts index 9f7ca1f90b..4b47b567bd 100644 --- a/packages/playwright-core/src/server/trace/recorder/snapshotter.ts +++ b/packages/playwright-core/src/server/trace/recorder/snapshotter.ts @@ -22,7 +22,7 @@ import { debugLogger } from '../../../utils/debugLogger'; import type { Frame } from '../../frames'; import type { SnapshotData } from './snapshotterInjected'; import { frameSnapshotStreamer } from './snapshotterInjected'; -import { calculateSha1, createGuid, monotonicTime } from '../../../utils/utils'; +import { calculateSha1, createGuid, monotonicTime } from '../../../utils'; import type { FrameSnapshot } from '../common/snapshotTypes'; import type { ElementHandle } from '../../dom'; import * as mime from 'mime'; diff --git a/packages/playwright-core/src/server/trace/recorder/tracing.ts b/packages/playwright-core/src/server/trace/recorder/tracing.ts index ac47e871e0..930d78ad06 100644 --- a/packages/playwright-core/src/server/trace/recorder/tracing.ts +++ b/packages/playwright-core/src/server/trace/recorder/tracing.ts @@ -25,7 +25,7 @@ import { commandsWithTracingSnapshots } from '../../../protocol/channels'; 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'; +import { assert, calculateSha1, createGuid, mkdirIfNeeded, monotonicTime, removeFolders } from '../../../utils'; import { Artifact } from '../../artifact'; import { BrowserContext } from '../../browserContext'; import { ElementHandle } from '../../dom'; diff --git a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts index 1c28d5e6e4..95f1f73ff4 100644 --- a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts +++ b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts @@ -19,7 +19,7 @@ import fs from 'fs'; import * as consoleApiSource from '../../../generated/consoleApiSource'; import { HttpServer } from '../../../utils/httpServer'; import { findChromiumChannel } from '../../registry'; -import { isUnderTest } from '../../../utils/utils'; +import { isUnderTest } from '../../../utils'; import type { BrowserContext } from '../../browserContext'; import { installAppIcon } from '../../chromium/crApp'; import { serverSideCallMetadata } from '../../instrumentation'; diff --git a/packages/playwright-core/src/server/transport.ts b/packages/playwright-core/src/server/transport.ts index 5e6bf8f94a..a57f3bb39c 100644 --- a/packages/playwright-core/src/server/transport.ts +++ b/packages/playwright-core/src/server/transport.ts @@ -17,7 +17,7 @@ import WebSocket from 'ws'; import type { Progress } from './progress'; -import { makeWaitForNextTask } from '../utils/utils'; +import { makeWaitForNextTask } from '../utils'; export type ProtocolRequest = { id: number; diff --git a/packages/playwright-core/src/server/webkit/webkit.ts b/packages/playwright-core/src/server/webkit/webkit.ts index a5ac94d958..861da13d86 100644 --- a/packages/playwright-core/src/server/webkit/webkit.ts +++ b/packages/playwright-core/src/server/webkit/webkit.ts @@ -24,7 +24,7 @@ import type { ConnectionTransport } from '../transport'; import type { BrowserOptions, PlaywrightOptions } from '../browser'; import type * as types from '../types'; import { rewriteErrorMessage } from '../../utils/stackTrace'; -import { wrapInASCIIBox } from '../../utils/utils'; +import { wrapInASCIIBox } from '../../utils'; export class WebKit extends BrowserType { constructor(playwrightOptions: PlaywrightOptions) { diff --git a/packages/playwright-core/src/server/webkit/wkBrowser.ts b/packages/playwright-core/src/server/webkit/wkBrowser.ts index d54ffd2fee..52de427cf1 100644 --- a/packages/playwright-core/src/server/webkit/wkBrowser.ts +++ b/packages/playwright-core/src/server/webkit/wkBrowser.ts @@ -20,7 +20,7 @@ import { Browser } from '../browser'; import { assertBrowserContextIsNotOwned, BrowserContext, verifyGeolocation } from '../browserContext'; import type { RegisteredListener } from '../../utils/eventsHelper'; import { eventsHelper } from '../../utils/eventsHelper'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import * as network from '../network'; import type { Page, PageBinding, PageDelegate } from '../page'; import type { ConnectionTransport } from '../transport'; diff --git a/packages/playwright-core/src/server/webkit/wkConnection.ts b/packages/playwright-core/src/server/webkit/wkConnection.ts index 7f8337fd11..1fe8dd66fd 100644 --- a/packages/playwright-core/src/server/webkit/wkConnection.ts +++ b/packages/playwright-core/src/server/webkit/wkConnection.ts @@ -16,7 +16,7 @@ */ import { EventEmitter } from 'events'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport'; import type { Protocol } from './protocol'; import { rewriteErrorMessage } from '../../utils/stackTrace'; diff --git a/packages/playwright-core/src/server/webkit/wkInput.ts b/packages/playwright-core/src/server/webkit/wkInput.ts index 5d0550ac1a..a0b7c3fce7 100644 --- a/packages/playwright-core/src/server/webkit/wkInput.ts +++ b/packages/playwright-core/src/server/webkit/wkInput.ts @@ -19,7 +19,7 @@ import * as input from '../input'; import type * as types from '../types'; import { macEditingCommands } from '../macEditingCommands'; import type { WKSession } from './wkConnection'; -import { isString } from '../../utils/utils'; +import { isString } from '../../utils'; import type { Page } from '../page'; function toModifiersMask(modifiers: Set): number { diff --git a/packages/playwright-core/src/server/webkit/wkInterceptableRequest.ts b/packages/playwright-core/src/server/webkit/wkInterceptableRequest.ts index de1eade0f8..3500f3ae9d 100644 --- a/packages/playwright-core/src/server/webkit/wkInterceptableRequest.ts +++ b/packages/playwright-core/src/server/webkit/wkInterceptableRequest.ts @@ -20,7 +20,7 @@ import * as network from '../network'; import type * as types from '../types'; import type { Protocol } from './protocol'; import type { WKSession } from './wkConnection'; -import { assert, headersObjectToArray, headersArrayToObject } from '../../utils/utils'; +import { assert, headersObjectToArray, headersArrayToObject } from '../../utils'; import { ManualPromise } from '../../utils'; const errorReasons: { [reason: string]: Protocol.Network.ResourceErrorType } = { diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts index 7f96f0be47..d7fff3b31e 100644 --- a/packages/playwright-core/src/server/webkit/wkPage.ts +++ b/packages/playwright-core/src/server/webkit/wkPage.ts @@ -19,7 +19,7 @@ import * as jpeg from 'jpeg-js'; import path from 'path'; import * as png from 'pngjs'; import { splitErrorMessage } from '../../utils/stackTrace'; -import { assert, createGuid, debugAssert, headersArrayToObject, headersObjectToArray, hostPlatform } from '../../utils/utils'; +import { assert, createGuid, debugAssert, headersArrayToObject, headersObjectToArray, hostPlatform } from '../../utils'; import type * as accessibility from '../accessibility'; import * as dialog from '../dialog'; import * as dom from '../dom'; diff --git a/packages/playwright-core/src/server/webkit/wkProvisionalPage.ts b/packages/playwright-core/src/server/webkit/wkProvisionalPage.ts index c41ece8c29..aa6c06e57d 100644 --- a/packages/playwright-core/src/server/webkit/wkProvisionalPage.ts +++ b/packages/playwright-core/src/server/webkit/wkProvisionalPage.ts @@ -19,7 +19,7 @@ import type { WKPage } from './wkPage'; import type { RegisteredListener } from '../../utils/eventsHelper'; import { eventsHelper } from '../../utils/eventsHelper'; import type { Protocol } from './protocol'; -import { assert } from '../../utils/utils'; +import { assert } from '../../utils'; export class WKProvisionalPage { readonly _session: WKSession; diff --git a/packages/playwright-core/src/utils/DEPS.list b/packages/playwright-core/src/utils/DEPS.list index 691f291065..dec0c0933d 100644 --- a/packages/playwright-core/src/utils/DEPS.list +++ b/packages/playwright-core/src/utils/DEPS.list @@ -1,2 +1,3 @@ [*] +./ ../third_party/diff_match_patch diff --git a/packages/playwright-core/src/utils/httpServer.ts b/packages/playwright-core/src/utils/httpServer.ts index fe6ffdee93..d413fec142 100644 --- a/packages/playwright-core/src/utils/httpServer.ts +++ b/packages/playwright-core/src/utils/httpServer.ts @@ -19,7 +19,7 @@ import fs from 'fs'; import path from 'path'; import { Server as WebSocketServer } from 'ws'; import * as mime from 'mime'; -import { assert } from './utils'; +import { assert } from './'; export type ServerRouteHandler = (request: http.IncomingMessage, response: http.ServerResponse) => boolean; diff --git a/packages/playwright-core/src/utils/index.ts b/packages/playwright-core/src/utils/index.ts index 635ed232dc..05b6fae351 100644 --- a/packages/playwright-core/src/utils/index.ts +++ b/packages/playwright-core/src/utils/index.ts @@ -14,8 +14,415 @@ * limitations under the License. */ +import type { SpawnOptions } from 'child_process'; +import { execSync, spawn } from 'child_process'; +import * as crypto from 'crypto'; +import fs from 'fs'; +import os from 'os'; +import path from 'path'; +import removeFolder from 'rimraf'; +import type stream from 'stream'; +import * as URL from 'url'; +import type { NameValue } from '../protocol/channels'; +import { getUbuntuVersionSync, parseOSReleaseText } from './ubuntuVersion'; + export { ManualPromise } from './manualPromise'; export { MultiMap } from './multimap'; export { raceAgainstTimeout, TimeoutRunner, TimeoutRunnerError } from './timeoutRunner'; export type { HTTPRequestParams } from './netUtils'; export { httpRequest, fetchData } from './netUtils'; + +export const existsAsync = (path: string): Promise => new Promise(resolve => fs.stat(path, err => resolve(!err))); + +export function spawnAsync(cmd: string, args: string[], options: SpawnOptions = {}): Promise<{stdout: string, stderr: string, code: number | null, error?: Error}> { + const process = spawn(cmd, args, Object.assign({ windowsHide: true }, options)); + + return new Promise(resolve => { + let stdout = ''; + let stderr = ''; + if (process.stdout) + process.stdout.on('data', data => stdout += data); + if (process.stderr) + process.stderr.on('data', data => stderr += data); + process.on('close', code => resolve({ stdout, stderr, code })); + process.on('error', error => resolve({ stdout, stderr, code: 0, error })); + }); +} + +// See https://joel.tools/microtasks/ +export function makeWaitForNextTask() { + // As of Mar 2021, Electron v12 doesn't create new task with `setImmediate` despite + // using Node 14 internally, so we fallback to `setTimeout(0)` instead. + // @see https://github.com/electron/electron/issues/28261 + if ((process.versions as any).electron) + return (callback: () => void) => setTimeout(callback, 0); + if (parseInt(process.versions.node, 10) >= 11) + return setImmediate; + + // Unlike Node 11, Node 10 and less have a bug with Task and MicroTask execution order: + // - https://github.com/nodejs/node/issues/22257 + // + // So we can't simply run setImmediate to dispatch code in a following task. + // However, we can run setImmediate from-inside setImmediate to make sure we're getting + // in the following task. + + let spinning = false; + const callbacks: (() => void)[] = []; + const loop = () => { + const callback = callbacks.shift(); + if (!callback) { + spinning = false; + return; + } + setImmediate(loop); + // Make sure to call callback() as the last thing since it's + // untrusted code that might throw. + callback(); + }; + + return (callback: () => void) => { + callbacks.push(callback); + if (!spinning) { + spinning = true; + setImmediate(loop); + } + }; +} + +export function assert(value: any, message?: string): asserts value { + if (!value) + throw new Error(message || 'Assertion error'); +} + +export function debugAssert(value: any, message?: string): asserts value { + if (isUnderTest() && !value) + throw new Error(message); +} + +export function isString(obj: any): obj is string { + return typeof obj === 'string' || obj instanceof String; +} + +export function isRegExp(obj: any): obj is RegExp { + return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]'; +} + +export function isObject(obj: any): obj is NonNullable { + return typeof obj === 'object' && obj !== null; +} + +export function isError(obj: any): obj is Error { + return obj instanceof Error || (obj && obj.__proto__ && obj.__proto__.name === 'Error'); +} + +const debugEnv = getFromENV('PWDEBUG') || ''; +export function debugMode() { + if (debugEnv === 'console') + return 'console'; + if (debugEnv === '0' || debugEnv === 'false') + return ''; + return debugEnv ? 'inspector' : ''; +} + +let _isUnderTest = false; +export function setUnderTest() { + _isUnderTest = true; +} +export function isUnderTest(): boolean { + return _isUnderTest; +} + +export function experimentalFeaturesEnabled() { + return isUnderTest() || !!process.env.PLAYWRIGHT_EXPERIMENTAL_FEATURES; +} + +export function getFromENV(name: string): string | undefined { + let value = process.env[name]; + value = value === undefined ? process.env[`npm_config_${name.toLowerCase()}`] : value; + value = value === undefined ? process.env[`npm_package_config_${name.toLowerCase()}`] : value; + return value; +} + +export function getAsBooleanFromENV(name: string): boolean { + const value = getFromENV(name); + return !!value && value !== 'false' && value !== '0'; +} + +export async function mkdirIfNeeded(filePath: string) { + // This will harmlessly throw on windows if the dirname is the root directory. + await fs.promises.mkdir(path.dirname(filePath), { recursive: true }).catch(() => {}); +} + +type HeadersArray = { name: string, value: string }[]; +type HeadersObject = { [key: string]: string }; + +export function headersObjectToArray(headers: HeadersObject, separator?: string, setCookieSeparator?: string): HeadersArray { + if (!setCookieSeparator) + setCookieSeparator = separator; + const result: HeadersArray = []; + for (const name in headers) { + const values = headers[name]; + if (separator) { + const sep = name.toLowerCase() === 'set-cookie' ? setCookieSeparator : separator; + for (const value of values.split(sep!)) + result.push({ name, value: value.trim() }); + } else { + result.push({ name, value: values }); + } + } + return result; +} + +export function headersArrayToObject(headers: HeadersArray, lowerCase: boolean): HeadersObject { + const result: HeadersObject = {}; + for (const { name, value } of headers) + result[lowerCase ? name.toLowerCase() : name] = value; + return result; +} + +export function monotonicTime(): number { + const [seconds, nanoseconds] = process.hrtime(); + return seconds * 1000 + (nanoseconds / 1000 | 0) / 1000; +} + +export function objectToArray(map?: { [key: string]: any }): NameValue[] | undefined { + if (!map) + return undefined; + const result = []; + for (const [name, value] of Object.entries(map)) + result.push({ name, value: String(value) }); + return result; +} + +export function arrayToObject(array?: NameValue[]): { [key: string]: string } | undefined { + if (!array) + return undefined; + const result: { [key: string]: string } = {}; + for (const { name, value } of array) + result[name] = value; + return result; +} + +export function calculateSha1(buffer: Buffer | string): string { + const hash = crypto.createHash('sha1'); + hash.update(buffer); + return hash.digest('hex'); +} + +export function createGuid(): string { + return crypto.randomBytes(16).toString('hex'); +} + +export async function removeFolders(dirs: string[]): Promise> { + return await Promise.all(dirs.map((dir: string) => { + return new Promise(fulfill => { + removeFolder(dir, { maxBusyTries: 10 }, error => { + fulfill(error ?? undefined); + }); + }); + })); +} + +export function canAccessFile(file: string) { + if (!file) + return false; + + try { + fs.accessSync(file); + return true; + } catch (e) { + return false; + } +} + +let cachedUserAgent: string | undefined; +export function getUserAgent(): string { + if (cachedUserAgent) + return cachedUserAgent; + try { + cachedUserAgent = determineUserAgent(); + } catch (e) { + cachedUserAgent = 'Playwright/unknown'; + } + return cachedUserAgent; +} + +function determineUserAgent(): string { + let osIdentifier = 'unknown'; + let osVersion = 'unknown'; + if (process.platform === 'win32') { + const version = os.release().split('.'); + osIdentifier = 'windows'; + osVersion = `${version[0]}.${version[1]}`; + } else if (process.platform === 'darwin') { + const version = execSync('sw_vers -productVersion', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim().split('.'); + osIdentifier = 'macOS'; + osVersion = `${version[0]}.${version[1]}`; + } else if (process.platform === 'linux') { + try { + // List of /etc/os-release values for different distributions could be + // found here: https://gist.github.com/aslushnikov/8ceddb8288e4cf9db3039c02e0f4fb75 + const osReleaseText = fs.readFileSync('/etc/os-release', 'utf8'); + const fields = parseOSReleaseText(osReleaseText); + osIdentifier = fields.get('id') || 'unknown'; + osVersion = fields.get('version_id') || 'unknown'; + } catch (e) { + // Linux distribution without /etc/os-release. + // Default to linux/unknown. + osIdentifier = 'linux'; + } + } + + const { langName, langVersion } = getClientLanguage(); + return `Playwright/${getPlaywrightVersion()} (${os.arch()}; ${osIdentifier} ${osVersion}) ${langName}/${langVersion}`; +} + +export function getClientLanguage(): { langName: string, langVersion: string } { + let langName = 'unknown'; + let langVersion = 'unknown'; + if (!process.env.PW_LANG_NAME) { + langName = 'node'; + langVersion = process.version.substring(1).split('.').slice(0, 2).join('.'); + } else if (['node', 'python', 'java', 'csharp'].includes(process.env.PW_LANG_NAME)) { + langName = process.env.PW_LANG_NAME; + langVersion = process.env.PW_LANG_NAME_VERSION ?? 'unknown'; + } + return { langName, langVersion }; +} + +export function getPlaywrightVersion(majorMinorOnly = false) { + const packageJson = require('./../../package.json'); + return majorMinorOnly ? packageJson.version.split('.').slice(0, 2).join('.') : packageJson.version; +} + +export function constructURLBasedOnBaseURL(baseURL: string | undefined, givenURL: string): string { + try { + return (new URL.URL(givenURL, baseURL)).toString(); + } catch (e) { + return givenURL; + } +} + +export type HostPlatform = 'win64' | + 'mac10.13' | + 'mac10.14' | + 'mac10.15' | + 'mac11' | 'mac11-arm64' | + 'mac12' | 'mac12-arm64' | + 'ubuntu18.04' | 'ubuntu18.04-arm64' | + 'ubuntu20.04' | 'ubuntu20.04-arm64' | + 'generic-linux' | 'generic-linux-arm64' | + ''; + +export const hostPlatform = ((): HostPlatform => { + const platform = os.platform(); + if (platform === 'darwin') { + const ver = os.release().split('.').map((a: string) => parseInt(a, 10)); + let macVersion = ''; + if (ver[0] < 18) { + // Everything before 10.14 is considered 10.13. + macVersion = 'mac10.13'; + } else if (ver[0] === 18) { + macVersion = 'mac10.14'; + } else if (ver[0] === 19) { + macVersion = 'mac10.15'; + } else { + // ver[0] >= 20 + const LAST_STABLE_MAC_MAJOR_VERSION = 12; + // Best-effort support for MacOS beta versions. + macVersion = 'mac' + Math.min(ver[0] - 9, LAST_STABLE_MAC_MAJOR_VERSION); + // BigSur is the first version that might run on Apple Silicon. + if (os.cpus().some(cpu => cpu.model.includes('Apple'))) + macVersion += '-arm64'; + } + return macVersion as HostPlatform; + } + if (platform === 'linux') { + const archSuffix = os.arch() === 'arm64' ? '-arm64' : ''; + const ubuntuVersion = getUbuntuVersionSync(); + if (!ubuntuVersion) + return ('generic-linux' + archSuffix) as HostPlatform; + if (parseInt(ubuntuVersion, 10) <= 19) + return ('ubuntu18.04' + archSuffix) as HostPlatform; + return ('ubuntu20.04' + archSuffix) as HostPlatform; + } + if (platform === 'win32') + return 'win64'; + return ''; +})(); + +export function wrapInASCIIBox(text: string, padding = 0): string { + const lines = text.split('\n'); + const maxLength = Math.max(...lines.map(line => line.length)); + return [ + '╔' + '═'.repeat(maxLength + padding * 2) + '╗', + ...lines.map(line => '║' + ' '.repeat(padding) + line + ' '.repeat(maxLength - line.length + padding) + '║'), + '╚' + '═'.repeat(maxLength + padding * 2) + '╝', + ].join('\n'); +} + +export function isFilePayload(value: any): boolean { + return typeof value === 'object' && value['name'] && value['mimeType'] && value['buffer']; +} + +export function streamToString(stream: stream.Readable): Promise { + return new Promise((resolve, reject) => { + const chunks: Buffer[] = []; + stream.on('data', chunk => chunks.push(Buffer.from(chunk))); + stream.on('error', reject); + stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); + }); +} + +export async function transformCommandsForRoot(commands: string[]): Promise<{ command: string, args: string[], elevatedPermissions: boolean}> { + const isRoot = process.getuid() === 0; + if (isRoot) + return { command: 'sh', args: ['-c', `${commands.join('&& ')}`], elevatedPermissions: false }; + const sudoExists = await spawnAsync('which', ['sudo']); + if (sudoExists.code === 0) + return { command: 'sudo', args: ['--', 'sh', '-c', `${commands.join('&& ')}`], elevatedPermissions: true }; + return { command: 'su', args: ['root', '-c', `${commands.join('&& ')}`], elevatedPermissions: true }; +} + +export class SigIntWatcher { + private _hadSignal: boolean = false; + private _sigintPromise: Promise; + private _sigintHandler: () => void; + constructor() { + let sigintCallback: () => void; + this._sigintPromise = new Promise(f => sigintCallback = f); + this._sigintHandler = () => { + // We remove the handler so that second Ctrl+C immediately kills the runner + // via the default sigint handler. This is handy in the case where our shutdown + // takes a lot of time or is buggy. + // + // When running through NPM we might get multiple SIGINT signals + // for a single Ctrl+C - this is an NPM bug present since at least NPM v6. + // https://github.com/npm/cli/issues/1591 + // https://github.com/npm/cli/issues/2124 + // + // Therefore, removing the handler too soon will just kill the process + // with default handler without printing the results. + // We work around this by giving NPM 1000ms to send us duplicate signals. + // The side effect is that slow shutdown or bug in our runner will force + // the user to hit Ctrl+C again after at least a second. + setTimeout(() => process.off('SIGINT', this._sigintHandler), 1000); + this._hadSignal = true; + sigintCallback(); + }; + process.on('SIGINT', this._sigintHandler); + } + + promise(): Promise { + return this._sigintPromise; + } + + hadSignal(): boolean { + return this._hadSignal; + } + + disarm() { + process.off('SIGINT', this._sigintHandler); + } +} + diff --git a/packages/playwright-core/src/utils/processLauncher.ts b/packages/playwright-core/src/utils/processLauncher.ts index 79dc2e8d4a..057ec81364 100644 --- a/packages/playwright-core/src/utils/processLauncher.ts +++ b/packages/playwright-core/src/utils/processLauncher.ts @@ -18,7 +18,7 @@ import * as childProcess from 'child_process'; import * as readline from 'readline'; import { eventsHelper } from './eventsHelper'; -import { isUnderTest, removeFolders } from './utils'; +import { isUnderTest, removeFolders } from './'; import rimraf from 'rimraf'; export type Env = {[key: string]: string | number | boolean | undefined}; diff --git a/packages/playwright-core/src/utils/socksProxy.ts b/packages/playwright-core/src/utils/socksProxy.ts index 245f04c650..4ef0474109 100644 --- a/packages/playwright-core/src/utils/socksProxy.ts +++ b/packages/playwright-core/src/utils/socksProxy.ts @@ -21,7 +21,7 @@ import net from 'net'; import util from 'util'; import { debugLogger } from './debugLogger'; import { createSocket } from './netUtils'; -import { assert, createGuid } from './utils'; +import { assert, createGuid } from './'; const dnsLookupAsync = util.promisify(dns.lookup); diff --git a/packages/playwright-core/src/utils/stackTrace.ts b/packages/playwright-core/src/utils/stackTrace.ts index 7042b4758e..4a2be30ffb 100644 --- a/packages/playwright-core/src/utils/stackTrace.ts +++ b/packages/playwright-core/src/utils/stackTrace.ts @@ -17,7 +17,7 @@ import path from 'path'; import type { StackFrame } from '../protocol/channels'; import StackUtils from 'stack-utils'; -import { isUnderTest } from './utils'; +import { isUnderTest } from './'; const stackUtils = new StackUtils(); diff --git a/packages/playwright-core/src/utils/timeoutRunner.ts b/packages/playwright-core/src/utils/timeoutRunner.ts index 4da10e7c44..c1a848caba 100644 --- a/packages/playwright-core/src/utils/timeoutRunner.ts +++ b/packages/playwright-core/src/utils/timeoutRunner.ts @@ -15,7 +15,7 @@ */ import { ManualPromise } from './manualPromise'; -import { monotonicTime } from './utils'; +import { monotonicTime } from './'; export class TimeoutRunnerError extends Error {} diff --git a/packages/playwright-core/src/utils/timeoutSettings.ts b/packages/playwright-core/src/utils/timeoutSettings.ts index 6b25f3975f..57b58df1fc 100644 --- a/packages/playwright-core/src/utils/timeoutSettings.ts +++ b/packages/playwright-core/src/utils/timeoutSettings.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { debugMode } from './utils'; +import { debugMode } from './'; export const DEFAULT_TIMEOUT = 30000; diff --git a/packages/playwright-core/src/utils/utils.ts b/packages/playwright-core/src/utils/utils.ts deleted file mode 100644 index 8a69c99fc7..0000000000 --- a/packages/playwright-core/src/utils/utils.ts +++ /dev/null @@ -1,422 +0,0 @@ -/** - * 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. - */ - -import type { SpawnOptions } from 'child_process'; -import { execSync, spawn } from 'child_process'; -import * as crypto from 'crypto'; -import fs from 'fs'; -import os from 'os'; -import path from 'path'; -import removeFolder from 'rimraf'; -import type stream from 'stream'; -import * as URL from 'url'; -import type { NameValue } from '../protocol/channels'; -import { getUbuntuVersionSync, parseOSReleaseText } from './ubuntuVersion'; - -export const existsAsync = (path: string): Promise => new Promise(resolve => fs.stat(path, err => resolve(!err))); - -export function spawnAsync(cmd: string, args: string[], options: SpawnOptions = {}): Promise<{stdout: string, stderr: string, code: number | null, error?: Error}> { - const process = spawn(cmd, args, Object.assign({ windowsHide: true }, options)); - - return new Promise(resolve => { - let stdout = ''; - let stderr = ''; - if (process.stdout) - process.stdout.on('data', data => stdout += data); - if (process.stderr) - process.stderr.on('data', data => stderr += data); - process.on('close', code => resolve({ stdout, stderr, code })); - process.on('error', error => resolve({ stdout, stderr, code: 0, error })); - }); -} - -// See https://joel.tools/microtasks/ -export function makeWaitForNextTask() { - // As of Mar 2021, Electron v12 doesn't create new task with `setImmediate` despite - // using Node 14 internally, so we fallback to `setTimeout(0)` instead. - // @see https://github.com/electron/electron/issues/28261 - if ((process.versions as any).electron) - return (callback: () => void) => setTimeout(callback, 0); - if (parseInt(process.versions.node, 10) >= 11) - return setImmediate; - - // Unlike Node 11, Node 10 and less have a bug with Task and MicroTask execution order: - // - https://github.com/nodejs/node/issues/22257 - // - // So we can't simply run setImmediate to dispatch code in a following task. - // However, we can run setImmediate from-inside setImmediate to make sure we're getting - // in the following task. - - let spinning = false; - const callbacks: (() => void)[] = []; - const loop = () => { - const callback = callbacks.shift(); - if (!callback) { - spinning = false; - return; - } - setImmediate(loop); - // Make sure to call callback() as the last thing since it's - // untrusted code that might throw. - callback(); - }; - - return (callback: () => void) => { - callbacks.push(callback); - if (!spinning) { - spinning = true; - setImmediate(loop); - } - }; -} - -export function assert(value: any, message?: string): asserts value { - if (!value) - throw new Error(message || 'Assertion error'); -} - -export function debugAssert(value: any, message?: string): asserts value { - if (isUnderTest() && !value) - throw new Error(message); -} - -export function isString(obj: any): obj is string { - return typeof obj === 'string' || obj instanceof String; -} - -export function isRegExp(obj: any): obj is RegExp { - return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]'; -} - -export function isObject(obj: any): obj is NonNullable { - return typeof obj === 'object' && obj !== null; -} - -export function isError(obj: any): obj is Error { - return obj instanceof Error || (obj && obj.__proto__ && obj.__proto__.name === 'Error'); -} - -const debugEnv = getFromENV('PWDEBUG') || ''; -export function debugMode() { - if (debugEnv === 'console') - return 'console'; - if (debugEnv === '0' || debugEnv === 'false') - return ''; - return debugEnv ? 'inspector' : ''; -} - -let _isUnderTest = false; -export function setUnderTest() { - _isUnderTest = true; -} -export function isUnderTest(): boolean { - return _isUnderTest; -} - -export function experimentalFeaturesEnabled() { - return isUnderTest() || !!process.env.PLAYWRIGHT_EXPERIMENTAL_FEATURES; -} - -export function getFromENV(name: string): string | undefined { - let value = process.env[name]; - value = value === undefined ? process.env[`npm_config_${name.toLowerCase()}`] : value; - value = value === undefined ? process.env[`npm_package_config_${name.toLowerCase()}`] : value; - return value; -} - -export function getAsBooleanFromENV(name: string): boolean { - const value = getFromENV(name); - return !!value && value !== 'false' && value !== '0'; -} - -export async function mkdirIfNeeded(filePath: string) { - // This will harmlessly throw on windows if the dirname is the root directory. - await fs.promises.mkdir(path.dirname(filePath), { recursive: true }).catch(() => {}); -} - -type HeadersArray = { name: string, value: string }[]; -type HeadersObject = { [key: string]: string }; - -export function headersObjectToArray(headers: HeadersObject, separator?: string, setCookieSeparator?: string): HeadersArray { - if (!setCookieSeparator) - setCookieSeparator = separator; - const result: HeadersArray = []; - for (const name in headers) { - const values = headers[name]; - if (separator) { - const sep = name.toLowerCase() === 'set-cookie' ? setCookieSeparator : separator; - for (const value of values.split(sep!)) - result.push({ name, value: value.trim() }); - } else { - result.push({ name, value: values }); - } - } - return result; -} - -export function headersArrayToObject(headers: HeadersArray, lowerCase: boolean): HeadersObject { - const result: HeadersObject = {}; - for (const { name, value } of headers) - result[lowerCase ? name.toLowerCase() : name] = value; - return result; -} - -export function monotonicTime(): number { - const [seconds, nanoseconds] = process.hrtime(); - return seconds * 1000 + (nanoseconds / 1000 | 0) / 1000; -} - -export function objectToArray(map?: { [key: string]: any }): NameValue[] | undefined { - if (!map) - return undefined; - const result = []; - for (const [name, value] of Object.entries(map)) - result.push({ name, value: String(value) }); - return result; -} - -export function arrayToObject(array?: NameValue[]): { [key: string]: string } | undefined { - if (!array) - return undefined; - const result: { [key: string]: string } = {}; - for (const { name, value } of array) - result[name] = value; - return result; -} - -export function calculateSha1(buffer: Buffer | string): string { - const hash = crypto.createHash('sha1'); - hash.update(buffer); - return hash.digest('hex'); -} - -export function createGuid(): string { - return crypto.randomBytes(16).toString('hex'); -} - -export async function removeFolders(dirs: string[]): Promise> { - return await Promise.all(dirs.map((dir: string) => { - return new Promise(fulfill => { - removeFolder(dir, { maxBusyTries: 10 }, error => { - fulfill(error ?? undefined); - }); - }); - })); -} - -export function canAccessFile(file: string) { - if (!file) - return false; - - try { - fs.accessSync(file); - return true; - } catch (e) { - return false; - } -} - -let cachedUserAgent: string | undefined; -export function getUserAgent(): string { - if (cachedUserAgent) - return cachedUserAgent; - try { - cachedUserAgent = determineUserAgent(); - } catch (e) { - cachedUserAgent = 'Playwright/unknown'; - } - return cachedUserAgent; -} - -function determineUserAgent(): string { - let osIdentifier = 'unknown'; - let osVersion = 'unknown'; - if (process.platform === 'win32') { - const version = os.release().split('.'); - osIdentifier = 'windows'; - osVersion = `${version[0]}.${version[1]}`; - } else if (process.platform === 'darwin') { - const version = execSync('sw_vers -productVersion', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim().split('.'); - osIdentifier = 'macOS'; - osVersion = `${version[0]}.${version[1]}`; - } else if (process.platform === 'linux') { - try { - // List of /etc/os-release values for different distributions could be - // found here: https://gist.github.com/aslushnikov/8ceddb8288e4cf9db3039c02e0f4fb75 - const osReleaseText = fs.readFileSync('/etc/os-release', 'utf8'); - const fields = parseOSReleaseText(osReleaseText); - osIdentifier = fields.get('id') || 'unknown'; - osVersion = fields.get('version_id') || 'unknown'; - } catch (e) { - // Linux distribution without /etc/os-release. - // Default to linux/unknown. - osIdentifier = 'linux'; - } - } - - const { langName, langVersion } = getClientLanguage(); - return `Playwright/${getPlaywrightVersion()} (${os.arch()}; ${osIdentifier} ${osVersion}) ${langName}/${langVersion}`; -} - -export function getClientLanguage(): { langName: string, langVersion: string } { - let langName = 'unknown'; - let langVersion = 'unknown'; - if (!process.env.PW_LANG_NAME) { - langName = 'node'; - langVersion = process.version.substring(1).split('.').slice(0, 2).join('.'); - } else if (['node', 'python', 'java', 'csharp'].includes(process.env.PW_LANG_NAME)) { - langName = process.env.PW_LANG_NAME; - langVersion = process.env.PW_LANG_NAME_VERSION ?? 'unknown'; - } - return { langName, langVersion }; -} - -export function getPlaywrightVersion(majorMinorOnly = false) { - const packageJson = require('./../../package.json'); - return majorMinorOnly ? packageJson.version.split('.').slice(0, 2).join('.') : packageJson.version; -} - -export function constructURLBasedOnBaseURL(baseURL: string | undefined, givenURL: string): string { - try { - return (new URL.URL(givenURL, baseURL)).toString(); - } catch (e) { - return givenURL; - } -} - -export type HostPlatform = 'win64' | - 'mac10.13' | - 'mac10.14' | - 'mac10.15' | - 'mac11' | 'mac11-arm64' | - 'mac12' | 'mac12-arm64' | - 'ubuntu18.04' | 'ubuntu18.04-arm64' | - 'ubuntu20.04' | 'ubuntu20.04-arm64' | - 'generic-linux' | 'generic-linux-arm64' | - ''; - -export const hostPlatform = ((): HostPlatform => { - const platform = os.platform(); - if (platform === 'darwin') { - const ver = os.release().split('.').map((a: string) => parseInt(a, 10)); - let macVersion = ''; - if (ver[0] < 18) { - // Everything before 10.14 is considered 10.13. - macVersion = 'mac10.13'; - } else if (ver[0] === 18) { - macVersion = 'mac10.14'; - } else if (ver[0] === 19) { - macVersion = 'mac10.15'; - } else { - // ver[0] >= 20 - const LAST_STABLE_MAC_MAJOR_VERSION = 12; - // Best-effort support for MacOS beta versions. - macVersion = 'mac' + Math.min(ver[0] - 9, LAST_STABLE_MAC_MAJOR_VERSION); - // BigSur is the first version that might run on Apple Silicon. - if (os.cpus().some(cpu => cpu.model.includes('Apple'))) - macVersion += '-arm64'; - } - return macVersion as HostPlatform; - } - if (platform === 'linux') { - const archSuffix = os.arch() === 'arm64' ? '-arm64' : ''; - const ubuntuVersion = getUbuntuVersionSync(); - if (!ubuntuVersion) - return ('generic-linux' + archSuffix) as HostPlatform; - if (parseInt(ubuntuVersion, 10) <= 19) - return ('ubuntu18.04' + archSuffix) as HostPlatform; - return ('ubuntu20.04' + archSuffix) as HostPlatform; - } - if (platform === 'win32') - return 'win64'; - return ''; -})(); - -export function wrapInASCIIBox(text: string, padding = 0): string { - const lines = text.split('\n'); - const maxLength = Math.max(...lines.map(line => line.length)); - return [ - '╔' + '═'.repeat(maxLength + padding * 2) + '╗', - ...lines.map(line => '║' + ' '.repeat(padding) + line + ' '.repeat(maxLength - line.length + padding) + '║'), - '╚' + '═'.repeat(maxLength + padding * 2) + '╝', - ].join('\n'); -} - -export function isFilePayload(value: any): boolean { - return typeof value === 'object' && value['name'] && value['mimeType'] && value['buffer']; -} - -export function streamToString(stream: stream.Readable): Promise { - return new Promise((resolve, reject) => { - const chunks: Buffer[] = []; - stream.on('data', chunk => chunks.push(Buffer.from(chunk))); - stream.on('error', reject); - stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); - }); -} - -export async function transformCommandsForRoot(commands: string[]): Promise<{ command: string, args: string[], elevatedPermissions: boolean}> { - const isRoot = process.getuid() === 0; - if (isRoot) - return { command: 'sh', args: ['-c', `${commands.join('&& ')}`], elevatedPermissions: false }; - const sudoExists = await spawnAsync('which', ['sudo']); - if (sudoExists.code === 0) - return { command: 'sudo', args: ['--', 'sh', '-c', `${commands.join('&& ')}`], elevatedPermissions: true }; - return { command: 'su', args: ['root', '-c', `${commands.join('&& ')}`], elevatedPermissions: true }; -} - -export class SigIntWatcher { - private _hadSignal: boolean = false; - private _sigintPromise: Promise; - private _sigintHandler: () => void; - constructor() { - let sigintCallback: () => void; - this._sigintPromise = new Promise(f => sigintCallback = f); - this._sigintHandler = () => { - // We remove the handler so that second Ctrl+C immediately kills the runner - // via the default sigint handler. This is handy in the case where our shutdown - // takes a lot of time or is buggy. - // - // When running through NPM we might get multiple SIGINT signals - // for a single Ctrl+C - this is an NPM bug present since at least NPM v6. - // https://github.com/npm/cli/issues/1591 - // https://github.com/npm/cli/issues/2124 - // - // Therefore, removing the handler too soon will just kill the process - // with default handler without printing the results. - // We work around this by giving NPM 1000ms to send us duplicate signals. - // The side effect is that slow shutdown or bug in our runner will force - // the user to hit Ctrl+C again after at least a second. - setTimeout(() => process.off('SIGINT', this._sigintHandler), 1000); - this._hadSignal = true; - sigintCallback(); - }; - process.on('SIGINT', this._sigintHandler); - } - - promise(): Promise { - return this._sigintPromise; - } - - hadSignal(): boolean { - return this._hadSignal; - } - - disarm() { - process.off('SIGINT', this._sigintHandler); - } -} - diff --git a/packages/playwright-test/src/ci.ts b/packages/playwright-test/src/ci.ts index 46a27dd7a6..0dfbcb3b85 100644 --- a/packages/playwright-test/src/ci.ts +++ b/packages/playwright-test/src/ci.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createGuid, spawnAsync } from 'playwright-core/lib/utils/utils'; +import { createGuid, spawnAsync } from 'playwright-core/lib/utils'; const GIT_OPERATIONS_TIMEOUT_MS = 1500; const kContentTypePlainText = 'text/plain'; diff --git a/packages/playwright-test/src/cli.ts b/packages/playwright-test/src/cli.ts index 52491be8e0..169ab20d62 100644 --- a/packages/playwright-test/src/cli.ts +++ b/packages/playwright-test/src/cli.ts @@ -29,7 +29,7 @@ import type { FilePatternFilter } from './util'; import { showHTMLReport } from './reporters/html'; import { GridServer } from 'playwright-core/lib/grid/gridServer'; import dockerFactory from 'playwright-core/lib/grid/dockerGridFactory'; -import { createGuid, hostPlatform } from 'playwright-core/lib/utils/utils'; +import { createGuid, hostPlatform } from 'playwright-core/lib/utils'; import { fileIsModule } from './loader'; const defaultTimeout = 30000; diff --git a/packages/playwright-test/src/expect.ts b/packages/playwright-test/src/expect.ts index ff68fb9c06..e702b27ff0 100644 --- a/packages/playwright-test/src/expect.ts +++ b/packages/playwright-test/src/expect.ts @@ -48,7 +48,7 @@ import { toMatchSnapshot, toHaveScreenshot as _toHaveScreenshot } from './matche import type { Expect } from './types'; import { currentTestInfo } from './globals'; import { serializeError, captureStackTrace, currentExpectTimeout } from './util'; -import { monotonicTime } from 'playwright-core/lib/utils/utils'; +import { monotonicTime } from 'playwright-core/lib/utils'; // from expect/build/types export type SyncExpectationResult = { diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.ts index 198506430e..4645e40862 100644 --- a/packages/playwright-test/src/index.ts +++ b/packages/playwright-test/src/index.ts @@ -19,7 +19,7 @@ import * as path from 'path'; import type { LaunchOptions, BrowserContextOptions, Page, BrowserContext, Video, APIRequestContext, Tracing } from 'playwright-core'; import type { TestType, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestInfo } from '../types/test'; import { rootTestType } from './testType'; -import { createGuid, removeFolders, debugMode } from 'playwright-core/lib/utils/utils'; +import { createGuid, removeFolders, debugMode } from 'playwright-core/lib/utils'; import { GridClient } from 'playwright-core/lib/grid/gridClient'; export { expect } from './expect'; export const _baseTest: TestType<{}, {}> = rootTestType.test; diff --git a/packages/playwright-test/src/loader.ts b/packages/playwright-test/src/loader.ts index b9fd27dedc..6c19c9d9ff 100644 --- a/packages/playwright-test/src/loader.ts +++ b/packages/playwright-test/src/loader.ts @@ -28,7 +28,7 @@ import { ProjectImpl } from './project'; import type { Reporter } from '../types/testReporter'; import type { BuiltInReporter } from './runner'; import { builtInReporters } from './runner'; -import { isRegExp } from 'playwright-core/lib/utils/utils'; +import { isRegExp } from 'playwright-core/lib/utils'; import { serializeError } from './util'; // To allow multiple loaders in the same process without clearing require cache, diff --git a/packages/playwright-test/src/matchers/matchers.ts b/packages/playwright-test/src/matchers/matchers.ts index d157e0d0a0..40c053f3d0 100644 --- a/packages/playwright-test/src/matchers/matchers.ts +++ b/packages/playwright-test/src/matchers/matchers.ts @@ -16,7 +16,7 @@ import type { Locator, Page, APIResponse } from 'playwright-core'; import type { FrameExpectOptions } from 'playwright-core/lib/client/types'; -import { constructURLBasedOnBaseURL } from 'playwright-core/lib/utils/utils'; +import { constructURLBasedOnBaseURL } from 'playwright-core/lib/utils'; import type { Expect } from '../types'; import { expectTypes, callLogText } from '../util'; import { toBeTruthy } from './toBeTruthy'; diff --git a/packages/playwright-test/src/matchers/toMatchText.ts b/packages/playwright-test/src/matchers/toMatchText.ts index ab1c28c2eb..00e5d9223e 100644 --- a/packages/playwright-test/src/matchers/toMatchText.ts +++ b/packages/playwright-test/src/matchers/toMatchText.ts @@ -16,7 +16,7 @@ import type { ExpectedTextValue } from 'playwright-core/lib/protocol/channels'; -import { isRegExp, isString } from 'playwright-core/lib/utils/utils'; +import { isRegExp, isString } from 'playwright-core/lib/utils'; import type { Expect } from '../types'; import type { ParsedStackTrace } from '../util'; import { expectTypes, callLogText, currentExpectTimeout, captureStackTrace } from '../util'; diff --git a/packages/playwright-test/src/mount.ts b/packages/playwright-test/src/mount.ts index 6ef3ffa9b3..a9ee20f3e6 100644 --- a/packages/playwright-test/src/mount.ts +++ b/packages/playwright-test/src/mount.ts @@ -15,7 +15,7 @@ */ import type { Page, ViewportSize } from '@playwright/test'; -import { createGuid } from 'playwright-core/lib/utils/utils'; +import { createGuid } from 'playwright-core/lib/utils'; export async function mount(page: Page, jsxOrType: any, options: any, baseURL: string, viewport: ViewportSize): Promise { await page.goto('about:blank'); diff --git a/packages/playwright-test/src/project.ts b/packages/playwright-test/src/project.ts index d5a83efb6f..e7454d6e13 100644 --- a/packages/playwright-test/src/project.ts +++ b/packages/playwright-test/src/project.ts @@ -19,7 +19,7 @@ import type { TestCase } from './test'; import { Suite } from './test'; import { FixturePool, isFixtureOption } from './fixtures'; import type { TestTypeImpl } from './testType'; -import { calculateSha1 } from 'playwright-core/lib/utils/utils'; +import { calculateSha1 } from 'playwright-core/lib/utils'; export class ProjectImpl { config: FullProjectInternal; diff --git a/packages/playwright-test/src/reporters/html.ts b/packages/playwright-test/src/reporters/html.ts index 8172dbb5ca..f55a841463 100644 --- a/packages/playwright-test/src/reporters/html.ts +++ b/packages/playwright-test/src/reporters/html.ts @@ -22,7 +22,7 @@ import type { TransformCallback } from 'stream'; import { Transform } from 'stream'; import type { FullConfig, Suite, Reporter } from '../../types/testReporter'; import { HttpServer } from 'playwright-core/lib/utils/httpServer'; -import { assert, calculateSha1, removeFolders } from 'playwright-core/lib/utils/utils'; +import { assert, calculateSha1, removeFolders } from 'playwright-core/lib/utils'; import type { JsonAttachment, JsonReport, JsonSuite, JsonTestCase, JsonTestResult, JsonTestStep } from './raw'; import RawReporter from './raw'; import yazl from 'yazl'; diff --git a/packages/playwright-test/src/reporters/raw.ts b/packages/playwright-test/src/reporters/raw.ts index aa150bbf86..221fdf4e81 100644 --- a/packages/playwright-test/src/reporters/raw.ts +++ b/packages/playwright-test/src/reporters/raw.ts @@ -17,7 +17,7 @@ import fs from 'fs'; import path from 'path'; import type { FullConfig, Location, Suite, TestCase, TestResult, TestStatus, TestStep } from '../../types/testReporter'; -import { assert, calculateSha1 } from 'playwright-core/lib/utils/utils'; +import { assert, calculateSha1 } from 'playwright-core/lib/utils'; import { sanitizeForFilePath } from '../util'; import { formatResultFailure } from './base'; import { toPosixPath, serializePatterns } from './json'; diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.ts index 0241117df0..95dcee3ac0 100644 --- a/packages/playwright-test/src/runner.ts +++ b/packages/playwright-test/src/runner.ts @@ -43,7 +43,7 @@ import type { Config } from './types'; import type { FullConfigInternal } from './types'; import { WebServer } from './webServer'; import { raceAgainstTimeout } from 'playwright-core/lib/utils'; -import { SigIntWatcher } from 'playwright-core/lib/utils/utils'; +import { SigIntWatcher } from 'playwright-core/lib/utils'; const removeFolderAsync = promisify(rimraf); const readDirAsync = promisify(fs.readdir); diff --git a/packages/playwright-test/src/testInfo.ts b/packages/playwright-test/src/testInfo.ts index 611791ae6f..0bb2ab91c6 100644 --- a/packages/playwright-test/src/testInfo.ts +++ b/packages/playwright-test/src/testInfo.ts @@ -17,7 +17,7 @@ import fs from 'fs'; import * as mime from 'mime'; import path from 'path'; -import { calculateSha1 } from 'playwright-core/lib/utils/utils'; +import { calculateSha1 } from 'playwright-core/lib/utils'; import type { TestError, TestInfo, TestStatus } from '../types/test'; import type { FullConfigInternal, FullProjectInternal } from './types'; import type { WorkerInitParams } from './ipc'; diff --git a/packages/playwright-test/src/util.ts b/packages/playwright-test/src/util.ts index c4c23264fe..130dca1697 100644 --- a/packages/playwright-test/src/util.ts +++ b/packages/playwright-test/src/util.ts @@ -22,7 +22,7 @@ import colors from 'colors/safe'; import type { TestError, Location } from './types'; import { default as minimatch } from 'minimatch'; import debug from 'debug'; -import { calculateSha1, isRegExp } from 'playwright-core/lib/utils/utils'; +import { calculateSha1, isRegExp } from 'playwright-core/lib/utils'; import { isInternalFileName } from 'playwright-core/lib/utils/stackTrace'; import { currentTestInfo } from './globals'; import type { ParsedStackTrace } from 'playwright-core/lib/utils/stackTrace'; diff --git a/tests/config/browserTest.ts b/tests/config/browserTest.ts index 23c1f38907..cb1a6d78a8 100644 --- a/tests/config/browserTest.ts +++ b/tests/config/browserTest.ts @@ -19,7 +19,7 @@ import * as os from 'os'; import type { PageTestFixtures, PageWorkerFixtures } from '../page/pageTestApi'; import * as path from 'path'; import type { BrowserContext, BrowserContextOptions, BrowserType, Page } from 'playwright-core'; -import { removeFolders } from '../../packages/playwright-core/lib/utils/utils'; +import { removeFolders } from '../../packages/playwright-core/lib/utils'; import { baseTest } from './baseTest'; import type { RemoteServerOptions } from './remoteServer'; import { RemoteServer } from './remoteServer'; diff --git a/tests/config/testModeFixtures.ts b/tests/config/testModeFixtures.ts index 7ac6264443..077866d131 100644 --- a/tests/config/testModeFixtures.ts +++ b/tests/config/testModeFixtures.ts @@ -36,7 +36,7 @@ export const testModeTest = test.extend<{}, TestModeWorkerOptions & TestModeWork driver: new DriverTestMode(), service2: new DefaultTestMode(), }[mode]; - require('playwright-core/lib/utils/utils').setUnderTest(); + require('playwright-core/lib/utils').setUnderTest(); const playwright = await testMode.setup(); await run(playwright); await testMode.teardown(); diff --git a/tests/library/browsertype-connect.spec.ts b/tests/library/browsertype-connect.spec.ts index f61f6f83d7..391fb78a44 100644 --- a/tests/library/browsertype-connect.spec.ts +++ b/tests/library/browsertype-connect.spec.ts @@ -18,7 +18,7 @@ import fs from 'fs'; import os from 'os'; import * as path from 'path'; -import { getUserAgent } from '../../packages/playwright-core/lib/utils/utils'; +import { getUserAgent } from '../../packages/playwright-core/lib/utils'; import WebSocket from 'ws'; import { expect, playwrightTest as test } from '../config/browserTest'; import { parseTrace, suppressCertificateWarning } from '../config/utils'; diff --git a/tests/library/chromium/chromium.spec.ts b/tests/library/chromium/chromium.spec.ts index 369c079d5c..b44af4e862 100644 --- a/tests/library/chromium/chromium.spec.ts +++ b/tests/library/chromium/chromium.spec.ts @@ -19,7 +19,7 @@ import { contextTest as test, expect } from '../../config/browserTest'; import { playwrightTest } from '../../config/browserTest'; import http from 'http'; import fs from 'fs'; -import { getUserAgent } from '../../../packages/playwright-core/lib/utils/utils'; +import { getUserAgent } from '../../../packages/playwright-core/lib/utils'; import { suppressCertificateWarning } from '../../config/utils'; test('should create a worker from a service worker', async ({ page, server }) => { diff --git a/tests/library/global-fetch.spec.ts b/tests/library/global-fetch.spec.ts index 8c1647a42a..666d6a3307 100644 --- a/tests/library/global-fetch.spec.ts +++ b/tests/library/global-fetch.spec.ts @@ -17,7 +17,7 @@ import http from 'http'; import os from 'os'; import * as util from 'util'; -import { getPlaywrightVersion } from '../../packages/playwright-core/lib/utils/utils'; +import { getPlaywrightVersion } from '../../packages/playwright-core/lib/utils'; import { expect, playwrightTest as it } from '../config/browserTest'; it.skip(({ mode }) => mode !== 'default'); diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index 282f295cf4..c6c7bdd5b9 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -18,7 +18,7 @@ import fs from 'fs'; import { test as baseTest, expect, createImage } from './playwright-test-fixtures'; import type { HttpServer } from '../../packages/playwright-core/lib/utils/httpServer'; import { startHtmlReportServer } from '../../packages/playwright-test/lib/reporters/html'; -import { spawnAsync } from 'playwright-core/lib/utils/utils'; +import { spawnAsync } from 'playwright-core/lib/utils'; const test = baseTest.extend<{ showReport: () => Promise }>({ showReport: async ({ page }, use, testInfo) => {