mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: use utils via index export (1) (#13398)
This commit is contained in:
parent
057b0498e6
commit
dbafe3bb4e
@ -22,10 +22,9 @@
|
||||
"./lib/grid/gridClient": "./lib/grid/gridClient.js",
|
||||
"./lib/grid/dockerGridFactory": "./lib/grid/dockerGridFactory.js",
|
||||
"./lib/outofprocess": "./lib/outofprocess.js",
|
||||
"./lib/utils/async": "./lib/utils/async.js",
|
||||
"./lib/utils": "./lib/utils/index.js",
|
||||
"./lib/utils/comparators": "./lib/utils/comparators.js",
|
||||
"./lib/utils/httpServer": "./lib/utils/httpServer.js",
|
||||
"./lib/utils/multimap": "./lib/utils/multimap.js",
|
||||
"./lib/utils/processLauncher": "./lib/utils/processLauncher.js",
|
||||
"./lib/utils/utils": "./lib/utils/utils.js",
|
||||
"./lib/utils/stackTrace": "./lib/utils/stackTrace.js",
|
||||
|
||||
@ -26,7 +26,7 @@ import { envObjectToArray } from './clientHelper';
|
||||
import { assert, headersObjectToArray, monotonicTime } from '../utils/utils';
|
||||
import type * as api from '../../types/types';
|
||||
import { kBrowserClosedError } from '../utils/errors';
|
||||
import { raceAgainstTimeout } from '../utils/async';
|
||||
import { raceAgainstTimeout } from '../utils';
|
||||
import type { Playwright } from './playwright';
|
||||
|
||||
export interface BrowserServerLauncher {
|
||||
|
||||
@ -22,14 +22,14 @@ import type { Headers, RemoteAddr, SecurityDetails, WaitForEventOptions } from '
|
||||
import fs from 'fs';
|
||||
import * as mime from 'mime';
|
||||
import { isString, headersObjectToArray } from '../utils/utils';
|
||||
import { ManualPromise } from '../utils/async';
|
||||
import { ManualPromise } from '../utils';
|
||||
import { Events } from './events';
|
||||
import type { Page } from './page';
|
||||
import { Waiter } from './waiter';
|
||||
import type * as api from '../../types/types';
|
||||
import type { HeadersArray, URLMatch } from '../common/types';
|
||||
import { urlMatches } from './clientHelper';
|
||||
import { MultiMap } from '../utils/multimap';
|
||||
import { MultiMap } from '../utils';
|
||||
import { APIResponse } from './fetch';
|
||||
|
||||
export type NetworkCookie = {
|
||||
|
||||
@ -19,7 +19,7 @@ import { IpcTransport } from './protocol/transport';
|
||||
import type { Playwright } from './client/playwright';
|
||||
import * as childProcess from 'child_process';
|
||||
import * as path from 'path';
|
||||
import { ManualPromise } from './utils/async';
|
||||
import { ManualPromise } from './utils';
|
||||
|
||||
export async function start(env: any = {}): Promise<{ playwright: Playwright, stop: () => Promise<void> }> {
|
||||
const client = new PlaywrightClient(env);
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
import fs from 'fs';
|
||||
import { assert } from '../utils/utils';
|
||||
import { ManualPromise } from '../utils/async';
|
||||
import { ManualPromise } from '../utils';
|
||||
import { SdkObject } from './instrumentation';
|
||||
|
||||
type SaveCallback = (localPath: string, error?: string) => Promise<void>;
|
||||
|
||||
@ -41,7 +41,7 @@ import type { CallMetadata } from '../instrumentation';
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import { registry } from '../registry';
|
||||
import { ManualPromise } from '../../utils/async';
|
||||
import { ManualPromise } from '../../utils';
|
||||
|
||||
const ARTIFACTS_FOLDER = path.join(os.tmpdir(), 'playwright-artifacts-');
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ import path from 'path';
|
||||
import yauzl from 'yauzl';
|
||||
import yazl from 'yazl';
|
||||
import type * as channels from '../../protocol/channels';
|
||||
import { ManualPromise } from '../../utils/async';
|
||||
import { ManualPromise } from '../../utils';
|
||||
import { assert, createGuid } from '../../utils/utils';
|
||||
import type { DispatcherScope } from './dispatcher';
|
||||
import { Dispatcher } from './dispatcher';
|
||||
|
||||
@ -34,7 +34,7 @@ import type { Protocol } from './protocol';
|
||||
import type { Progress } from '../progress';
|
||||
import { splitErrorMessage } from '../../utils/stackTrace';
|
||||
import { debugLogger } from '../../utils/debugLogger';
|
||||
import { ManualPromise } from '../../utils/async';
|
||||
import { ManualPromise } from '../../utils';
|
||||
|
||||
export const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ import { BrowserContext } from './browserContext';
|
||||
import type { Progress } from './progress';
|
||||
import { ProgressController } from './progress';
|
||||
import { assert, constructURLBasedOnBaseURL, makeWaitForNextTask } from '../utils/utils';
|
||||
import { ManualPromise } from '../utils/async';
|
||||
import { ManualPromise } from '../utils';
|
||||
import { debugLogger } from '../utils/debugLogger';
|
||||
import type { CallMetadata } from './instrumentation';
|
||||
import { serverSideCallMetadata, SdkObject } from './instrumentation';
|
||||
|
||||
@ -19,7 +19,7 @@ import * as utilityScriptSource from '../generated/utilityScriptSource';
|
||||
import { serializeAsCallArgument } from './common/utilityScriptSerializers';
|
||||
import { type UtilityScript } from './injected/utilityScript';
|
||||
import { SdkObject } from './instrumentation';
|
||||
import { ManualPromise } from '../utils/async';
|
||||
import { ManualPromise } from '../utils';
|
||||
|
||||
export type ObjectId = string;
|
||||
export type RemoteObject = {
|
||||
|
||||
@ -18,7 +18,7 @@ import type * as frames from './frames';
|
||||
import type * as types from './types';
|
||||
import type * as channels from '../protocol/channels';
|
||||
import { assert } from '../utils/utils';
|
||||
import { ManualPromise } from '../utils/async';
|
||||
import { ManualPromise } from '../utils';
|
||||
import { SdkObject } from './instrumentation';
|
||||
import type { NameValue } from '../common/types';
|
||||
import { APIRequestContext } from './fetch';
|
||||
|
||||
@ -31,7 +31,7 @@ import { FileChooser } from './fileChooser';
|
||||
import type { Progress } from './progress';
|
||||
import { ProgressController } from './progress';
|
||||
import { assert, isError } from '../utils/utils';
|
||||
import { ManualPromise } from '../utils/async';
|
||||
import { ManualPromise } from '../utils';
|
||||
import { debugLogger } from '../utils/debugLogger';
|
||||
import type { ImageComparatorOptions } from '../utils/comparators';
|
||||
import { getComparator } from '../utils/comparators';
|
||||
|
||||
@ -19,7 +19,7 @@ import { assert, monotonicTime } from '../utils/utils';
|
||||
import type { LogName } from '../utils/debugLogger';
|
||||
import type { CallMetadata, Instrumentation, SdkObject } from './instrumentation';
|
||||
import type { ElementHandle } from './dom';
|
||||
import { ManualPromise } from '../utils/async';
|
||||
import { ManualPromise } from '../utils';
|
||||
import type { LogEntry } from './injected/injectedScript';
|
||||
|
||||
export interface Progress {
|
||||
|
||||
@ -24,7 +24,7 @@ import type { ParsedSelector } from './common/selectorParser';
|
||||
import type * as types from './types';
|
||||
import type { Progress } from './progress';
|
||||
import { assert } from '../utils/utils';
|
||||
import { MultiMap } from '../utils/multimap';
|
||||
import { MultiMap } from '../utils';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
||||
@ -25,7 +25,7 @@ import { calculateSha1, monotonicTime } from '../../../utils/utils';
|
||||
import type { RegisteredListener } from '../../../utils/eventsHelper';
|
||||
import { eventsHelper } from '../../../utils/eventsHelper';
|
||||
import * as mime from 'mime';
|
||||
import { ManualPromise } from '../../../utils/async';
|
||||
import { ManualPromise } from '../../../utils';
|
||||
|
||||
const FALLBACK_HTTP_VERSION = 'HTTP/1.1';
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ import { createGuid, monotonicTime } from '../../utils/utils';
|
||||
import { metadataToCallLog } from './recorder/recorderUtils';
|
||||
import { Debugger } from './debugger';
|
||||
import { EventEmitter } from 'events';
|
||||
import { raceAgainstTimeout } from '../../utils/async';
|
||||
import { raceAgainstTimeout } from '../../utils';
|
||||
|
||||
type BindingSource = { frame: Frame, page: Page };
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ import yazl from 'yazl';
|
||||
import type { NameValue } from '../../../common/types';
|
||||
import type { TracingTracingStopChunkParams } from '../../../protocol/channels';
|
||||
import { commandsWithTracingSnapshots } from '../../../protocol/channels';
|
||||
import { ManualPromise } from '../../../utils/async';
|
||||
import { ManualPromise } from '../../../utils';
|
||||
import type { RegisteredListener } from '../../../utils/eventsHelper';
|
||||
import { eventsHelper } from '../../../utils/eventsHelper';
|
||||
import { assert, calculateSha1, createGuid, mkdirIfNeeded, monotonicTime, removeFolders } from '../../../utils/utils';
|
||||
|
||||
@ -21,7 +21,7 @@ import type * as types from '../types';
|
||||
import type { Protocol } from './protocol';
|
||||
import type { WKSession } from './wkConnection';
|
||||
import { assert, headersObjectToArray, headersArrayToObject } from '../../utils/utils';
|
||||
import { ManualPromise } from '../../utils/async';
|
||||
import { ManualPromise } from '../../utils';
|
||||
|
||||
const errorReasons: { [reason: string]: Protocol.Network.ResourceErrorType } = {
|
||||
'aborted': 'Cancellation',
|
||||
|
||||
@ -43,7 +43,7 @@ import { WKInterceptableRequest, WKRouteImpl } from './wkInterceptableRequest';
|
||||
import { WKProvisionalPage } from './wkProvisionalPage';
|
||||
import { WKWorkers } from './wkWorkers';
|
||||
import { debugLogger } from '../../utils/debugLogger';
|
||||
import { ManualPromise } from '../../utils/async';
|
||||
import { ManualPromise } from '../../utils';
|
||||
|
||||
const UTILITY_WORLD_NAME = '__playwright_utility_world__';
|
||||
const BINDING_CALL_MESSAGE = '__playwright_binding_call__';
|
||||
|
||||
19
packages/playwright-core/src/utils/index.ts
Normal file
19
packages/playwright-core/src/utils/index.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { ManualPromise } from './manualPromise';
|
||||
export { MultiMap } from './multimap';
|
||||
export { raceAgainstTimeout, TimeoutRunner, TimeoutRunnerError } from './timeoutRunner';
|
||||
55
packages/playwright-core/src/utils/manualPromise.ts
Normal file
55
packages/playwright-core/src/utils/manualPromise.ts
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export class ManualPromise<T> extends Promise<T> {
|
||||
private _resolve!: (t: T) => void;
|
||||
private _reject!: (e: Error) => void;
|
||||
private _isDone: boolean;
|
||||
|
||||
constructor() {
|
||||
let resolve: (t: T) => void;
|
||||
let reject: (e: Error) => void;
|
||||
super((f, r) => {
|
||||
resolve = f;
|
||||
reject = r;
|
||||
});
|
||||
this._isDone = false;
|
||||
this._resolve = resolve!;
|
||||
this._reject = reject!;
|
||||
}
|
||||
|
||||
isDone() {
|
||||
return this._isDone;
|
||||
}
|
||||
|
||||
resolve(t: T) {
|
||||
this._isDone = true;
|
||||
this._resolve(t);
|
||||
}
|
||||
|
||||
reject(e: Error) {
|
||||
this._isDone = true;
|
||||
this._reject(e);
|
||||
}
|
||||
|
||||
static override get [Symbol.species]() {
|
||||
return Promise;
|
||||
}
|
||||
|
||||
override get [Symbol.toStringTag]() {
|
||||
return 'ManualPromise';
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ManualPromise } from './manualPromise';
|
||||
import { monotonicTime } from './utils';
|
||||
|
||||
export class TimeoutRunnerError extends Error {}
|
||||
@ -23,6 +24,7 @@ type TimeoutRunnerData = {
|
||||
timer: NodeJS.Timer | undefined,
|
||||
timeoutPromise: ManualPromise<any>,
|
||||
};
|
||||
|
||||
export class TimeoutRunner {
|
||||
private _running: TimeoutRunnerData | undefined;
|
||||
private _timeout: number;
|
||||
@ -107,43 +109,3 @@ export async function raceAgainstTimeout<T>(cb: () => Promise<T>, timeout: numbe
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export class ManualPromise<T> extends Promise<T> {
|
||||
private _resolve!: (t: T) => void;
|
||||
private _reject!: (e: Error) => void;
|
||||
private _isDone: boolean;
|
||||
|
||||
constructor() {
|
||||
let resolve: (t: T) => void;
|
||||
let reject: (e: Error) => void;
|
||||
super((f, r) => {
|
||||
resolve = f;
|
||||
reject = r;
|
||||
});
|
||||
this._isDone = false;
|
||||
this._resolve = resolve!;
|
||||
this._reject = reject!;
|
||||
}
|
||||
|
||||
isDone() {
|
||||
return this._isDone;
|
||||
}
|
||||
|
||||
resolve(t: T) {
|
||||
this._isDone = true;
|
||||
this._resolve(t);
|
||||
}
|
||||
|
||||
reject(e: Error) {
|
||||
this._isDone = true;
|
||||
this._reject(e);
|
||||
}
|
||||
|
||||
static override get [Symbol.species]() {
|
||||
return Promise;
|
||||
}
|
||||
|
||||
override get [Symbol.toStringTag]() {
|
||||
return 'ManualPromise';
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ import type { RunPayload, TestBeginPayload, TestEndPayload, DonePayload, TestOut
|
||||
import type { TestResult, Reporter, TestStep, TestError } from '../types/testReporter';
|
||||
import type { Suite, TestCase } from './test';
|
||||
import type { Loader } from './loader';
|
||||
import { ManualPromise } from 'playwright-core/lib/utils/async';
|
||||
import { ManualPromise } from 'playwright-core/lib/utils';
|
||||
|
||||
export type TestGroup = {
|
||||
workerHash: string;
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import expectLibrary from 'expect';
|
||||
import { raceAgainstTimeout } from 'playwright-core/lib/utils/async';
|
||||
import { raceAgainstTimeout } from 'playwright-core/lib/utils';
|
||||
import path from 'path';
|
||||
import {
|
||||
INVERTED_COLOR,
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
import { formatLocation, debugTest } from './util';
|
||||
import * as crypto from 'crypto';
|
||||
import type { FixturesWithLocation, Location, WorkerInfo } from './types';
|
||||
import { ManualPromise } from 'playwright-core/lib/utils/async';
|
||||
import { ManualPromise } from 'playwright-core/lib/utils';
|
||||
import type { TestInfoImpl } from './testInfo';
|
||||
import type { FixtureDescription, TimeoutManager } from './timeoutManager';
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ import { assert, calculateSha1 } from 'playwright-core/lib/utils/utils';
|
||||
import { sanitizeForFilePath } from '../util';
|
||||
import { formatResultFailure } from './base';
|
||||
import { toPosixPath, serializePatterns } from './json';
|
||||
import { MultiMap } from 'playwright-core/lib/utils/multimap';
|
||||
import { MultiMap } from 'playwright-core/lib/utils';
|
||||
import { codeFrameColumns } from '@babel/code-frame';
|
||||
import type { FullConfigInternal } from '../types';
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ import { Minimatch } from 'minimatch';
|
||||
import type { Config } from './types';
|
||||
import type { FullConfigInternal } from './types';
|
||||
import { WebServer } from './webServer';
|
||||
import { raceAgainstTimeout } from 'playwright-core/lib/utils/async';
|
||||
import { raceAgainstTimeout } from 'playwright-core/lib/utils';
|
||||
import { SigIntWatcher } from 'playwright-core/lib/utils/utils';
|
||||
|
||||
const removeFolderAsync = promisify(rimraf);
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import colors from 'colors/safe';
|
||||
import { TimeoutRunner, TimeoutRunnerError } from 'playwright-core/lib/utils/async';
|
||||
import { TimeoutRunner, TimeoutRunnerError } from 'playwright-core/lib/utils';
|
||||
import type { TestError } from '../types/test';
|
||||
import type { Location } from './types';
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ import http from 'http';
|
||||
import https from 'https';
|
||||
import net from 'net';
|
||||
import debug from 'debug';
|
||||
import { raceAgainstTimeout } from 'playwright-core/lib/utils/async';
|
||||
import { raceAgainstTimeout } from 'playwright-core/lib/utils';
|
||||
import type { WebServerConfig } from './types';
|
||||
import { launchProcess } from 'playwright-core/lib/utils/processLauncher';
|
||||
import type { Reporter } from '../types/testReporter';
|
||||
|
||||
@ -26,7 +26,7 @@ import type { Suite, TestCase } from './test';
|
||||
import type { Annotation, TestError, TestStepInternal } from './types';
|
||||
import type { ProjectImpl } from './project';
|
||||
import { FixtureRunner } from './fixtures';
|
||||
import { ManualPromise } from 'playwright-core/lib/utils/async';
|
||||
import { ManualPromise } from 'playwright-core/lib/utils';
|
||||
import { TestInfoImpl } from './testInfo';
|
||||
import type { TimeSlot } from './timeoutManager';
|
||||
import { TimeoutManager } from './timeoutManager';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user