Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/playwright-ct-core/src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { wrapObject } from './injected/serializers';
import { Router } from './router';

import type { ContextReuseMode, FullConfigInternal } from '../../playwright/src/common/config';
import type { config, FullConfigInternal } from 'playwright/lib/common';
import type { RouterFixture } from '../index';
import type { ImportRef } from './injected/importRegistry';
import type { Component, JsxComponent, MountOptions, ObjectComponentOptions } from '../types/component';
Expand All @@ -37,7 +37,7 @@ type TestFixtures = PlaywrightTestArgs & PlaywrightTestOptions & {
};
type WorkerFixtures = PlaywrightWorkerArgs & PlaywrightWorkerOptions;
type BaseTestFixtures = {
_optionContextReuseMode: ContextReuseMode
_optionContextReuseMode: config.ContextReuseMode
};

export const fixtures: Fixtures<TestFixtures, WorkerFixtures, BaseTestFixtures> = {
Expand Down
15 changes: 7 additions & 8 deletions packages/playwright-ct-core/src/tsxTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

import path from 'path';

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

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

let jsxComponentNames: Set<string>;
let importInfos: Map<string, ImportInfo>;
Expand All @@ -28,10 +27,10 @@ type TsxTransformOptions = {
setTransformData: (key: string, value: any) => void;
};

export default declare((api: BabelAPI, options: TsxTransformOptions) => {
export default babel.declare((api: babel.BabelAPI, options: TsxTransformOptions) => {
api.assertVersion(7);

const result: PluginObj = {
const result: babel.PluginObj = {
name: 'playwright-debug-transform',
visitor: {
Program: {
Expand Down Expand Up @@ -130,9 +129,9 @@ export default declare((api: BabelAPI, options: TsxTransformOptions) => {
return result;
});

function collectJsxComponentUsages(node: T.Node): Set<string> {
function collectJsxComponentUsages(node: babel.T.Node): Set<string> {
const names = new Set<string>();
traverse(node, {
babel.traverse(node, {
enter: p => {
// Treat JSX-everything as component usages.
if (t.isJSXElement(p.node)) {
Expand All @@ -153,7 +152,7 @@ export type ImportInfo = {
remoteName: string | undefined;
};

export function importInfo(importNode: T.ImportDeclaration, specifier: T.ImportSpecifier | T.ImportDefaultSpecifier, filename: string): { localName: string, info: ImportInfo } {
export function importInfo(importNode: babel.T.ImportDeclaration, specifier: babel.T.ImportSpecifier | babel.T.ImportDefaultSpecifier, filename: string): { localName: string, info: ImportInfo } {
const importSource = importNode.source.value;
const idPrefix = path.join(filename, '..', importSource).replace(/[^\w_\d]/g, '_');

Expand Down
7 changes: 3 additions & 4 deletions packages/playwright-ct-core/src/vitePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import path from 'path';

import { iso, utils } from 'playwright-core/lib/coreBundle';
import { colors, debug, stoppable } from 'playwright-core/lib/utilsBundle';
import { setExternalDependencies } from 'playwright/lib/transform/compilationCache';
import { resolveHook } from 'playwright/lib/transform/transform';
import { cc, transform } from 'playwright/lib/common';
import { removeDirAndLogToConsole } from 'playwright/lib/util';

import { source as injectedSource } from './generated/indexSource';
Expand Down Expand Up @@ -177,7 +176,7 @@ export async function buildBundle(config: FullConfig, configDir: string): Promis
for (const d of buildInfo.deps[component])
deps.add(d);
}
setExternalDependencies(importingFile, [...deps]);
cc.setExternalDependencies(importingFile, [...deps]);
}
}

Expand Down Expand Up @@ -255,7 +254,7 @@ function vitePlugin(registerSource: string, templateDir: string, buildInfo: Buil

async writeBundle(this: PluginContext) {
for (const importInfo of importInfos.values()) {
const importPath = resolveHook(importInfo.filename, importInfo.importSource);
const importPath = transform.resolveHook(importInfo.filename, importInfo.importSource);
if (!importPath)
continue;
const deps = new Set<string>();
Expand Down
11 changes: 5 additions & 6 deletions packages/playwright-ct-core/src/viteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import fs from 'fs';
import path from 'path';

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

import type { ImportInfo } from './tsxTransform';
Expand Down Expand Up @@ -145,18 +144,18 @@ export async function createConfig(dirs: ComponentDirs, config: FullConfig, fram
}

export async function populateComponentsFromTests(componentRegistry: ComponentRegistry, componentsByImportingFile?: Map<string, string[]>) {
const importInfos: Map<string, ImportInfo[]> = await getUserData('playwright-ct-core');
const importInfos: Map<string, ImportInfo[]> = await cc.getUserData('playwright-ct-core');
for (const [file, importList] of importInfos) {
for (const importInfo of importList)
componentRegistry.set(importInfo.id, importInfo);
if (componentsByImportingFile)
componentsByImportingFile.set(file, importList.map(i => resolveHook(i.filename, i.importSource)).filter(Boolean) as string[]);
componentsByImportingFile.set(file, importList.map(i => transform.resolveHook(i.filename, i.importSource)).filter(Boolean) as string[]);
}
}

export function hasJSComponents(components: ImportInfo[]): boolean {
for (const component of components) {
const importPath = resolveHook(component.filename, component.importSource);
const importPath = transform.resolveHook(component.filename, component.importSource);
const extname = importPath ? path.extname(importPath) : '';
if (extname === '.js' || (importPath && !extname && fs.existsSync(importPath + '.js')))
return true;
Expand Down Expand Up @@ -189,7 +188,7 @@ export function transformIndexFile(id: string, content: string, templateDir: str
lines.push(registerSource);

for (const value of importInfos.values()) {
const importPath = resolveHook(value.filename, value.importSource) || value.importSource;
const importPath = transform.resolveHook(value.filename, value.importSource) || value.importSource;
lines.push(`const ${value.id} = () => import('${importPath?.replaceAll(path.sep, '/')}').then((mod) => mod.${value.remoteName || 'default'});`);
}

Expand Down
6 changes: 1 addition & 5 deletions packages/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@
"default": "./index.js"
},
"./package.json": "./package.json",
"./lib/common/configLoader": "./lib/common/configLoader.js",
"./lib/common": "./lib/common/index.js",
"./lib/fsWatcher": "./lib/fsWatcher.js",
"./lib/mcp/index": "./lib/mcp/index.js",
"./lib/program": "./lib/program.js",
"./lib/reporters/base": "./lib/reporters/base.js",
"./lib/reporters/list": "./lib/reporters/list.js",
"./lib/transform/babelBundle": "./lib/transform/babelBundle.js",
"./lib/transform/compilationCache": "./lib/transform/compilationCache.js",
"./lib/transform/esmLoader": "./lib/transform/esmLoader.js",
"./lib/transform/transform": "./lib/transform/transform.js",
"./lib/plugins": "./lib/plugins/index.js",
"./lib/runner/testRunner": "./lib/runner/testRunner.js",
"./jsx-runtime": {
Expand Down
22 changes: 11 additions & 11 deletions packages/playwright/src/agents/generateAgents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import colors from 'colors/safe';
import yaml from 'yaml';
import { mkdirIfNeeded } from '@utils/fileUtils';

import { FullConfigInternal } from '../common/config';
import { defaultSeedFile, findSeedFile, seedFileContent, seedProject } from '../mcp/test/seed';
import { parseAgentSpec } from './agentParser';

import type { AgentSpec } from './agentParser';
import type { FullConfigInternal } from '../common';

/* eslint-disable no-console */

Expand All @@ -35,8 +35,8 @@ async function loadAgentSpecs(): Promise<AgentSpec[]> {
}

export class ClaudeGenerator {
static async init(config: FullConfigInternal, projectName: string, prompts: boolean) {
await initRepo(config, projectName, {
static async init(fullConfig: FullConfigInternal, projectName: string, prompts: boolean) {
await initRepo(fullConfig, projectName, {
promptsFolder: prompts ? '.claude/prompts' : undefined,
});

Expand Down Expand Up @@ -91,8 +91,8 @@ export class ClaudeGenerator {
}

export class OpencodeGenerator {
static async init(config: FullConfigInternal, projectName: string, prompts: boolean) {
await initRepo(config, projectName, {
static async init(fullConfig: FullConfigInternal, projectName: string, prompts: boolean) {
await initRepo(fullConfig, projectName, {
defaultAgentName: 'Build',
promptsFolder: prompts ? '.opencode/prompts' : undefined
});
Expand Down Expand Up @@ -156,9 +156,9 @@ export class OpencodeGenerator {
}
}
export class CopilotGenerator {
static async init(config: FullConfigInternal, projectName: string, prompts: boolean) {
static async init(fullConfig: FullConfigInternal, projectName: string, prompts: boolean) {

await initRepo(config, projectName, {
await initRepo(fullConfig, projectName, {
defaultAgentName: 'agent',
promptsFolder: prompts ? '.github/prompts' : undefined,
promptSuffix: 'prompt'
Expand Down Expand Up @@ -228,8 +228,8 @@ export class CopilotGenerator {
}

export class VSCodeGenerator {
static async init(config: FullConfigInternal, projectName: string) {
await initRepo(config, projectName, {
static async init(fullConfig: FullConfigInternal, projectName: string) {
await initRepo(fullConfig, projectName, {
promptsFolder: undefined
});
const agents = await loadAgentSpecs();
Expand Down Expand Up @@ -341,8 +341,8 @@ type RepoParams = {
defaultAgentName?: string;
};

async function initRepo(config: FullConfigInternal, projectName: string, options: RepoParams) {
const project = seedProject(config, projectName);
async function initRepo(fullConfig: FullConfigInternal, projectName: string, options: RepoParams) {
const project = seedProject(fullConfig, projectName);
console.log(` 🎭 Using project "${project.project.name}" as a primary project`);

if (!fs.existsSync('specs')) {
Expand Down
7 changes: 3 additions & 4 deletions packages/playwright/src/cli/reportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import fs from 'fs';
import path from 'path';

import { gracefullyProcessExitDoNotHang } from '@utils/processLauncher';
import { builtInReporters, defaultReporter } from '../common/config';
import { loadConfigFromFile, loadEmptyConfigForMergeReports } from '../common/configLoader';
import { builtInReporters, config as commonConfig, configLoader } from '../common';
import { showHTMLReport } from '../reporters/html';
import { createMergedReport } from '../reporters/merge';

Expand All @@ -31,7 +30,7 @@ export async function showReport(report: string | undefined, host: string, port:

export async function mergeReports(reportDir: string | undefined, opts: { [key: string]: any }) {
const configFile = opts.config;
const config = configFile ? await loadConfigFromFile(configFile) : await loadEmptyConfigForMergeReports();
const config = configFile ? await configLoader.loadConfigFromFile(configFile) : await configLoader.loadEmptyConfigForMergeReports();

const dir = path.resolve(process.cwd(), reportDir || '');
const dirStat = await fs.promises.stat(dir).catch(e => null);
Expand All @@ -43,7 +42,7 @@ export async function mergeReports(reportDir: string | undefined, opts: { [key:
if (!reporterDescriptions && configFile)
reporterDescriptions = config.config.reporter;
if (!reporterDescriptions)
reporterDescriptions = [[defaultReporter]];
reporterDescriptions = [[commonConfig.defaultReporter]];
const rootDirOverride = configFile ? config.config.rootDir : undefined;
await createMergedReport(config, dir, reporterDescriptions!, rootDirOverride);
gracefullyProcessExitDoNotHang(0);
Expand Down
19 changes: 8 additions & 11 deletions packages/playwright/src/cli/testActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,20 @@ import path from 'path';
import { gracefullyProcessExitDoNotHang } from '@utils/processLauncher';
import { startProfiling, stopProfiling } from '@utils/profiler';

import { builtInReporters } from '../common/config';
import { loadConfigFromFile, resolveConfigLocation } from '../common/configLoader';
import { builtInReporters, configLoader, ipc } from '../common';
import { terminalScreen } from '../reporters/base';
import { filterProjects } from '../runner/projectUtils';
import * as testServer from '../runner/testServer';
import { runWatchModeLoop } from '../runner/watchMode';
import { runAllTestsWithConfig, TestRunner } from '../runner/testRunner';
import { createErrorCollectingReporter } from '../runner/reporters';

import type { ConfigCLIOverrides } from '../common/ipc';
import type { ReporterDescription } from '../../types/test';

export async function runTests(args: string[], opts: { [key: string]: any }) {
await startProfiling();
const cliOverrides = overridesFromOptions(opts);

const config = await loadConfigFromFile(opts.config, cliOverrides, opts.deps === false);
const config = await configLoader.loadConfigFromFile(opts.config, cliOverrides, opts.deps === false);
config.cliArgs = args;
config.cliGrep = opts.grep as string | undefined;
config.cliOnlyChanged = opts.onlyChanged === true ? 'HEAD' : opts.onlyChanged;
Expand Down Expand Up @@ -75,7 +72,7 @@ export async function runTests(args: string[], opts: { [key: string]: any }) {
throw new Error(`--only-changed is not supported in watch mode. If you'd like that to change, file an issue and let us know about your usecase for it.`);

const status = await runWatchModeLoop(
resolveConfigLocation(opts.config),
configLoader.resolveConfigLocation(opts.config),
{
projects: opts.project,
files: args,
Expand Down Expand Up @@ -103,19 +100,19 @@ export async function runTestServerAction(opts: { [key: string]: any }) {
}

export async function clearCache(opts: { [key: string]: any }) {
const runner = new TestRunner(resolveConfigLocation(opts.config), {});
const runner = new TestRunner(configLoader.resolveConfigLocation(opts.config), {});
const { status } = await runner.clearCache(createErrorCollectingReporter(terminalScreen));
const exitCode = status === 'interrupted' ? 130 : (status === 'passed' ? 0 : 1);
gracefullyProcessExitDoNotHang(exitCode);
}

function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverrides {
function overridesFromOptions(options: { [key: string]: any }): ipc.ConfigCLIOverrides {
if (options.ui) {
options.debug = undefined;
options.trace = undefined;
}

const overrides: ConfigCLIOverrides = {
const overrides: ipc.ConfigCLIOverrides = {
debug: options.debug,
failOnFlakyTests: options.failOnFlakyTests ? true : undefined,
forbidOnly: options.forbidOnly ? true : undefined,
Expand Down Expand Up @@ -172,7 +169,7 @@ function resolveReporterOption(reporter?: string): ReporterDescription[] | undef
return reporter.split(',').map((r: string) => [resolveReporter(r)]);
}

function resolveShardOption(shard?: string): ConfigCLIOverrides['shard'] {
function resolveShardOption(shard?: string): ipc.ConfigCLIOverrides['shard'] {
if (!shard)
return undefined;

Expand Down Expand Up @@ -200,7 +197,7 @@ function resolveShardOption(shard?: string): ConfigCLIOverrides['shard'] {
return { current, total };
}

function resolveShardWeightsOption(): ConfigCLIOverrides['shardWeights'] {
function resolveShardWeightsOption(): ipc.ConfigCLIOverrides['shardWeights'] {
const shardWeights = process.env.PWTEST_SHARD_WEIGHTS;
if (!shardWeights)
return undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright/src/common/DEPS.list
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
@utils/**
../util.ts
../transform
../isomorphic/teleReceiver.ts
../isomorphic
../globals.ts
../package.ts

[testType.ts]
../matchers/expect.ts
10 changes: 1 addition & 9 deletions packages/playwright/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import os from 'os';
import path from 'path';

import { packageJSON } from '../package';
import { getPackageJsonPath, mergeObjects } from '../util';
import { getPackageJsonPath, mergeObjects, takeFirst } from '../util';

import type { Config, Fixtures, Metadata, Project, ReporterDescription } from '../../types/test';
import type { TestRunnerPluginRegistration } from '../plugins';
Expand Down Expand Up @@ -216,14 +216,6 @@ export class FullProjectInternal {
}
}

export function takeFirst<T>(...args: (T | undefined)[]): T {
for (const arg of args) {
if (arg !== undefined)
return arg;
}
return undefined as any as T;
}

function pathResolve(baseDir: string, relative: string | undefined): string | undefined {
if (!relative)
return undefined;
Expand Down
35 changes: 35 additions & 0 deletions packages/playwright/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* 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 * as babel from '../transform/babelBundle';
export * as cc from '../transform/compilationCache';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is impossible to guess on the call site, keep the long name

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a ref to a chrome compositor!

export * as config from './config';
export * as configLoader from './configLoader';
export * as esm from './esmLoaderHost';
export * as fixtures from './fixtures';
export * as ipc from './ipc';
export * as poolBuilder from './poolBuilder';
export * as processRunner from './process';
export * as suiteUtils from './suiteUtils';
export * as test from './test';
export * as testLoader from './testLoader';
export * as testType from './testType';
export * as transform from '../transform/transform';
export { FullConfigInternal, builtInReporters } from './config';
export { ProcessRunner, startProcessRunner } from './process';
export { defineConfig } from './configLoader';
export { mergeTests } from './testType';
export type { ConfigLocation } from './config';
Loading
Loading