Skip to content

Commit

Permalink
chore: organize imports in packages
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Feb 7, 2025
1 parent 4a7f6a6 commit 6940117
Show file tree
Hide file tree
Showing 111 changed files with 639 additions and 427 deletions.
10 changes: 5 additions & 5 deletions docs/src/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Create `tests/auth.setup.ts` that will prepare authenticated browser state for a

```js title="tests/auth.setup.ts"
import { test as setup, expect } from '@playwright/test';
import path from 'path';
import * as path from 'path';

const authFile = path.join(__dirname, '../playwright/.auth/user.json');

Expand Down Expand Up @@ -143,8 +143,8 @@ Create `playwright/fixtures.ts` file that will [override `storageState` fixture]

```js title="playwright/fixtures.ts"
import { test as baseTest, expect } from '@playwright/test';
import fs from 'fs';
import path from 'path';
import * as fs from 'fs';
import * as path from 'path';

export * from '@playwright/test';
export const test = baseTest.extend<{}, { workerStorageState: string }>({
Expand Down Expand Up @@ -348,8 +348,8 @@ Alternatively, in a [worker fixture](#moderate-one-account-per-parallel-worker):

```js title="playwright/fixtures.ts"
import { test as baseTest, request } from '@playwright/test';
import fs from 'fs';
import path from 'path';
import * as fs from 'fs';
import * as path from 'path';

export * from '@playwright/test';
export const test = baseTest.extend<{}, { workerStorageState: string }>({
Expand Down
2 changes: 1 addition & 1 deletion docs/src/chrome-extensions-js-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ First, add fixtures that will load the extension:

```js title="fixtures.ts"
import { test as base, chromium, type BrowserContext } from '@playwright/test';
import path from 'path';
import * as path from 'path';

export const test = base.extend<{
context: BrowserContext;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/evaluating.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Next, add init script to the page.

```js
import { test, expect } from '@playwright/test';
import path from 'path';
import * as path from 'path';

test.beforeEach(async ({ page }) => {
// Add script for every test in the beforeEach hook.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/test-api/class-testconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Here is an example that uses [`method: TestInfo.outputPath`] to create a tempora

```js
import { test, expect } from '@playwright/test';
import fs from 'fs';
import * as fs from 'fs';

test('example test', async ({}, testInfo) => {
const file = testInfo.outputPath('temporary-file.txt');
Expand Down
2 changes: 1 addition & 1 deletion docs/src/test-api/class-testinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ Returns a path inside the [`property: TestInfo.outputDir`] where the test can sa

```js
import { test, expect } from '@playwright/test';
import fs from 'fs';
import * as fs from 'fs';

test('example test', async ({}, testInfo) => {
const file = testInfo.outputPath('dir', 'temporary-file.txt');
Expand Down
2 changes: 1 addition & 1 deletion docs/src/test-api/class-testproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Here is an example that uses [`method: TestInfo.outputPath`] to create a tempora

```js
import { test, expect } from '@playwright/test';
import fs from 'fs';
import * as fs from 'fs';

test('example test', async ({}, testInfo) => {
const file = testInfo.outputPath('temporary-file.txt');
Expand Down
6 changes: 3 additions & 3 deletions docs/src/test-parameterize-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ To make environment variables easier to manage, consider something like `.env` f
```js title="playwright.config.ts"
import { defineConfig } from '@playwright/test';
import dotenv from 'dotenv';
import path from 'path';
import * as path from 'path';

// Read from ".env" file.
dotenv.config({ path: path.resolve(__dirname, '.env') });
Expand Down Expand Up @@ -309,8 +309,8 @@ See for example this CSV file, in our example `input.csv`:
Based on this we'll generate some tests by using the [csv-parse](https://www.npmjs.com/package/csv-parse) library from NPM:

```js title="test.spec.ts"
import fs from 'fs';
import path from 'path';
import * as fs from 'fs';
import * as path from 'path';
import { test } from '@playwright/test';
import { parse } from 'csv-parse/sync';

Expand Down
6 changes: 3 additions & 3 deletions docs/src/webview2.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ Using the following, Playwright will run your WebView2 application as a sub-proc

```js title="webView2Test.ts"
import { test as base } from '@playwright/test';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import childProcess from 'child_process';

const EXECUTABLE_PATH = path.join(
Expand Down
4 changes: 3 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ export default [{
}],
}
}, {
files: ['packages/playwright-core/**/*.ts'],
files: [
'packages/**/*.ts',
],
rules: {
...importOrderRules
},
Expand Down
4 changes: 2 additions & 2 deletions packages/html-reporter/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import fs from 'fs';
import path from 'path';
import * as fs from 'fs';
import * as path from 'path';
import type { Plugin, UserConfig } from 'vite';

export function bundle(): Plugin {
Expand Down
4 changes: 2 additions & 2 deletions packages/html-reporter/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import { devices, defineConfig } from '@playwright/experimental-ct-react';
import path from 'path';
import url from 'url';
import * as path from 'path';
import * as url from 'url';

export default defineConfig({
testDir: 'src',
Expand Down
11 changes: 7 additions & 4 deletions packages/playwright-ct-core/src/devServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
* limitations under the License.
*/

import fs from 'fs';
import path from 'path';
import * as fs from 'fs';
import * as path from 'path';

import { Watcher } from 'playwright/lib/fsWatcher';
import type { PluginContext } from 'rollup';

import { source as injectedSource } from './generated/indexSource';
import { createConfig, populateComponentsFromTests, resolveDirs, transformIndexFile, frameworkConfig } from './viteUtils';
import { createConfig, frameworkConfig, populateComponentsFromTests, resolveDirs, transformIndexFile } from './viteUtils';

import type { ComponentRegistry } from './viteUtils';
import type { FullConfig } from 'playwright/test';
import type { PluginContext } from 'rollup';

export async function runDevServer(config: FullConfig): Promise<() => Promise<void>> {
const { registerSourceFile, frameworkPluginFactory } = frameworkConfig(config);
Expand Down
9 changes: 5 additions & 4 deletions packages/playwright-ct-core/src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

import type { Fixtures, Locator, Page, BrowserContextOptions, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, BrowserContext } from 'playwright/test';
import type { Component, JsxComponent, MountOptions, ObjectComponentOptions } from '../types/component';
import type { ContextReuseMode, FullConfigInternal } from '../../playwright/src/common/config';
import type { ImportRef } from './injected/importRegistry';
import { wrapObject } from './injected/serializers';
import { Router } from './router';

import type { ContextReuseMode, FullConfigInternal } from '../../playwright/src/common/config';
import type { RouterFixture } from '../index';
import type { ImportRef } from './injected/importRegistry';
import type { Component, JsxComponent, MountOptions, ObjectComponentOptions } from '../types/component';
import type { BrowserContext, BrowserContextOptions, Fixtures, Locator, Page, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from 'playwright/test';

let boundCallbacksForMount: Function[] = [];

Expand Down
8 changes: 5 additions & 3 deletions packages/playwright-ct-core/src/tsxTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
* limitations under the License.
*/

import path from 'path';
import type { T, BabelAPI, PluginObj } from 'playwright/src/transform/babelBundle';
import { types, declare, traverse } from 'playwright/lib/transform/babelBundle';
import * as path from 'path';

import { declare, traverse, types } from 'playwright/lib/transform/babelBundle';
import { setTransformData } from 'playwright/lib/transform/transform';

import type { BabelAPI, PluginObj, T } from 'playwright/src/transform/babelBundle';
const t: typeof T = types;

let jsxComponentNames: Set<string>;
Expand Down
32 changes: 18 additions & 14 deletions packages/playwright-ct-core/src/vitePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,29 @@
* limitations under the License.
*/

import fs from 'fs';
import type http from 'http';
import type { AddressInfo } from 'net';
import path from 'path';
import { assert, calculateSha1, getPlaywrightVersion, isURLAvailable } from 'playwright-core/lib/utils';
import { debug } from 'playwright-core/lib/utilsBundle';
import * as fs from 'fs';
import * as path from 'path';

import { setExternalDependencies } from 'playwright/lib/transform/compilationCache';
import { resolveHook } from 'playwright/lib/transform/transform';
import { removeDirAndLogToConsole } from 'playwright/lib/util';
import { stoppable } from 'playwright/lib/utilsBundle';
import type { FullConfig, Suite } from 'playwright/types/testReporter';
import type { PluginContext } from 'rollup';
import type { Plugin, ResolveFn, ResolvedConfig } from 'vite';
import type { TestRunnerPlugin } from '../../playwright/src/plugins';
import { assert, calculateSha1, getPlaywrightVersion, isURLAvailable } from 'playwright-core/lib/utils';
import { debug } from 'playwright-core/lib/utilsBundle';

import { runDevServer } from './devServer';
import { source as injectedSource } from './generated/indexSource';
import { createConfig, frameworkConfig, hasJSComponents, populateComponentsFromTests, resolveDirs, resolveEndpoint, transformIndexFile } from './viteUtils';

import type { ImportInfo } from './tsxTransform';
import type { ComponentRegistry } from './viteUtils';
import { createConfig, frameworkConfig, hasJSComponents, populateComponentsFromTests, resolveDirs, resolveEndpoint, transformIndexFile } from './viteUtils';
import { resolveHook } from 'playwright/lib/transform/transform';
import { runDevServer } from './devServer';
import { removeDirAndLogToConsole } from 'playwright/lib/util';
import type { TestRunnerPlugin } from '../../playwright/src/plugins';
import type http from 'http';
import type { AddressInfo } from 'net';
import type { FullConfig, Suite } from 'playwright/types/testReporter';
import type { PluginContext } from 'rollup';
import type { Plugin, ResolveFn, ResolvedConfig } from 'vite';


const log = debug('pw:vite');

Expand Down
13 changes: 8 additions & 5 deletions packages/playwright-ct-core/src/viteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
* limitations under the License.
*/

import fs from 'fs';
import path from 'path';
import { debug } from 'playwright-core/lib/utilsBundle';
import * as fs from 'fs';
import * as path from 'path';

import { getUserData } from 'playwright/lib/transform/compilationCache';
import { resolveHook } from 'playwright/lib/transform/transform';
import { debug } from 'playwright-core/lib/utilsBundle';

import type { ImportInfo } from './tsxTransform';
import type { PlaywrightTestConfig as BasePlaywrightTestConfig } from 'playwright/types/test';
import type { FullConfig } from 'playwright/types/testReporter';
import type { InlineConfig, Plugin, TransformResult, UserConfig } from 'vite';
import type { ImportInfo } from './tsxTransform';
import { resolveHook } from 'playwright/lib/transform/transform';


const log = debug('pw:vite');

Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-tools/src/examples/browser-anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

/* eslint-disable no-console */

import playwright from 'playwright';
import Anthropic from '@anthropic-ai/sdk';
import dotenv from 'dotenv';
import browser from '@playwright/experimental-tools/browser';
import dotenv from 'dotenv';
import playwright from 'playwright';

dotenv.config();

Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-tools/src/examples/browser-openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

/* eslint-disable no-console */

import playwright from 'playwright';
import browser from '@playwright/experimental-tools/browser';
import dotenv from 'dotenv';
import OpenAI from 'openai';
import playwright from 'playwright';

import type { ChatCompletionMessageParam, ChatCompletionTool } from 'openai/resources';

dotenv.config();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

/* eslint-disable no-console */

import playwright from 'playwright';
import Anthropic from '@anthropic-ai/sdk';
import computer from '@playwright/experimental-tools/computer-20241022';
import dotenv from 'dotenv';
import computer, { type ToolResult } from '@playwright/experimental-tools/computer-20241022';
import playwright from 'playwright';

import type { BetaImageBlockParam, BetaTextBlockParam } from '@anthropic-ai/sdk/resources/beta/messages/messages';
import type { ToolResult } from '@playwright/experimental-tools/computer-20241022';

dotenv.config();

Expand Down
8 changes: 5 additions & 3 deletions packages/playwright-tools/src/tools/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* limitations under the License.
*/

import type playwright from 'playwright';
import type { JSONSchemaType, ToolDeclaration } from '../../types';
import type { ToolResult } from '../../browser';
import { waitForNetwork } from './utils';

import type { ToolResult } from '../../browser';
import type { JSONSchemaType, ToolDeclaration } from '../../types';
import type playwright from 'playwright';


type LocatorEx = playwright.Locator & {
_generateLocatorString: () => Promise<string>;
};
Expand Down
8 changes: 5 additions & 3 deletions packages/playwright-tools/src/tools/computer-20241022.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* limitations under the License.
*/

import type playwright from 'playwright';
import type { JSONSchemaType } from '../../types';
import type { ToolResult } from '../../computer-20241022';
import { waitForNetwork } from './utils';

import type { ToolResult } from '../../computer-20241022';
import type { JSONSchemaType } from '../../types';
import type playwright from 'playwright';


export async function call(page: playwright.Page, toolName: string, input: Record<string, JSONSchemaType>): Promise<ToolResult> {
if (toolName !== 'computer')
throw new Error('Unsupported tool');
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-tools/src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
* limitations under the License.
*/

import type playwright from 'playwright';
import { ManualPromise } from 'playwright-core/lib/utils';

import type playwright from 'playwright';

export async function waitForNetwork<R>(page: playwright.Page, callback: () => Promise<R>): Promise<R> {
const requests = new Set<playwright.Request>();
let frameNavigated = false;
Expand Down
10 changes: 6 additions & 4 deletions packages/playwright/bundles/babel/src/babelBundleImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
* limitations under the License.
*/

import path from 'path';
import * as path from 'path';

import * as babel from '@babel/core';
import traverseFunction from '@babel/traverse';

import type { BabelFileResult, NodePath, PluginObj, TransformOptions } from '@babel/core';
import type { TSExportAssignment, ImportDeclaration } from '@babel/types';
import type { TemplateBuilder } from '@babel/template';
import * as babel from '@babel/core';
import type { ImportDeclaration, TSExportAssignment } from '@babel/types';

export { codeFrameColumns } from '@babel/code-frame';
export { declare } from '@babel/helper-plugin-utils';
export { types } from '@babel/core';
import traverseFunction from '@babel/traverse';
export const traverse = traverseFunction;

function babelTransformOptions(isTypeScript: boolean, isModule: boolean, pluginsPrologue: [string, any?][], pluginsEpilogue: [string, any?][]): TransformOptions {
Expand Down
6 changes: 4 additions & 2 deletions packages/playwright/bundles/expect/src/expectBundleImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/

import * as mu from 'jest-matcher-utils';

import * as am from '../third_party/asymmetricMatchers';
import expectLibrary from '../third_party/index';

export const expect = expectLibrary;
export * as mock from 'jest-mock';
import * as am from '../third_party/asymmetricMatchers';
import * as mu from 'jest-matcher-utils';

export const asymmetricMatchers = {
any: am.any,
Expand Down
Loading

0 comments on commit 6940117

Please sign in to comment.