🚀 Socket Launch Week Day 4:Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection.Learn more
Sign In

@limrun/playwright

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@limrun/playwright - npm Package Compare versions

Comparing version
1.56.1-lim.1
to
1.60.0-lim.1
+89
lib/agents/agentParser.js
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var agentParser_exports = {};
__export(agentParser_exports, {
parseAgentSpec: () => parseAgentSpec
});
module.exports = __toCommonJS(agentParser_exports);
var import_fs = __toESM(require("fs"));
const yaml = require("playwright-core/lib/utilsBundle").yaml;
async function parseAgentSpec(filePath) {
const source = await import_fs.default.promises.readFile(filePath, "utf-8");
const { header, content } = extractYamlAndContent(source);
const { instructions, examples } = extractInstructionsAndExamples(content);
return {
...header,
instructions,
examples
};
}
function extractYamlAndContent(markdown) {
const lines = markdown.split("\n");
if (lines[0] !== "---")
throw new Error("Markdown file must start with YAML front matter (---)");
let yamlEndIndex = -1;
for (let i = 1; i < lines.length; i++) {
if (lines[i] === "---") {
yamlEndIndex = i;
break;
}
}
if (yamlEndIndex === -1)
throw new Error("YAML front matter must be closed with ---");
const yamlLines = lines.slice(1, yamlEndIndex);
const yamlRaw = yamlLines.join("\n");
const contentLines = lines.slice(yamlEndIndex + 1);
const content = contentLines.join("\n");
let header;
try {
header = yaml.parse(yamlRaw);
} catch (error) {
throw new Error(`Failed to parse YAML header: ${error.message}`);
}
if (!header.name)
throw new Error('YAML header must contain a "name" field');
if (!header.description)
throw new Error('YAML header must contain a "description" field');
return { header, content };
}
function extractInstructionsAndExamples(content) {
const examples = [];
const instructions = content.split("<example>")[0].trim();
const exampleRegex = /<example>([\s\S]*?)<\/example>/g;
let match;
while ((match = exampleRegex.exec(content)) !== null) {
const example = match[1].trim();
examples.push(example.replace(/[\n]/g, " ").replace(/ +/g, " "));
}
return { instructions, examples };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
parseAgentSpec
});
name: "Copilot Setup Steps"
on:
workflow_dispatch:
push:
paths:
- .github/workflows/copilot-setup-steps.yml
pull_request:
paths:
- .github/workflows/copilot-setup-steps.yml
jobs:
copilot-setup-steps:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
# Customize this step as needed
- name: Build application
run: npx run build
---
agent: ${defaultAgentName}
description: Produce test coverage
---
Parameters:
- Task: the task to perform
- Seed file (optional): the seed file to use, defaults to `${seedFile}`
- Test plan file (optional): the test plan file to write, under `specs/` folder.
1. Call #playwright-test-planner subagent with prompt:
<plan>
<task-text><!-- the task --></task-text>
<seed-file><!-- path to seed file --></seed-file>
<plan-file><!-- path to test plan file to generate --></plan-file>
</plan>
2. For each test case from the test plan file (1.1, 1.2, ...), one after another, not in parallel, call #playwright-test-generator subagent with prompt:
<generate>
<test-suite><!-- Verbatim name of the test spec group w/o ordinal like "Multiplication tests" --></test-suite>
<test-name><!-- Name of the test case without the ordinal like "should add two numbers" --></test-name>
<test-file><!-- Name of the file to save the test into, like tests/multiplication/should-add-two-numbers.spec.ts --></test-file>
<seed-file><!-- Seed file path from test plan --></seed-file>
<body><!-- Test case content including steps and expectations --></body>
</generate>
3. Call #playwright-test-healer subagent with prompt:
<heal>Run all tests and fix the failing ones one after another.</heal>
---
agent: playwright-test-generator
description: Generate test plan
---
Generate tests for the test plan's bullet 1.1 Add item to card.
Test plan: `specs/coverage.plan.md`
---
name: playwright-test-generator
description: Use this agent when you need to create automated browser tests using Playwright
model: sonnet
color: blue
tools:
- search
- playwright-test/browser_click
- playwright-test/browser_drag
- playwright-test/browser_evaluate
- playwright-test/browser_file_upload
- playwright-test/browser_handle_dialog
- playwright-test/browser_hover
- playwright-test/browser_navigate
- playwright-test/browser_press_key
- playwright-test/browser_select_option
- playwright-test/browser_snapshot
- playwright-test/browser_type
- playwright-test/browser_verify_element_visible
- playwright-test/browser_verify_list_visible
- playwright-test/browser_verify_text_visible
- playwright-test/browser_verify_value
- playwright-test/browser_wait_for
- playwright-test/generator_read_log
- playwright-test/generator_setup_page
- playwright-test/generator_write_test
---
You are a Playwright Test Generator, an expert in browser automation and end-to-end testing.
Your specialty is creating robust, reliable Playwright tests that accurately simulate user interactions and validate
application behavior.
# For each test you generate
- Obtain the test plan with all the steps and verification specification
- Run the `generator_setup_page` tool to set up page for the scenario
- For each step and verification in the scenario, do the following:
- Use Playwright tool to manually execute it in real-time.
- Use the step description as the intent for each Playwright tool call.
- Retrieve generator log via `generator_read_log`
- Immediately after reading the test log, invoke `generator_write_test` with the generated source code
- File should contain single test
- File name must be fs-friendly scenario name
- Test must be placed in a describe matching the top-level test plan item
- Test title must match the scenario name
- Includes a comment with the step text before each step execution. Do not duplicate comments if step requires
multiple actions.
- Always use best practices from the log when generating tests.
<example-generation>
For following plan:
```markdown file=specs/plan.md
### 1. Adding New Todos
**Seed:** `tests/seed.spec.ts`
#### 1.1 Add Valid Todo
**Steps:**
1. Click in the "What needs to be done?" input field
#### 1.2 Add Multiple Todos
...
```
Following file is generated:
```ts file=add-valid-todo.spec.ts
// spec: specs/plan.md
// seed: tests/seed.spec.ts
test.describe('Adding New Todos', () => {
test('Add Valid Todo', async { page } => {
// 1. Click in the "What needs to be done?" input field
await page.click(...);
...
});
});
```
</example-generation>
<example>
Context: User wants to generate a test for the test plan item.
<test-suite><!-- Verbatim name of the test spec group w/o ordinal like "Multiplication tests" --></test-suite>
<test-name><!-- Name of the test case without the ordinal like "should add two numbers" --></test-name>
<test-file><!-- Name of the file to save the test into, like tests/multiplication/should-add-two-numbers.spec.ts --></test-file>
<seed-file><!-- Seed file path from test plan --></seed-file>
<body><!-- Test case content including steps and expectations --></body>
</example>
---
agent: playwright-test-healer
description: Fix tests
---
Run all my tests and fix the failing ones.
---
name: playwright-test-healer
description: Use this agent when you need to debug and fix failing Playwright tests
model: sonnet
color: red
tools:
- search
- edit
- playwright-test/browser_console_messages
- playwright-test/browser_evaluate
- playwright-test/browser_generate_locator
- playwright-test/browser_network_request
- playwright-test/browser_network_requests
- playwright-test/browser_snapshot
- playwright-test/test_debug
- playwright-test/test_list
- playwright-test/test_run
---
You are the Playwright Test Healer, an expert test automation engineer specializing in debugging and
resolving Playwright test failures. Your mission is to systematically identify, diagnose, and fix
broken Playwright tests using a methodical approach.
Your workflow:
1. **Initial Execution**: Run all tests using `test_run` tool to identify failing tests
2. **Debug failed tests**: For each failing test run `test_debug`.
3. **Error Investigation**: When the test pauses on errors, use available Playwright MCP tools to:
- Examine the error details
- Capture page snapshot to understand the context
- Analyze selectors, timing issues, or assertion failures
4. **Root Cause Analysis**: Determine the underlying cause of the failure by examining:
- Element selectors that may have changed
- Timing and synchronization issues
- Data dependencies or test environment problems
- Application changes that broke test assumptions
5. **Code Remediation**: Edit the test code to address identified issues, focusing on:
- Updating selectors to match current application state
- Fixing assertions and expected values
- Improving test reliability and maintainability
- For inherently dynamic data, utilize regular expressions to produce resilient locators
6. **Verification**: Restart the test after each fix to validate the changes
7. **Iteration**: Repeat the investigation and fixing process until the test passes cleanly
Key principles:
- Be systematic and thorough in your debugging approach
- Document your findings and reasoning for each fix
- Prefer robust, maintainable solutions over quick hacks
- Use Playwright best practices for reliable test automation
- If multiple errors exist, fix them one at a time and retest
- Provide clear explanations of what was broken and how you fixed it
- You will continue this process until the test runs successfully without any failures or errors.
- If the error persists and you have high level of confidence that the test is correct, mark this test as test.fixme()
so that it is skipped during the execution. Add a comment before the failing step explaining what is happening instead
of the expected behavior.
- Do not ask user questions, you are not interactive tool, do the most reasonable thing possible to pass the test.
- Never wait for networkidle or use other discouraged or deprecated apis
---
agent: playwright-test-planner
description: Create test plan
---
Create test plan for "add to cart" functionality of my app.
- Seed file: `${seedFile}`
- Test plan: `specs/coverage.plan.md`
---
name: playwright-test-planner
description: Use this agent when you need to create comprehensive test plan for a web application or website
model: sonnet
color: green
tools:
- search
- playwright-test/browser_click
- playwright-test/browser_close
- playwright-test/browser_console_messages
- playwright-test/browser_drag
- playwright-test/browser_evaluate
- playwright-test/browser_file_upload
- playwright-test/browser_handle_dialog
- playwright-test/browser_hover
- playwright-test/browser_navigate
- playwright-test/browser_navigate_back
- playwright-test/browser_network_request
- playwright-test/browser_network_requests
- playwright-test/browser_press_key
- playwright-test/browser_run_code_unsafe
- playwright-test/browser_select_option
- playwright-test/browser_snapshot
- playwright-test/browser_take_screenshot
- playwright-test/browser_type
- playwright-test/browser_wait_for
- playwright-test/planner_setup_page
- playwright-test/planner_save_plan
---
You are an expert web test planner with extensive experience in quality assurance, user experience testing, and test
scenario design. Your expertise includes functional testing, edge case identification, and comprehensive test coverage
planning.
You will:
1. **Navigate and Explore**
- Invoke the `planner_setup_page` tool once to set up page before using any other tools
- Explore the browser snapshot
- Do not take screenshots unless absolutely necessary
- Use `browser_*` tools to navigate and discover interface
- Thoroughly explore the interface, identifying all interactive elements, forms, navigation paths, and functionality
2. **Analyze User Flows**
- Map out the primary user journeys and identify critical paths through the application
- Consider different user types and their typical behaviors
3. **Design Comprehensive Scenarios**
Create detailed test scenarios that cover:
- Happy path scenarios (normal user behavior)
- Edge cases and boundary conditions
- Error handling and validation
4. **Structure Test Plans**
Each scenario must include:
- Clear, descriptive title
- Detailed step-by-step instructions
- Expected outcomes where appropriate
- Assumptions about starting state (always assume blank/fresh state)
- Success criteria and failure conditions
5. **Create Documentation**
Submit your test plan using `planner_save_plan` tool.
**Quality Standards**:
- Write steps that are specific enough for any tester to follow
- Include negative testing scenarios
- Ensure scenarios are independent and can be run in any order
**Output Format**: Always save the complete test plan as a markdown file with clear headings, numbered steps, and
professional formatting suitable for sharing with development and QA teams.
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var reportActions_exports = {};
__export(reportActions_exports, {
mergeReports: () => mergeReports,
showReport: () => showReport
});
module.exports = __toCommonJS(reportActions_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_common = require("../common");
var import_runner = require("../runner");
const { gracefullyProcessExitDoNotHang } = require("playwright-core/lib/coreBundle").utils;
async function showReport(report, host, port) {
await import_runner.html.showHTMLReport(report, host, port);
}
async function mergeReports(reportDir, opts) {
const configFile = opts.config;
const config = configFile ? await import_common.configLoader.loadConfigFromFile(configFile) : await import_common.configLoader.loadEmptyConfigForMergeReports();
const dir = import_path.default.resolve(process.cwd(), reportDir || "");
const dirStat = await import_fs.default.promises.stat(dir).catch((e) => null);
if (!dirStat)
throw new Error("Directory does not exist: " + dir);
if (!dirStat.isDirectory())
throw new Error(`"${dir}" is not a directory`);
let reporterDescriptions = resolveReporterOption(opts.reporter);
if (!reporterDescriptions && configFile)
reporterDescriptions = config.config.reporter;
if (!reporterDescriptions)
reporterDescriptions = [[import_common.config.defaultReporter]];
const rootDirOverride = configFile ? config.config.rootDir : void 0;
await import_runner.merge.createMergedReport(config, dir, reporterDescriptions, rootDirOverride);
gracefullyProcessExitDoNotHang(0);
}
function resolveReporterOption(reporter) {
if (!reporter || !reporter.length)
return void 0;
return reporter.split(",").map((r) => [resolveReporter(r)]);
}
function resolveReporter(id) {
if (import_common.builtInReporters.includes(id))
return id;
const localPath = import_path.default.resolve(process.cwd(), id);
if (import_fs.default.existsSync(localPath))
return localPath;
return require.resolve(id, { paths: [process.cwd()] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
mergeReports,
showReport
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testActions_exports = {};
__export(testActions_exports, {
clearCache: () => clearCache,
runTestServerAction: () => runTestServerAction,
runTests: () => runTests
});
module.exports = __toCommonJS(testActions_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_common = require("../common");
var import_runner = require("../runner");
const { gracefullyProcessExitDoNotHang } = require("playwright-core/lib/coreBundle").utils;
const { startProfiling, stopProfiling } = require("playwright-core/lib/coreBundle").utils;
async function runTests(args, opts) {
await startProfiling();
const cliOverrides = overridesFromOptions(opts);
const config = await import_common.configLoader.loadConfigFromFile(opts.config, cliOverrides, opts.deps === false);
const options = {
locations: args.length ? args : void 0,
grep: opts.grep,
grepInvert: opts.grepInvert,
onlyChanged: opts.onlyChanged === true ? "HEAD" : opts.onlyChanged,
listMode: !!opts.list,
projectFilter: opts.project || void 0,
passWithNoTests: !!opts.passWithNoTests,
lastFailed: !!opts.lastFailed,
testList: opts.testList ? import_path.default.resolve(process.cwd(), opts.testList) : void 0,
testListInvert: opts.testListInvert ? import_path.default.resolve(process.cwd(), opts.testListInvert) : void 0,
shardWeights: resolveShardWeightsOption()
};
import_runner.projectUtils.filterProjects(config.projects, options.projectFilter);
if (opts.ui || opts.uiHost || opts.uiPort) {
if (opts.onlyChanged)
throw new Error(`--only-changed is not supported in UI mode. If you'd like that to change, see https://github.com/microsoft/playwright/issues/15075 for more details.`);
const status2 = await import_runner.testServer.runUIMode(opts.config, cliOverrides, {
host: opts.uiHost,
port: opts.uiPort ? +opts.uiPort : void 0,
args,
grep: opts.grep,
grepInvert: opts.grepInvert,
project: opts.project || void 0,
reporter: Array.isArray(opts.reporter) ? opts.reporter : opts.reporter ? [opts.reporter] : void 0
});
await stopProfiling("runner");
const exitCode2 = status2 === "interrupted" ? 130 : status2 === "passed" ? 0 : 1;
gracefullyProcessExitDoNotHang(exitCode2);
return;
}
if (process.env.PWTEST_WATCH) {
if (opts.onlyChanged)
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 status2 = await import_runner.watchMode.runWatchModeLoop(
import_common.configLoader.resolveConfigLocation(opts.config),
{
projects: opts.project,
files: args,
grep: opts.grep
}
);
await stopProfiling("runner");
const exitCode2 = status2 === "interrupted" ? 130 : status2 === "passed" ? 0 : 1;
gracefullyProcessExitDoNotHang(exitCode2);
return;
}
const status = await import_runner.testRunner.runAllTestsWithConfig(config, options);
await stopProfiling("runner");
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
gracefullyProcessExitDoNotHang(exitCode);
}
async function runTestServerAction(opts) {
const host = opts.host;
const port = opts.port ? +opts.port : void 0;
const status = await import_runner.testServer.runTestServer(opts.config, {}, { host, port });
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
gracefullyProcessExitDoNotHang(exitCode);
}
async function clearCache(opts) {
const runner = new import_runner.testRunner.TestRunner(import_common.configLoader.resolveConfigLocation(opts.config), {});
const { status } = await runner.clearCache(import_runner.runnerReporters.createErrorCollectingReporter(import_runner.base.terminalScreen));
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
gracefullyProcessExitDoNotHang(exitCode);
}
function overridesFromOptions(options) {
if (options.ui) {
options.debug = void 0;
options.trace = void 0;
}
const overrides = {
debug: options.debug,
failOnFlakyTests: options.failOnFlakyTests ? true : void 0,
forbidOnly: options.forbidOnly ? true : void 0,
fullyParallel: options.fullyParallel ? true : void 0,
globalTimeout: options.globalTimeout ? parseInt(options.globalTimeout, 10) : void 0,
maxFailures: options.x ? 1 : options.maxFailures ? parseInt(options.maxFailures, 10) : void 0,
outputDir: options.output ? import_path.default.resolve(process.cwd(), options.output) : void 0,
pause: !!process.env.PWPAUSE,
quiet: options.quiet ? options.quiet : void 0,
repeatEach: options.repeatEach ? parseInt(options.repeatEach, 10) : void 0,
retries: options.retries ? parseInt(options.retries, 10) : void 0,
reporter: resolveReporterOption(options.reporter),
shard: resolveShardOption(options.shard),
timeout: options.timeout ? parseInt(options.timeout, 10) : void 0,
tsconfig: options.tsconfig ? import_path.default.resolve(process.cwd(), options.tsconfig) : void 0,
ignoreSnapshots: options.ignoreSnapshots ? !!options.ignoreSnapshots : void 0,
updateSnapshots: options.updateSnapshots,
updateSourceMethod: options.updateSourceMethod,
use: {
trace: options.trace
},
workers: options.workers
};
if (options.browser) {
const browserOpt = options.browser.toLowerCase();
if (!["all", "chromium", "firefox", "webkit"].includes(browserOpt))
throw new Error(`Unsupported browser "${options.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
const browserNames = browserOpt === "all" ? ["chromium", "firefox", "webkit"] : [browserOpt];
overrides.projects = browserNames.map((browserName) => {
return {
name: browserName,
use: { browserName }
};
});
}
if (options.headed)
overrides.use.headless = false;
if (options.debug === "inspector") {
overrides.use.headless = false;
process.env.PWDEBUG = "1";
}
if (overrides.tsconfig && !import_fs.default.existsSync(overrides.tsconfig))
throw new Error(`--tsconfig "${options.tsconfig}" does not exist`);
return overrides;
}
function resolveReporterOption(reporter) {
if (!reporter || !reporter.length)
return void 0;
return reporter.split(",").map((r) => [resolveReporter(r)]);
}
function resolveShardOption(shard) {
if (!shard)
return void 0;
const shardPair = shard.split("/");
if (shardPair.length !== 2) {
throw new Error(
`--shard "${shard}", expected format is "current/all", 1-based, for example "3/5".`
);
}
const current = parseInt(shardPair[0], 10);
const total = parseInt(shardPair[1], 10);
if (isNaN(total) || total < 1)
throw new Error(`--shard "${shard}" total must be a positive number`);
if (isNaN(current) || current < 1 || current > total) {
throw new Error(
`--shard "${shard}" current must be a positive number, not greater than shard total`
);
}
return { current, total };
}
function resolveShardWeightsOption() {
const shardWeights = process.env.PWTEST_SHARD_WEIGHTS;
if (!shardWeights)
return void 0;
return shardWeights.split(":").map((w) => {
const weight = parseInt(w, 10);
if (isNaN(weight) || weight < 0)
throw new Error(`PWTEST_SHARD_WEIGHTS="${shardWeights}" weights must be non-negative numbers`);
return weight;
});
}
function resolveReporter(id) {
if (import_common.builtInReporters.includes(id))
return id;
const localPath = import_path.default.resolve(process.cwd(), id);
if (import_fs.default.existsSync(localPath))
return localPath;
return require.resolve(id, { paths: [process.cwd()] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
clearCache,
runTestServerAction,
runTests
});

Sorry, the diff of this file is too big to display

# packages/playwright/lib/common/index.js
# total: 111.2 KB
## Inlined (20)
11.6 KB packages/playwright/src/common/config.ts
13.7 KB packages/playwright/src/common/configLoader.ts
2.1 KB packages/playwright/src/common/esmLoaderHost.ts
10.9 KB packages/playwright/src/common/fixtures.ts
0.8 KB packages/playwright/src/common/index.ts
1.3 KB packages/playwright/src/common/ipc.ts
2.1 KB packages/playwright/src/common/poolBuilder.ts
3.7 KB packages/playwright/src/common/process.ts
4.7 KB packages/playwright/src/common/suiteUtils.ts
7.9 KB packages/playwright/src/common/test.ts
2.1 KB packages/playwright/src/common/testLoader.ts
12.5 KB packages/playwright/src/common/testType.ts
1.2 KB packages/playwright/src/common/validators.ts
1.3 KB packages/playwright/src/isomorphic/teleReceiver.ts
9.6 KB packages/playwright/src/transform/compilationCache.ts
1.1 KB packages/playwright/src/transform/pirates.ts
1.1 KB packages/playwright/src/transform/portTransport.ts
10.2 KB packages/playwright/src/transform/transform.ts
2.9 KB packages/playwright/src/transform/tsconfig-loader.ts
7.5 KB packages/playwright/src/util.ts
## External (9)
../globals
../matchers/expect
../package
../transform/esmLoader.js
playwright
playwright-core/lib/bootstrap
playwright-core/lib/coreBundle
playwright-core/lib/utilsBundle
playwright-core/package.json
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var errorContext_exports = {};
__export(errorContext_exports, {
buildErrorContext: () => buildErrorContext
});
module.exports = __toCommonJS(errorContext_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_util = require("./util");
const { parseErrorStack } = require("playwright-core/lib/coreBundle").iso;
const { stripAnsiEscapes } = require("playwright-core/lib/coreBundle").iso;
const fixTestInstructions = `# Instructions
- Following Playwright test failed.
- Explain why, be concise, respect Playwright best practices.
- Provide a snippet of code with the fix, if possible.
`;
function buildErrorContext(options) {
const { titlePath, location, errors, pageSnapshot } = options;
const meaningfulErrors = errors.filter((e) => !!e.message);
if (!meaningfulErrors.length && !pageSnapshot)
return void 0;
const lines = [
fixTestInstructions,
"# Test info",
"",
`- Name: ${titlePath.join(" >> ")}`,
`- Location: ${(0, import_util.relativeFilePath)(location.file)}:${location.line}:${location.column}`
];
if (meaningfulErrors.length) {
lines.push("", "# Error details");
for (const error of meaningfulErrors) {
lines.push(
"",
"```",
stripAnsiEscapes(error.message || ""),
"```"
);
if (error.errorContext) {
lines.push(
"",
"```yaml",
error.errorContext,
"```"
);
}
}
}
if (pageSnapshot) {
lines.push(
"",
"# Page snapshot",
"",
"```yaml",
pageSnapshot,
"```"
);
}
const lastError = meaningfulErrors[meaningfulErrors.length - 1];
const codeFrame = lastError ? buildCodeFrame(lastError, location) : void 0;
if (codeFrame) {
lines.push(
"",
"# Test source",
"",
"```ts",
codeFrame,
"```"
);
}
return lines.join("\n");
}
function buildCodeFrame(error, testLocation) {
const stack = error.stack;
if (!stack)
return void 0;
const parsed = parseErrorStack(stack, import_path.default.sep);
const errorLocation = parsed.location;
if (!errorLocation)
return void 0;
let source;
try {
source = import_fs.default.readFileSync(errorLocation.file, "utf8");
} catch {
return void 0;
}
const sourceLines = source.split("\n");
const linesAbove = 100;
const linesBelow = 100;
const start = Math.max(0, errorLocation.line - linesAbove - 1);
const end = Math.min(sourceLines.length, errorLocation.line + linesBelow);
const scope = sourceLines.slice(start, end);
const lineNumberWidth = String(end).length;
const message = stripAnsiEscapes(error.message || "").split("\n")[0] || void 0;
const frame = scope.map((line, index) => `${start + index + 1 === errorLocation.line ? "> " : " "}${(start + index + 1).toString().padEnd(lineNumberWidth, " ")} | ${line}`);
if (message)
frame.splice(errorLocation.line - start, 0, `${" ".repeat(lineNumberWidth + 2)} | ${" ".repeat(Math.max(0, errorLocation.column - 2))} ^ ${message}`);
return frame.join("\n");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
buildErrorContext
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var globals_exports = {};
__export(globals_exports, {
currentTestInfo: () => currentTestInfo,
currentlyLoadingFileSuite: () => currentlyLoadingFileSuite,
isWorkerProcess: () => isWorkerProcess,
setCurrentTestInfo: () => setCurrentTestInfo,
setCurrentlyLoadingFileSuite: () => setCurrentlyLoadingFileSuite,
setIsWorkerProcess: () => setIsWorkerProcess
});
module.exports = __toCommonJS(globals_exports);
let currentTestInfoValue = null;
function setCurrentTestInfo(testInfo) {
currentTestInfoValue = testInfo;
}
function currentTestInfo() {
return currentTestInfoValue;
}
let currentFileSuite;
function setCurrentlyLoadingFileSuite(suite) {
currentFileSuite = suite;
}
function currentlyLoadingFileSuite() {
return currentFileSuite;
}
let _isWorkerProcess = false;
function setIsWorkerProcess() {
_isWorkerProcess = true;
}
function isWorkerProcess() {
return _isWorkerProcess;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
currentTestInfo,
currentlyLoadingFileSuite,
isWorkerProcess,
setCurrentTestInfo,
setCurrentlyLoadingFileSuite,
setIsWorkerProcess
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/playwright/src/isomorphic/index.ts
var index_exports = {};
__export(index_exports, {
TestServerConnection: () => TestServerConnection,
TestServerConnectionClosedError: () => TestServerConnectionClosedError,
WebSocketTestServerTransport: () => WebSocketTestServerTransport
});
module.exports = __toCommonJS(index_exports);
// packages/playwright/src/isomorphic/events.ts
var Disposable;
((Disposable2) => {
function disposeAll(disposables) {
for (const disposable of disposables.splice(0))
disposable.dispose();
}
Disposable2.disposeAll = disposeAll;
})(Disposable || (Disposable = {}));
var EventEmitter = class {
constructor() {
this._listeners = /* @__PURE__ */ new Set();
this.event = (listener, disposables) => {
this._listeners.add(listener);
let disposed = false;
const self = this;
const result = {
dispose() {
if (!disposed) {
disposed = true;
self._listeners.delete(listener);
}
}
};
if (disposables)
disposables.push(result);
return result;
};
}
fire(event) {
const dispatch = !this._deliveryQueue;
if (!this._deliveryQueue)
this._deliveryQueue = [];
for (const listener of this._listeners)
this._deliveryQueue.push({ listener, event });
if (!dispatch)
return;
for (let index = 0; index < this._deliveryQueue.length; index++) {
const { listener, event: event2 } = this._deliveryQueue[index];
listener.call(null, event2);
}
this._deliveryQueue = void 0;
}
dispose() {
this._listeners.clear();
if (this._deliveryQueue)
this._deliveryQueue = [];
}
};
// packages/playwright/src/isomorphic/testServerConnection.ts
var TestServerConnectionClosedError = class extends Error {
};
var WebSocketTestServerTransport = class {
constructor(url) {
this._ws = new WebSocket(url);
}
onmessage(listener) {
this._ws.addEventListener("message", (event) => listener(event.data.toString()));
}
onopen(listener) {
this._ws.addEventListener("open", listener);
}
onerror(listener) {
this._ws.addEventListener("error", listener);
}
onclose(listener) {
this._ws.addEventListener("close", listener);
}
send(data) {
this._ws.send(data);
}
close() {
this._ws.close();
}
};
var TestServerConnection = class {
constructor(transport) {
this._onCloseEmitter = new EventEmitter();
this._onReportEmitter = new EventEmitter();
this._onStdioEmitter = new EventEmitter();
this._onTestFilesChangedEmitter = new EventEmitter();
this._onLoadTraceRequestedEmitter = new EventEmitter();
this._onTestPausedEmitter = new EventEmitter();
this._lastId = 0;
this._callbacks = /* @__PURE__ */ new Map();
this._isClosed = false;
this.onClose = this._onCloseEmitter.event;
this.onReport = this._onReportEmitter.event;
this.onStdio = this._onStdioEmitter.event;
this.onTestFilesChanged = this._onTestFilesChangedEmitter.event;
this.onLoadTraceRequested = this._onLoadTraceRequestedEmitter.event;
this.onTestPaused = this._onTestPausedEmitter.event;
this._transport = transport;
this._transport.onmessage((data) => {
const message = JSON.parse(data);
const { id, result, error, method, params } = message;
if (id) {
const callback = this._callbacks.get(id);
if (!callback)
return;
this._callbacks.delete(id);
if (error)
callback.reject(new Error(error));
else
callback.resolve(result);
} else {
this._dispatchEvent(method, params);
}
});
const pingInterval = setInterval(() => this._sendMessage("ping").catch(() => {
}), 3e4);
this._connectedPromise = new Promise((f, r) => {
this._transport.onopen(f);
this._transport.onerror(r);
});
this._transport.onclose(() => {
this._isClosed = true;
this._onCloseEmitter.fire();
clearInterval(pingInterval);
for (const callback of this._callbacks.values())
callback.reject(callback.error);
this._callbacks.clear();
});
}
isClosed() {
return this._isClosed;
}
async _sendMessage(method, params) {
const logForTest = globalThis.__logForTest;
logForTest?.({ method, params });
await this._connectedPromise;
const id = ++this._lastId;
const message = { id, method, params };
const error = new TestServerConnectionClosedError(`${method}: test server connection closed`);
this._transport.send(JSON.stringify(message));
return new Promise((resolve, reject) => {
this._callbacks.set(id, { resolve, reject, error });
});
}
_sendMessageNoReply(method, params) {
this._sendMessage(method, params).catch(() => {
});
}
_dispatchEvent(method, params) {
if (method === "report")
this._onReportEmitter.fire(params);
else if (method === "stdio")
this._onStdioEmitter.fire(params);
else if (method === "testFilesChanged")
this._onTestFilesChangedEmitter.fire(params);
else if (method === "loadTraceRequested")
this._onLoadTraceRequestedEmitter.fire(params);
else if (method === "testPaused")
this._onTestPausedEmitter.fire(params);
}
async initialize(params) {
await this._sendMessage("initialize", params);
}
async ping(params) {
await this._sendMessage("ping", params);
}
async pingNoReply(params) {
this._sendMessageNoReply("ping", params);
}
async watch(params) {
await this._sendMessage("watch", params);
}
watchNoReply(params) {
this._sendMessageNoReply("watch", params);
}
async open(params) {
await this._sendMessage("open", params);
}
openNoReply(params) {
this._sendMessageNoReply("open", params);
}
async resizeTerminal(params) {
await this._sendMessage("resizeTerminal", params);
}
resizeTerminalNoReply(params) {
this._sendMessageNoReply("resizeTerminal", params);
}
async checkBrowsers(params) {
return await this._sendMessage("checkBrowsers", params);
}
async installBrowsers(params) {
await this._sendMessage("installBrowsers", params);
}
async runGlobalSetup(params) {
return await this._sendMessage("runGlobalSetup", params);
}
async runGlobalTeardown(params) {
return await this._sendMessage("runGlobalTeardown", params);
}
async clearCache(params) {
return await this._sendMessage("clearCache", params);
}
async listFiles(params) {
return await this._sendMessage("listFiles", params);
}
async listTests(params) {
return await this._sendMessage("listTests", params);
}
async runTests(params) {
return await this._sendMessage("runTests", params);
}
async findRelatedTestFiles(params) {
return await this._sendMessage("findRelatedTestFiles", params);
}
async stopTests(params) {
await this._sendMessage("stopTests", params);
}
stopTestsNoReply(params) {
this._sendMessageNoReply("stopTests", params);
}
async closeGracefully(params) {
await this._sendMessage("closeGracefully", params);
}
close() {
try {
this._transport.close();
} catch {
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestServerConnection,
TestServerConnectionClosedError,
WebSocketTestServerTransport
});
# packages/playwright/lib/isomorphic.js
# total: 8.0 KB
## Inlined (3)
1.3 KB packages/playwright/src/isomorphic/events.ts
0.3 KB packages/playwright/src/isomorphic/index.ts
5.3 KB packages/playwright/src/isomorphic/testServerConnection.ts
## External (0)
"use strict";
// packages/playwright/src/loader/loaderProcessEntry.ts
var import_common2 = require("../common");
// packages/playwright/src/loader/loaderMain.ts
var import_common = require("../common");
var LoaderMain = class extends import_common.ProcessRunner {
constructor(serializedConfig) {
super();
this._poolBuilder = import_common.poolBuilder.PoolBuilder.createForLoader();
this._serializedConfig = serializedConfig;
}
_config() {
if (!this._configPromise)
this._configPromise = import_common.configLoader.deserializeConfig(this._serializedConfig);
return this._configPromise;
}
async loadTestFile(params) {
const testErrors = [];
const config = await this._config();
const fileSuite = await import_common.testLoader.loadTestFile(params.file, config, testErrors);
this._poolBuilder.buildPools(fileSuite);
return { fileSuite: fileSuite._deepSerialize(), testErrors };
}
async getCompilationCacheFromLoader() {
await import_common.esm.incorporateCompilationCache();
return import_common.cc.serializeCompilationCache();
}
};
var create = (config) => new LoaderMain(config);
// packages/playwright/src/loader/loaderProcessEntry.ts
(0, import_common2.startProcessRunner)(create);
# packages/playwright/lib/loader/loaderProcessEntry.js
# total: 1.2 KB
## Inlined (2)
1.0 KB packages/playwright/src/loader/loaderMain.ts
0.1 KB packages/playwright/src/loader/loaderProcessEntry.ts
## External (1)
../common
packages/playwright/lib/matchers/expect.js
THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
The following npm packages are inlined into this bundle.
- @babel/code-frame@7.29.0 (https://github.com/babel/babel)
- @babel/helper-validator-identifier@7.28.5 (https://github.com/babel/babel)
- @jest/diff-sequences@30.0.1 (https://github.com/jestjs/jest)
- @jest/expect-utils@30.2.0 (https://github.com/jestjs/jest)
- @jest/get-type@30.1.0 (https://github.com/jestjs/jest)
- ansi-styles@4.3.0 (https://github.com/chalk/ansi-styles)
- ansi-styles@5.2.0 (https://github.com/chalk/ansi-styles)
- braces@3.0.3 (https://github.com/micromatch/braces)
- chalk@4.1.2 (https://github.com/chalk/chalk)
- color-convert@2.0.1 (https://github.com/Qix-/color-convert)
- color-name@1.1.4 (https://github.com/colorjs/color-name)
- escape-string-regexp@2.0.0 (https://github.com/sindresorhus/escape-string-regexp)
- fill-range@7.1.1 (https://github.com/jonschlinkert/fill-range)
- graceful-fs@4.2.11 (https://github.com/isaacs/node-graceful-fs)
- has-flag@4.0.0 (https://github.com/sindresorhus/has-flag)
- is-number@7.0.0 (https://github.com/jonschlinkert/is-number)
- jest-diff@30.2.0 (https://github.com/jestjs/jest)
- jest-matcher-utils@30.2.0 (https://github.com/jestjs/jest)
- jest-message-util@30.2.0 (https://github.com/jestjs/jest)
- js-tokens@4.0.0 (https://github.com/lydell/js-tokens)
- micromatch@4.0.8 (https://github.com/micromatch/micromatch)
- picocolors@1.1.1 (https://github.com/alexeyraspopov/picocolors)
- picomatch@2.3.2 (https://github.com/micromatch/picomatch)
- pretty-format@30.2.0 (https://github.com/jestjs/jest)
- react-is@18.3.1 (https://github.com/facebook/react)
- slash@3.0.0 (https://github.com/sindresorhus/slash)
- stack-utils@2.0.6 (https://github.com/tapjs/stack-utils)
- supports-color@7.2.0 (https://github.com/chalk/supports-color)
- to-regex-range@5.0.1 (https://github.com/micromatch/to-regex-range)
%% @babel/code-frame@7.29.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF @babel/code-frame@7.29.0 NOTICES AND INFORMATION
%% @babel/helper-validator-identifier@7.28.5 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF @babel/helper-validator-identifier@7.28.5 NOTICES AND INFORMATION
%% @jest/diff-sequences@30.0.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Copyright Contributors to the Jest project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF @jest/diff-sequences@30.0.1 NOTICES AND INFORMATION
%% @jest/expect-utils@30.2.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Copyright Contributors to the Jest project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF @jest/expect-utils@30.2.0 NOTICES AND INFORMATION
%% @jest/get-type@30.1.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Copyright Contributors to the Jest project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF @jest/get-type@30.1.0 NOTICES AND INFORMATION
%% ansi-styles@4.3.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF ansi-styles@4.3.0 NOTICES AND INFORMATION
%% ansi-styles@5.2.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF ansi-styles@5.2.0 NOTICES AND INFORMATION
%% braces@3.0.3 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2014-present, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF braces@3.0.3 NOTICES AND INFORMATION
%% chalk@4.1.2 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF chalk@4.1.2 NOTICES AND INFORMATION
%% color-convert@2.0.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
Copyright (c) 2011-2016 Heather Arthur <fayearthur@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF color-convert@2.0.1 NOTICES AND INFORMATION
%% color-name@1.1.4 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2015 Dmitry Ivanov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF color-name@1.1.4 NOTICES AND INFORMATION
%% escape-string-regexp@2.0.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF escape-string-regexp@2.0.0 NOTICES AND INFORMATION
%% fill-range@7.1.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2014-present, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF fill-range@7.1.1 NOTICES AND INFORMATION
%% graceful-fs@4.2.11 NOTICES AND INFORMATION BEGIN HERE
=========================================
The ISC License
Copyright (c) 2011-2022 Isaac Z. Schlueter, Ben Noordhuis, and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
=========================================
END OF graceful-fs@4.2.11 NOTICES AND INFORMATION
%% has-flag@4.0.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF has-flag@4.0.0 NOTICES AND INFORMATION
%% is-number@7.0.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2014-present, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF is-number@7.0.0 NOTICES AND INFORMATION
%% jest-diff@30.2.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Copyright Contributors to the Jest project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF jest-diff@30.2.0 NOTICES AND INFORMATION
%% jest-matcher-utils@30.2.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Copyright Contributors to the Jest project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF jest-matcher-utils@30.2.0 NOTICES AND INFORMATION
%% jest-message-util@30.2.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Copyright Contributors to the Jest project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF jest-message-util@30.2.0 NOTICES AND INFORMATION
%% js-tokens@4.0.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2014, 2015, 2016, 2017, 2018 Simon Lydell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF js-tokens@4.0.0 NOTICES AND INFORMATION
%% micromatch@4.0.8 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2014-present, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF micromatch@4.0.8 NOTICES AND INFORMATION
%% picocolors@1.1.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
ISC License
Copyright (c) 2021-2024 Oleksii Raspopov, Kostiantyn Denysov, Anton Verinov
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
=========================================
END OF picocolors@1.1.1 NOTICES AND INFORMATION
%% picomatch@2.3.2 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2017-present, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF picomatch@2.3.2 NOTICES AND INFORMATION
%% pretty-format@30.2.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Meta Platforms, Inc. and affiliates.
Copyright Contributors to the Jest project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF pretty-format@30.2.0 NOTICES AND INFORMATION
%% react-is@18.3.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Facebook, Inc. and its affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF react-is@18.3.1 NOTICES AND INFORMATION
%% slash@3.0.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF slash@3.0.0 NOTICES AND INFORMATION
%% stack-utils@2.0.6 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2016-2022 Isaac Z. Schlueter <i@izs.me>, James Talmage <james@talmage.io> (github.com/jamestalmage), and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF stack-utils@2.0.6 NOTICES AND INFORMATION
%% supports-color@7.2.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF supports-color@7.2.0 NOTICES AND INFORMATION
%% to-regex-range@5.0.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2015-present, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF to-regex-range@5.0.1 NOTICES AND INFORMATION
SUMMARY
=========================================
Total Packages: 29
=========================================
# packages/playwright/lib/matchers/expect.js
# total: 513.7 KB
## Inlined (64)
7.9 KB node_modules/@babel/code-frame/lib/index.js
12.6 KB node_modules/@babel/helper-validator-identifier/lib/identifier.js
1.6 KB node_modules/@babel/helper-validator-identifier/lib/index.js
1.7 KB node_modules/@babel/helper-validator-identifier/lib/keyword.js
15.9 KB node_modules/@jest/diff-sequences/build/index.js
24.9 KB node_modules/@jest/expect-utils/build/index.js
0.8 KB node_modules/@jest/expect-utils/build/index.mjs
1.8 KB node_modules/@jest/get-type/build/index.js
4.8 KB node_modules/ansi-styles/index.js
1.9 KB node_modules/braces/index.js
1.7 KB node_modules/braces/lib/compile.js
2.1 KB node_modules/braces/lib/constants.js
3.1 KB node_modules/braces/lib/expand.js
7.0 KB node_modules/braces/lib/parse.js
0.9 KB node_modules/braces/lib/stringify.js
2.4 KB node_modules/braces/lib/utils.js
3.1 KB node_modules/chalk/node_modules/supports-color/index.js
5.8 KB node_modules/chalk/source/index.js
3.9 KB node_modules/chalk/source/templates.js
1.3 KB node_modules/chalk/source/util.js
18.7 KB node_modules/color-convert/conversions.js
1.8 KB node_modules/color-convert/index.js
2.1 KB node_modules/color-convert/route.js
5.2 KB node_modules/color-name/index.js
6.8 KB node_modules/fill-range/index.js
0.4 KB node_modules/has-flag/index.js
0.4 KB node_modules/is-number/index.js
53.2 KB node_modules/jest-diff/build/index.js
25.2 KB node_modules/jest-matcher-utils/build/index.js
2.7 KB node_modules/jest-matcher-utils/build/index.mjs
15.3 KB node_modules/jest-message-util/build/index.js
0.5 KB node_modules/jest-message-util/build/index.mjs
0.7 KB node_modules/jest-message-util/node_modules/graceful-fs/clone.js
12.2 KB node_modules/jest-message-util/node_modules/graceful-fs/graceful-fs.js
3.0 KB node_modules/jest-message-util/node_modules/graceful-fs/legacy-streams.js
9.3 KB node_modules/jest-message-util/node_modules/graceful-fs/polyfills.js
1.4 KB node_modules/js-tokens/index.js
5.8 KB node_modules/micromatch/index.js
0.2 KB node_modules/micromatch/node_modules/picomatch/index.js
5.3 KB node_modules/micromatch/node_modules/picomatch/lib/constants.js
33.9 KB node_modules/micromatch/node_modules/picomatch/lib/parse.js
5.3 KB node_modules/micromatch/node_modules/picomatch/lib/picomatch.js
9.6 KB node_modules/micromatch/node_modules/picomatch/lib/scan.js
2.2 KB node_modules/micromatch/node_modules/picomatch/lib/utils.js
3.1 KB node_modules/picocolors/picocolors.js
42.7 KB node_modules/pretty-format/build/index.js
4.4 KB node_modules/pretty-format/node_modules/ansi-styles/index.js
7.7 KB node_modules/pretty-format/node_modules/react-is/cjs/react-is.development.js
3.3 KB node_modules/pretty-format/node_modules/react-is/cjs/react-is.production.min.js
0.3 KB node_modules/pretty-format/node_modules/react-is/index.js
0.4 KB node_modules/slash/index.js
7.6 KB node_modules/stack-utils/index.js
0.4 KB node_modules/stack-utils/node_modules/escape-string-regexp/index.js
6.8 KB node_modules/to-regex-range/index.js
10.3 KB packages/playwright/src/matchers/expect.ts
45.2 KB packages/playwright/src/matchers/expectLibrary.ts
3.3 KB packages/playwright/src/matchers/matcherHint.ts
16.0 KB packages/playwright/src/matchers/matchers.ts
1.3 KB packages/playwright/src/matchers/toBeTruthy.ts
2.1 KB packages/playwright/src/matchers/toEqual.ts
2.4 KB packages/playwright/src/matchers/toHaveURL.ts
5.6 KB packages/playwright/src/matchers/toMatchAriaSnapshot.ts
15.1 KB packages/playwright/src/matchers/toMatchSnapshot.ts
3.0 KB packages/playwright/src/matchers/toMatchText.ts
## External (2)
playwright-core/lib/coreBundle
playwright-core/lib/utilsBundle
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var package_exports = {};
__export(package_exports, {
libPath: () => libPath,
packageJSON: () => packageJSON,
packageRoot: () => packageRoot
});
module.exports = __toCommonJS(package_exports);
var import_path = __toESM(require("path"));
const packageRoot = import_path.default.join(__dirname, "..");
const packageJSON = require(import_path.default.join(packageRoot, "package.json"));
function libPath(...parts) {
return import_path.default.join(packageRoot, "lib", ...parts);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
libPath,
packageJSON,
packageRoot
});

Sorry, the diff of this file is too big to display

# packages/playwright/lib/runner/index.js
# total: 288.6 KB
## Inlined (45)
1.3 KB packages/playwright/src/isomorphic/events.ts
0.1 KB packages/playwright/src/isomorphic/folders.ts
0.9 KB packages/playwright/src/isomorphic/stringInternPool.ts
15.1 KB packages/playwright/src/isomorphic/teleReceiver.ts
3.9 KB packages/playwright/src/isomorphic/teleSuiteUpdater.ts
4.8 KB packages/playwright/src/isomorphic/testServerConnection.ts
0.0 KB packages/playwright/src/isomorphic/testTree.ts
5.0 KB packages/playwright/src/plugins/gitCommitInfoPlugin.ts
8.6 KB packages/playwright/src/plugins/webServerPlugin.ts
20.7 KB packages/playwright/src/reporters/base.ts
4.0 KB packages/playwright/src/reporters/blob.ts
2.3 KB packages/playwright/src/reporters/dot.ts
0.1 KB packages/playwright/src/reporters/empty.ts
3.5 KB packages/playwright/src/reporters/github.ts
26.2 KB packages/playwright/src/reporters/html.ts
3.1 KB packages/playwright/src/reporters/internalReporter.ts
7.1 KB packages/playwright/src/reporters/json.ts
10.3 KB packages/playwright/src/reporters/junit.ts
3.8 KB packages/playwright/src/reporters/line.ts
8.6 KB packages/playwright/src/reporters/list.ts
1.4 KB packages/playwright/src/reporters/listModeReporter.ts
18.5 KB packages/playwright/src/reporters/merge.ts
2.5 KB packages/playwright/src/reporters/multiplexer.ts
2.0 KB packages/playwright/src/reporters/reporterV2.ts
8.7 KB packages/playwright/src/reporters/teleEmitter.ts
19.0 KB packages/playwright/src/runner/dispatcher.ts
1.5 KB packages/playwright/src/runner/fsWatcher.ts
0.5 KB packages/playwright/src/runner/index.ts
1.2 KB packages/playwright/src/runner/lastRun.ts
1.6 KB packages/playwright/src/runner/loaderHost.ts
12.5 KB packages/playwright/src/runner/loadUtils.ts
5.8 KB packages/playwright/src/runner/processHost.ts
7.8 KB packages/playwright/src/runner/projectUtils.ts
5.5 KB packages/playwright/src/runner/rebase.ts
3.5 KB packages/playwright/src/runner/reporters.ts
1.6 KB packages/playwright/src/runner/sigIntWatcher.ts
3.5 KB packages/playwright/src/runner/taskRunner.ts
14.4 KB packages/playwright/src/runner/tasks.ts
3.6 KB packages/playwright/src/runner/testGroups.ts
13.9 KB packages/playwright/src/runner/testRunner.ts
8.8 KB packages/playwright/src/runner/testServer.ts
0.2 KB packages/playwright/src/runner/uiModeReporter.ts
1.7 KB packages/playwright/src/runner/vcs.ts
13.1 KB packages/playwright/src/runner/watchMode.ts
2.1 KB packages/playwright/src/runner/workerHost.ts
## External (8)
../common
../loader/loaderProcessEntry.js
../transform/babelBundle
../util
../worker/workerProcessEntry.js
playwright-core
playwright-core/lib/coreBundle
playwright-core/lib/utilsBundle

Sorry, the diff of this file is too big to display

# packages/playwright/lib/transform/babelBundle.js
# total: 2724.2 KB
## Inlined (319)
5.7 KB node_modules/@ampproject/remapping/dist/remapping.umd.js
7.9 KB node_modules/@babel/code-frame/lib/index.js
0.5 KB node_modules/@babel/compat-data/data/native-modules.json
18.6 KB node_modules/@babel/compat-data/data/plugins.json
0.2 KB node_modules/@babel/compat-data/native-modules.js
0.1 KB node_modules/@babel/compat-data/plugins.js
8.3 KB node_modules/@babel/core/lib/config/caching.js
20.1 KB node_modules/@babel/core/lib/config/config-chain.js
7.6 KB node_modules/@babel/core/lib/config/config-descriptors.js
11.6 KB node_modules/@babel/core/lib/config/files/configuration.js
0.2 KB node_modules/@babel/core/lib/config/files/import.cjs
2.1 KB node_modules/@babel/core/lib/config/files/index.js
8.0 KB node_modules/@babel/core/lib/config/files/module-types.js
1.8 KB node_modules/@babel/core/lib/config/files/package.js
8.4 KB node_modules/@babel/core/lib/config/files/plugins.js
1.0 KB node_modules/@babel/core/lib/config/files/utils.js
12.1 KB node_modules/@babel/core/lib/config/full.js
3.1 KB node_modules/@babel/core/lib/config/helpers/config-api.js
0.7 KB node_modules/@babel/core/lib/config/helpers/deep-array.js
0.4 KB node_modules/@babel/core/lib/config/helpers/environment.js
3.7 KB node_modules/@babel/core/lib/config/index.js
2.1 KB node_modules/@babel/core/lib/config/item.js
5.8 KB node_modules/@babel/core/lib/config/partial.js
1.3 KB node_modules/@babel/core/lib/config/pattern-to-regex.js
1.1 KB node_modules/@babel/core/lib/config/plugin.js
3.3 KB node_modules/@babel/core/lib/config/printer.js
1.8 KB node_modules/@babel/core/lib/config/resolve-targets.js
1.1 KB node_modules/@babel/core/lib/config/util.js
11.0 KB node_modules/@babel/core/lib/config/validation/option-assertions.js
8.6 KB node_modules/@babel/core/lib/config/validation/options.js
2.4 KB node_modules/@babel/core/lib/config/validation/plugins.js
2.6 KB node_modules/@babel/core/lib/config/validation/removed.js
0.6 KB node_modules/@babel/core/lib/errors/config-error.js
3.6 KB node_modules/@babel/core/lib/errors/rewrite-stack-trace.js
3.1 KB node_modules/@babel/core/lib/gensync-utils/async.js
0.7 KB node_modules/@babel/core/lib/gensync-utils/fs.js
1.6 KB node_modules/@babel/core/lib/gensync-utils/functional.js
6.5 KB node_modules/@babel/core/lib/index.js
1.6 KB node_modules/@babel/core/lib/parse.js
2.5 KB node_modules/@babel/core/lib/parser/index.js
14.1 KB node_modules/@babel/core/lib/parser/util/missing-plugin-helper.js
5.0 KB node_modules/@babel/core/lib/tools/build-external-helpers.js
1.8 KB node_modules/@babel/core/lib/transform-ast.js
1.2 KB node_modules/@babel/core/lib/transform-file.js
1.7 KB node_modules/@babel/core/lib/transform.js
2.3 KB node_modules/@babel/core/lib/transformation/block-hoist-plugin.js
0.2 KB node_modules/@babel/core/lib/transformation/file/babel-7-helpers.cjs
6.8 KB node_modules/@babel/core/lib/transformation/file/file.js
2.6 KB node_modules/@babel/core/lib/transformation/file/generate.js
1.0 KB node_modules/@babel/core/lib/transformation/file/merge-map.js
3.3 KB node_modules/@babel/core/lib/transformation/index.js
4.1 KB node_modules/@babel/core/lib/transformation/normalize-file.js
1.8 KB node_modules/@babel/core/lib/transformation/normalize-opts.js
1.4 KB node_modules/@babel/core/lib/transformation/plugin-pass.js
1.9 KB node_modules/@babel/core/lib/transformation/util/clone-deep.js
44.8 KB node_modules/@babel/core/lib/vendor/import-meta-resolve.js
38.4 KB node_modules/@babel/core/node_modules/semver/semver.js
7.1 KB node_modules/@babel/generator/lib/buffer.js
3.1 KB node_modules/@babel/generator/lib/generators/base.js
6.8 KB node_modules/@babel/generator/lib/generators/classes.js
2.5 KB node_modules/@babel/generator/lib/generators/deprecated.js
9.5 KB node_modules/@babel/generator/lib/generators/expressions.js
18.9 KB node_modules/@babel/generator/lib/generators/flow.js
4.3 KB node_modules/@babel/generator/lib/generators/index.js
3.5 KB node_modules/@babel/generator/lib/generators/jsx.js
7.0 KB node_modules/@babel/generator/lib/generators/methods.js
9.7 KB node_modules/@babel/generator/lib/generators/modules.js
8.1 KB node_modules/@babel/generator/lib/generators/statements.js
1.3 KB node_modules/@babel/generator/lib/generators/template-literals.js
6.1 KB node_modules/@babel/generator/lib/generators/types.js
21.5 KB node_modules/@babel/generator/lib/generators/typescript.js
4.6 KB node_modules/@babel/generator/lib/index.js
2.5 KB node_modules/@babel/generator/lib/node/index.js
11.4 KB node_modules/@babel/generator/lib/node/parentheses.js
0.8 KB node_modules/@babel/generator/lib/nodes.js
29.0 KB node_modules/@babel/generator/lib/printer.js
3.4 KB node_modules/@babel/generator/lib/source-map.js
6.4 KB node_modules/@babel/generator/lib/token-map.js
0.7 KB node_modules/@babel/helper-annotate-as-pure/lib/index.js
1.2 KB node_modules/@babel/helper-compilation-targets/lib/debug.js
2.7 KB node_modules/@babel/helper-compilation-targets/lib/filter-items.js
8.7 KB node_modules/@babel/helper-compilation-targets/lib/index.js
0.6 KB node_modules/@babel/helper-compilation-targets/lib/options.js
1.2 KB node_modules/@babel/helper-compilation-targets/lib/pretty.js
0.8 KB node_modules/@babel/helper-compilation-targets/lib/targets.js
2.2 KB node_modules/@babel/helper-compilation-targets/lib/utils.js
38.5 KB node_modules/@babel/helper-compilation-targets/node_modules/semver/semver.js
5.1 KB node_modules/@babel/helper-create-class-features-plugin/lib/decorators-2018-09.js
59.9 KB node_modules/@babel/helper-create-class-features-plugin/lib/decorators.js
7.3 KB node_modules/@babel/helper-create-class-features-plugin/lib/features.js
43.4 KB node_modules/@babel/helper-create-class-features-plugin/lib/fields.js
11.1 KB node_modules/@babel/helper-create-class-features-plugin/lib/index.js
4.9 KB node_modules/@babel/helper-create-class-features-plugin/lib/misc.js
0.8 KB node_modules/@babel/helper-create-class-features-plugin/lib/typescript.js
38.5 KB node_modules/@babel/helper-create-class-features-plugin/node_modules/semver/semver.js
0.4 KB node_modules/@babel/helper-globals/data/builtin-lower.json
1.0 KB node_modules/@babel/helper-globals/data/builtin-upper.json
14.3 KB node_modules/@babel/helper-member-expression-to-functions/lib/index.js
4.6 KB node_modules/@babel/helper-module-imports/lib/import-builder.js
12.0 KB node_modules/@babel/helper-module-imports/lib/import-injector.js
1.3 KB node_modules/@babel/helper-module-imports/lib/index.js
0.3 KB node_modules/@babel/helper-module-imports/lib/is-module.js
1.9 KB node_modules/@babel/helper-module-transforms/lib/dynamic-import.js
1.9 KB node_modules/@babel/helper-module-transforms/lib/get-module-name.js
14.7 KB node_modules/@babel/helper-module-transforms/lib/index.js
1.2 KB node_modules/@babel/helper-module-transforms/lib/lazy-modules.js
14.6 KB node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js
14.8 KB node_modules/@babel/helper-module-transforms/lib/rewrite-live-references.js
0.8 KB node_modules/@babel/helper-module-transforms/lib/rewrite-this.js
1.2 KB node_modules/@babel/helper-optimise-call-expression/lib/index.js
2.8 KB node_modules/@babel/helper-plugin-utils/lib/index.js
11.6 KB node_modules/@babel/helper-replace-supers/lib/index.js
1.2 KB node_modules/@babel/helper-skip-transparent-expression-wrappers/lib/index.js
8.9 KB node_modules/@babel/helper-string-parser/lib/index.js
12.6 KB node_modules/@babel/helper-validator-identifier/lib/identifier.js
1.6 KB node_modules/@babel/helper-validator-identifier/lib/index.js
1.7 KB node_modules/@babel/helper-validator-identifier/lib/keyword.js
0.9 KB node_modules/@babel/helper-validator-option/lib/find-suggestion.js
0.6 KB node_modules/@babel/helper-validator-option/lib/index.js
1.7 KB node_modules/@babel/helper-validator-option/lib/validator.js
117.4 KB node_modules/@babel/helpers/lib/helpers-generated.js
4.1 KB node_modules/@babel/helpers/lib/index.js
556.4 KB node_modules/@babel/parser/lib/index.js
1.6 KB node_modules/@babel/plugin-proposal-decorators/lib/index.js
9.0 KB node_modules/@babel/plugin-proposal-decorators/lib/transformer-legacy.js
0.6 KB node_modules/@babel/plugin-syntax-async-generators/lib/index.js
3.2 KB node_modules/@babel/plugin-syntax-decorators/lib/index.js
1.5 KB node_modules/@babel/plugin-syntax-import-attributes/lib/index.js
0.6 KB node_modules/@babel/plugin-syntax-json-strings/lib/index.js
0.7 KB node_modules/@babel/plugin-syntax-jsx/lib/index.js
0.6 KB node_modules/@babel/plugin-syntax-object-rest-spread/lib/index.js
0.6 KB node_modules/@babel/plugin-syntax-optional-catch-binding/lib/index.js
1.4 KB node_modules/@babel/plugin-syntax-typescript/lib/index.js
0.9 KB node_modules/@babel/plugin-transform-class-properties/lib/index.js
6.6 KB node_modules/@babel/plugin-transform-class-static-block/lib/index.js
23.5 KB node_modules/@babel/plugin-transform-destructuring/lib/index.js
7.3 KB node_modules/@babel/plugin-transform-explicit-resource-management/lib/index.js
1.9 KB node_modules/@babel/plugin-transform-export-namespace-from/lib/index.js
2.0 KB node_modules/@babel/plugin-transform-logical-assignment-operators/lib/index.js
0.9 KB node_modules/@babel/plugin-transform-modules-commonjs/lib/dynamic-import.js
1.3 KB node_modules/@babel/plugin-transform-modules-commonjs/lib/hooks.js
8.8 KB node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js
1.5 KB node_modules/@babel/plugin-transform-modules-commonjs/lib/lazy.js
2.5 KB node_modules/@babel/plugin-transform-nullish-coalescing-operator/lib/index.js
1.0 KB node_modules/@babel/plugin-transform-numeric-separator/lib/index.js
9.9 KB node_modules/@babel/plugin-transform-optional-chaining/lib/index.js
0.9 KB node_modules/@babel/plugin-transform-private-methods/lib/index.js
24.0 KB node_modules/@babel/plugin-transform-react-jsx/lib/create-plugin.js
0.4 KB node_modules/@babel/plugin-transform-react-jsx/lib/index.js
2.5 KB node_modules/@babel/plugin-transform-typescript/lib/const-enum.js
11.0 KB node_modules/@babel/plugin-transform-typescript/lib/enum.js
1.2 KB node_modules/@babel/plugin-transform-typescript/lib/global-types.js
19.8 KB node_modules/@babel/plugin-transform-typescript/lib/index.js
7.2 KB node_modules/@babel/plugin-transform-typescript/lib/namespace.js
6.3 KB node_modules/@babel/preset-typescript/lib/index.js
1.4 KB node_modules/@babel/preset-typescript/package.json
2.7 KB node_modules/@babel/template/lib/builder.js
1.8 KB node_modules/@babel/template/lib/formatters.js
1.0 KB node_modules/@babel/template/lib/index.js
2.2 KB node_modules/@babel/template/lib/literal.js
3.3 KB node_modules/@babel/template/lib/options.js
5.2 KB node_modules/@babel/template/lib/parse.js
4.9 KB node_modules/@babel/template/lib/populate.js
0.7 KB node_modules/@babel/template/lib/string.js
1.2 KB node_modules/@babel/traverse/lib/cache.js
3.7 KB node_modules/@babel/traverse/lib/context.js
0.5 KB node_modules/@babel/traverse/lib/hub.js
2.9 KB node_modules/@babel/traverse/lib/index.js
4.1 KB node_modules/@babel/traverse/lib/path/ancestry.js
1.8 KB node_modules/@babel/traverse/lib/path/comments.js
8.2 KB node_modules/@babel/traverse/lib/path/context.js
23.4 KB node_modules/@babel/traverse/lib/path/conversion.js
12.3 KB node_modules/@babel/traverse/lib/path/evaluation.js
11.8 KB node_modules/@babel/traverse/lib/path/family.js
12.0 KB node_modules/@babel/traverse/lib/path/index.js
4.8 KB node_modules/@babel/traverse/lib/path/inference/index.js
5.2 KB node_modules/@babel/traverse/lib/path/inference/inferer-reference.js
7.4 KB node_modules/@babel/traverse/lib/path/inference/inferers.js
0.8 KB node_modules/@babel/traverse/lib/path/inference/util.js
14.2 KB node_modules/@babel/traverse/lib/path/introspection.js
6.0 KB node_modules/@babel/traverse/lib/path/lib/hoister.js
1.5 KB node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
5.0 KB node_modules/@babel/traverse/lib/path/lib/virtual-types-validator.js
1.9 KB node_modules/@babel/traverse/lib/path/lib/virtual-types.js
8.9 KB node_modules/@babel/traverse/lib/path/modification.js
2.2 KB node_modules/@babel/traverse/lib/path/removal.js
10.1 KB node_modules/@babel/traverse/lib/path/replacement.js
2.3 KB node_modules/@babel/traverse/lib/scope/binding.js
34.9 KB node_modules/@babel/traverse/lib/scope/index.js
4.3 KB node_modules/@babel/traverse/lib/scope/lib/renamer.js
2.1 KB node_modules/@babel/traverse/lib/scope/traverseForScope.js
1.0 KB node_modules/@babel/traverse/lib/traverse-node.js
8.7 KB node_modules/@babel/traverse/lib/visitors.js
0.6 KB node_modules/@babel/types/lib/asserts/assertNode.js
49.7 KB node_modules/@babel/types/lib/asserts/generated/index.js
0.6 KB node_modules/@babel/types/lib/builders/flow/createFlowUnionType.js
1.2 KB node_modules/@babel/types/lib/builders/flow/createTypeAnnotationBasedOnTypeof.js
1.0 KB node_modules/@babel/types/lib/builders/generated/index.js
96.2 KB node_modules/@babel/types/lib/builders/generated/lowercase.js
28.6 KB node_modules/@babel/types/lib/builders/generated/uppercase.js
0.4 KB node_modules/@babel/types/lib/builders/productions.js
0.9 KB node_modules/@babel/types/lib/builders/react/buildChildren.js
0.8 KB node_modules/@babel/types/lib/builders/typescript/createTSUnionType.js
0.3 KB node_modules/@babel/types/lib/clone/clone.js
0.4 KB node_modules/@babel/types/lib/clone/cloneDeep.js
0.4 KB node_modules/@babel/types/lib/clone/cloneDeepWithoutLoc.js
3.7 KB node_modules/@babel/types/lib/clone/cloneNode.js
0.4 KB node_modules/@babel/types/lib/clone/cloneWithoutLoc.js
0.5 KB node_modules/@babel/types/lib/comments/addComment.js
0.6 KB node_modules/@babel/types/lib/comments/addComments.js
0.4 KB node_modules/@babel/types/lib/comments/inheritInnerComments.js
0.4 KB node_modules/@babel/types/lib/comments/inheritLeadingComments.js
0.7 KB node_modules/@babel/types/lib/comments/inheritsComments.js
0.4 KB node_modules/@babel/types/lib/comments/inheritTrailingComments.js
0.4 KB node_modules/@babel/types/lib/comments/removeComments.js
6.5 KB node_modules/@babel/types/lib/constants/generated/index.js
2.9 KB node_modules/@babel/types/lib/constants/index.js
0.4 KB node_modules/@babel/types/lib/converters/ensureBlock.js
2.6 KB node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js
0.5 KB node_modules/@babel/types/lib/converters/toBindingIdentifierName.js
0.9 KB node_modules/@babel/types/lib/converters/toBlock.js
0.5 KB node_modules/@babel/types/lib/converters/toComputedKey.js
0.9 KB node_modules/@babel/types/lib/converters/toExpression.js
0.8 KB node_modules/@babel/types/lib/converters/toIdentifier.js
1.2 KB node_modules/@babel/types/lib/converters/toKeyAlias.js
0.7 KB node_modules/@babel/types/lib/converters/toSequenceExpression.js
1.1 KB node_modules/@babel/types/lib/converters/toStatement.js
3.2 KB node_modules/@babel/types/lib/converters/valueToNode.js
61.0 KB node_modules/@babel/types/lib/definitions/core.js
0.4 KB node_modules/@babel/types/lib/definitions/deprecated-aliases.js
3.4 KB node_modules/@babel/types/lib/definitions/experimental.js
18.1 KB node_modules/@babel/types/lib/definitions/flow.js
3.1 KB node_modules/@babel/types/lib/definitions/index.js
4.8 KB node_modules/@babel/types/lib/definitions/jsx.js
0.9 KB node_modules/@babel/types/lib/definitions/misc.js
1.2 KB node_modules/@babel/types/lib/definitions/placeholders.js
18.5 KB node_modules/@babel/types/lib/definitions/typescript.js
10.8 KB node_modules/@babel/types/lib/definitions/utils.js
18.1 KB node_modules/@babel/types/lib/index.js
0.6 KB node_modules/@babel/types/lib/modifications/appendToMemberExpression.js
2.2 KB node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js
0.9 KB node_modules/@babel/types/lib/modifications/inherits.js
0.7 KB node_modules/@babel/types/lib/modifications/prependToMemberExpression.js
0.9 KB node_modules/@babel/types/lib/modifications/removeProperties.js
0.5 KB node_modules/@babel/types/lib/modifications/removePropertiesDeep.js
2.3 KB node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js
1.4 KB node_modules/@babel/types/lib/retrievers/getAssignmentIdentifiers.js
3.3 KB node_modules/@babel/types/lib/retrievers/getBindingIdentifiers.js
2.0 KB node_modules/@babel/types/lib/retrievers/getFunctionName.js
0.5 KB node_modules/@babel/types/lib/retrievers/getOuterBindingIdentifiers.js
1.4 KB node_modules/@babel/types/lib/traverse/traverse.js
1.1 KB node_modules/@babel/types/lib/traverse/traverseFast.js
1.4 KB node_modules/@babel/types/lib/utils/deprecationWarning.js
0.4 KB node_modules/@babel/types/lib/utils/inherit.js
1.4 KB node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js
0.5 KB node_modules/@babel/types/lib/utils/shallowEqual.js
0.5 KB node_modules/@babel/types/lib/validators/buildMatchMemberExpression.js
105.3 KB node_modules/@babel/types/lib/validators/generated/index.js
0.9 KB node_modules/@babel/types/lib/validators/is.js
0.9 KB node_modules/@babel/types/lib/validators/isBinding.js
0.5 KB node_modules/@babel/types/lib/validators/isBlockScoped.js
0.6 KB node_modules/@babel/types/lib/validators/isImmutable.js
0.5 KB node_modules/@babel/types/lib/validators/isLet.js
0.4 KB node_modules/@babel/types/lib/validators/isNode.js
1.7 KB node_modules/@babel/types/lib/validators/isNodesEquivalent.js
0.6 KB node_modules/@babel/types/lib/validators/isPlaceholderType.js
3.0 KB node_modules/@babel/types/lib/validators/isReferenced.js
0.6 KB node_modules/@babel/types/lib/validators/isScope.js
0.5 KB node_modules/@babel/types/lib/validators/isSpecifierDefault.js
0.6 KB node_modules/@babel/types/lib/validators/isType.js
0.8 KB node_modules/@babel/types/lib/validators/isValidES3Identifier.js
0.7 KB node_modules/@babel/types/lib/validators/isValidIdentifier.js
0.5 KB node_modules/@babel/types/lib/validators/isVar.js
1.6 KB node_modules/@babel/types/lib/validators/matchesPattern.js
0.3 KB node_modules/@babel/types/lib/validators/react/isCompatTag.js
0.5 KB node_modules/@babel/types/lib/validators/react/isReactComponent.js
1.7 KB node_modules/@babel/types/lib/validators/validate.js
12.8 KB node_modules/@jridgewell/gen-mapping/dist/gen-mapping.umd.js
5.8 KB node_modules/@jridgewell/resolve-uri/dist/resolve-uri.umd.js
16.9 KB node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js
21.4 KB node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js
0.4 KB node_modules/browserslist/error.js
37.3 KB node_modules/browserslist/index.js
14.3 KB node_modules/browserslist/node.js
2.1 KB node_modules/browserslist/parse.js
28.2 KB node_modules/caniuse-lite/data/agents.js
0.4 KB node_modules/caniuse-lite/data/browsers.js
2.8 KB node_modules/caniuse-lite/data/browserVersions.js
0.5 KB node_modules/caniuse-lite/dist/lib/statuses.js
0.3 KB node_modules/caniuse-lite/dist/lib/supported.js
1.7 KB node_modules/caniuse-lite/dist/unpacker/agents.js
0.2 KB node_modules/caniuse-lite/dist/unpacker/browsers.js
0.2 KB node_modules/caniuse-lite/dist/unpacker/browserVersions.js
1.6 KB node_modules/caniuse-lite/dist/unpacker/feature.js
0.7 KB node_modules/caniuse-lite/dist/unpacker/region.js
6.8 KB node_modules/convert-source-map/index.js
4.6 KB node_modules/debug/src/browser.js
5.8 KB node_modules/debug/src/common.js
0.3 KB node_modules/debug/src/index.js
4.2 KB node_modules/debug/src/node.js
4.2 KB node_modules/electron-to-chromium/versions.js
9.3 KB node_modules/gensync/index.js
0.4 KB node_modules/has-flag/index.js
1.4 KB node_modules/js-tokens/index.js
9.1 KB node_modules/jsesc/jsesc.js
0.3 KB node_modules/json5/lib/index.js
20.2 KB node_modules/json5/lib/parse.js
6.8 KB node_modules/json5/lib/stringify.js
15.5 KB node_modules/json5/lib/unicode.js
0.9 KB node_modules/json5/lib/util.js
8.2 KB node_modules/lru-cache/index.js
2.8 KB node_modules/ms/index.js
33.0 KB node_modules/node-releases/data/processed/envs.json
2.3 KB node_modules/node-releases/data/release-schedule/release-schedule.json
3.1 KB node_modules/picocolors/picocolors.js
3.4 KB node_modules/supports-color/index.js
0.3 KB node_modules/yallist/iterator.js
9.7 KB node_modules/yallist/yallist.js
3.5 KB packages/playwright/src/transform/babelBundle.ts
## External (0)
packages/playwright/lib/transform/esmLoader.js
THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
The following npm packages are inlined into this bundle.
- balanced-match@1.0.2 (https://github.com/juliangruber/balanced-match)
- brace-expansion@1.1.12 (https://github.com/juliangruber/brace-expansion)
- buffer-from@1.1.2 (https://github.com/LinusU/buffer-from)
- concat-map@0.0.1 (https://github.com/substack/node-concat-map)
- debug@4.4.3 (https://github.com/debug-js/debug)
- has-flag@4.0.0 (https://github.com/sindresorhus/has-flag)
- json5@2.2.3 (https://github.com/json5/json5)
- mime@3.0.0 (https://github.com/broofa/mime)
- minimatch@3.1.5 (https://github.com/isaacs/minimatch)
- ms@2.1.3 (https://github.com/vercel/ms)
- source-map-support@0.5.21 (https://github.com/evanw/node-source-map-support)
- source-map@0.6.1 (https://github.com/mozilla/source-map)
- supports-color@8.1.1 (https://github.com/chalk/supports-color)
%% balanced-match@1.0.2 NOTICES AND INFORMATION BEGIN HERE
=========================================
(MIT)
Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF balanced-match@1.0.2 NOTICES AND INFORMATION
%% brace-expansion@1.1.12 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF brace-expansion@1.1.12 NOTICES AND INFORMATION
%% buffer-from@1.1.2 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) 2016, 2018 Linus Unnebäck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF buffer-from@1.1.2 NOTICES AND INFORMATION
%% concat-map@0.0.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
This software is released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF concat-map@0.0.1 NOTICES AND INFORMATION
%% debug@4.4.3 NOTICES AND INFORMATION BEGIN HERE
=========================================
(The MIT License)
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2018-2021 Josh Junon
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the 'Software'), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF debug@4.4.3 NOTICES AND INFORMATION
%% has-flag@4.0.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF has-flag@4.0.0 NOTICES AND INFORMATION
%% json5@2.2.3 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) 2012-2018 Aseem Kishore, and [others].
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[others]: https://github.com/json5/json5/contributors
=========================================
END OF json5@2.2.3 NOTICES AND INFORMATION
%% mime@3.0.0 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2010 Benjamin Thomas, Robert Kieffer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
=========================================
END OF mime@3.0.0 NOTICES AND INFORMATION
%% minimatch@3.1.5 NOTICES AND INFORMATION BEGIN HERE
=========================================
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
=========================================
END OF minimatch@3.1.5 NOTICES AND INFORMATION
%% ms@2.1.3 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2020 Vercel, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF ms@2.1.3 NOTICES AND INFORMATION
%% source-map-support@0.5.21 NOTICES AND INFORMATION BEGIN HERE
=========================================
The MIT License (MIT)
Copyright (c) 2014 Evan Wallace
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=========================================
END OF source-map-support@0.5.21 NOTICES AND INFORMATION
%% source-map@0.6.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
Copyright (c) 2009-2011, Mozilla Foundation and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the names of the Mozilla Foundation nor the names of project
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================
END OF source-map@0.6.1 NOTICES AND INFORMATION
%% supports-color@8.1.1 NOTICES AND INFORMATION BEGIN HERE
=========================================
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF supports-color@8.1.1 NOTICES AND INFORMATION
SUMMARY
=========================================
Total Packages: 13
=========================================
# packages/playwright/lib/transform/esmLoader.js
# total: 245.0 KB
## Inlined (46)
1.5 KB node_modules/balanced-match/index.js
4.4 KB node_modules/brace-expansion/index.js
1.8 KB node_modules/buffer-from/index.js
0.5 KB node_modules/concat-map/index.js
4.6 KB node_modules/debug/src/browser.js
5.8 KB node_modules/debug/src/common.js
0.3 KB node_modules/debug/src/index.js
4.2 KB node_modules/debug/src/node.js
0.4 KB node_modules/has-flag/index.js
0.2 KB node_modules/json5/lib/index.js
20.2 KB node_modules/json5/lib/parse.js
6.8 KB node_modules/json5/lib/stringify.js
15.5 KB node_modules/json5/lib/unicode.js
0.9 KB node_modules/json5/lib/util.js
0.2 KB node_modules/mime/index.js
2.0 KB node_modules/mime/Mime.js
26.8 KB node_modules/mime/types/other.js
10.1 KB node_modules/mime/types/standard.js
20.9 KB node_modules/minimatch/minimatch.js
2.8 KB node_modules/ms/index.js
16.1 KB node_modules/source-map-support/source-map-support.js
2.2 KB node_modules/source-map/lib/array-set.js
1.7 KB node_modules/source-map/lib/base64-vlq.js
1.1 KB node_modules/source-map/lib/base64.js
1.5 KB node_modules/source-map/lib/binary-search.js
1.3 KB node_modules/source-map/lib/mapping-list.js
0.9 KB node_modules/source-map/lib/quick-sort.js
24.0 KB node_modules/source-map/lib/source-map-consumer.js
10.6 KB node_modules/source-map/lib/source-map-generator.js
9.6 KB node_modules/source-map/lib/source-node.js
8.6 KB node_modules/source-map/lib/util.js
0.3 KB node_modules/source-map/source-map.js
3.4 KB node_modules/supports-color/index.js
0.1 KB packages/isomorphic/rtti.ts
0.2 KB packages/isomorphic/stackTrace.ts
0.2 KB packages/isomorphic/stringUtils.ts
6.3 KB packages/playwright/src/transform/compilationCache.ts
3.1 KB packages/playwright/src/transform/esmLoader.ts
1.1 KB packages/playwright/src/transform/pirates.ts
1.1 KB packages/playwright/src/transform/portTransport.ts
9.7 KB packages/playwright/src/transform/transform.ts
2.9 KB packages/playwright/src/transform/tsconfig-loader.ts
4.6 KB packages/playwright/src/util.ts
0.2 KB packages/utils/crypto.ts
0.2 KB packages/utils/debug.ts
0.5 KB packages/utils/env.ts
## External (3)
../globals
../package
playwright-core/package.json

Sorry, the diff of this file is too big to display

# packages/playwright/lib/worker/workerProcessEntry.js
# total: 123.4 KB
## Inlined (12)
4.7 KB packages/playwright/src/util.ts
8.6 KB packages/playwright/src/worker/fixtureRunner.ts
20.8 KB packages/playwright/src/worker/testInfo.ts
11.6 KB packages/playwright/src/worker/testTracing.ts
5.4 KB packages/playwright/src/worker/timeoutManager.ts
0.3 KB packages/playwright/src/worker/util.ts
21.0 KB packages/playwright/src/worker/workerMain.ts
0.1 KB packages/playwright/src/worker/workerProcessEntry.ts
6.0 KB packages/utils/third_party/yauzl/buffer-crc32.js
9.3 KB packages/utils/third_party/yauzl/fd-slicer.js
32.2 KB packages/utils/third_party/yauzl/index.js
1.4 KB packages/utils/third_party/yauzl/pend.js
## External (6)
../common
../globals
../matchers/expect
playwright-core/lib/coreBundle
playwright-core/lib/utilsBundle
playwright-core/package.json
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Portions Copyright (c) Microsoft Corporation.
Portions Copyright 2017 Google Inc.
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.
Playwright
Copyright (c) Microsoft Corporation
This software contains code derived from the Puppeteer project (https://github.com/puppeteer/puppeteer),
available under the Apache 2.0 license (https://github.com/puppeteer/puppeteer/blob/master/LICENSE).
# 🎭 Playwright
[![npm version](https://img.shields.io/npm/v/playwright.svg)](https://www.npmjs.com/package/playwright) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-148.0.7778.96-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-150.0.2-blue.svg?logo=firefoxbrowser)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> <!-- GEN:webkit-version-badge -->[![WebKit version](https://img.shields.io/badge/webkit-26.4-blue.svg?logo=safari)](https://webkit.org/)<!-- GEN:stop --> [![Join Discord](https://img.shields.io/badge/join-discord-informational)](https://aka.ms/playwright/discord)
## [Documentation](https://playwright.dev) | [API reference](https://playwright.dev/docs/api/class-playwright)
Playwright is a framework for web automation and testing. It drives Chromium, Firefox, and WebKit with a single API — in your tests, in your scripts, and as a tool for AI agents.
## Get Started
Choose the path that fits your workflow:
| | Best for | Install |
|---|---|---|
| **[Playwright Test](#playwright-test)** | End-to-end testing | `npm init playwright@latest` |
| **[Playwright CLI](#playwright-cli)** | Coding agents (Claude Code, Copilot) | `npm i -g @playwright/cli@latest` |
| **[Playwright MCP](#playwright-mcp)** | AI agents and LLM-driven automation | `npx @playwright/mcp@latest` |
| **[Playwright Library](#playwright-library)** | Browser automation scripts | `npm i playwright` |
| **[VS Code Extension](#vs-code-extension)** | Test authoring and debugging in VS Code | [Install from Marketplace](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright) |
---
## Playwright Test
Playwright Test is a full-featured test runner built for end-to-end testing. It runs tests across Chromium, Firefox, and WebKit with full browser isolation, auto-waiting, and web-first assertions.
### Install
```bash
npm init playwright@latest
```
Or add manually:
```bash
npm i -D @playwright/test
npx playwright install
```
### Write a test
```TypeScript
import { test, expect } from '@playwright/test';
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});
test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');
await page.getByRole('link', { name: 'Get started' }).click();
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});
```
### Run tests
```bash
npx playwright test
```
Tests run in parallel across all configured browsers, in headless mode by default. Each test gets a fresh browser context — full isolation with near-zero overhead.
### Key capabilities
**Auto-wait and web-first assertions.** No artificial timeouts. Playwright waits for elements to be actionable, and assertions automatically retry until conditions are met.
**Locators.** Find elements with resilient locators that mirror how users see the page:
```TypeScript
page.getByRole('button', { name: 'Submit' })
page.getByLabel('Email')
page.getByPlaceholder('Search...')
page.getByTestId('login-form')
```
**Test isolation.** Each test runs in its own browser context — equivalent to a fresh browser profile. Save authentication state once and reuse it across tests:
```TypeScript
// Save state after login
await page.context().storageState({ path: 'auth.json' });
// Reuse in other tests
test.use({ storageState: 'auth.json' });
```
**Tracing.** Capture execution traces, screenshots, and videos on failure. Inspect every action, DOM snapshot, network request, and console message in the [Trace Viewer](https://playwright.dev/docs/trace-viewer):
```TypeScript
// playwright.config.ts
export default defineConfig({
use: {
trace: 'on-first-retry',
},
});
```
```bash
npx playwright show-trace trace.zip
```
<!-- TODO: screenshot of trace viewer -->
**Parallelism.** Tests run in parallel by default across all configured browsers.
[Full testing documentation](https://playwright.dev/docs/intro)
---
## Playwright CLI
[Playwright CLI](https://github.com/microsoft/playwright-cli) is a command-line interface for browser automation designed for coding agents. It's more token-efficient than MCP — commands avoid loading large tool schemas and accessibility trees into the model context.
### Install
```bash
npm install -g @playwright/cli@latest
```
Optionally install skills for richer agent integration:
```bash
playwright-cli install --skills
```
### Usage
Point your coding agent at a task:
```
Test the "add todo" flow on https://demo.playwright.dev/todomvc using playwright-cli.
Take screenshots for all successful and failing scenarios.
```
Or run commands directly:
```bash
playwright-cli open https://demo.playwright.dev/todomvc/ --headed
playwright-cli type "Buy groceries"
playwright-cli press Enter
playwright-cli screenshot
```
### Session monitoring
Use `playwright-cli show` to open a visual dashboard with live screencast previews of all running browser sessions. Click any session to zoom in and take remote control.
```bash
playwright-cli show
```
<!-- TODO: screenshot of playwright-cli show dashboard -->
[Full CLI documentation](https://playwright.dev/docs/cli-agent) | [GitHub](https://github.com/microsoft/playwright-cli)
---
## Playwright MCP
The [Playwright MCP server](https://github.com/microsoft/playwright-mcp) gives AI agents full browser control through the [Model Context Protocol](https://modelcontextprotocol.io). Agents interact with pages using structured accessibility snapshots — no vision models or screenshots required.
### Setup
Add to your MCP client (VS Code, Cursor, Claude Desktop, Windsurf, etc.):
```json
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}
```
**One-click install for VS Code:**
[<img src="https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20MCP%20Server&color=0098FF" alt="Install in VS Code" />](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522playwright%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522%2540playwright%252Fmcp%2540latest%2522%255D%257D)
**For Claude Code:**
```bash
claude mcp add playwright npx @playwright/mcp@latest
```
### How it works
Ask your AI assistant to interact with any web page:
```
Navigate to https://demo.playwright.dev/todomvc and add a few todo items.
```
The agent sees the page as a structured accessibility tree:
```
- heading "todos" [level=1]
- textbox "What needs to be done?" [ref=e5]
- listitem:
- checkbox "Toggle Todo" [ref=e10]
- text: "Buy groceries"
```
It uses element refs like `e5` and `e10` to click, type, and interact — deterministically and without visual ambiguity. Tools cover navigation, form filling, screenshots, network mocking, storage management, and more.
[Full MCP documentation](https://playwright.dev/docs/mcp) | [GitHub](https://github.com/microsoft/playwright-mcp)
---
## Playwright Library
Use `playwright` as a library for browser automation scripts — web scraping, PDF generation, screenshot capture, and any workflow that needs programmatic browser control without a test runner.
### Install
```bash
npm i playwright
```
### Examples
**Take a screenshot:**
```TypeScript
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://playwright.dev/');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
```
**Generate a PDF:**
```TypeScript
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://playwright.dev/');
await page.pdf({ path: 'page.pdf', format: 'A4' });
await browser.close();
```
**Emulate a mobile device:**
```TypeScript
import { chromium, devices } from 'playwright';
const browser = await chromium.launch();
const context = await browser.newContext(devices['iPhone 15']);
const page = await context.newPage();
await page.goto('https://playwright.dev/');
await page.screenshot({ path: 'mobile.png' });
await browser.close();
```
**Intercept network requests:**
```TypeScript
import { chromium } from 'playwright';
const browser = await chromium.launch();
const page = await browser.newPage();
await page.route('**/*.{png,jpg,jpeg}', route => route.abort());
await page.goto('https://playwright.dev/');
await browser.close();
```
[Library documentation](https://playwright.dev/docs/library) | [API reference](https://playwright.dev/docs/api/class-playwright)
---
## VS Code Extension
The [Playwright VS Code extension](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright) brings test running, debugging, and code generation directly into your editor.
<!-- TODO: hero screenshot of VS Code with Playwright sidebar -->
**Run and debug tests** from the editor with a single click. Set breakpoints, inspect variables, and step through test execution with a live browser view.
**Generate tests with CodeGen.** Click "Record new" to open a browser — navigate and interact with your app while Playwright writes the test code for you.
**Pick locators.** Hover over any element in the browser to see the best available locator, then click to copy it to your clipboard.
**Trace Viewer integration.** Enable "Show Trace Viewer" in the sidebar to get a full execution trace after each test run — DOM snapshots, network requests, console logs, and screenshots at every step.
[Install the extension](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright) | [VS Code guide](https://playwright.dev/docs/getting-started-vscode)
---
## Cross-Browser Support
| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium<sup>1</sup> <!-- GEN:chromium-version -->148.0.7778.96<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->26.4<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Firefox <!-- GEN:firefox-version -->150.0.2<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Headless and headed execution on all platforms. <sup>1</sup> Uses [Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing) by default.
## Other Languages
Playwright is also available for [Python](https://playwright.dev/python/docs/intro), [.NET](https://playwright.dev/dotnet/docs/intro), and [Java](https://playwright.dev/java/docs/intro).
## Resources
* [Documentation](https://playwright.dev)
* [API reference](https://playwright.dev/docs/api/class-playwright)
* [MCP server](https://github.com/microsoft/playwright-mcp)
* [CLI for coding agents](https://github.com/microsoft/playwright-cli)
* [VS Code extension](https://github.com/microsoft/playwright-vscode)
* [Contribution guide](CONTRIBUTING.md)
* [Changelog](https://github.com/microsoft/playwright/releases)
* [Discord](https://aka.ms/playwright/discord)
+287
-203

@@ -31,5 +31,6 @@ "use strict";

__export(generateAgents_exports, {
initClaudeCodeRepo: () => initClaudeCodeRepo,
initOpencodeRepo: () => initOpencodeRepo,
initVSCodeRepo: () => initVSCodeRepo
ClaudeGenerator: () => ClaudeGenerator,
CopilotGenerator: () => CopilotGenerator,
OpencodeGenerator: () => OpencodeGenerator,
VSCodeGenerator: () => VSCodeGenerator
});

@@ -39,227 +40,310 @@ module.exports = __toCommonJS(generateAgents_exports);

var import_path = __toESM(require("path"));
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
class AgentParser {
static async parseFile(filePath) {
const rawMarkdown = await import_fs.default.promises.readFile(filePath, "utf-8");
const { header, content } = this.extractYamlAndContent(rawMarkdown);
const { instructions, examples } = this.extractInstructionsAndExamples(content);
return { header, instructions, examples };
}
static extractYamlAndContent(markdown) {
const lines = markdown.split("\n");
if (lines[0] !== "---")
throw new Error("Markdown file must start with YAML front matter (---)");
let yamlEndIndex = -1;
for (let i = 1; i < lines.length; i++) {
if (lines[i] === "---") {
yamlEndIndex = i;
break;
var import_seed = require("../mcp/test/seed");
var import_agentParser = require("./agentParser");
const colors = require("playwright-core/lib/utilsBundle").colors;
const yaml = require("playwright-core/lib/utilsBundle").yaml;
const { mkdirIfNeeded } = require("playwright-core/lib/coreBundle").utils;
async function loadAgentSpecs() {
const files = await import_fs.default.promises.readdir(__dirname);
return Promise.all(files.filter((file) => file.endsWith(".agent.md")).map((file) => (0, import_agentParser.parseAgentSpec)(import_path.default.join(__dirname, file))));
}
class ClaudeGenerator {
static async init(fullConfig, projectName, prompts) {
await initRepo(fullConfig, projectName, {
promptsFolder: prompts ? ".claude/prompts" : void 0
});
const agents = await loadAgentSpecs();
await import_fs.default.promises.mkdir(".claude/agents", { recursive: true });
for (const agent of agents)
await writeFile(`.claude/agents/${agent.name}.md`, ClaudeGenerator.agentSpec(agent), "\u{1F916}", "agent definition");
const mcpServer = process.platform === "win32" ? { command: "cmd", args: ["/c", "npx", "playwright", "run-test-mcp-server"] } : { command: "npx", args: ["playwright", "run-test-mcp-server"] };
await writeFile(".mcp.json", JSON.stringify({
mcpServers: {
"playwright-test": mcpServer
}
}
if (yamlEndIndex === -1)
throw new Error("YAML front matter must be closed with ---");
const yamlLines = lines.slice(1, yamlEndIndex);
const yamlRaw = yamlLines.join("\n");
const contentLines = lines.slice(yamlEndIndex + 1);
const content = contentLines.join("\n");
let header;
try {
header = import_utilsBundle.yaml.parse(yamlRaw);
} catch (error) {
throw new Error(`Failed to parse YAML header: ${error.message}`);
}
if (!header.name)
throw new Error('YAML header must contain a "name" field');
if (!header.description)
throw new Error('YAML header must contain a "description" field');
return { header, content };
}, null, 2), "\u{1F527}", "mcp configuration");
initRepoDone();
}
static extractInstructionsAndExamples(content) {
const examples = [];
const instructions = content.split("<example>")[0].trim();
const exampleRegex = /<example>([\s\S]*?)<\/example>/g;
let match;
while ((match = exampleRegex.exec(content)) !== null) {
const example = match[1].trim();
examples.push(example.replace(/[\n]/g, " ").replace(/ +/g, " "));
static agentSpec(agent) {
const claudeToolMap = /* @__PURE__ */ new Map([
["search", ["Glob", "Grep", "Read", "LS"]],
["edit", ["Edit", "MultiEdit", "Write"]]
]);
function asClaudeTool(tool) {
const [first, second] = tool.split("/");
if (!second)
return (claudeToolMap.get(first) || [first]).join(", ");
return `mcp__${first}__${second}`;
}
return { instructions, examples };
const examples = agent.examples.length ? ` Examples: ${agent.examples.map((example) => `<example>${example}</example>`).join("")}` : "";
const lines = [];
const header = {
name: agent.name,
description: agent.description + examples,
tools: agent.tools.map((tool) => asClaudeTool(tool)).join(", "),
model: agent.model,
color: agent.color
};
lines.push(`---`);
lines.push(yaml.stringify(header, { lineWidth: 1e5 }) + `---`);
lines.push("");
lines.push(agent.instructions);
return lines.join("\n");
}
}
const claudeToolMap = /* @__PURE__ */ new Map([
["ls", ["Glob"]],
["grep", ["Grep"]],
["read", ["Read"]],
["edit", ["Edit", "MultiEdit"]],
["write", ["Write"]]
]);
const commonMcpServers = {
playwrightTest: {
type: "local",
command: "npx",
args: ["playwright", "run-test-mcp-server"]
class OpencodeGenerator {
static async init(fullConfig, projectName, prompts) {
await initRepo(fullConfig, projectName, {
defaultAgentName: "Build",
promptsFolder: prompts ? ".opencode/prompts" : void 0
});
const agents = await loadAgentSpecs();
for (const agent of agents) {
const prompt = [agent.instructions];
prompt.push("");
prompt.push(...agent.examples.map((example) => `<example>${example}</example>`));
await writeFile(`.opencode/prompts/${agent.name}.md`, prompt.join("\n"), "\u{1F916}", "agent definition");
}
await writeFile("opencode.json", OpencodeGenerator.configuration(agents), "\u{1F527}", "opencode configuration");
initRepoDone();
}
};
function saveAsClaudeCode(agent) {
function asClaudeTool(tool) {
const [first, second] = tool.split("/");
if (!second)
return (claudeToolMap.get(first) || [first]).join(", ");
return `mcp__${first}__${second}`;
static configuration(agents) {
const opencodeToolMap = /* @__PURE__ */ new Map([
["search", ["ls", "glob", "grep", "read"]],
["edit", ["edit", "write"]]
]);
const asOpencodeTool = (tools, tool) => {
const [first, second] = tool.split("/");
if (!second) {
for (const tool2 of opencodeToolMap.get(first) || [first])
tools[tool2] = true;
} else {
tools[`${first}*${second}`] = true;
}
};
const result = {};
result["$schema"] = "https://opencode.ai/config.json";
result["mcp"] = {};
result["tools"] = {
"playwright*": false
};
result["agent"] = {};
for (const agent of agents) {
const tools = {};
result["agent"][agent.name] = {
description: agent.description,
mode: "subagent",
prompt: `{file:.opencode/prompts/${agent.name}.md}`,
tools
};
for (const tool of agent.tools)
asOpencodeTool(tools, tool);
}
result["mcp"]["playwright-test"] = {
type: "local",
command: ["npx", "playwright", "run-test-mcp-server"],
enabled: true
};
return JSON.stringify(result, null, 2);
}
const lines = [];
lines.push(`---`);
lines.push(`name: playwright-test-${agent.header.name}`);
lines.push(`description: ${agent.header.description}. Examples: ${agent.examples.map((example) => `<example>${example}</example>`).join("")}`);
lines.push(`tools: ${agent.header.tools.map((tool) => asClaudeTool(tool)).join(", ")}`);
lines.push(`model: ${agent.header.model}`);
lines.push(`color: ${agent.header.color}`);
lines.push(`---`);
lines.push("");
lines.push(agent.instructions);
return lines.join("\n");
}
const opencodeToolMap = /* @__PURE__ */ new Map([
["ls", ["ls", "glob"]],
["grep", ["grep"]],
["read", ["read"]],
["edit", ["edit"]],
["write", ["write"]]
]);
function saveAsOpencodeJson(agents) {
function asOpencodeTool(tools, tool) {
const [first, second] = tool.split("/");
if (!second) {
for (const tool2 of opencodeToolMap.get(first) || [first])
tools[tool2] = true;
} else {
tools[`${first}*${second}`] = true;
class CopilotGenerator {
static async init(fullConfig, projectName, prompts) {
await initRepo(fullConfig, projectName, {
defaultAgentName: "agent",
promptsFolder: prompts ? ".github/prompts" : void 0,
promptSuffix: "prompt"
});
const agents = await loadAgentSpecs();
await import_fs.default.promises.mkdir(".github/agents", { recursive: true });
for (const agent of agents)
await writeFile(`.github/agents/${agent.name}.agent.md`, CopilotGenerator.agentSpec(agent), "\u{1F916}", "agent definition");
await deleteFile(`.github/chatmodes/ \u{1F3AD} planner.chatmode.md`, "legacy planner chatmode");
await deleteFile(`.github/chatmodes/\u{1F3AD} generator.chatmode.md`, "legacy generator chatmode");
await deleteFile(`.github/chatmodes/\u{1F3AD} healer.chatmode.md`, "legacy healer chatmode");
await deleteFile(`.github/agents/ \u{1F3AD} planner.agent.md`, "legacy planner agent");
await deleteFile(`.github/agents/\u{1F3AD} generator.agent.md`, "legacy generator agent");
await deleteFile(`.github/agents/\u{1F3AD} healer.agent.md`, "legacy healer agent");
await VSCodeGenerator.appendToMCPJson();
const mcpConfig = { mcpServers: CopilotGenerator.mcpServers };
if (!import_fs.default.existsSync(".github/copilot-setup-steps.yml")) {
const yaml2 = import_fs.default.readFileSync(import_path.default.join(__dirname, "copilot-setup-steps.yml"), "utf-8");
await writeFile(".github/workflows/copilot-setup-steps.yml", yaml2, "\u{1F527}", "GitHub Copilot setup steps");
}
console.log("");
console.log("");
console.log(" \u{1F527} TODO: GitHub > Settings > Copilot > Coding agent > MCP configuration");
console.log("------------------------------------------------------------------");
console.log(JSON.stringify(mcpConfig, null, 2));
console.log("------------------------------------------------------------------");
initRepoDone();
}
const result = {};
result["$schema"] = "https://opencode.ai/config.json";
result["mcp"] = {};
result["tools"] = {
"playwright*": false
};
result["agent"] = {};
for (const agent of agents) {
const tools = {};
result["agent"]["playwright-test-" + agent.header.name] = {
description: agent.header.description,
mode: "subagent",
prompt: `{file:.opencode/prompts/playwright-test-${agent.header.name}.md}`,
tools
static agentSpec(agent) {
const examples = agent.examples.length ? ` Examples: ${agent.examples.map((example) => `<example>${example}</example>`).join("")}` : "";
const lines = [];
const header = {
"name": agent.name,
"description": agent.description + examples,
"tools": agent.tools,
"model": "Claude Sonnet 4.6",
"mcp-servers": CopilotGenerator.mcpServers
};
for (const tool of agent.header.tools)
asOpencodeTool(tools, tool);
lines.push(`---`);
lines.push(yaml.stringify(header, { lineWidth: 1e5 }) + `---`);
lines.push("");
lines.push(agent.instructions);
lines.push("");
return lines.join("\n");
}
const server = commonMcpServers.playwrightTest;
result["mcp"]["playwright-test"] = {
type: server.type,
command: [server.command, ...server.args],
enabled: true
};
return JSON.stringify(result, null, 2);
}
async function loadAgents() {
const files = await import_fs.default.promises.readdir(__dirname);
return Promise.all(files.filter((file) => file.endsWith(".md")).map((file) => AgentParser.parseFile(import_path.default.join(__dirname, file))));
}
async function writeFile(filePath, content) {
console.log(`Writing file: ${filePath}`);
await import_fs.default.promises.writeFile(filePath, content, "utf-8");
}
async function initClaudeCodeRepo() {
const agents = await loadAgents();
await import_fs.default.promises.mkdir(".claude/agents", { recursive: true });
for (const agent of agents)
await writeFile(`.claude/agents/playwright-test-${agent.header.name}.md`, saveAsClaudeCode(agent));
await writeFile(".mcp.json", JSON.stringify({
mcpServers: {
static {
this.mcpServers = {
"playwright-test": {
command: commonMcpServers.playwrightTest.command,
args: commonMcpServers.playwrightTest.args
"type": "stdio",
"command": "npx",
"args": [
"playwright",
"run-test-mcp-server"
],
"tools": ["*"]
}
}
}, null, 2));
};
}
}
const vscodeToolMap = /* @__PURE__ */ new Map([
["ls", ["search/listDirectory", "search/fileSearch"]],
["grep", ["search/textSearch"]],
["read", ["search/readFile"]],
["edit", ["edit/editFiles"]],
["write", ["edit/createFile", "edit/createDirectory"]]
]);
const vscodeToolsOrder = ["edit/createFile", "edit/createDirectory", "edit/editFiles", "search/fileSearch", "search/textSearch", "search/listDirectory", "search/readFile"];
const vscodeMcpName = "playwright-test";
function saveAsVSCodeChatmode(agent) {
function asVscodeTool(tool) {
const [first, second] = tool.split("/");
if (second)
return `${vscodeMcpName}/${second}`;
return vscodeToolMap.get(first) || first;
class VSCodeGenerator {
static async init(fullConfig, projectName) {
await initRepo(fullConfig, projectName, {
promptsFolder: void 0
});
const agents = await loadAgentSpecs();
const nameMap = /* @__PURE__ */ new Map([
["playwright-test-planner", " \u{1F3AD} planner"],
["playwright-test-generator", "\u{1F3AD} generator"],
["playwright-test-healer", "\u{1F3AD} healer"]
]);
await import_fs.default.promises.mkdir(".github/chatmodes", { recursive: true });
for (const agent of agents)
await writeFile(`.github/chatmodes/${nameMap.get(agent.name)}.chatmode.md`, VSCodeGenerator.agentSpec(agent), "\u{1F916}", "chatmode definition");
await VSCodeGenerator.appendToMCPJson();
initRepoDone();
}
const tools = agent.header.tools.map(asVscodeTool).flat().sort((a, b) => {
const indexA = vscodeToolsOrder.indexOf(a);
const indexB = vscodeToolsOrder.indexOf(b);
if (indexA === -1 && indexB === -1)
return a.localeCompare(b);
if (indexA === -1)
return 1;
if (indexB === -1)
return -1;
return indexA - indexB;
}).map((tool) => `'${tool}'`).join(", ");
const lines = [];
lines.push(`---`);
lines.push(`description: ${agent.header.description}.`);
lines.push(`tools: [${tools}]`);
lines.push(`---`);
lines.push("");
lines.push(agent.instructions);
for (const example of agent.examples)
lines.push(`<example>${example}</example>`);
return lines.join("\n");
static async appendToMCPJson() {
await import_fs.default.promises.mkdir(".vscode", { recursive: true });
const mcpJsonPath = ".vscode/mcp.json";
let mcpJson = {
servers: {},
inputs: []
};
try {
mcpJson = JSON.parse(import_fs.default.readFileSync(mcpJsonPath, "utf8"));
} catch {
}
if (!mcpJson.servers)
mcpJson.servers = {};
mcpJson.servers["playwright-test"] = {
type: "stdio",
command: "npx",
args: ["playwright", "run-test-mcp-server"]
};
await writeFile(mcpJsonPath, JSON.stringify(mcpJson, null, 2), "\u{1F527}", "mcp configuration");
}
static agentSpec(agent) {
const vscodeToolMap = /* @__PURE__ */ new Map([
["search", ["search/listDirectory", "search/fileSearch", "search/textSearch"]],
["read", ["search/readFile"]],
["edit", ["edit/editFiles"]],
["write", ["edit/createFile", "edit/createDirectory"]]
]);
const vscodeToolsOrder = ["edit/createFile", "edit/createDirectory", "edit/editFiles", "search/fileSearch", "search/textSearch", "search/listDirectory", "search/readFile"];
const vscodeMcpName = "playwright-test";
function asVscodeTool(tool) {
const [first, second] = tool.split("/");
if (second)
return `${vscodeMcpName}/${second}`;
return vscodeToolMap.get(first) || first;
}
const tools = agent.tools.map(asVscodeTool).flat().sort((a, b) => {
const indexA = vscodeToolsOrder.indexOf(a);
const indexB = vscodeToolsOrder.indexOf(b);
if (indexA === -1 && indexB === -1)
return a.localeCompare(b);
if (indexA === -1)
return 1;
if (indexB === -1)
return -1;
return indexA - indexB;
}).map((tool) => `'${tool}'`).join(", ");
const lines = [];
lines.push(`---`);
lines.push(`description: ${agent.description}.`);
lines.push(`tools: [${tools}]`);
lines.push(`---`);
lines.push("");
lines.push(agent.instructions);
for (const example of agent.examples)
lines.push(`<example>${example}</example>`);
lines.push("");
return lines.join("\n");
}
}
async function initVSCodeRepo() {
const agents = await loadAgents();
await import_fs.default.promises.mkdir(".github/chatmodes", { recursive: true });
for (const agent of agents)
await writeFile(`.github/chatmodes/${agent.header.name === "planner" ? " " : ""}\u{1F3AD} ${agent.header.name}.chatmode.md`, saveAsVSCodeChatmode(agent));
await import_fs.default.promises.mkdir(".vscode", { recursive: true });
const mcpJsonPath = ".vscode/mcp.json";
let mcpJson = {
servers: {},
inputs: []
};
async function writeFile(filePath, content, icon, description) {
console.log(` ${icon} ${import_path.default.relative(process.cwd(), filePath)} ${colors.dim("- " + description)}`);
await mkdirIfNeeded(filePath);
await import_fs.default.promises.writeFile(filePath, content, "utf-8");
}
async function deleteFile(filePath, description) {
try {
mcpJson = JSON.parse(import_fs.default.readFileSync(mcpJsonPath, "utf8"));
if (!import_fs.default.existsSync(filePath))
return;
} catch {
return;
}
if (!mcpJson.servers)
mcpJson.servers = {};
mcpJson.servers["playwright-test"] = {
type: "stdio",
command: commonMcpServers.playwrightTest.command,
args: commonMcpServers.playwrightTest.args
};
await writeFile(mcpJsonPath, JSON.stringify(mcpJson, null, 2));
console.log(` \u2702\uFE0F ${import_path.default.relative(process.cwd(), filePath)} ${colors.dim("- " + description)}`);
await import_fs.default.promises.unlink(filePath);
}
async function initOpencodeRepo() {
const agents = await loadAgents();
await import_fs.default.promises.mkdir(".opencode/prompts", { recursive: true });
for (const agent of agents) {
const prompt = [agent.instructions];
prompt.push("");
prompt.push(...agent.examples.map((example) => `<example>${example}</example>`));
await writeFile(`.opencode/prompts/playwright-test-${agent.header.name}.md`, prompt.join("\n"));
async function initRepo(fullConfig, projectName, options) {
const project = (0, import_seed.seedProject)(fullConfig, projectName);
console.log(` \u{1F3AD} Using project "${project.project.name}" as a primary project`);
if (!import_fs.default.existsSync("specs")) {
await import_fs.default.promises.mkdir("specs");
await writeFile(import_path.default.join("specs", "README.md"), `# Specs
This is a directory for test plans.
`, "\u{1F4DD}", "directory for test plans");
}
await writeFile("opencode.json", saveAsOpencodeJson(agents));
let seedFile = await (0, import_seed.findSeedFile)(project);
if (!seedFile) {
seedFile = (0, import_seed.defaultSeedFile)(project);
await writeFile(seedFile, import_seed.seedFileContent, "\u{1F331}", "default environment seed file");
}
if (options.promptsFolder) {
await import_fs.default.promises.mkdir(options.promptsFolder, { recursive: true });
for (const promptFile of await import_fs.default.promises.readdir(__dirname)) {
if (!promptFile.endsWith(".prompt.md"))
continue;
const shortName = promptFile.replace(".prompt.md", "");
const fileName = options.promptSuffix ? `${shortName}.${options.promptSuffix}.md` : `${shortName}.md`;
const content = await loadPrompt(promptFile, {
defaultAgentName: "default",
...options,
seedFile: import_path.default.relative(process.cwd(), seedFile)
});
await writeFile(import_path.default.join(options.promptsFolder, fileName), content, "\u{1F4DD}", "prompt template");
}
}
}
function initRepoDone() {
console.log(" \u2705 Done.");
}
async function loadPrompt(file, params) {
const content = await import_fs.default.promises.readFile(import_path.default.join(__dirname, file), "utf-8");
return Object.entries(params).reduce((acc, [key, value]) => {
return acc.replace(new RegExp(`\\\${${key}}`, "g"), value);
}, content);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
initClaudeCodeRepo,
initOpencodeRepo,
initVSCodeRepo
ClaudeGenerator,
CopilotGenerator,
OpencodeGenerator,
VSCodeGenerator
});
+242
-145

@@ -32,6 +32,7 @@ "use strict";

_baseTest: () => _baseTest,
defineConfig: () => import_configLoader.defineConfig,
_utilityTest: () => _utilityTest,
defineConfig: () => import_common2.defineConfig,
expect: () => import_expect.expect,
mergeExpects: () => import_expect2.mergeExpects,
mergeTests: () => import_testType2.mergeTests,
mergeTests: () => import_common2.mergeTests,
test: () => test

@@ -43,12 +44,20 @@ });

var playwrightLibrary = __toESM(require("playwright-core"));
var import_utils = require("playwright-core/lib/utils");
var import_globals = require("./common/globals");
var import_testType = require("./common/testType");
var import_errorContext = require("./errorContext");
var import_common = require("./common");
var globals = __toESM(require("./globals"));
var import_package = require("./package");
var import_browserBackend = require("./mcp/test/browserBackend");
var import_expect = require("./matchers/expect");
var import_configLoader = require("./common/configLoader");
var import_testType2 = require("./common/testType");
var import_common2 = require("./common");
var import_expect2 = require("./matchers/expect");
const _baseTest = import_testType.rootTestType.test;
(0, import_utils.setBoxedStackPrefixes)([import_path.default.dirname(require.resolve("../package.json"))]);
const { asLocatorDescription } = require("playwright-core/lib/coreBundle").iso;
const { getActionGroup, renderTitleForCall } = require("playwright-core/lib/coreBundle").iso;
const { escapeHTML } = require("playwright-core/lib/coreBundle").iso;
const { jsonStringifyForceASCII } = require("playwright-core/lib/coreBundle").utils;
const { createGuid } = require("playwright-core/lib/coreBundle").utils;
const { debugMode } = require("playwright-core/lib/coreBundle").utils;
const { setBoxedStackPrefixes } = require("playwright-core/lib/coreBundle").utils;
const { currentZone } = require("playwright-core/lib/coreBundle").utils;
const _baseTest = import_common.testType.rootTestType.test;
setBoxedStackPrefixes([import_package.packageRoot]);
if (process["__pw_initiator__"]) {

@@ -65,8 +74,126 @@ const originalStackTraceLimit = Error.stackTraceLimit;

}
const utilityFixtures = {
playwright: [async ({}, use) => {
await use(require("playwright-core"));
}, { scope: "worker", box: true }],
screenshot: ["off", { scope: "worker", option: true, box: true }],
trace: ["off", { scope: "worker", option: true, box: true }],
testIdAttribute: ["data-testid", { option: true, box: true }],
_combinedContextOptions: [{}, { box: true }],
_setupArtifacts: [async ({ playwright, screenshot, _combinedContextOptions }, use, testInfo) => {
testInfo.setTimeout(testInfo.project.timeout);
const artifactsRecorder = new ArtifactsRecorder(playwright, tracing().artifactsDir(), screenshot);
await artifactsRecorder.willStartTest(testInfo);
const tracingGroupSteps = [];
const pausedContexts = /* @__PURE__ */ new Set();
const csiListener = {
onApiCallBegin: (data, channel) => {
const testInfo2 = globals.currentTestInfo();
if (!testInfo2 || data.apiName.includes("setTestIdAttribute") || data.apiName === "tracing.groupEnd")
return;
const zone = currentZone().data("stepZone");
const isExpectCall = data.apiName === "locator._expect" || data.apiName === "frame._expect" || data.apiName === "page._expectScreenshot";
if (zone && zone.category === "expect" && isExpectCall) {
if (zone.apiName)
data.apiName = zone.apiName;
if (zone.shortTitle || zone.title)
data.title = zone.shortTitle ?? zone.title;
data.stepId = zone.stepId;
return;
}
const step = testInfo2._addStep({
location: data.frames[0],
category: "pw:api",
title: renderTitle(channel.type, channel.method, channel.params, data.title),
apiName: data.apiName,
params: channel.params,
group: getActionGroup({ type: channel.type, method: channel.method })
}, tracingGroupSteps[tracingGroupSteps.length - 1]);
data.userData = step;
data.stepId = step.stepId;
if (data.apiName === "tracing.group")
tracingGroupSteps.push(step);
},
onApiCallEnd: (data) => {
if (data.apiName === "tracing.group")
return;
if (data.apiName === "tracing.groupEnd") {
const step2 = tracingGroupSteps.pop();
step2?.complete({ error: data.error });
return;
}
const step = data.userData;
step?.complete({ error: data.error });
},
onWillPause: ({ keepTestTimeout }) => {
if (!keepTestTimeout)
globals.currentTestInfo()?._setIgnoreTimeouts(true);
},
runBeforeCreateBrowserContext: async (options) => {
for (const [key, value] of Object.entries(_combinedContextOptions)) {
if (!(key in options))
options[key] = value;
}
},
runBeforeCreateRequestContext: async (options) => {
for (const [key, value] of Object.entries(_combinedContextOptions)) {
if (!(key in options))
options[key] = value;
}
},
runAfterCreateBrowserContext: async (context) => {
context.debugger.on("pausedstatechanged", () => {
const paused = !!context.debugger.pausedDetails();
if (pausedContexts.has(context) && !paused) {
pausedContexts.delete(context);
testInfo._setIgnoreTimeouts(false);
} else if (!pausedContexts.has(context) && paused) {
pausedContexts.add(context);
testInfo._setIgnoreTimeouts(true);
}
});
await artifactsRecorder.didCreateBrowserContext(context);
const currentTestInfo = globals.currentTestInfo();
if (currentTestInfo) {
attachConnectedHeaderIfNeeded(currentTestInfo, context.browser());
currentTestInfo._onCustomMessageCallback = (0, import_browserBackend.createCustomMessageHandler)(currentTestInfo, context);
await (0, import_browserBackend.runDaemonForContext)(currentTestInfo, context);
}
},
runAfterCreateRequestContext: async (context) => {
await artifactsRecorder.didCreateRequestContext(context);
},
runBeforeCloseBrowserContext: async (context) => {
await artifactsRecorder.willCloseBrowserContext(context);
},
runBeforeCloseRequestContext: async (context) => {
await artifactsRecorder.willCloseRequestContext(context);
}
};
const clientInstrumentation = playwright._instrumentation;
clientInstrumentation.addListener(csiListener);
await use();
clientInstrumentation.removeListener(csiListener);
await artifactsRecorder.didFinishTest();
}, { auto: "all-hooks-included", title: "trace recording", box: true, timeout: 0 }],
request: async ({ playwright }, use) => {
const request = await playwright.request.newContext();
await use(request);
const hook = test.info()._currentHookType();
if (hook === "beforeAll") {
await request.dispose({ reason: [
`Fixture { request } from beforeAll cannot be reused in a test.`,
` - Recommended fix: use a separate { request } in the test.`,
` - Alternatively, manually create APIRequestContext in beforeAll and dispose it in afterAll.`,
`See https://playwright.dev/docs/api-testing#sending-api-requests-from-ui-tests for more details.`
].join("\n") });
} else {
await request.dispose();
}
}
};
const _utilityTest = _baseTest.extend(utilityFixtures);
const playwrightFixtures = {
defaultBrowserType: ["chromium", { scope: "worker", option: true, box: true }],
browserName: [({ defaultBrowserType }, use) => use(defaultBrowserType), { scope: "worker", option: true, box: true }],
playwright: [async ({}, use) => {
await use(require("playwright-core"));
}, { scope: "worker", box: true }],
headless: [({ launchOptions }, use) => use(launchOptions.headless ?? true), { scope: "worker", option: true, box: true }],

@@ -78,5 +205,3 @@ channel: [({ launchOptions }, use) => use(launchOptions.channel), { scope: "worker", option: true, box: true }],

}, { scope: "worker", option: true, box: true }],
screenshot: ["off", { scope: "worker", option: true, box: true }],
video: ["off", { scope: "worker", option: true, box: true }],
trace: ["off", { scope: "worker", option: true, box: true }],
_browserOptions: [async ({ playwright, headless, channel, launchOptions }, use) => {

@@ -86,3 +211,4 @@ const options = {

...launchOptions,
tracesDir: tracing().tracesDir()
tracesDir: tracing().tracesDir(),
artifactsDir: tracing().artifactsDir()
};

@@ -97,12 +223,12 @@ if (headless !== void 0)

}, { scope: "worker", auto: true, box: true }],
browser: [async ({ playwright, browserName, _browserOptions, connectOptions }, use, testInfo) => {
if (!["chromium", "firefox", "webkit", "_bidiChromium", "_bidiFirefox"].includes(browserName))
browser: [async ({ playwright, browserName, _browserOptions, connectOptions }, use, workerInfo) => {
if (!["chromium", "firefox", "webkit"].includes(browserName))
throw new Error(`Unexpected browserName "${browserName}", must be one of "chromium", "firefox" or "webkit"`);
if (connectOptions) {
const browser2 = await playwright[browserName].connect({
const browser2 = await playwright[browserName].connect(connectOptions.wsEndpoint, {
...connectOptions,
exposeNetwork: connectOptions.exposeNetwork ?? connectOptions._exposeNetwork,
exposeNetwork: connectOptions.exposeNetwork,
headers: {
// HTTP headers are ASCII only (not UTF-8).
"x-playwright-launch-options": (0, import_utils.jsonStringifyForceASCII)(_browserOptions),
"x-playwright-launch-options": jsonStringifyForceASCII(_browserOptions),
...connectOptions.headers

@@ -116,2 +242,4 @@ }

const browser = await playwright[browserName].launch();
if (process.env.PLAYWRIGHT_DASHBOARD)
await browser.bind(`worker-${workerInfo.parallelIndex}`);
await use(browser);

@@ -141,3 +269,2 @@ await browser.close({ reason: "Test ended." });

actionTimeout: [0, { option: true, box: true }],
testIdAttribute: ["data-testid", { option: true, box: true }],
navigationTimeout: [0, { option: true, box: true }],

@@ -173,3 +300,3 @@ baseURL: [async ({}, use) => {

serviceWorkers
}, use) => {
}, use, testInfo) => {
const options = {};

@@ -224,87 +351,17 @@ if (acceptDownloads !== void 0)

});
}, { box: true }],
_setupContextOptions: [async ({ playwright, _combinedContextOptions, actionTimeout, navigationTimeout, testIdAttribute }, use, testInfo) => {
}, { scope: "test", box: true }],
_setupContextOptions: [async ({ playwright, actionTimeout, navigationTimeout, testIdAttribute }, use, _testInfo) => {
const testInfo = _testInfo;
if (testIdAttribute)
playwrightLibrary.selectors.setTestIdAttribute(testIdAttribute);
testInfo.snapshotSuffix = process.platform;
if ((0, import_utils.debugMode)() === "inspector")
testInfo._setDebugMode();
playwright._defaultContextOptions = _combinedContextOptions;
playwright._defaultContextTimeout = testInfo._pauseOnError() ? 5e3 : actionTimeout || 0;
testInfo._onCustomMessageCallback = () => Promise.reject(new Error("Only tests that use default Playwright context or page fixture support test_debug"));
if (debugMode() === "inspector")
testInfo._setIgnoreTimeouts(true);
playwright._defaultContextTimeout = actionTimeout || 0;
playwright._defaultContextNavigationTimeout = navigationTimeout || 0;
await use();
playwright._defaultContextOptions = void 0;
playwright._defaultContextTimeout = void 0;
playwright._defaultContextNavigationTimeout = void 0;
}, { auto: "all-hooks-included", title: "context configuration", box: true }],
_setupArtifacts: [async ({ playwright, screenshot }, use, testInfo) => {
testInfo.setTimeout(testInfo.project.timeout);
const artifactsRecorder = new ArtifactsRecorder(playwright, tracing().artifactsDir(), screenshot);
await artifactsRecorder.willStartTest(testInfo);
const tracingGroupSteps = [];
const csiListener = {
onApiCallBegin: (data, channel) => {
const testInfo2 = (0, import_globals.currentTestInfo)();
if (!testInfo2 || data.apiName.includes("setTestIdAttribute") || data.apiName === "tracing.groupEnd")
return;
const zone = (0, import_utils.currentZone)().data("stepZone");
const isExpectCall = data.apiName === "locator._expect" || data.apiName === "frame._expect" || data.apiName === "page._expectScreenshot";
if (zone && zone.category === "expect" && isExpectCall) {
if (zone.apiName)
data.apiName = zone.apiName;
if (zone.title)
data.title = zone.title;
data.stepId = zone.stepId;
return;
}
const step = testInfo2._addStep({
location: data.frames[0],
category: "pw:api",
title: renderTitle(channel.type, channel.method, channel.params, data.title),
apiName: data.apiName,
params: channel.params,
group: (0, import_utils.getActionGroup)({ type: channel.type, method: channel.method })
}, tracingGroupSteps[tracingGroupSteps.length - 1]);
data.userData = step;
data.stepId = step.stepId;
if (data.apiName === "tracing.group")
tracingGroupSteps.push(step);
},
onApiCallEnd: (data) => {
if (data.apiName === "tracing.group")
return;
if (data.apiName === "tracing.groupEnd") {
const step2 = tracingGroupSteps.pop();
step2?.complete({ error: data.error });
return;
}
const step = data.userData;
step?.complete({ error: data.error });
},
onWillPause: ({ keepTestTimeout }) => {
if (!keepTestTimeout)
(0, import_globals.currentTestInfo)()?._setDebugMode();
},
runAfterCreateBrowserContext: async (context) => {
await artifactsRecorder?.didCreateBrowserContext(context);
const testInfo2 = (0, import_globals.currentTestInfo)();
if (testInfo2)
attachConnectedHeaderIfNeeded(testInfo2, context.browser());
},
runAfterCreateRequestContext: async (context) => {
await artifactsRecorder?.didCreateRequestContext(context);
},
runBeforeCloseBrowserContext: async (context) => {
await artifactsRecorder?.willCloseBrowserContext(context);
},
runBeforeCloseRequestContext: async (context) => {
await artifactsRecorder?.willCloseRequestContext(context);
}
};
const clientInstrumentation = playwright._instrumentation;
clientInstrumentation.addListener(csiListener);
await use();
clientInstrumentation.removeListener(csiListener);
await artifactsRecorder.didFinishTest();
}, { auto: "all-hooks-included", title: "trace recording", box: true, timeout: 0 }],
_contextFactory: [async ({

@@ -331,6 +388,8 @@ browser,

}
const show = typeof video === "string" ? void 0 : video.show;
const videoOptions = captureVideo ? {
recordVideo: {
dir: tracing().artifactsDir(),
size: typeof video === "string" ? void 0 : video.size
size: typeof video === "string" ? void 0 : video.size,
showActions: show?.actions
}

@@ -389,8 +448,10 @@ } : {};

}, { scope: "worker", title: "context", box: true }],
context: async ({ browser, _reuseContext, _contextFactory }, use, testInfo) => {
context: async ({ browser, video, _reuseContext, _contextFactory }, use, testInfoPublic) => {
const browserImpl = browser;
const testInfo = testInfoPublic;
const show = typeof video === "string" ? void 0 : video.show;
attachConnectedHeaderIfNeeded(testInfo, browserImpl);
if (!_reuseContext) {
const { context: context2, close } = await _contextFactory();
testInfo._onDidFinishTestFunctions.unshift(() => (0, import_browserBackend.runBrowserBackendAtEnd)(context2, testInfo.errors[0]?.message));
await installScreencastTitleUpdater(testInfo, context2, show?.test);
await use(context2);

@@ -401,3 +462,3 @@ await close();

const context = await browserImpl._wrapApiCall(() => browserImpl._newContextForReuse(), { internal: true });
testInfo._onDidFinishTestFunctions.unshift(() => (0, import_browserBackend.runBrowserBackendAtEnd)(context, testInfo.errors[0]?.message));
await installScreencastTitleUpdater(testInfo, context, show?.test);
await use(context);

@@ -416,17 +477,2 @@ const closeReason = testInfo.status === "timedOut" ? "Test timeout of " + testInfo.timeout + "ms exceeded." : "Test ended.";

await use(page);
},
request: async ({ playwright }, use) => {
const request = await playwright.request.newContext();
await use(request);
const hook = test.info()._currentHookType();
if (hook === "beforeAll") {
await request.dispose({ reason: [
`Fixture { request } from beforeAll cannot be reused in a test.`,
` - Recommended fix: use a separate { request } in the test.`,
` - Alternatively, manually create APIRequestContext in beforeAll and dispose it in afterAll.`,
`See https://playwright.dev/docs/api-testing#sending-api-requests-from-ui-tests for more details.`
].join("\n") });
} else {
await request.dispose();
}
}

@@ -466,8 +512,8 @@ };

function resolveFileToConfig(file) {
const config = test.info().config.configFile;
if (!config || !file)
const config2 = test.info().config.configFile;
if (!config2 || !file)
return file;
if (import_path.default.isAbsolute(file))
return file;
return import_path.default.resolve(import_path.default.dirname(config), file);
return import_path.default.resolve(import_path.default.dirname(config2), file);
}

@@ -551,3 +597,3 @@ function resolveClientCerticates(clientCertificates) {

try {
const path2 = temporary ? this._createTemporaryArtifact((0, import_utils.createGuid)() + this._extension) : this._createAttachmentPath();
const path2 = temporary ? this._createTemporaryArtifact(createGuid() + this._extension) : this._createAttachmentPath();
await this._doSnapshot(page, path2);

@@ -579,3 +625,3 @@ if (temporary)

this._testInfo = testInfo;
testInfo._onDidFinishTestFunctions.push(() => this.didFinishTestFunction());
testInfo._onDidFinishTestFunctionCallbacks.add(() => this.didFinishTestFunction());
this._screenshotRecorder.fixOrdinal();

@@ -599,2 +645,4 @@ await Promise.all(this._playwright._allContexts().map((context) => this.didCreateBrowserContext(context)));

return;
if (this._testInfo.errors.some((e) => e.errorContext))
return;
if (this._pageSnapshot)

@@ -607,3 +655,3 @@ return;

await page._wrapApiCall(async () => {
this._pageSnapshot = await page._snapshotForAI({ timeout: 5e3 });
this._pageSnapshot = await page.ariaSnapshot({ mode: "ai", timeout: 5e3 });
}, { internal: true });

@@ -614,6 +662,6 @@ } catch {

async didCreateRequestContext(context) {
await this._startTraceChunkOnContextCreation(context, context._tracing);
await this._startTraceChunkOnContextCreation(context, context.tracing);
}
async willCloseRequestContext(context) {
await this._stopTracing(context, context._tracing);
await this._stopTracing(context, context.tracing);
}

@@ -630,3 +678,3 @@ async didFinishTestFunction() {

}).concat(leftoverApiRequests.map(async (context2) => {
await this._stopTracing(context2, context2._tracing);
await this._stopTracing(context2, context2.tracing);
})));

@@ -637,17 +685,19 @@ await this._screenshotRecorder.persistTemporary();

await this._takePageSnapshot(context);
if (this._pageSnapshot && this._testInfo.errors.length > 0 && !this._testInfo.attachments.some((a) => a.name === "error-context")) {
const lines = [
"# Page snapshot",
"",
"```yaml",
this._pageSnapshot,
"```"
];
const filePath = this._testInfo.outputPath("error-context.md");
await import_fs.default.promises.writeFile(filePath, lines.join("\n"), "utf8");
this._testInfo._attach({
name: "error-context",
contentType: "text/markdown",
path: filePath
}, void 0);
if (this._testInfo.errors.length > 0) {
const hasMatcherAriaSnapshot = this._testInfo.errors.some((e) => e.errorContext);
const errorContextContent = (0, import_errorContext.buildErrorContext)({
titlePath: this._testInfo.titlePath,
location: { file: this._testInfo.file, line: this._testInfo.line, column: this._testInfo.column },
errors: this._testInfo.errors,
pageSnapshot: hasMatcherAriaSnapshot ? void 0 : this._pageSnapshot
});
if (errorContextContent) {
const filePath = this._testInfo.outputPath("error-context.md");
await import_fs.default.promises.writeFile(filePath, errorContextContent, "utf8");
this._testInfo._attach({
name: "error-context",
contentType: "text/markdown",
path: filePath
}, void 0);
}
}

@@ -685,7 +735,53 @@ }

}
async function installScreencastTitleUpdater(testInfo, context, testAnnotate) {
if (!testAnnotate)
return;
const testTitle = testAnnotate.level === "file" ? [testInfo.titlePath[0]] : testInfo.titlePath;
const stepStack = [];
const overlays = /* @__PURE__ */ new Map();
const position = testAnnotate.position ?? "top-left";
const fontSize = testAnnotate.fontSize ?? 14;
const level = testAnnotate.level ?? "step";
const updateOverlay = async () => {
const parts = level === "step" ? [...testTitle, ...stepStack] : testTitle;
const html = createTestOverlay(parts, position, fontSize);
for (const page of context.pages()) {
await overlays.get(page)?.dispose();
overlays.delete(page);
const disposable = await page.screencast.showOverlay(html);
overlays.set(page, disposable);
}
};
testInfo._onUserStepBegin = async (title) => {
stepStack.push(title);
await updateOverlay();
};
testInfo._onUserStepEnd = async () => {
stepStack.pop();
await updateOverlay();
};
context.on("page", async () => {
void updateOverlay();
});
await updateOverlay();
}
function createTestOverlay(parts, position, fontSize) {
const positionStyles = {
"top-left": "top: 6px; left: 6px;",
"top": "top: 6px; left: 50%; transform: translateX(-50%);",
"top-right": "top: 6px; right: 6px;",
"bottom-left": "bottom: 6px; left: 6px;",
"bottom": "bottom: 6px; left: 50%; transform: translateX(-50%);",
"bottom-right": "bottom: 6px; right: 6px;"
};
const posStyle = positionStyles[position] ?? positionStyles["top-left"];
return `<div style="white-space: nowrap; font-size: ${fontSize}px; padding: 3px 6px; background: rgba(0,0,0,0.5); color: white; border-radius: 4px; position: absolute; ${posStyle}">
${parts.map((p) => `<div>${escapeHTML(p)}</div>`).join("")}
</div>`;
}
function renderTitle(type, method, params, title) {
const prefix = (0, import_utils.renderTitleForCall)({ title, type, method, params });
const prefix = renderTitleForCall({ title, type, method, params });
let selector;
if (params?.["selector"] && typeof params.selector === "string")
selector = (0, import_utils.asLocatorDescription)("javascript", params.selector);
selector = asLocatorDescription("javascript", params.selector);
return prefix + (selector ? ` ${selector}` : "");

@@ -696,6 +792,7 @@ }

}
const test = _baseTest.extend(playwrightFixtures);
const test = _utilityTest.extend(playwrightFixtures);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
_baseTest,
_utilityTest,
defineConfig,

@@ -702,0 +799,0 @@ expect,

@@ -31,23 +31,50 @@ "use strict";

__export(browserBackend_exports, {
runBrowserBackendAtEnd: () => runBrowserBackendAtEnd
createCustomMessageHandler: () => createCustomMessageHandler,
runDaemonForContext: () => runDaemonForContext
});
module.exports = __toCommonJS(browserBackend_exports);
var mcp = __toESM(require("../sdk/exports"));
var import_globals = require("../../common/globals");
var import_util = require("../../util");
var import_config = require("../browser/config");
var import_browserServerBackend = require("../browser/browserServerBackend");
var import_tab = require("../browser/tab");
async function runBrowserBackendAtEnd(context, errorMessage) {
const testInfo = (0, import_globals.currentTestInfo)();
if (!testInfo)
return;
const shouldPause = errorMessage ? testInfo?._pauseOnError() : testInfo?._pauseAtEnd();
if (!shouldPause)
return;
var import_crypto = __toESM(require("crypto"));
const { stripAnsiEscapes } = require("playwright-core/lib/coreBundle").iso;
function createCustomMessageHandler(testInfo, context) {
let backend;
const config = { capabilities: ["testing"] };
let tools;
context.once("close", () => {
void backend?.dispose();
backend = void 0;
});
return async (data) => {
if (!tools)
({ tools } = require("playwright-core/lib/coreBundle"));
const toolList = tools.filteredTools(config);
if (data.initialize) {
if (backend)
throw new Error("MCP backend is already initialized");
backend = new tools.BrowserBackend(config, context, toolList);
await backend.initialize(data.initialize.clientInfo);
const pausedMessage = await generatePausedMessage(tools, testInfo, context);
return { initialize: { pausedMessage } };
}
if (data.callTool) {
if (!backend)
throw new Error("MCP backend is not initialized");
return { callTool: await backend.callTool(data.callTool.name, data.callTool.arguments) };
}
if (data.close) {
await backend?.dispose();
backend = void 0;
return { close: {} };
}
throw new Error("Unknown MCP request");
};
}
async function generatePausedMessage(tools, testInfo, context) {
const lines = [];
if (errorMessage)
lines.push(`### Paused on error:`, (0, import_util.stripAnsiEscapes)(errorMessage));
else
if (testInfo.errors.length) {
lines.push(`### Paused on error:`);
for (const error of testInfo.errors)
lines.push(stripAnsiEscapes(error.message || ""));
} else {
lines.push(`### Paused at end of test. ready for interaction`);
}
for (let i = 0; i < context.pages().length; i++) {

@@ -62,7 +89,7 @@ const page = context.pages()[i];

);
let console = errorMessage ? await import_tab.Tab.collectConsoleMessages(page) : [];
console = console.filter((msg) => !msg.type || msg.type === "error");
if (console.length) {
let console2 = testInfo.errors.length ? await tools.Tab.collectConsoleMessages(page) : [];
console2 = console2.filter((msg) => msg.type === "error");
if (console2.length) {
lines.push("- Console Messages:");
for (const message of console)
for (const message of console2)
lines.push(` - ${message.toString()}`);

@@ -73,3 +100,3 @@ }

"```yaml",
await page._snapshotForAI(),
await page.ariaSnapshot({ mode: "ai" }),
"```"

@@ -79,24 +106,24 @@ );

lines.push("");
if (errorMessage)
if (testInfo.errors.length)
lines.push(`### Task`, `Try recovering from the error prior to continuing`);
const config = {
...import_config.defaultConfig,
capabilities: ["testing"]
};
await mcp.runOnPauseBackendLoop(new import_browserServerBackend.BrowserServerBackend(config, identityFactory(context)), lines.join("\n"));
return lines.join("\n");
}
function identityFactory(browserContext) {
return {
createContext: async (clientInfo, abortSignal, toolName) => {
return {
browserContext,
close: async () => {
}
};
}
};
async function runDaemonForContext(testInfo, context) {
if (testInfo._configInternal.configCLIOverrides.debug !== "cli")
return false;
const sessionName = `tw-${import_crypto.default.randomBytes(3).toString("hex")}`;
await context.browser().bind(sessionName, { workspaceDir: testInfo.project.testDir });
console.log([
`### The test is currently paused at the start`,
``,
`### Debugging Instructions`,
`- Run "playwright-cli attach ${sessionName}" to attach to this test`
].join("\n"));
await context.debugger.requestPause();
return true;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
runBrowserBackendAtEnd
createCustomMessageHandler,
runDaemonForContext
});

@@ -38,5 +38,6 @@ "use strict";

var import_path = __toESM(require("path"));
var import_bundle = require("../sdk/bundle");
var import_testTool = require("./testTool");
var import_testContext = require("./testContext");
const z = require("playwright-core/lib/utilsBundle").z;
const { isPathInside, resolveWithinRoot } = require("playwright-core/lib/coreBundle").utils;
const setupPage = (0, import_testTool.defineTestTool)({

@@ -47,14 +48,14 @@ schema: {

description: "Setup the page for test.",
inputSchema: import_bundle.z.object({
plan: import_bundle.z.string().describe("The plan for the test. This should be the actual test plan with all the steps."),
project: import_bundle.z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
seedFile: import_bundle.z.string().optional().describe('A seed file contains a single test that is used to setup the page for testing, for example: "tests/seed.spec.ts". If no seed file is provided, a default seed file is created.')
inputSchema: z.object({
plan: z.string().describe("The plan for the test. This should be the actual test plan with all the steps."),
project: z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
seedFile: z.string().optional().describe('A seed file contains a single test that is used to setup the page for testing, for example: "tests/seed.spec.ts". If no seed file is provided, a default seed file is created.')
}),
type: "readOnly"
},
handle: async (context, params, progress) => {
handle: async (context, params, signal) => {
const seed = await context.getOrCreateSeedFile(params.seedFile, params.project);
context.generatorJournal = new import_testContext.GeneratorJournal(context.rootPath, params.plan, seed);
await context.runSeedTest(seed.file, seed.projectName, progress);
return { content: [] };
const { output, status } = await context.runSeedTest(seed.file, seed.projectName, signal);
return { content: [{ type: "text", text: output }], isError: status !== "paused" };
}

@@ -67,3 +68,3 @@ });

description: "Retrieve the performed test log",
inputSchema: import_bundle.z.object({}),
inputSchema: z.object({}),
type: "readOnly"

@@ -86,5 +87,5 @@ },

description: "Write the generated test to the test file",
inputSchema: import_bundle.z.object({
fileName: import_bundle.z.string().describe("The file to write the test to"),
code: import_bundle.z.string().describe("The generated test code")
inputSchema: z.object({
fileName: z.string().describe("The file to write the test to"),
code: z.string().describe("The generated test code")
}),

@@ -100,8 +101,7 @@ type: "readOnly"

const config = await testRunner.loadConfig();
const resolvedFile = resolveWithinRoot(context.rootPath, params.fileName);
const dirs = [];
for (const project of config.projects) {
const testDir = import_path.default.relative(context.rootPath, project.project.testDir).replace(/\\/g, "/");
const fileName = params.fileName.replace(/\\/g, "/");
if (fileName.startsWith(testDir)) {
const resolvedFile = import_path.default.resolve(context.rootPath, fileName);
const projectTestDir = project.project.testDir;
if (resolvedFile && isPathInside(projectTestDir, resolvedFile)) {
await import_fs.default.promises.mkdir(import_path.default.dirname(resolvedFile), { recursive: true });

@@ -117,3 +117,3 @@ await import_fs.default.promises.writeFile(resolvedFile, params.code);

}
dirs.push(testDir);
dirs.push(import_path.default.relative(context.rootPath, projectTestDir).replace(/\\/g, "/"));
}

@@ -120,0 +120,0 @@ throw new Error(`Test file did not match any of the test dirs: ${dirs.join(", ")}`);

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -18,10 +20,23 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var plannerTools_exports = {};
__export(plannerTools_exports, {
setupPage: () => setupPage
saveTestPlan: () => saveTestPlan,
setupPage: () => setupPage,
submitTestPlan: () => submitTestPlan
});
module.exports = __toCommonJS(plannerTools_exports);
var import_bundle = require("../sdk/bundle");
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_testTool = require("./testTool");
const z = require("playwright-core/lib/utilsBundle").z;
const { resolveWithinRoot } = require("playwright-core/lib/coreBundle").utils;
const setupPage = (0, import_testTool.defineTestTool)({

@@ -32,17 +47,106 @@ schema: {

description: "Setup the page for test planning",
inputSchema: import_bundle.z.object({
project: import_bundle.z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
seedFile: import_bundle.z.string().optional().describe('A seed file contains a single test that is used to setup the page for testing, for example: "tests/seed.spec.ts". If no seed file is provided, a default seed file is created.')
inputSchema: z.object({
project: z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
seedFile: z.string().optional().describe('A seed file contains a single test that is used to setup the page for testing, for example: "tests/seed.spec.ts". If no seed file is provided, a default seed file is created.')
}),
type: "readOnly"
},
handle: async (context, params, progress) => {
handle: async (context, params, signal) => {
const seed = await context.getOrCreateSeedFile(params.seedFile, params.project);
await context.runSeedTest(seed.file, seed.projectName, progress);
return { content: [] };
const { output, status } = await context.runSeedTest(seed.file, seed.projectName, signal);
return { content: [{ type: "text", text: output }], isError: status !== "paused" };
}
});
const planSchema = z.object({
overview: z.string().describe("A brief overview of the application to be tested"),
suites: z.array(z.object({
name: z.string().describe("The name of the suite"),
seedFile: z.string().describe("A seed file that was used to setup the page for testing."),
tests: z.array(z.object({
name: z.string().describe("The name of the test"),
file: z.string().describe('The file the test should be saved to, for example: "tests/<suite-name>/<test-name>.spec.ts".'),
steps: z.array(z.object({
perform: z.string().optional().describe(`Action to perform. For example: 'Click on the "Submit" button'.`),
expect: z.string().array().describe(`Expected result of the action where appropriate. For example: 'The page should show the "Thank you for your submission" message'`)
}))
}))
}))
});
const submitTestPlan = (0, import_testTool.defineTestTool)({
schema: {
name: "planner_submit_plan",
title: "Submit test plan",
description: "Submit the test plan to the test planner",
inputSchema: planSchema,
type: "readOnly"
},
handle: async (context, params) => {
return {
content: [{
type: "text",
text: JSON.stringify(params, null, 2)
}]
};
}
});
const saveTestPlan = (0, import_testTool.defineTestTool)({
schema: {
name: "planner_save_plan",
title: "Save test plan as markdown file",
description: "Save the test plan as a markdown file",
inputSchema: planSchema.extend({
name: z.string().describe('The name of the test plan, for example: "Test Plan".'),
fileName: z.string().describe('The file to save the test plan to, for example: "spec/test.plan.md". Relative to the workspace root.')
}),
type: "readOnly"
},
handle: async (context, params) => {
const lines = [];
lines.push(`# ${params.name}`);
lines.push(``);
lines.push(`## Application Overview`);
lines.push(``);
lines.push(params.overview);
lines.push(``);
lines.push(`## Test Scenarios`);
for (let i = 0; i < params.suites.length; i++) {
lines.push(``);
const suite = params.suites[i];
lines.push(`### ${i + 1}. ${suite.name}`);
lines.push(``);
lines.push(`**Seed:** \`${suite.seedFile}\``);
for (let j = 0; j < suite.tests.length; j++) {
lines.push(``);
const test = suite.tests[j];
lines.push(`#### ${i + 1}.${j + 1}. ${test.name}`);
lines.push(``);
lines.push(`**File:** \`${test.file}\``);
lines.push(``);
lines.push(`**Steps:**`);
for (let k = 0; k < test.steps.length; k++) {
lines.push(` ${k + 1}. ${test.steps[k].perform ?? "-"}`);
for (const expect of test.steps[k].expect)
lines.push(` - expect: ${expect}`);
}
}
}
lines.push(``);
const resolvedFile = resolveWithinRoot(context.rootPath, params.fileName);
if (!resolvedFile)
throw new Error(`Plan file name must be a relative path inside the workspace: ${params.fileName}`);
await import_fs.default.promises.mkdir(import_path.default.dirname(resolvedFile), { recursive: true });
await import_fs.default.promises.writeFile(resolvedFile, lines.join("\n"));
return {
content: [{
type: "text",
text: `Test plan saved to ${params.fileName}`
}]
};
}
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
setupPage
saveTestPlan,
setupPage,
submitTestPlan
});

@@ -31,3 +31,6 @@ "use strict";

__export(seed_exports, {
ensureSeedTest: () => ensureSeedTest,
defaultSeedFile: () => defaultSeedFile,
ensureSeedFile: () => ensureSeedFile,
findSeedFile: () => findSeedFile,
seedFileContent: () => seedFileContent,
seedProject: () => seedProject

@@ -38,8 +41,8 @@ });

var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_projectUtils = require("../../runner/projectUtils");
function seedProject(config, projectName) {
var import_runner = require("../../runner");
const { mkdirIfNeeded } = require("playwright-core/lib/coreBundle").utils;
function seedProject(fullConfig, projectName) {
if (!projectName)
return (0, import_projectUtils.findTopLevelProjects)(config)[0];
const project = config.projects.find((p) => p.project.name === projectName);
return import_runner.projectUtils.findTopLevelProjects(fullConfig)[0];
const project = fullConfig.projects.find((p) => p.project.name === projectName);
if (!project)

@@ -49,14 +52,20 @@ throw new Error(`Project ${projectName} not found`);

}
async function ensureSeedTest(project, logNew) {
const files = await (0, import_projectUtils.collectFilesForProject)(project);
const seed = files.find((file) => import_path.default.basename(file).includes("seed"));
if (seed)
return seed;
async function findSeedFile(project) {
const files = await import_runner.projectUtils.collectFilesForProject(project);
return files.find((file) => import_path.default.basename(file).includes("seed"));
}
function defaultSeedFile(project) {
const testDir = project.project.testDir;
const seedFile = import_path.default.resolve(testDir, "seed.spec.ts");
if (logNew) {
console.log(`Writing file: ${import_path.default.relative(process.cwd(), seedFile)}`);
}
await (0, import_utils.mkdirIfNeeded)(seedFile);
await import_fs.default.promises.writeFile(seedFile, `import { test, expect } from '@playwright/test';
return import_path.default.resolve(testDir, "seed.spec.ts");
}
async function ensureSeedFile(project) {
const seedFile = await findSeedFile(project);
if (seedFile)
return seedFile;
const seedFilePath = defaultSeedFile(project);
await mkdirIfNeeded(seedFilePath);
await import_fs.default.promises.writeFile(seedFilePath, seedFileContent);
return seedFilePath;
}
const seedFileContent = `import { test, expect } from '@playwright/test';

@@ -68,9 +77,10 @@ test.describe('Test group', () => {

});
`);
return seedFile;
}
`;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ensureSeedTest,
defaultSeedFile,
ensureSeedFile,
findSeedFile,
seedFileContent,
seedProject
});

@@ -25,10 +25,15 @@ "use strict";

var import_stream = require("stream");
var import_util = require("../../util");
class StringWriteStream extends import_stream.Writable {
constructor(progress) {
constructor(output, stdio) {
super();
this._progress = progress;
this._output = output;
this._prefix = stdio === "stdout" ? "" : "[err] ";
}
_write(chunk, encoding, callback) {
const text = chunk.toString();
this._progress({ message: text.endsWith("\n") ? text.slice(0, -1) : text });
let text = (0, import_util.stripAnsiEscapes)(chunk.toString());
if (text.endsWith("\n"))
text = text.slice(0, -1);
if (text)
this._output.push(this._prefix + text);
callback();

@@ -35,0 +40,0 @@ }

@@ -31,6 +31,8 @@ "use strict";

__export(testBackend_exports, {
TestServerBackend: () => TestServerBackend
TestServerBackend: () => TestServerBackend,
testServerBackendTools: () => testServerBackendTools
});
module.exports = __toCommonJS(testBackend_exports);
var mcp = __toESM(require("../sdk/exports"));
var import_events = __toESM(require("events"));
var import_coreBundle = require("playwright-core/lib/coreBundle");
var import_testContext = require("./testContext");

@@ -40,60 +42,60 @@ var testTools = __toESM(require("./testTools.js"));

var plannerTools = __toESM(require("./plannerTools.js"));
var import_tools = require("../browser/tools");
var import_configLoader = require("../../common/configLoader");
var import_response = require("../browser/response");
class TestServerBackend {
constructor(configOption, options) {
const zod = require("playwright-core/lib/utilsBundle").z;
const typesWithIntent = ["action", "assertion", "input"];
const testServerBackendTools = [
plannerTools.saveTestPlan,
plannerTools.setupPage,
plannerTools.submitTestPlan,
generatorTools.setupPage,
generatorTools.generatorReadLog,
generatorTools.generatorWriteTest,
testTools.listTests,
testTools.runTests,
testTools.debugTest,
...import_coreBundle.tools.browserTools.map((tool) => wrapBrowserTool(tool))
];
class TestServerBackend extends import_events.default {
constructor(configPath, options) {
super();
this.name = "Playwright";
this.version = "0.0.1";
this._tools = [
plannerTools.setupPage,
generatorTools.setupPage,
generatorTools.generatorReadLog,
generatorTools.generatorWriteTest,
testTools.listTests,
testTools.runTests,
testTools.debugTest
];
this._context = new import_testContext.TestContext(options);
this._configOption = configOption;
this._options = options || {};
this._configPath = configPath;
}
async initialize(server, clientInfo) {
const rootPath = mcp.firstRootPath(clientInfo);
if (this._configOption) {
this._context.initialize(rootPath, (0, import_configLoader.resolveConfigLocation)(this._configOption));
return;
}
if (rootPath) {
this._context.initialize(rootPath, (0, import_configLoader.resolveConfigLocation)(rootPath));
return;
}
this._context.initialize(rootPath, (0, import_configLoader.resolveConfigLocation)(void 0));
async initialize(clientInfo) {
this._context = new import_testContext.TestContext(clientInfo, this._configPath, this._options);
}
async listTools() {
return [
...this._tools.map((tool) => mcp.toMcpTool(tool.schema)),
...import_tools.browserTools.map((tool) => mcp.toMcpTool(tool.schema, { addIntent: true }))
];
}
async afterCallTool(name, args, result) {
if (!import_tools.browserTools.find((tool) => tool.schema.name === name))
return;
const response = (0, import_response.parseResponse)(result);
if (response && !response.isError && response.code && typeof args?.["intent"] === "string")
this._context.generatorJournal?.logStep(args["intent"], response.code);
}
async callTool(name, args, progress) {
const tool = this._tools.find((tool2) => tool2.schema.name === name);
async callTool(name, args, signal) {
const tool = testServerBackendTools.find((tool2) => tool2.schema.name === name);
if (!tool)
throw new Error(`Tool not found: ${name}. Available tools: ${this._tools.map((tool2) => tool2.schema.name).join(", ")}`);
const parsedArguments = tool.schema.inputSchema.parse(args || {});
return await tool.handle(this._context, parsedArguments, progress);
throw new Error(`Tool not found: ${name}. Available tools: ${testServerBackendTools.map((tool2) => tool2.schema.name).join(", ")}`);
try {
return await tool.handle(this._context, tool.schema.inputSchema.parse(args || {}), signal);
} catch (e) {
return { content: [{ type: "text", text: String(e) }], isError: true };
}
}
serverClosed() {
void this._context.close();
async dispose() {
await this._context?.close();
}
}
function wrapBrowserTool(tool) {
const inputSchema = typesWithIntent.includes(tool.schema.type) ? tool.schema.inputSchema.extend({
intent: zod.string().describe("The intent of the call, for example the test step description plan idea")
}) : tool.schema.inputSchema;
return {
schema: {
...tool.schema,
inputSchema
},
handle: async (context, params, _signal) => {
const response = await context.sendMessageToPausedTest({ callTool: { name: tool.schema.name, arguments: params } });
return response.callTool;
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestServerBackend
TestServerBackend,
testServerBackendTools
});

@@ -32,14 +32,20 @@ "use strict";

GeneratorJournal: () => GeneratorJournal,
TestContext: () => TestContext
TestContext: () => TestContext,
createScreen: () => createScreen
});
module.exports = __toCommonJS(testContext_exports);
var import_fs = __toESM(require("fs"));
var import_os = __toESM(require("os"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_base = require("../../reporters/base");
var import_list = __toESM(require("../../reporters/list"));
var import_coreBundle = require("playwright-core/lib/coreBundle");
var import_runner = require("../../runner");
var import_streams = require("./streams");
var import_util = require("../../util");
var import_testRunner = require("../../runner/testRunner");
var import_seed = require("./seed");
var import_common = require("../../common");
const debug = require("playwright-core/lib/utilsBundle").debug;
const { noColors } = require("playwright-core/lib/coreBundle").iso;
const { ManualPromise, signalToPromise } = require("playwright-core/lib/coreBundle").iso;
const { escapeRegExp } = require("playwright-core/lib/coreBundle").iso;
const { toPosixPath } = require("playwright-core/lib/coreBundle").utils;
class GeneratorJournal {

@@ -60,3 +66,3 @@ constructor(rootPath, plan, seed) {

result.push(this._plan);
result.push(`# Seed file: ${import_path.default.relative(this._rootPath, this._seed.file)}`);
result.push(`# Seed file: ${toPosixPath(import_path.default.relative(this._rootPath, this._seed.file))}`);
result.push("```ts");

@@ -75,31 +81,57 @@ result.push(this._seed.content);

class TestContext {
constructor(options) {
this.options = options;
constructor(clientInfo, configPath, options) {
this._testOpQueue = Promise.resolve();
this._clientInfo = clientInfo;
this._configLocation = import_common.configLoader.resolveConfigLocation(configPath || clientInfo.cwd);
this.rootPath = clientInfo.cwd || this._configLocation.configDir;
if (options?.headless !== void 0)
this.computedHeaded = !options.headless;
else
this.computedHeaded = !process.env.CI && !(import_os.default.platform() === "linux" && !process.env.DISPLAY);
}
initialize(rootPath, configLocation) {
this.configLocation = configLocation;
this.rootPath = rootPath || configLocation.configDir;
async _enqueue(fn) {
const next = this._testOpQueue.then(fn);
this._testOpQueue = next.then(() => {
});
return await next;
}
existingTestRunner() {
return this._testRunner;
return this._testRunnerAndScreen?.testRunner;
}
async _cleanupTestRunner() {
if (!this._testRunnerAndScreen)
return;
await this._testRunnerAndScreen.testRunner.stopTests();
this._testRunnerAndScreen.claimStdio();
try {
await this._testRunnerAndScreen.testRunner.runGlobalTeardown();
} finally {
this._testRunnerAndScreen.releaseStdio();
this._testRunnerAndScreen = void 0;
}
}
async createTestRunner() {
if (this._testRunner)
await this._testRunner.stopTests();
const testRunner = new import_testRunner.TestRunner(this.configLocation, {});
await testRunner.initialize({});
this._testRunner = testRunner;
testRunner.on(import_testRunner.TestRunnerEvent.TestFilesChanged, (testFiles) => {
this._testRunner?.emit(import_testRunner.TestRunnerEvent.TestFilesChanged, testFiles);
await this._cleanupTestRunner();
const runner = new import_runner.testRunner.TestRunner(this._configLocation, {});
await runner.initialize({});
const testPaused = new ManualPromise();
const testRunnerAndScreen = {
...createScreen(),
testRunner: runner,
waitForTestPaused: () => testPaused
};
this._testRunnerAndScreen = testRunnerAndScreen;
runner.on(import_runner.testRunner.TestRunnerEvent.TestPaused, (params) => {
testRunnerAndScreen.sendMessageToPausedTest = params.sendMessage;
testPaused.resolve();
});
this._testRunner = testRunner;
return testRunner;
return testRunnerAndScreen;
}
async getOrCreateSeedFile(seedFile, projectName) {
const configDir = this.configLocation.configDir;
const testRunner = await this.createTestRunner();
const config = await testRunner.loadConfig();
const configDir = this._configLocation.configDir;
const { testRunner: runner } = await this.createTestRunner();
const config = await runner.loadConfig();
const project = (0, import_seed.seedProject)(config, projectName);
if (!seedFile) {
seedFile = await (0, import_seed.ensureSeedTest)(project, false);
seedFile = await (0, import_seed.ensureSeedFile)(project);
} else {

@@ -129,10 +161,6 @@ const candidateFiles = [];

}
async runSeedTest(seedFile, projectName, progress) {
const { screen } = this.createScreen(progress);
const configDir = this.configLocation.configDir;
const reporter = new import_list.default({ configDir, screen });
const testRunner = await this.createTestRunner();
const result = await testRunner.runTests(reporter, {
headed: !this.options?.headless,
locations: ["/" + (0, import_utils.escapeRegExp)(seedFile) + "/"],
async runSeedTest(seedFile, projectName, signal) {
const result = await this.runTestsWithGlobalSetupAndPossiblePause({
headed: this.computedHeaded,
locations: ["/" + escapeRegExp(seedFile) + "/"],
projects: [projectName],

@@ -144,22 +172,113 @@ timeout: 0,

failOnLoadErrors: true
});
if (result.status === "passed" && !reporter.suite?.allTests().length)
throw new Error("seed test not found.");
if (result.status !== "passed")
throw new Error("Errors while running the seed test.");
}, signal);
if (result.status === "passed")
result.output += "\nError: seed test not found.";
else if (result.status !== "paused")
result.output += "\nError while running the seed test.";
return result;
}
createScreen(progress) {
const stream = new import_streams.StringWriteStream(progress);
const screen = {
...import_base.terminalScreen,
isTTY: false,
colors: import_utils.noColors,
stdout: stream,
stderr: stream
async runTestsWithGlobalSetupAndPossiblePause(params, signal) {
return this._enqueue(() => this._runTestsImpl(params, signal));
}
async _runTestsImpl(params, signal) {
const configDir = this._configLocation.configDir;
const testRunnerAndScreen = await this.createTestRunner();
const { testRunner: runner, screen, claimStdio, releaseStdio } = testRunnerAndScreen;
claimStdio();
try {
const setupReporter = new MCPListReporter({ configDir, screen, includeTestId: true });
const { status: status2 } = await runner.runGlobalSetup([setupReporter]);
if (status2 !== "passed")
return { output: testRunnerAndScreen.output.join("\n"), status: status2 };
} finally {
releaseStdio();
}
let status = "passed";
const cleanup = async () => {
claimStdio();
try {
const result = await runner.runGlobalTeardown();
if (status === "passed")
status = result.status;
} finally {
releaseStdio();
}
};
return { screen, stream };
const abortPromise = signal ? signalToPromise(signal).promise.then(() => "interrupted") : new Promise(() => {
});
try {
const reporter = new MCPListReporter({ configDir, screen, includeTestId: true });
status = await Promise.race([
runner.runTests(reporter, params).then((result) => result.status),
testRunnerAndScreen.waitForTestPaused().then(() => "paused"),
abortPromise
]);
if (status === "interrupted") {
await runner.stopTests();
await cleanup();
return { output: testRunnerAndScreen.output.join("\n"), status };
}
if (status === "paused") {
const response = await testRunnerAndScreen.sendMessageToPausedTest({ request: { initialize: { clientInfo: this._clientInfo } } });
if (response.error)
throw new Error(response.error.message);
testRunnerAndScreen.output.push(response.response.initialize.pausedMessage);
return { output: testRunnerAndScreen.output.join("\n"), status };
}
} catch (e) {
status = "failed";
testRunnerAndScreen.output.push(String(e));
await cleanup();
return { output: testRunnerAndScreen.output.join("\n"), status };
}
await cleanup();
return { output: testRunnerAndScreen.output.join("\n"), status };
}
async close() {
await this._enqueue(() => this._cleanupTestRunner()).catch((e) => debug("pw:mcp:error")(e));
}
async sendMessageToPausedTest(request) {
const sendMessage = this._testRunnerAndScreen?.sendMessageToPausedTest;
if (!sendMessage)
throw new Error("Must setup test before interacting with the page");
const result = await sendMessage({ request });
if (result.error)
throw new Error(result.error.message);
if (typeof request?.callTool?.arguments?.["intent"] === "string") {
const response = import_coreBundle.tools.parseResponse(result.response.callTool);
if (response && !response.isError && response.code)
this.generatorJournal?.logStep(request.callTool.arguments["intent"], response.code);
}
return result.response;
}
}
function createScreen() {
const output = [];
const stdout = new import_streams.StringWriteStream(output, "stdout");
const stderr = new import_streams.StringWriteStream(output, "stderr");
const screen = {
...import_runner.base.terminalScreen,
isTTY: false,
colors: noColors,
stdout,
stderr
};
const originalStdoutWrite = process.stdout.write;
const originalStderrWrite = process.stderr.write;
const claimStdio = () => {
process.stdout.write = (chunk) => {
stdout.write(chunk);
return true;
};
process.stderr.write = (chunk) => {
stderr.write(chunk);
return true;
};
};
const releaseStdio = () => {
process.stdout.write = originalStdoutWrite;
process.stderr.write = originalStderrWrite;
};
return { screen, claimStdio, releaseStdio, output };
}
const bestPracticesMarkdown = `

@@ -177,6 +296,13 @@ # Best practices

`;
class MCPListReporter extends import_runner.ListReporter {
async onTestPaused() {
await new Promise(() => {
});
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
GeneratorJournal,
TestContext
TestContext,
createScreen
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -20,10 +18,2 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

@@ -37,6 +27,5 @@ var testTools_exports = {};

module.exports = __toCommonJS(testTools_exports);
var import_bundle = require("../sdk/bundle");
var import_list = __toESM(require("../../reporters/list"));
var import_listModeReporter = __toESM(require("../../reporters/listModeReporter"));
var import_runner = require("../../runner");
var import_testTool = require("./testTool");
const z = require("playwright-core/lib/utilsBundle").z;
const listTests = (0, import_testTool.defineTestTool)({

@@ -47,11 +36,10 @@ schema: {

description: "List tests",
inputSchema: import_bundle.z.object({}),
inputSchema: z.object({}),
type: "readOnly"
},
handle: async (context, _, progress) => {
const { screen } = context.createScreen(progress);
const reporter = new import_listModeReporter.default({ screen, includeTestId: true });
const testRunner = await context.createTestRunner();
handle: async (context) => {
const { testRunner, screen, output } = await context.createTestRunner();
const reporter = new import_runner.ListModeReporter({ screen, includeTestId: true });
await testRunner.listTests(reporter, {});
return { content: [] };
return { content: output.map((text) => ({ type: "text", text })) };
}

@@ -64,19 +52,15 @@ });

description: "Run tests",
inputSchema: import_bundle.z.object({
locations: import_bundle.z.array(import_bundle.z.string()).optional().describe('Folder, file or location to run: "test/e2e" or "test/e2e/file.spec.ts" or "test/e2e/file.spec.ts:20"'),
projects: import_bundle.z.array(import_bundle.z.string()).optional().describe('Projects to run, projects from playwright.config.ts, by default runs all projects. Running with "chromium" is a good start')
inputSchema: z.object({
locations: z.array(z.string()).optional().describe('Folder, file or location to run: "test/e2e" or "test/e2e/file.spec.ts" or "test/e2e/file.spec.ts:20"'),
projects: z.array(z.string()).optional().describe('Projects to run, projects from playwright.config.ts, by default runs all projects. Running with "chromium" is a good start')
}),
type: "readOnly"
},
handle: async (context, params, progress) => {
const { screen } = context.createScreen(progress);
const configDir = context.configLocation.configDir;
const reporter = new import_list.default({ configDir, screen, includeTestId: true, prefixStdio: "out" });
const testRunner = await context.createTestRunner();
await testRunner.runTests(reporter, {
locations: params.locations,
handle: async (context, params, signal) => {
const { output } = await context.runTestsWithGlobalSetupAndPossiblePause({
locations: params.locations ?? [],
projects: params.projects,
disableConfigReporters: true
});
return { content: [] };
}, signal);
return { content: [{ type: "text", text: output }] };
}

@@ -89,6 +73,6 @@ });

description: "Debug single test",
inputSchema: import_bundle.z.object({
test: import_bundle.z.object({
id: import_bundle.z.string().describe("Test ID to debug."),
title: import_bundle.z.string().describe("Human readable test title for granting permission to debug the test.")
inputSchema: z.object({
test: z.object({
id: z.string().describe("Test ID to debug."),
title: z.string().describe("Human readable test title for granting permission to debug the test.")
})

@@ -98,9 +82,7 @@ }),

},
handle: async (context, params, progress) => {
const { screen } = context.createScreen(progress);
const configDir = context.configLocation.configDir;
const reporter = new import_list.default({ configDir, screen, includeTestId: true, prefixStdio: "out" });
const testRunner = await context.createTestRunner();
await testRunner.runTests(reporter, {
headed: !context.options?.headless,
handle: async (context, params, signal) => {
const { output, status } = await context.runTestsWithGlobalSetupAndPossiblePause({
headed: context.computedHeaded,
locations: [],
// we can make this faster by passing the test's location, so we don't need to scan all tests to find the ID
testIds: [params.test.id],

@@ -111,5 +93,6 @@ // For automatic recovery

pauseOnError: true,
disableConfigReporters: true
});
return { content: [] };
disableConfigReporters: true,
actionTimeout: 5e3
}, signal);
return { content: [{ type: "text", text: output }], isError: status !== "paused" && status !== "passed" };
}

@@ -116,0 +99,0 @@ });

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -20,40 +18,21 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var program_exports = {};
__export(program_exports, {
program: () => import_program2.program
program: () => program
});
module.exports = __toCommonJS(program_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_program = require("playwright-core/lib/cli/program");
var import_utils = require("playwright-core/lib/utils");
var import_config = require("./common/config");
var import_configLoader = require("./common/configLoader");
var import_program2 = require("playwright-core/lib/cli/program");
var import_base = require("./reporters/base");
var import_html = require("./reporters/html");
var import_merge = require("./reporters/merge");
var import_projectUtils = require("./runner/projectUtils");
var testServer = __toESM(require("./runner/testServer"));
var import_watchMode = require("./runner/watchMode");
var import_testRunner = require("./runner/testRunner");
var import_reporters = require("./runner/reporters");
var import_exports = require("./mcp/sdk/exports");
var import_bootstrap = require("playwright-core/lib/bootstrap");
var import_coreBundle = require("playwright-core/lib/coreBundle");
var import_common = require("./common");
var import_testActions = require("./cli/testActions");
var import_reportActions = require("./cli/reportActions");
var import_testBackend = require("./mcp/test/testBackend");
var import_seed = require("./mcp/test/seed");
var import_program3 = require("./mcp/program");
var import_watchdog = require("./mcp/browser/watchdog");
var import_generateAgents = require("./agents/generateAgents");
const packageJSON = require("../package.json");
function addTestCommand(program3) {
const command = program3.command("test [test-filter...]");
var import_package = require("./package");
const { program } = require("playwright-core/lib/utilsBundle");
const { gracefullyProcessExitDoNotHang } = require("playwright-core/lib/coreBundle").utils;
import_coreBundle.libCli.decorateProgram(program);
function addTestCommand(program2) {
const command = program2.command("test [test-filter...]");
command.description("run tests with Playwright Test");

@@ -72,6 +51,6 @@ const options = testOptions.sort((a, b) => a[0].replace(/-/g, "").localeCompare(b[0].replace(/-/g, "")));

try {
await runTests(args, opts);
await (0, import_testActions.runTests)(args, opts);
} catch (e) {
console.error(e);
(0, import_utils.gracefullyProcessExitDoNotHang)(1);
gracefullyProcessExitDoNotHang(1);
}

@@ -89,24 +68,12 @@ });

}
function addClearCacheCommand(program3) {
const command = program3.command("clear-cache");
function addClearCacheCommand(program2) {
const command = program2.command("clear-cache");
command.description("clears build and test caches");
command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
command.action(async (opts) => {
const runner = new import_testRunner.TestRunner((0, import_configLoader.resolveConfigLocation)(opts.config), {});
const { status } = await runner.clearCache((0, import_reporters.createErrorCollectingReporter)(import_base.terminalScreen));
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode);
await (0, import_testActions.clearCache)(opts);
});
}
function addDevServerCommand(program3) {
const command = program3.command("dev-server", { hidden: true });
command.description("start dev server");
command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
command.action(async (options) => {
const runner = new import_testRunner.TestRunner((0, import_configLoader.resolveConfigLocation)(options.config), {});
await runner.startDevServer((0, import_reporters.createErrorCollectingReporter)(import_base.terminalScreen), "in-process");
});
}
function addTestServerCommand(program3) {
const command = program3.command("test-server", { hidden: true });
function addTestServerCommand(program2) {
const command = program2.command("test-server", { hidden: true });
command.description("start test server");

@@ -116,8 +83,12 @@ command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);

command.option("--port <port>", "Port to start the server on", "0");
command.action((opts) => runTestServer(opts));
command.action(async (opts) => {
await (0, import_testActions.runTestServerAction)(opts);
});
}
function addShowReportCommand(program3) {
const command = program3.command("show-report [report]");
function addShowReportCommand(program2) {
const command = program2.command("show-report [report]");
command.description("show HTML report");
command.action((report, options) => (0, import_html.showHTMLReport)(report, options.host, +options.port));
command.action(async (report, options) => {
await (0, import_reportActions.showReport)(report, options.host, +options.port);
});
command.option("--host <host>", "Host to serve report on", "localhost");

@@ -128,20 +99,22 @@ command.option("--port <port>", "Port to serve report on", "9323");

When specified, opens given report, otherwise opens last generated report.
Accepts a directory or a .zip archive whose top-level entry is "index.html" (e.g. one downloaded from a CI artifact).
Examples:
$ npx playwright show-report
$ npx playwright show-report playwright-report`);
$ npx playwright show-report playwright-report
$ npx playwright show-report playwright-report.zip`);
}
function addMergeReportsCommand(program3) {
const command = program3.command("merge-reports [dir]");
function addMergeReportsCommand(program2) {
const command = program2.command("merge-reports [dir]");
command.description("merge multiple blob reports (for sharded tests) into a single report");
command.action(async (dir, options) => {
try {
await mergeReports(dir, options);
await (0, import_reportActions.mergeReports)(dir, options);
} catch (e) {
console.error(e);
(0, import_utils.gracefullyProcessExitDoNotHang)(1);
gracefullyProcessExitDoNotHang(1);
}
});
command.option("-c, --config <file>", `Configuration file. Can be used to specify additional configuration for the output report.`);
command.option("--reporter <reporter>", `Reporter to use, comma-separated, can be ${import_config.builtInReporters.map((name) => `"${name}"`).join(", ")} (default: "${import_config.defaultReporter}")`);
command.option("--reporter <reporter>", `Reporter to use, comma-separated, can be ${import_common.builtInReporters.map((name) => `"${name}"`).join(", ")} (default: "${import_common.config.defaultReporter}")`);
command.addHelpText("afterAll", `

@@ -154,9 +127,4 @@ Arguments [dir]:

}
function addBrowserMCPServerCommand(program3) {
const command = program3.command("run-mcp-server", { hidden: true });
command.description("Interact with the browser over MCP");
(0, import_program3.decorateCommand)(command, packageJSON.version);
}
function addTestMCPServerCommand(program3) {
const command = program3.command("run-test-mcp-server", { hidden: true });
function addTestMCPServerCommand(program2) {
const command = program2.command("run-test-mcp-server", { hidden: true });
command.description("Interact with the test runner over MCP");

@@ -168,201 +136,39 @@ command.option("--headless", "run browser in headless mode, headed by default");

command.action(async (options) => {
(0, import_watchdog.setupExitWatchdog)();
const backendFactory = {
import_coreBundle.tools.setupExitWatchdog();
const factory = {
name: "Playwright Test Runner",
nameInConfig: "playwright-test-runner",
version: packageJSON.version,
create: () => new import_testBackend.TestServerBackend(options.config, { muteConsole: options.port === void 0, headless: options.headless })
version: import_package.packageJSON.version,
toolSchemas: import_testBackend.testServerBackendTools.map((tool) => tool.schema),
create: async () => new import_testBackend.TestServerBackend(options.config, { muteConsole: options.port === void 0, headless: options.headless }),
disposed: async () => {
}
};
const mdbUrl = await (0, import_exports.runMainBackend)(
backendFactory,
{
port: options.port === void 0 ? void 0 : +options.port
}
);
if (mdbUrl)
console.error("MCP Listening on: ", mdbUrl);
await import_coreBundle.tools.start(factory, { port: options.port === void 0 ? void 0 : +options.port, host: options.host });
});
}
function addInitAgentsCommand(program3) {
const command = program3.command("init-agents");
function addInitAgentsCommand(program2) {
const command = program2.command("init-agents");
command.description("Initialize repository agents");
const option = command.createOption("--loop <loop>", "Agentic loop provider");
option.choices(["vscode", "claude", "opencode"]);
option.choices(["claude", "copilot", "opencode", "vscode", "vscode-legacy"]);
command.addOption(option);
command.option("-c, --config <file>", `Configuration file to find a project to use for seed test`);
command.option("--project <project>", "Project to use for seed test");
command.option("--prompts", "Whether to include prompts in the agent initialization");
command.action(async (opts) => {
const loadedConfig = await import_common.configLoader.loadConfigFromFile(opts.config);
if (opts.loop === "opencode") {
await (0, import_generateAgents.initOpencodeRepo)();
} else if (opts.loop === "vscode") {
await (0, import_generateAgents.initVSCodeRepo)();
await import_generateAgents.OpencodeGenerator.init(loadedConfig, opts.project, opts.prompts);
} else if (opts.loop === "vscode-legacy") {
await import_generateAgents.VSCodeGenerator.init(loadedConfig, opts.project);
} else if (opts.loop === "claude") {
await (0, import_generateAgents.initClaudeCodeRepo)();
await import_generateAgents.ClaudeGenerator.init(loadedConfig, opts.project, opts.prompts);
} else {
command.help();
await import_generateAgents.CopilotGenerator.init(loadedConfig, opts.project, opts.prompts);
return;
}
const config = await (0, import_configLoader.loadConfigFromFile)(opts.config);
const project = (0, import_seed.seedProject)(config, opts.project);
await (0, import_seed.ensureSeedTest)(project, true);
});
}
async function runTests(args, opts) {
await (0, import_utils.startProfiling)();
const cliOverrides = overridesFromOptions(opts);
const config = await (0, import_configLoader.loadConfigFromFile)(opts.config, cliOverrides, opts.deps === false);
config.cliArgs = args;
config.cliGrep = opts.grep;
config.cliOnlyChanged = opts.onlyChanged === true ? "HEAD" : opts.onlyChanged;
config.cliGrepInvert = opts.grepInvert;
config.cliListOnly = !!opts.list;
config.cliProjectFilter = opts.project || void 0;
config.cliPassWithNoTests = !!opts.passWithNoTests;
config.cliLastFailed = !!opts.lastFailed;
config.cliTestList = opts.testList ? import_path.default.resolve(process.cwd(), opts.testList) : void 0;
config.cliTestListInvert = opts.testListInvert ? import_path.default.resolve(process.cwd(), opts.testListInvert) : void 0;
(0, import_projectUtils.filterProjects)(config.projects, config.cliProjectFilter);
if (opts.ui || opts.uiHost || opts.uiPort) {
if (opts.onlyChanged)
throw new Error(`--only-changed is not supported in UI mode. If you'd like that to change, see https://github.com/microsoft/playwright/issues/15075 for more details.`);
const status2 = await testServer.runUIMode(opts.config, cliOverrides, {
host: opts.uiHost,
port: opts.uiPort ? +opts.uiPort : void 0,
args,
grep: opts.grep,
grepInvert: opts.grepInvert,
project: opts.project || void 0,
reporter: Array.isArray(opts.reporter) ? opts.reporter : opts.reporter ? [opts.reporter] : void 0
});
await (0, import_utils.stopProfiling)("runner");
const exitCode2 = status2 === "interrupted" ? 130 : status2 === "passed" ? 0 : 1;
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode2);
return;
}
if (process.env.PWTEST_WATCH) {
if (opts.onlyChanged)
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 status2 = await (0, import_watchMode.runWatchModeLoop)(
(0, import_configLoader.resolveConfigLocation)(opts.config),
{
projects: opts.project,
files: args,
grep: opts.grep
}
);
await (0, import_utils.stopProfiling)("runner");
const exitCode2 = status2 === "interrupted" ? 130 : status2 === "passed" ? 0 : 1;
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode2);
return;
}
const status = await (0, import_testRunner.runAllTestsWithConfig)(config);
await (0, import_utils.stopProfiling)("runner");
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode);
}
async function runTestServer(opts) {
const host = opts.host || "localhost";
const port = opts.port ? +opts.port : 0;
const status = await testServer.runTestServer(opts.config, {}, { host, port });
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode);
}
async function mergeReports(reportDir, opts) {
const configFile = opts.config;
const config = configFile ? await (0, import_configLoader.loadConfigFromFile)(configFile) : await (0, import_configLoader.loadEmptyConfigForMergeReports)();
const dir = import_path.default.resolve(process.cwd(), reportDir || "");
const dirStat = await import_fs.default.promises.stat(dir).catch((e) => null);
if (!dirStat)
throw new Error("Directory does not exist: " + dir);
if (!dirStat.isDirectory())
throw new Error(`"${dir}" is not a directory`);
let reporterDescriptions = resolveReporterOption(opts.reporter);
if (!reporterDescriptions && configFile)
reporterDescriptions = config.config.reporter;
if (!reporterDescriptions)
reporterDescriptions = [[import_config.defaultReporter]];
const rootDirOverride = configFile ? config.config.rootDir : void 0;
await (0, import_merge.createMergedReport)(config, dir, reporterDescriptions, rootDirOverride);
(0, import_utils.gracefullyProcessExitDoNotHang)(0);
}
function overridesFromOptions(options) {
const overrides = {
failOnFlakyTests: options.failOnFlakyTests ? true : void 0,
forbidOnly: options.forbidOnly ? true : void 0,
fullyParallel: options.fullyParallel ? true : void 0,
globalTimeout: options.globalTimeout ? parseInt(options.globalTimeout, 10) : void 0,
maxFailures: options.x ? 1 : options.maxFailures ? parseInt(options.maxFailures, 10) : void 0,
outputDir: options.output ? import_path.default.resolve(process.cwd(), options.output) : void 0,
quiet: options.quiet ? options.quiet : void 0,
repeatEach: options.repeatEach ? parseInt(options.repeatEach, 10) : void 0,
retries: options.retries ? parseInt(options.retries, 10) : void 0,
reporter: resolveReporterOption(options.reporter),
shard: resolveShardOption(options.shard),
timeout: options.timeout ? parseInt(options.timeout, 10) : void 0,
tsconfig: options.tsconfig ? import_path.default.resolve(process.cwd(), options.tsconfig) : void 0,
ignoreSnapshots: options.ignoreSnapshots ? !!options.ignoreSnapshots : void 0,
updateSnapshots: options.updateSnapshots,
updateSourceMethod: options.updateSourceMethod,
workers: options.workers
};
if (options.browser) {
const browserOpt = options.browser.toLowerCase();
if (!["all", "chromium", "firefox", "webkit"].includes(browserOpt))
throw new Error(`Unsupported browser "${options.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
const browserNames = browserOpt === "all" ? ["chromium", "firefox", "webkit"] : [browserOpt];
overrides.projects = browserNames.map((browserName) => {
return {
name: browserName,
use: { browserName }
};
});
}
if (options.headed || options.debug)
overrides.use = { headless: false };
if (!options.ui && options.debug) {
overrides.debug = true;
process.env.PWDEBUG = "1";
}
if (!options.ui && options.trace) {
overrides.use = overrides.use || {};
overrides.use.trace = options.trace;
}
if (overrides.tsconfig && !import_fs.default.existsSync(overrides.tsconfig))
throw new Error(`--tsconfig "${options.tsconfig}" does not exist`);
return overrides;
}
function resolveReporterOption(reporter) {
if (!reporter || !reporter.length)
return void 0;
return reporter.split(",").map((r) => [resolveReporter(r)]);
}
function resolveShardOption(shard) {
if (!shard)
return void 0;
const shardPair = shard.split("/");
if (shardPair.length !== 2) {
throw new Error(
`--shard "${shard}", expected format is "current/all", 1-based, for example "3/5".`
);
}
const current = parseInt(shardPair[0], 10);
const total = parseInt(shardPair[1], 10);
if (isNaN(total) || total < 1)
throw new Error(`--shard "${shard}" total must be a positive number`);
if (isNaN(current) || current < 1 || current > total) {
throw new Error(
`--shard "${shard}" current must be a positive number, not greater than shard total`
);
}
return { current, total };
}
function resolveReporter(id) {
if (import_config.builtInReporters.includes(id))
return id;
const localPath = import_path.default.resolve(process.cwd(), id);
if (import_fs.default.existsSync(localPath))
return localPath;
return require.resolve(id, { paths: [process.cwd()] });
}
const kTraceModes = ["on", "off", "on-first-retry", "on-all-retries", "retain-on-failure", "retain-on-first-failure"];
const kTraceModes = ["on", "off", "on-first-retry", "on-all-retries", "retain-on-failure", "retain-on-first-failure", "retain-on-failure-and-retries"];
const testOptions = [

@@ -372,3 +178,3 @@ /* deprecated */

["-c, --config <file>", { description: `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"` }],
["--debug", { description: `Run tests with Playwright Inspector. Shortcut for "PWDEBUG=1" environment variable and "--timeout=0 --max-failures=1 --headed --workers=1" options` }],
["--debug [mode]", { description: `Run tests with Playwright Inspector. Shortcut for "PWDEBUG=1" environment variable and "--timeout=0 --max-failures=1 --headed --workers=1" options`, choices: ["inspector", "cli"], preset: "inspector" }],
["--fail-on-flaky-tests", { description: `Fail if any test is flagged as flaky (default: false)` }],

@@ -392,8 +198,9 @@ ["--forbid-only", { description: `Fail if test.only is called (default: false)` }],

["--repeat-each <N>", { description: `Run each test N times (default: 1)` }],
["--reporter <reporter>", { description: `Reporter to use, comma-separated, can be ${import_config.builtInReporters.map((name) => `"${name}"`).join(", ")} (default: "${import_config.defaultReporter}")` }],
["--reporter <reporter>", { description: `Reporter to use, comma-separated, can be ${import_common.builtInReporters.map((name) => `"${name}"`).join(", ")} (default: "${import_common.config.defaultReporter}")` }],
["--retries <retries>", { description: `Maximum retry count for flaky tests, zero for no retries (default: no retries)` }],
["--run-agents <mode>", { description: `Run agents to generate the code for page.perform`, choices: ["missing", "all", "none"], preset: "none" }],
["--shard <shard>", { description: `Shard tests and execute only the selected shard, specify in the form "current/all", 1-based, for example "3/5"` }],
["--test-list <file>", { description: `Path to a file containing a list of tests to run. See https://playwright.dev/docs/test-cli for more details.` }],
["--test-list-invert <file>", { description: `Path to a file containing a list of tests to skip. See https://playwright.dev/docs/test-cli for more details.` }],
["--timeout <timeout>", { description: `Specify test timeout threshold in milliseconds, zero for unlimited (default: ${import_config.defaultTimeout})` }],
["--timeout <timeout>", { description: `Specify test timeout threshold in milliseconds, zero for unlimited (default: ${import_common.config.defaultTimeout})` }],
["--trace <mode>", { description: `Force tracing mode`, choices: kTraceModes }],

@@ -409,11 +216,9 @@ ["--tsconfig <path>", { description: `Path to a single tsconfig applicable to all imported files (default: look up tsconfig for each imported file separately)` }],

];
addTestCommand(import_program.program);
addShowReportCommand(import_program.program);
addMergeReportsCommand(import_program.program);
addClearCacheCommand(import_program.program);
addBrowserMCPServerCommand(import_program.program);
addTestMCPServerCommand(import_program.program);
addDevServerCommand(import_program.program);
addTestServerCommand(import_program.program);
addInitAgentsCommand(import_program.program);
addTestCommand(program);
addShowReportCommand(program);
addMergeReportsCommand(program);
addClearCacheCommand(program);
addTestMCPServerCommand(program);
addTestServerCommand(program);
addInitAgentsCommand(program);
// Annotate the CommonJS export names for ESM import in node:

@@ -420,0 +225,0 @@ 0 && (module.exports = {

@@ -33,5 +33,3 @@ "use strict";

ansiRegex: () => ansiRegex,
createFileFiltersFromArguments: () => createFileFiltersFromArguments,
createFileMatcher: () => createFileMatcher,
createFileMatcherFromArguments: () => createFileMatcherFromArguments,
createTitleMatcher: () => createTitleMatcher,

@@ -60,2 +58,3 @@ debugTest: () => debugTest,

stripAnsiEscapes: () => stripAnsiEscapes,
takeFirst: () => takeFirst,
trimLongString: () => trimLongString,

@@ -69,4 +68,10 @@ windowsFilesystemFriendlyLength: () => windowsFilesystemFriendlyLength

var import_util = __toESM(require("util"));
var import_utils = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
const debug = require("playwright-core/lib/utilsBundle").debug;
const mime = require("playwright-core/lib/utilsBundle").mime;
const minimatch = require("playwright-core/lib/utilsBundle").minimatch;
const { calculateSha1 } = require("playwright-core/lib/coreBundle").utils;
const { sanitizeForFilePath } = require("playwright-core/lib/coreBundle").utils;
const { isRegExp } = require("playwright-core/lib/coreBundle").iso;
const { parseStackFrame, stringifyStackFrames } = require("playwright-core/lib/coreBundle").iso;
const { ansiRegex, isString, stripAnsiEscapes } = require("playwright-core/lib/coreBundle").iso;
const PLAYWRIGHT_TEST_PATH = import_path.default.join(__dirname, "..");

@@ -79,3 +84,3 @@ const PLAYWRIGHT_CORE_PATH = import_path.default.dirname(require.resolve("playwright-core/package.json"));

return { message: name + e.message, stack: e.stack || "", cause };
const stackLines = (0, import_utils.stringifyStackFrames)(filteredStackTrace(e.stack?.split("\n") || []));
const stackLines = stringifyStackFrames(filteredStackTrace(e.stack?.split("\n") || []));
return {

@@ -88,5 +93,7 @@ message: name + e.message,

function filterStackFile(file) {
if (!process.env.PWDEBUGIMPL && file.startsWith(PLAYWRIGHT_TEST_PATH))
if (process.env.PWDEBUGIMPL)
return true;
if (file.startsWith(PLAYWRIGHT_TEST_PATH))
return false;
if (!process.env.PWDEBUGIMPL && file.startsWith(PLAYWRIGHT_CORE_PATH))
if (file.startsWith(PLAYWRIGHT_CORE_PATH))
return false;

@@ -98,3 +105,3 @@ return true;

for (const line of rawStack) {
const frame = (0, import_utils.parseStackFrame)(line, import_path.default.sep, !!process.env.PWDEBUGIMPL);
const frame = parseStackFrame(line, import_path.default.sep, !!process.env.PWDEBUGIMPL);
if (!frame || !frame.file)

@@ -123,12 +130,2 @@ continue;

}
function createFileFiltersFromArguments(args) {
return args.map((arg) => {
const parsed = parseLocationArg(arg);
return { re: forceRegExp(parsed.file), line: parsed.line, column: parsed.column };
});
}
function createFileMatcherFromArguments(args) {
const filters = createFileFiltersFromArguments(args);
return createFileMatcher(filters.map((filter) => filter.re || filter.exact || ""));
}
function createFileMatcher(patterns) {

@@ -138,3 +135,3 @@ const reList = [];

for (const pattern of Array.isArray(patterns) ? patterns : [patterns]) {
if ((0, import_utils.isRegExp)(pattern)) {
if (isRegExp(pattern)) {
reList.push(pattern);

@@ -163,3 +160,3 @@ } else {

for (const pattern of filePatterns) {
if ((0, import_utilsBundle.minimatch)(filePath, pattern, { nocase: true, dot: true }))
if (minimatch(filePath, pattern, { nocase: true, dot: true }))
return true;

@@ -209,7 +206,8 @@ }

function expectTypes(receiver, types, matcherName) {
if (typeof receiver !== "object" || !types.includes(receiver.constructor.name)) {
if (typeof receiver !== "object" || !types.includes(receiver._apiName)) {
const receiverString = typeof receiver === "object" && receiver !== null ? `${receiver.constructor.name} ${import_util.default.inspect(receiver)}` : String(receiver);
const commaSeparated = types.slice();
const lastType = commaSeparated.pop();
const typesString = commaSeparated.length ? commaSeparated.join(", ") + " or " + lastType : lastType;
throw new Error(`${matcherName} can be only used with ${typesString} object${types.length > 1 ? "s" : ""}`);
throw new Error(`${matcherName} can be only used with ${typesString} object${types.length > 1 ? "s" : ""}, was called with ${receiverString}`);
}

@@ -221,3 +219,3 @@ }

return s;
const hash = (0, import_utils.calculateSha1)(s);
const hash = calculateSha1(s);
const middle = `-${hash.substring(0, 5)}-`;

@@ -236,3 +234,3 @@ const start = Math.floor((length - middle.length) / 2);

const base = filePath.substring(0, filePath.length - ext.length);
return (0, import_utils.sanitizeForFilePath)(base) + ext;
return sanitizeForFilePath(base) + ext;
}

@@ -245,3 +243,3 @@ function getContainedPath(parentPath, subPath = "") {

}
const debugTest = (0, import_utilsBundle.debug)("pw:test");
const debugTest = debug("pw:test");
const folderToPackageJsonPath = /* @__PURE__ */ new Map();

@@ -279,10 +277,10 @@ function getPackageJsonPath(folderPath) {

if (options.path !== void 0) {
const hash = (0, import_utils.calculateSha1)(options.path);
if (!(0, import_utils.isString)(name))
const hash = calculateSha1(options.path);
if (!isString(name))
throw new Error('"name" should be string.');
const sanitizedNamePrefix = (0, import_utils.sanitizeForFilePath)(name) + "-";
const sanitizedNamePrefix = sanitizeForFilePath(name) + "-";
const dest = import_path.default.join(outputPath, "attachments", sanitizedNamePrefix + hash + import_path.default.extname(options.path));
await import_fs.default.promises.mkdir(import_path.default.dirname(dest), { recursive: true });
await import_fs.default.promises.copyFile(options.path, dest);
const contentType = options.contentType ?? (import_utilsBundle.mime.getType(import_path.default.basename(options.path)) || "application/octet-stream");
const contentType = options.contentType ?? (mime.getType(import_path.default.basename(options.path)) || "application/octet-stream");
return { name, contentType, path: dest };

@@ -381,5 +379,8 @@ } else {

}
const ansiRegex = new RegExp("([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))", "g");
function stripAnsiEscapes(str) {
return str.replace(ansiRegex, "");
function takeFirst(...args) {
for (const arg of args) {
if (arg !== void 0)
return arg;
}
return void 0;
}

@@ -390,5 +391,3 @@ // Annotate the CommonJS export names for ESM import in node:

ansiRegex,
createFileFiltersFromArguments,
createFileMatcher,
createFileMatcherFromArguments,
createTitleMatcher,

@@ -417,4 +416,5 @@ debugTest,

stripAnsiEscapes,
takeFirst,
trimLongString,
windowsFilesystemFriendlyLength
});
{
"name": "@limrun/playwright",
"version": "1.56.1-lim.1",
"version": "1.60.0-lim.1",
"description": "A high-level API to automate web browsers",

@@ -22,19 +22,9 @@ "repository": {

"./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/mcp/browser/tools": "./lib/mcp/browser/tools.js",
"./lib/mcp/program": "./lib/mcp/program.js",
"./lib/mcp/sdk/bundle": "./lib/mcp/sdk/bundle.js",
"./lib/mcp/sdk/exports": "./lib/mcp/sdk/exports.js",
"./lib/program": "./lib/program.js",
"./lib/reporters/base": "./lib/reporters/base.js",
"./lib/reporters/list": "./lib/reporters/list.js",
"./lib/runner": "./lib/runner/index.js",
"./lib/isomorphic": "./lib/isomorphic/index.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/internalsForTest": "./lib/internalsForTest.js",
"./lib/plugins": "./lib/plugins/index.js",
"./lib/runner/testRunner": "./lib/runner/testRunner.js",
"./jsx-runtime": {

@@ -46,3 +36,2 @@ "import": "./jsx-runtime.mjs",

"./lib/util": "./lib/util.js",
"./lib/utilsBundle": "./lib/utilsBundle.js",
"./types/test": {

@@ -69,3 +58,3 @@ "types": "./types/test.d.ts"

"dependencies": {
"playwright-core": "npm:@limrun/playwright-core@1.56.1-lim.1"
"playwright-core": "npm:@limrun/playwright-core@1.60.0-lim.1"
},

@@ -72,0 +61,0 @@ "optionalDependencies": {

@@ -28,2 +28,4 @@ /**

export const _android = playwright._android;
export const _baseTest = playwright._baseTest;
export const _utilityTest = playwright._utilityTest;
export const test = playwright.test;

@@ -30,0 +32,0 @@ export const expect = playwright.expect;

@@ -18,4 +18,4 @@ // This file is generated by /utils/generate_types/index.js

import type { TestStatus, Metadata, PlaywrightTestOptions, PlaywrightWorkerOptions, ReporterDescription, FullConfig, FullProject, Location } from './test';
export type { FullConfig, FullProject, TestStatus, Location } from './test';
import type { TestStatus, Metadata, PlaywrightTestOptions, PlaywrightWorkerOptions, ReporterDescription, FullConfig, FullProject, Location, WorkerInfo } from './test';
export type { FullConfig, FullProject, TestStatus, Location, WorkerInfo } from './test';

@@ -123,4 +123,4 @@ /**

* called when standard output is produced in the worker process, possibly during a test execution, and
* [reporter.onError(error)](https://playwright.dev/docs/api/class-reporter#reporter-on-error) is called when
* something went wrong outside of the test execution.
* [reporter.onError(error[, workerInfo])](https://playwright.dev/docs/api/class-reporter#reporter-on-error) is called
* when something went wrong outside of the test execution.
*

@@ -132,2 +132,7 @@ * If your custom reporter does not print anything to the terminal, implement

*
* **Reporter errors**
*
* Playwright will swallow any errors thrown in your custom reporter methods. If you need to detect or fail on
* reporter errors, you must wrap and handle them yourself.
*
* **Merged report API notes**

@@ -170,4 +175,6 @@ *

* @param error The error.
* @param workerInfo Contains information about the worker that produced this error. `undefined` for errors that are not associated with
* a specific worker.
*/
onError?(error: TestError): void;
onError?(error: TestError, workerInfo?: WorkerInfo): void;

@@ -299,2 +306,3 @@ /**

parallelIndex: number;
shardIndex?: number;
status: TestStatus | undefined;

@@ -301,0 +309,0 @@ duration: number;

---
name: generator
description: Use this agent when you need to create automated browser tests using Playwright
model: sonnet
color: blue
tools:
- ls
- grep
- read
- playwright-test/browser_click
- playwright-test/browser_drag
- playwright-test/browser_evaluate
- playwright-test/browser_file_upload
- playwright-test/browser_handle_dialog
- playwright-test/browser_hover
- playwright-test/browser_navigate
- playwright-test/browser_press_key
- playwright-test/browser_select_option
- playwright-test/browser_snapshot
- playwright-test/browser_type
- playwright-test/browser_verify_element_visible
- playwright-test/browser_verify_list_visible
- playwright-test/browser_verify_text_visible
- playwright-test/browser_verify_value
- playwright-test/browser_wait_for
- playwright-test/generator_read_log
- playwright-test/generator_setup_page
- playwright-test/generator_write_test
---
You are a Playwright Test Generator, an expert in browser automation and end-to-end testing.
Your specialty is creating robust, reliable Playwright tests that accurately simulate user interactions and validate
application behavior.
# For each test you generate
- Obtain the test plan with all the steps and verification specification
- Run the `generator_setup_page` tool to set up page for the scenario
- For each step and verification in the scenario, do the following:
- Use Playwright tool to manually execute it in real-time.
- Use the step description as the intent for each Playwright tool call.
- Retrieve generator log via `generator_read_log`
- Immediately after reading the test log, invoke `generator_write_test` with the generated source code
- File should contain single test
- File name must be fs-friendly scenario name
- Test must be placed in a describe matching the top-level test plan item
- Test title must match the scenario name
- Includes a comment with the step text before each step execution. Do not duplicate comments if step requires
multiple actions.
- Always use best practices from the log when generating tests.
<example-generation>
For following plan:
```markdown file=specs/plan.md
### 1. Adding New Todos
**Seed:** `tests/seed.spec.ts`
#### 1.1 Add Valid Todo
**Steps:**
1. Click in the "What needs to be done?" input field
#### 1.2 Add Multiple Todos
...
```
Following file is generated:
```ts file=add-valid-todo.spec.ts
// spec: specs/plan.md
// seed: tests/seed.spec.ts
test.describe('Adding New Todos', () => {
test('Add Valid Todo', async { page } => {
// 1. Click in the "What needs to be done?" input field
await page.click(...);
...
});
});
```
</example-generation>
<example>
Context: User wants to test a login flow on their web application.
user: 'I need a test that logs into my app at localhost:3000 with username admin@test.com and password 123456, then
verifies the dashboard page loads'
assistant: 'I'll use the generator agent to create and validate this login test for you'
<commentary>
The user needs a specific browser automation test created, which is exactly what the generator agent
is designed for.
</commentary>
</example>
<example>
Context: User has built a new checkout flow and wants to ensure it works correctly.
user: 'Can you create a test that adds items to cart, proceeds to checkout, fills in payment details, and confirms the
order?'
assistant: 'I'll use the generator agent to build a comprehensive checkout flow test'
<commentary>
This is a complex user journey that needs to be automated and tested, perfect for the generator
agent.
</commentary>
</example>
---
name: healer
description: Use this agent when you need to debug and fix failing Playwright tests
color: red
model: sonnet
tools:
- ls
- grep
- read
- write
- edit
- playwright-test/browser_console_messages
- playwright-test/browser_evaluate
- playwright-test/browser_generate_locator
- playwright-test/browser_network_requests
- playwright-test/browser_snapshot
- playwright-test/test_debug
- playwright-test/test_list
- playwright-test/test_run
---
You are the Playwright Test Healer, an expert test automation engineer specializing in debugging and
resolving Playwright test failures. Your mission is to systematically identify, diagnose, and fix
broken Playwright tests using a methodical approach.
Your workflow:
1. **Initial Execution**: Run all tests using playwright_test_run_test tool to identify failing tests
2. **Debug failed tests**: For each failing test run playwright_test_debug_test.
3. **Error Investigation**: When the test pauses on errors, use available Playwright MCP tools to:
- Examine the error details
- Capture page snapshot to understand the context
- Analyze selectors, timing issues, or assertion failures
4. **Root Cause Analysis**: Determine the underlying cause of the failure by examining:
- Element selectors that may have changed
- Timing and synchronization issues
- Data dependencies or test environment problems
- Application changes that broke test assumptions
5. **Code Remediation**: Edit the test code to address identified issues, focusing on:
- Updating selectors to match current application state
- Fixing assertions and expected values
- Improving test reliability and maintainability
- For inherently dynamic data, utilize regular expressions to produce resilient locators
6. **Verification**: Restart the test after each fix to validate the changes
7. **Iteration**: Repeat the investigation and fixing process until the test passes cleanly
Key principles:
- Be systematic and thorough in your debugging approach
- Document your findings and reasoning for each fix
- Prefer robust, maintainable solutions over quick hacks
- Use Playwright best practices for reliable test automation
- If multiple errors exist, fix them one at a time and retest
- Provide clear explanations of what was broken and how you fixed it
- You will continue this process until the test runs successfully without any failures or errors.
- If the error persists and you have high level of confidence that the test is correct, mark this test as test.fixme()
so that it is skipped during the execution. Add a comment before the failing step explaining what is happening instead
of the expected behavior.
- Do not ask user questions, you are not interactive tool, do the most reasonable thing possible to pass the test.
- Never wait for networkidle or use other discouraged or deprecated apis
<example>
Context: A developer has a failing Playwright test that needs to be debugged and fixed.
user: 'The login test is failing, can you fix it?'
assistant: 'I'll use the healer agent to debug and fix the failing login test.'
<commentary>
The user has identified a specific failing test that needs debugging and fixing, which is exactly what the
healer agent is designed for.
</commentary>
</example>
<example>
Context: After running a test suite, several tests are reported as failing.
user: 'Test user-registration.spec.ts is broken after the recent changes'
assistant: 'Let me use the healer agent to investigate and fix the user-registration test.'
<commentary>
A specific test file is failing and needs debugging, which requires the systematic approach of the
playwright-test-healer agent.
</commentary>
</example>
---
name: planner
description: Use this agent when you need to create comprehensive test plan for a web application or website
model: sonnet
color: green
tools:
- ls
- grep
- read
- write
- playwright-test/browser_click
- playwright-test/browser_close
- playwright-test/browser_console_messages
- playwright-test/browser_drag
- playwright-test/browser_evaluate
- playwright-test/browser_file_upload
- playwright-test/browser_handle_dialog
- playwright-test/browser_hover
- playwright-test/browser_navigate
- playwright-test/browser_navigate_back
- playwright-test/browser_network_requests
- playwright-test/browser_press_key
- playwright-test/browser_select_option
- playwright-test/browser_snapshot
- playwright-test/browser_take_screenshot
- playwright-test/browser_type
- playwright-test/browser_wait_for
- playwright-test/planner_setup_page
---
You are an expert web test planner with extensive experience in quality assurance, user experience testing, and test
scenario design. Your expertise includes functional testing, edge case identification, and comprehensive test coverage
planning.
You will:
1. **Navigate and Explore**
- Invoke the `planner_setup_page` tool once to set up page before using any other tools
- Explore the browser snapshot
- Do not take screenshots unless absolutely necessary
- Use browser_* tools to navigate and discover interface
- Thoroughly explore the interface, identifying all interactive elements, forms, navigation paths, and functionality
2. **Analyze User Flows**
- Map out the primary user journeys and identify critical paths through the application
- Consider different user types and their typical behaviors
3. **Design Comprehensive Scenarios**
Create detailed test scenarios that cover:
- Happy path scenarios (normal user behavior)
- Edge cases and boundary conditions
- Error handling and validation
4. **Structure Test Plans**
Each scenario must include:
- Clear, descriptive title
- Detailed step-by-step instructions
- Expected outcomes where appropriate
- Assumptions about starting state (always assume blank/fresh state)
- Success criteria and failure conditions
5. **Create Documentation**
Save your test plan as requested:
- Executive summary of the tested page/application
- Individual scenarios as separate sections
- Each scenario formatted with numbered steps
- Clear expected results for verification
<example-spec>
# TodoMVC Application - Comprehensive Test Plan
## Application Overview
The TodoMVC application is a React-based todo list manager that provides core task management functionality. The
application features:
- **Task Management**: Add, edit, complete, and delete individual todos
- **Bulk Operations**: Mark all todos as complete/incomplete and clear all completed todos
- **Filtering**: View todos by All, Active, or Completed status
- **URL Routing**: Support for direct navigation to filtered views via URLs
- **Counter Display**: Real-time count of active (incomplete) todos
- **Persistence**: State maintained during session (browser refresh behavior not tested)
## Test Scenarios
### 1. Adding New Todos
**Seed:** `tests/seed.spec.ts`
#### 1.1 Add Valid Todo
**Steps:**
1. Click in the "What needs to be done?" input field
2. Type "Buy groceries"
3. Press Enter key
**Expected Results:**
- Todo appears in the list with unchecked checkbox
- Counter shows "1 item left"
- Input field is cleared and ready for next entry
- Todo list controls become visible (Mark all as complete checkbox)
#### 1.2
...
</example-spec>
**Quality Standards**:
- Write steps that are specific enough for any tester to follow
- Include negative testing scenarios
- Ensure scenarios are independent and can be run in any order
**Output Format**: Always save the complete test plan as a markdown file with clear headings, numbered steps, and
professional formatting suitable for sharing with development and QA teams.
<example>
Context: User wants to test a new e-commerce checkout flow.
user: 'I need test scenarios for our new checkout process at https://mystore.com/checkout'
assistant: 'I'll use the planner agent to navigate to your checkout page and create comprehensive test
scenarios.'
<commentary>
The user needs test planning for a specific web page, so use the planner agent to explore and create
test scenarios.
</commentary>
</example>
<example>
Context: User has deployed a new feature and wants thorough testing coverage.
user: 'Can you help me test our new user dashboard at https://app.example.com/dashboard?'
assistant: 'I'll launch the planner agent to explore your dashboard and develop detailed test
scenarios.'
<commentary>
This requires web exploration and test scenario creation, perfect for the planner agent.
</commentary>
</example>
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var config_exports = {};
__export(config_exports, {
FullConfigInternal: () => FullConfigInternal,
FullProjectInternal: () => FullProjectInternal,
builtInReporters: () => builtInReporters,
defaultGrep: () => defaultGrep,
defaultReporter: () => defaultReporter,
defaultTimeout: () => defaultTimeout,
getProjectId: () => getProjectId,
takeFirst: () => takeFirst,
toReporters: () => toReporters
});
module.exports = __toCommonJS(config_exports);
var import_fs = __toESM(require("fs"));
var import_os = __toESM(require("os"));
var import_path = __toESM(require("path"));
var import_util = require("../util");
const defaultTimeout = 3e4;
class FullConfigInternal {
constructor(location, userConfig, configCLIOverrides, metadata) {
this.projects = [];
this.cliArgs = [];
this.cliListOnly = false;
this.preOnlyTestFilters = [];
this.postShardTestFilters = [];
this.defineConfigWasUsed = false;
this.globalSetups = [];
this.globalTeardowns = [];
if (configCLIOverrides.projects && userConfig.projects)
throw new Error(`Cannot use --browser option when configuration file defines projects. Specify browserName in the projects instead.`);
const { resolvedConfigFile, configDir } = location;
const packageJsonPath = (0, import_util.getPackageJsonPath)(configDir);
const packageJsonDir = packageJsonPath ? import_path.default.dirname(packageJsonPath) : process.cwd();
this.configDir = configDir;
this.configCLIOverrides = configCLIOverrides;
const privateConfiguration = userConfig["@playwright/test"];
this.plugins = (privateConfiguration?.plugins || []).map((p) => ({ factory: p }));
this.singleTSConfigPath = pathResolve(configDir, userConfig.tsconfig);
this.captureGitInfo = userConfig.captureGitInfo;
this.failOnFlakyTests = takeFirst(configCLIOverrides.failOnFlakyTests, userConfig.failOnFlakyTests, false);
this.globalSetups = (Array.isArray(userConfig.globalSetup) ? userConfig.globalSetup : [userConfig.globalSetup]).map((s) => resolveScript(s, configDir)).filter((script) => script !== void 0);
this.globalTeardowns = (Array.isArray(userConfig.globalTeardown) ? userConfig.globalTeardown : [userConfig.globalTeardown]).map((s) => resolveScript(s, configDir)).filter((script) => script !== void 0);
userConfig.metadata = userConfig.metadata || {};
this.config = {
configFile: resolvedConfigFile,
rootDir: pathResolve(configDir, userConfig.testDir) || configDir,
forbidOnly: takeFirst(configCLIOverrides.forbidOnly, userConfig.forbidOnly, false),
fullyParallel: takeFirst(configCLIOverrides.fullyParallel, userConfig.fullyParallel, false),
globalSetup: this.globalSetups[0] ?? null,
globalTeardown: this.globalTeardowns[0] ?? null,
globalTimeout: takeFirst(configCLIOverrides.debug ? 0 : void 0, configCLIOverrides.globalTimeout, userConfig.globalTimeout, 0),
grep: takeFirst(userConfig.grep, defaultGrep),
grepInvert: takeFirst(userConfig.grepInvert, null),
maxFailures: takeFirst(configCLIOverrides.debug ? 1 : void 0, configCLIOverrides.maxFailures, userConfig.maxFailures, 0),
metadata: metadata ?? userConfig.metadata,
preserveOutput: takeFirst(userConfig.preserveOutput, "always"),
reporter: takeFirst(configCLIOverrides.reporter, resolveReporters(userConfig.reporter, configDir), [[defaultReporter]]),
reportSlowTests: takeFirst(userConfig.reportSlowTests, {
max: 5,
threshold: 3e5
/* 5 minutes */
}),
quiet: takeFirst(configCLIOverrides.quiet, userConfig.quiet, false),
projects: [],
shard: takeFirst(configCLIOverrides.shard, userConfig.shard, null),
updateSnapshots: takeFirst(configCLIOverrides.updateSnapshots, userConfig.updateSnapshots, "missing"),
updateSourceMethod: takeFirst(configCLIOverrides.updateSourceMethod, userConfig.updateSourceMethod, "patch"),
version: require("../../package.json").version,
workers: resolveWorkers(takeFirst(configCLIOverrides.debug ? 1 : void 0, configCLIOverrides.workers, userConfig.workers, "50%")),
webServer: null
};
for (const key in userConfig) {
if (key.startsWith("@"))
this.config[key] = userConfig[key];
}
this.config[configInternalSymbol] = this;
const webServers = takeFirst(userConfig.webServer, null);
if (Array.isArray(webServers)) {
this.config.webServer = null;
this.webServers = webServers;
} else if (webServers) {
this.config.webServer = webServers;
this.webServers = [webServers];
} else {
this.webServers = [];
}
const projectConfigs = configCLIOverrides.projects || userConfig.projects || [{ ...userConfig, workers: void 0 }];
this.projects = projectConfigs.map((p) => new FullProjectInternal(configDir, userConfig, this, p, this.configCLIOverrides, packageJsonDir));
resolveProjectDependencies(this.projects);
this._assignUniqueProjectIds(this.projects);
this.config.projects = this.projects.map((p) => p.project);
}
_assignUniqueProjectIds(projects) {
const usedNames = /* @__PURE__ */ new Set();
for (const p of projects) {
const name = p.project.name || "";
for (let i = 0; i < projects.length; ++i) {
const candidate = name + (i ? i : "");
if (usedNames.has(candidate))
continue;
p.id = candidate;
p.project.__projectId = p.id;
usedNames.add(candidate);
break;
}
}
}
}
class FullProjectInternal {
constructor(configDir, config, fullConfig, projectConfig, configCLIOverrides, packageJsonDir) {
this.id = "";
this.deps = [];
this.fullConfig = fullConfig;
const testDir = takeFirst(pathResolve(configDir, projectConfig.testDir), pathResolve(configDir, config.testDir), fullConfig.configDir);
this.snapshotPathTemplate = takeFirst(projectConfig.snapshotPathTemplate, config.snapshotPathTemplate);
this.project = {
grep: takeFirst(projectConfig.grep, config.grep, defaultGrep),
grepInvert: takeFirst(projectConfig.grepInvert, config.grepInvert, null),
outputDir: takeFirst(configCLIOverrides.outputDir, pathResolve(configDir, projectConfig.outputDir), pathResolve(configDir, config.outputDir), import_path.default.join(packageJsonDir, "test-results")),
// Note: we either apply the cli override for repeatEach or not, depending on whether the
// project is top-level vs dependency. See collectProjectsAndTestFiles in loadUtils.
repeatEach: takeFirst(projectConfig.repeatEach, config.repeatEach, 1),
retries: takeFirst(configCLIOverrides.retries, projectConfig.retries, config.retries, 0),
metadata: takeFirst(projectConfig.metadata, config.metadata, {}),
name: takeFirst(projectConfig.name, config.name, ""),
testDir,
snapshotDir: takeFirst(pathResolve(configDir, projectConfig.snapshotDir), pathResolve(configDir, config.snapshotDir), testDir),
testIgnore: takeFirst(projectConfig.testIgnore, config.testIgnore, []),
testMatch: takeFirst(projectConfig.testMatch, config.testMatch, "**/*.@(spec|test).?(c|m)[jt]s?(x)"),
timeout: takeFirst(configCLIOverrides.debug ? 0 : void 0, configCLIOverrides.timeout, projectConfig.timeout, config.timeout, defaultTimeout),
use: (0, import_util.mergeObjects)(config.use, projectConfig.use, configCLIOverrides.use),
dependencies: projectConfig.dependencies || [],
teardown: projectConfig.teardown
};
this.fullyParallel = takeFirst(configCLIOverrides.fullyParallel, projectConfig.fullyParallel, config.fullyParallel, void 0);
this.expect = takeFirst(projectConfig.expect, config.expect, {});
if (this.expect.toHaveScreenshot?.stylePath) {
const stylePaths = Array.isArray(this.expect.toHaveScreenshot.stylePath) ? this.expect.toHaveScreenshot.stylePath : [this.expect.toHaveScreenshot.stylePath];
this.expect.toHaveScreenshot.stylePath = stylePaths.map((stylePath) => import_path.default.resolve(configDir, stylePath));
}
this.respectGitIgnore = takeFirst(projectConfig.respectGitIgnore, config.respectGitIgnore, !projectConfig.testDir && !config.testDir);
this.ignoreSnapshots = takeFirst(configCLIOverrides.ignoreSnapshots, projectConfig.ignoreSnapshots, config.ignoreSnapshots, false);
this.workers = projectConfig.workers ? resolveWorkers(projectConfig.workers) : void 0;
if (configCLIOverrides.debug && this.workers)
this.workers = 1;
}
}
function takeFirst(...args) {
for (const arg of args) {
if (arg !== void 0)
return arg;
}
return void 0;
}
function pathResolve(baseDir, relative) {
if (!relative)
return void 0;
return import_path.default.resolve(baseDir, relative);
}
function resolveReporters(reporters, rootDir) {
return toReporters(reporters)?.map(([id, arg]) => {
if (builtInReporters.includes(id))
return [id, arg];
return [require.resolve(id, { paths: [rootDir] }), arg];
});
}
function resolveWorkers(workers) {
if (typeof workers === "string") {
if (workers.endsWith("%")) {
const cpus = import_os.default.cpus().length;
return Math.max(1, Math.floor(cpus * (parseInt(workers, 10) / 100)));
}
const parsedWorkers = parseInt(workers, 10);
if (isNaN(parsedWorkers))
throw new Error(`Workers ${workers} must be a number or percentage.`);
return parsedWorkers;
}
return workers;
}
function resolveProjectDependencies(projects) {
const teardownSet = /* @__PURE__ */ new Set();
for (const project of projects) {
for (const dependencyName of project.project.dependencies) {
const dependencies = projects.filter((p) => p.project.name === dependencyName);
if (!dependencies.length)
throw new Error(`Project '${project.project.name}' depends on unknown project '${dependencyName}'`);
if (dependencies.length > 1)
throw new Error(`Project dependencies should have unique names, reading ${dependencyName}`);
project.deps.push(...dependencies);
}
if (project.project.teardown) {
const teardowns = projects.filter((p) => p.project.name === project.project.teardown);
if (!teardowns.length)
throw new Error(`Project '${project.project.name}' has unknown teardown project '${project.project.teardown}'`);
if (teardowns.length > 1)
throw new Error(`Project teardowns should have unique names, reading ${project.project.teardown}`);
const teardown = teardowns[0];
project.teardown = teardown;
teardownSet.add(teardown);
}
}
for (const teardown of teardownSet) {
if (teardown.deps.length)
throw new Error(`Teardown project ${teardown.project.name} must not have dependencies`);
}
for (const project of projects) {
for (const dep of project.deps) {
if (teardownSet.has(dep))
throw new Error(`Project ${project.project.name} must not depend on a teardown project ${dep.project.name}`);
}
}
}
function toReporters(reporters) {
if (!reporters)
return;
if (typeof reporters === "string")
return [[reporters]];
return reporters;
}
const builtInReporters = ["list", "line", "dot", "json", "junit", "null", "github", "html", "blob"];
function resolveScript(id, rootDir) {
if (!id)
return void 0;
const localPath = import_path.default.resolve(rootDir, id);
if (import_fs.default.existsSync(localPath))
return localPath;
return require.resolve(id, { paths: [rootDir] });
}
const defaultGrep = /.*/;
const defaultReporter = process.env.CI ? "dot" : "list";
const configInternalSymbol = Symbol("configInternalSymbol");
function getProjectId(project) {
return project.__projectId;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
FullConfigInternal,
FullProjectInternal,
builtInReporters,
defaultGrep,
defaultReporter,
defaultTimeout,
getProjectId,
takeFirst,
toReporters
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var configLoader_exports = {};
__export(configLoader_exports, {
defineConfig: () => defineConfig,
deserializeConfig: () => deserializeConfig,
loadConfig: () => loadConfig,
loadConfigFromFile: () => loadConfigFromFile,
loadEmptyConfigForMergeReports: () => loadEmptyConfigForMergeReports,
resolveConfigLocation: () => resolveConfigLocation
});
module.exports = __toCommonJS(configLoader_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_transform = require("../transform/transform");
var import_util = require("../util");
var import_config = require("./config");
var import_esmLoaderHost = require("./esmLoaderHost");
var import_compilationCache = require("../transform/compilationCache");
const kDefineConfigWasUsed = Symbol("defineConfigWasUsed");
const defineConfig = (...configs) => {
let result = configs[0];
for (let i = 1; i < configs.length; ++i) {
const config = configs[i];
const prevProjects = result.projects;
result = {
...result,
...config,
expect: {
...result.expect,
...config.expect
},
use: {
...result.use,
...config.use
},
build: {
...result.build,
...config.build
},
webServer: [
...Array.isArray(result.webServer) ? result.webServer : result.webServer ? [result.webServer] : [],
...Array.isArray(config.webServer) ? config.webServer : config.webServer ? [config.webServer] : []
]
};
if (!result.projects && !config.projects)
continue;
const projectOverrides = /* @__PURE__ */ new Map();
for (const project of config.projects || [])
projectOverrides.set(project.name, project);
const projects = [];
for (const project of prevProjects || []) {
const projectOverride = projectOverrides.get(project.name);
if (projectOverride) {
projects.push({
...project,
...projectOverride,
use: {
...project.use,
...projectOverride.use
}
});
projectOverrides.delete(project.name);
} else {
projects.push(project);
}
}
projects.push(...projectOverrides.values());
result.projects = projects;
}
result[kDefineConfigWasUsed] = true;
return result;
};
async function deserializeConfig(data) {
if (data.compilationCache)
(0, import_compilationCache.addToCompilationCache)(data.compilationCache);
return await loadConfig(data.location, data.configCLIOverrides, void 0, data.metadata ? JSON.parse(data.metadata) : void 0);
}
async function loadUserConfig(location) {
let object = location.resolvedConfigFile ? await (0, import_transform.requireOrImport)(location.resolvedConfigFile) : {};
if (object && typeof object === "object" && "default" in object)
object = object["default"];
return object;
}
async function loadConfig(location, overrides, ignoreProjectDependencies = false, metadata) {
if (!(0, import_esmLoaderHost.registerESMLoader)()) {
if (location.resolvedConfigFile && (0, import_util.fileIsModule)(location.resolvedConfigFile))
throw (0, import_util.errorWithFile)(location.resolvedConfigFile, `Playwright requires Node.js 18.19 or higher to load esm modules. Please update your version of Node.js.`);
}
(0, import_transform.setSingleTSConfig)(overrides?.tsconfig);
await (0, import_esmLoaderHost.configureESMLoader)();
const userConfig = await loadUserConfig(location);
validateConfig(location.resolvedConfigFile || "<default config>", userConfig);
const fullConfig = new import_config.FullConfigInternal(location, userConfig, overrides || {}, metadata);
fullConfig.defineConfigWasUsed = !!userConfig[kDefineConfigWasUsed];
if (ignoreProjectDependencies) {
for (const project of fullConfig.projects) {
project.deps = [];
project.teardown = void 0;
}
}
const babelPlugins = userConfig["@playwright/test"]?.babelPlugins || [];
const external = userConfig.build?.external || [];
(0, import_transform.setTransformConfig)({ babelPlugins, external });
if (!overrides?.tsconfig)
(0, import_transform.setSingleTSConfig)(fullConfig?.singleTSConfigPath);
await (0, import_esmLoaderHost.configureESMLoaderTransformConfig)();
return fullConfig;
}
function validateConfig(file, config) {
if (typeof config !== "object" || !config)
throw (0, import_util.errorWithFile)(file, `Configuration file must export a single object`);
validateProject(file, config, "config");
if ("forbidOnly" in config && config.forbidOnly !== void 0) {
if (typeof config.forbidOnly !== "boolean")
throw (0, import_util.errorWithFile)(file, `config.forbidOnly must be a boolean`);
}
if ("globalSetup" in config && config.globalSetup !== void 0) {
if (Array.isArray(config.globalSetup)) {
config.globalSetup.forEach((item, index) => {
if (typeof item !== "string")
throw (0, import_util.errorWithFile)(file, `config.globalSetup[${index}] must be a string`);
});
} else if (typeof config.globalSetup !== "string") {
throw (0, import_util.errorWithFile)(file, `config.globalSetup must be a string`);
}
}
if ("globalTeardown" in config && config.globalTeardown !== void 0) {
if (Array.isArray(config.globalTeardown)) {
config.globalTeardown.forEach((item, index) => {
if (typeof item !== "string")
throw (0, import_util.errorWithFile)(file, `config.globalTeardown[${index}] must be a string`);
});
} else if (typeof config.globalTeardown !== "string") {
throw (0, import_util.errorWithFile)(file, `config.globalTeardown must be a string`);
}
}
if ("globalTimeout" in config && config.globalTimeout !== void 0) {
if (typeof config.globalTimeout !== "number" || config.globalTimeout < 0)
throw (0, import_util.errorWithFile)(file, `config.globalTimeout must be a non-negative number`);
}
if ("grep" in config && config.grep !== void 0) {
if (Array.isArray(config.grep)) {
config.grep.forEach((item, index) => {
if (!(0, import_utils.isRegExp)(item))
throw (0, import_util.errorWithFile)(file, `config.grep[${index}] must be a RegExp`);
});
} else if (!(0, import_utils.isRegExp)(config.grep)) {
throw (0, import_util.errorWithFile)(file, `config.grep must be a RegExp`);
}
}
if ("grepInvert" in config && config.grepInvert !== void 0) {
if (Array.isArray(config.grepInvert)) {
config.grepInvert.forEach((item, index) => {
if (!(0, import_utils.isRegExp)(item))
throw (0, import_util.errorWithFile)(file, `config.grepInvert[${index}] must be a RegExp`);
});
} else if (!(0, import_utils.isRegExp)(config.grepInvert)) {
throw (0, import_util.errorWithFile)(file, `config.grepInvert must be a RegExp`);
}
}
if ("maxFailures" in config && config.maxFailures !== void 0) {
if (typeof config.maxFailures !== "number" || config.maxFailures < 0)
throw (0, import_util.errorWithFile)(file, `config.maxFailures must be a non-negative number`);
}
if ("preserveOutput" in config && config.preserveOutput !== void 0) {
if (typeof config.preserveOutput !== "string" || !["always", "never", "failures-only"].includes(config.preserveOutput))
throw (0, import_util.errorWithFile)(file, `config.preserveOutput must be one of "always", "never" or "failures-only"`);
}
if ("projects" in config && config.projects !== void 0) {
if (!Array.isArray(config.projects))
throw (0, import_util.errorWithFile)(file, `config.projects must be an array`);
config.projects.forEach((project, index) => {
validateProject(file, project, `config.projects[${index}]`);
});
}
if ("quiet" in config && config.quiet !== void 0) {
if (typeof config.quiet !== "boolean")
throw (0, import_util.errorWithFile)(file, `config.quiet must be a boolean`);
}
if ("reporter" in config && config.reporter !== void 0) {
if (Array.isArray(config.reporter)) {
config.reporter.forEach((item, index) => {
if (!Array.isArray(item) || item.length <= 0 || item.length > 2 || typeof item[0] !== "string")
throw (0, import_util.errorWithFile)(file, `config.reporter[${index}] must be a tuple [name, optionalArgument]`);
});
} else if (typeof config.reporter !== "string") {
throw (0, import_util.errorWithFile)(file, `config.reporter must be a string`);
}
}
if ("reportSlowTests" in config && config.reportSlowTests !== void 0 && config.reportSlowTests !== null) {
if (!config.reportSlowTests || typeof config.reportSlowTests !== "object")
throw (0, import_util.errorWithFile)(file, `config.reportSlowTests must be an object`);
if (!("max" in config.reportSlowTests) || typeof config.reportSlowTests.max !== "number" || config.reportSlowTests.max < 0)
throw (0, import_util.errorWithFile)(file, `config.reportSlowTests.max must be a non-negative number`);
if (!("threshold" in config.reportSlowTests) || typeof config.reportSlowTests.threshold !== "number" || config.reportSlowTests.threshold < 0)
throw (0, import_util.errorWithFile)(file, `config.reportSlowTests.threshold must be a non-negative number`);
}
if ("shard" in config && config.shard !== void 0 && config.shard !== null) {
if (!config.shard || typeof config.shard !== "object")
throw (0, import_util.errorWithFile)(file, `config.shard must be an object`);
if (!("total" in config.shard) || typeof config.shard.total !== "number" || config.shard.total < 1)
throw (0, import_util.errorWithFile)(file, `config.shard.total must be a positive number`);
if (!("current" in config.shard) || typeof config.shard.current !== "number" || config.shard.current < 1 || config.shard.current > config.shard.total)
throw (0, import_util.errorWithFile)(file, `config.shard.current must be a positive number, not greater than config.shard.total`);
}
if ("updateSnapshots" in config && config.updateSnapshots !== void 0) {
if (typeof config.updateSnapshots !== "string" || !["all", "changed", "missing", "none"].includes(config.updateSnapshots))
throw (0, import_util.errorWithFile)(file, `config.updateSnapshots must be one of "all", "changed", "missing" or "none"`);
}
if ("tsconfig" in config && config.tsconfig !== void 0) {
if (typeof config.tsconfig !== "string")
throw (0, import_util.errorWithFile)(file, `config.tsconfig must be a string`);
if (!import_fs.default.existsSync(import_path.default.resolve(file, "..", config.tsconfig)))
throw (0, import_util.errorWithFile)(file, `config.tsconfig does not exist`);
}
}
function validateProject(file, project, title) {
if (typeof project !== "object" || !project)
throw (0, import_util.errorWithFile)(file, `${title} must be an object`);
if ("name" in project && project.name !== void 0) {
if (typeof project.name !== "string")
throw (0, import_util.errorWithFile)(file, `${title}.name must be a string`);
}
if ("outputDir" in project && project.outputDir !== void 0) {
if (typeof project.outputDir !== "string")
throw (0, import_util.errorWithFile)(file, `${title}.outputDir must be a string`);
}
if ("repeatEach" in project && project.repeatEach !== void 0) {
if (typeof project.repeatEach !== "number" || project.repeatEach < 0)
throw (0, import_util.errorWithFile)(file, `${title}.repeatEach must be a non-negative number`);
}
if ("retries" in project && project.retries !== void 0) {
if (typeof project.retries !== "number" || project.retries < 0)
throw (0, import_util.errorWithFile)(file, `${title}.retries must be a non-negative number`);
}
if ("testDir" in project && project.testDir !== void 0) {
if (typeof project.testDir !== "string")
throw (0, import_util.errorWithFile)(file, `${title}.testDir must be a string`);
}
for (const prop of ["testIgnore", "testMatch"]) {
if (prop in project && project[prop] !== void 0) {
const value = project[prop];
if (Array.isArray(value)) {
value.forEach((item, index) => {
if (typeof item !== "string" && !(0, import_utils.isRegExp)(item))
throw (0, import_util.errorWithFile)(file, `${title}.${prop}[${index}] must be a string or a RegExp`);
});
} else if (typeof value !== "string" && !(0, import_utils.isRegExp)(value)) {
throw (0, import_util.errorWithFile)(file, `${title}.${prop} must be a string or a RegExp`);
}
}
}
if ("timeout" in project && project.timeout !== void 0) {
if (typeof project.timeout !== "number" || project.timeout < 0)
throw (0, import_util.errorWithFile)(file, `${title}.timeout must be a non-negative number`);
}
if ("use" in project && project.use !== void 0) {
if (!project.use || typeof project.use !== "object")
throw (0, import_util.errorWithFile)(file, `${title}.use must be an object`);
}
if ("ignoreSnapshots" in project && project.ignoreSnapshots !== void 0) {
if (typeof project.ignoreSnapshots !== "boolean")
throw (0, import_util.errorWithFile)(file, `${title}.ignoreSnapshots must be a boolean`);
}
if ("workers" in project && project.workers !== void 0) {
if (typeof project.workers === "number" && project.workers <= 0)
throw (0, import_util.errorWithFile)(file, `${title}.workers must be a positive number`);
else if (typeof project.workers === "string" && !project.workers.endsWith("%"))
throw (0, import_util.errorWithFile)(file, `${title}.workers must be a number or percentage`);
}
}
function resolveConfigLocation(configFile) {
const configFileOrDirectory = configFile ? import_path.default.resolve(process.cwd(), configFile) : process.cwd();
const resolvedConfigFile = resolveConfigFile(configFileOrDirectory);
return {
resolvedConfigFile,
configDir: resolvedConfigFile ? import_path.default.dirname(resolvedConfigFile) : configFileOrDirectory
};
}
function resolveConfigFile(configFileOrDirectory) {
const resolveConfig = (configFile) => {
if (import_fs.default.existsSync(configFile))
return configFile;
};
const resolveConfigFileFromDirectory = (directory) => {
for (const ext of [".ts", ".js", ".mts", ".mjs", ".cts", ".cjs"]) {
const configFile = resolveConfig(import_path.default.resolve(directory, "playwright.config" + ext));
if (configFile)
return configFile;
}
};
if (!import_fs.default.existsSync(configFileOrDirectory))
throw new Error(`${configFileOrDirectory} does not exist`);
if (import_fs.default.statSync(configFileOrDirectory).isDirectory()) {
const configFile = resolveConfigFileFromDirectory(configFileOrDirectory);
if (configFile)
return configFile;
return void 0;
}
return configFileOrDirectory;
}
async function loadConfigFromFile(configFile, overrides, ignoreDeps) {
return await loadConfig(resolveConfigLocation(configFile), overrides, ignoreDeps);
}
async function loadEmptyConfigForMergeReports() {
return await loadConfig({ configDir: process.cwd() });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
defineConfig,
deserializeConfig,
loadConfig,
loadConfigFromFile,
loadEmptyConfigForMergeReports,
resolveConfigLocation
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var esmLoaderHost_exports = {};
__export(esmLoaderHost_exports, {
configureESMLoader: () => configureESMLoader,
configureESMLoaderTransformConfig: () => configureESMLoaderTransformConfig,
incorporateCompilationCache: () => incorporateCompilationCache,
registerESMLoader: () => registerESMLoader,
startCollectingFileDeps: () => startCollectingFileDeps,
stopCollectingFileDeps: () => stopCollectingFileDeps
});
module.exports = __toCommonJS(esmLoaderHost_exports);
var import_url = __toESM(require("url"));
var import_compilationCache = require("../transform/compilationCache");
var import_portTransport = require("../transform/portTransport");
var import_transform = require("../transform/transform");
let loaderChannel;
function registerESMLoader() {
if (process.env.PW_DISABLE_TS_ESM)
return true;
if (loaderChannel)
return true;
const register = require("node:module").register;
if (!register)
return false;
const { port1, port2 } = new MessageChannel();
register(import_url.default.pathToFileURL(require.resolve("../transform/esmLoader")), {
data: { port: port2 },
transferList: [port2]
});
loaderChannel = createPortTransport(port1);
return true;
}
function createPortTransport(port) {
return new import_portTransport.PortTransport(port, async (method, params) => {
if (method === "pushToCompilationCache")
(0, import_compilationCache.addToCompilationCache)(params.cache);
});
}
async function startCollectingFileDeps() {
if (!loaderChannel)
return;
await loaderChannel.send("startCollectingFileDeps", {});
}
async function stopCollectingFileDeps(file) {
if (!loaderChannel)
return;
await loaderChannel.send("stopCollectingFileDeps", { file });
}
async function incorporateCompilationCache() {
if (!loaderChannel)
return;
const result = await loaderChannel.send("getCompilationCache", {});
(0, import_compilationCache.addToCompilationCache)(result.cache);
}
async function configureESMLoader() {
if (!loaderChannel)
return;
await loaderChannel.send("setSingleTSConfig", { tsconfig: (0, import_transform.singleTSConfig)() });
await loaderChannel.send("addToCompilationCache", { cache: (0, import_compilationCache.serializeCompilationCache)() });
}
async function configureESMLoaderTransformConfig() {
if (!loaderChannel)
return;
await loaderChannel.send("setSingleTSConfig", { tsconfig: (0, import_transform.singleTSConfig)() });
await loaderChannel.send("setTransformConfig", { config: (0, import_transform.transformConfig)() });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
configureESMLoader,
configureESMLoaderTransformConfig,
incorporateCompilationCache,
registerESMLoader,
startCollectingFileDeps,
stopCollectingFileDeps
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var expectBundle_exports = {};
__export(expectBundle_exports, {
DIM_COLOR: () => DIM_COLOR,
EXPECTED_COLOR: () => EXPECTED_COLOR,
INVERTED_COLOR: () => INVERTED_COLOR,
RECEIVED_COLOR: () => RECEIVED_COLOR,
asymmetricMatchers: () => asymmetricMatchers,
expect: () => expect,
matcherUtils: () => matcherUtils,
mock: () => mock,
printReceived: () => printReceived
});
module.exports = __toCommonJS(expectBundle_exports);
const expect = require("./expectBundleImpl").expect;
const mock = require("./expectBundleImpl").mock;
const asymmetricMatchers = require("./expectBundleImpl").asymmetricMatchers;
const matcherUtils = require("./expectBundleImpl").matcherUtils;
const EXPECTED_COLOR = require("./expectBundleImpl").EXPECTED_COLOR;
const INVERTED_COLOR = require("./expectBundleImpl").INVERTED_COLOR;
const RECEIVED_COLOR = require("./expectBundleImpl").RECEIVED_COLOR;
const DIM_COLOR = require("./expectBundleImpl").DIM_COLOR;
const printReceived = require("./expectBundleImpl").printReceived;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
DIM_COLOR,
EXPECTED_COLOR,
INVERTED_COLOR,
RECEIVED_COLOR,
asymmetricMatchers,
expect,
matcherUtils,
mock,
printReceived
});

Sorry, the diff of this file is too big to display

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var fixtures_exports = {};
__export(fixtures_exports, {
FixturePool: () => FixturePool,
fixtureParameterNames: () => fixtureParameterNames,
formatPotentiallyInternalLocation: () => formatPotentiallyInternalLocation,
inheritFixtureNames: () => inheritFixtureNames
});
module.exports = __toCommonJS(fixtures_exports);
var import_crypto = __toESM(require("crypto"));
var import_util = require("../util");
const kScopeOrder = ["test", "worker"];
function isFixtureTuple(value) {
return Array.isArray(value) && typeof value[1] === "object";
}
function isFixtureOption(value) {
return isFixtureTuple(value) && !!value[1].option;
}
class FixturePool {
constructor(fixturesList, onLoadError, parentPool, disallowWorkerFixtures, optionOverrides) {
this._registrations = new Map(parentPool ? parentPool._registrations : []);
this._onLoadError = onLoadError;
const allOverrides = optionOverrides?.overrides ?? {};
const overrideKeys = new Set(Object.keys(allOverrides));
for (const list of fixturesList) {
this._appendFixtureList(list, !!disallowWorkerFixtures, false);
const selectedOverrides = {};
for (const [key, value] of Object.entries(list.fixtures)) {
if (isFixtureOption(value) && overrideKeys.has(key))
selectedOverrides[key] = [allOverrides[key], value[1]];
}
if (Object.entries(selectedOverrides).length)
this._appendFixtureList({ fixtures: selectedOverrides, location: optionOverrides.location }, !!disallowWorkerFixtures, true);
}
this.digest = this.validate();
}
_appendFixtureList(list, disallowWorkerFixtures, isOptionsOverride) {
const { fixtures, location } = list;
for (const entry of Object.entries(fixtures)) {
const name = entry[0];
let value = entry[1];
let options;
if (isFixtureTuple(value)) {
options = {
auto: value[1].auto ?? false,
scope: value[1].scope || "test",
option: !!value[1].option,
timeout: value[1].timeout,
customTitle: value[1].title,
box: value[1].box
};
value = value[0];
}
let fn = value;
const previous = this._registrations.get(name);
if (previous && options) {
if (previous.scope !== options.scope) {
this._addLoadError(`Fixture "${name}" has already been registered as a { scope: '${previous.scope}' } fixture defined in ${(0, import_util.formatLocation)(previous.location)}.`, location);
continue;
}
if (previous.auto !== options.auto) {
this._addLoadError(`Fixture "${name}" has already been registered as a { auto: '${previous.scope}' } fixture defined in ${(0, import_util.formatLocation)(previous.location)}.`, location);
continue;
}
} else if (previous) {
options = { auto: previous.auto, scope: previous.scope, option: previous.option, timeout: previous.timeout, customTitle: previous.customTitle };
} else if (!options) {
options = { auto: false, scope: "test", option: false, timeout: void 0 };
}
if (!kScopeOrder.includes(options.scope)) {
this._addLoadError(`Fixture "${name}" has unknown { scope: '${options.scope}' }.`, location);
continue;
}
if (options.scope === "worker" && disallowWorkerFixtures) {
this._addLoadError(`Cannot use({ ${name} }) in a describe group, because it forces a new worker.
Make it top-level in the test file or put in the configuration file.`, location);
continue;
}
if (fn === void 0 && options.option && previous) {
let original = previous;
while (!original.optionOverride && original.super)
original = original.super;
fn = original.fn;
}
const deps = fixtureParameterNames(fn, location, (e) => this._onLoadError(e));
const registration = { id: "", name, location, scope: options.scope, fn, auto: options.auto, option: options.option, timeout: options.timeout, customTitle: options.customTitle, box: options.box, deps, super: previous, optionOverride: isOptionsOverride };
registrationId(registration);
this._registrations.set(name, registration);
}
}
validate() {
const markers = /* @__PURE__ */ new Map();
const stack = [];
let hasDependencyErrors = false;
const addDependencyError = (message, location) => {
hasDependencyErrors = true;
this._addLoadError(message, location);
};
const visit = (registration, boxedOnly) => {
markers.set(registration, "visiting");
stack.push(registration);
for (const name of registration.deps) {
const dep = this.resolve(name, registration);
if (!dep) {
if (name === registration.name)
addDependencyError(`Fixture "${registration.name}" references itself, but does not have a base implementation.`, registration.location);
else
addDependencyError(`Fixture "${registration.name}" has unknown parameter "${name}".`, registration.location);
continue;
}
if (kScopeOrder.indexOf(registration.scope) > kScopeOrder.indexOf(dep.scope)) {
addDependencyError(`${registration.scope} fixture "${registration.name}" cannot depend on a ${dep.scope} fixture "${name}" defined in ${formatPotentiallyInternalLocation(dep.location)}.`, registration.location);
continue;
}
if (!markers.has(dep)) {
visit(dep, boxedOnly);
} else if (markers.get(dep) === "visiting") {
const index = stack.indexOf(dep);
const allRegs = stack.slice(index, stack.length);
const filteredRegs = allRegs.filter((r) => !r.box);
const regs = boxedOnly ? filteredRegs : allRegs;
const names2 = regs.map((r) => `"${r.name}"`);
addDependencyError(`Fixtures ${names2.join(" -> ")} -> "${dep.name}" form a dependency cycle: ${regs.map((r) => formatPotentiallyInternalLocation(r.location)).join(" -> ")} -> ${formatPotentiallyInternalLocation(dep.location)}`, dep.location);
continue;
}
}
markers.set(registration, "visited");
stack.pop();
};
const names = Array.from(this._registrations.keys()).sort();
for (const name of names) {
const registration = this._registrations.get(name);
if (!registration.box)
visit(registration, true);
}
if (!hasDependencyErrors) {
for (const name of names) {
const registration = this._registrations.get(name);
if (registration.box)
visit(registration, false);
}
}
const hash = import_crypto.default.createHash("sha1");
for (const name of names) {
const registration = this._registrations.get(name);
if (registration.scope === "worker")
hash.update(registration.id + ";");
}
return hash.digest("hex");
}
validateFunction(fn, prefix, location) {
for (const name of fixtureParameterNames(fn, location, (e) => this._onLoadError(e))) {
const registration = this._registrations.get(name);
if (!registration)
this._addLoadError(`${prefix} has unknown parameter "${name}".`, location);
}
}
resolve(name, forFixture) {
if (name === forFixture?.name)
return forFixture.super;
return this._registrations.get(name);
}
autoFixtures() {
return [...this._registrations.values()].filter((r) => r.auto !== false);
}
_addLoadError(message, location) {
this._onLoadError({ message, location });
}
}
const signatureSymbol = Symbol("signature");
function formatPotentiallyInternalLocation(location) {
const isUserFixture = location && (0, import_util.filterStackFile)(location.file);
return isUserFixture ? (0, import_util.formatLocation)(location) : "<builtin>";
}
function fixtureParameterNames(fn, location, onError) {
if (typeof fn !== "function")
return [];
if (!fn[signatureSymbol])
fn[signatureSymbol] = innerFixtureParameterNames(fn, location, onError);
return fn[signatureSymbol];
}
function inheritFixtureNames(from, to) {
to[signatureSymbol] = from[signatureSymbol];
}
function innerFixtureParameterNames(fn, location, onError) {
const text = filterOutComments(fn.toString());
const match = text.match(/(?:async)?(?:\s+function)?[^(]*\(([^)]*)/);
if (!match)
return [];
const trimmedParams = match[1].trim();
if (!trimmedParams)
return [];
const [firstParam] = splitByComma(trimmedParams);
if (firstParam[0] !== "{" || firstParam[firstParam.length - 1] !== "}") {
onError({ message: "First argument must use the object destructuring pattern: " + firstParam, location });
return [];
}
const props = splitByComma(firstParam.substring(1, firstParam.length - 1)).map((prop) => {
const colon = prop.indexOf(":");
return colon === -1 ? prop.trim() : prop.substring(0, colon).trim();
});
const restProperty = props.find((prop) => prop.startsWith("..."));
if (restProperty) {
onError({ message: `Rest property "${restProperty}" is not supported. List all used fixtures explicitly, separated by comma.`, location });
return [];
}
return props;
}
function filterOutComments(s) {
const result = [];
let commentState = "none";
for (let i = 0; i < s.length; ++i) {
if (commentState === "singleline") {
if (s[i] === "\n")
commentState = "none";
} else if (commentState === "multiline") {
if (s[i - 1] === "*" && s[i] === "/")
commentState = "none";
} else if (commentState === "none") {
if (s[i] === "/" && s[i + 1] === "/") {
commentState = "singleline";
} else if (s[i] === "/" && s[i + 1] === "*") {
commentState = "multiline";
i += 2;
} else {
result.push(s[i]);
}
}
}
return result.join("");
}
function splitByComma(s) {
const result = [];
const stack = [];
let start = 0;
for (let i = 0; i < s.length; i++) {
if (s[i] === "{" || s[i] === "[") {
stack.push(s[i] === "{" ? "}" : "]");
} else if (s[i] === stack[stack.length - 1]) {
stack.pop();
} else if (!stack.length && s[i] === ",") {
const token = s.substring(start, i).trim();
if (token)
result.push(token);
start = i + 1;
}
}
const lastToken = s.substring(start).trim();
if (lastToken)
result.push(lastToken);
return result;
}
const registrationIdMap = /* @__PURE__ */ new Map();
let lastId = 0;
function registrationId(registration) {
if (registration.id)
return registration.id;
const key = registration.name + "@@@" + (registration.super ? registrationId(registration.super) : "");
let map = registrationIdMap.get(key);
if (!map) {
map = /* @__PURE__ */ new Map();
registrationIdMap.set(key, map);
}
if (!map.has(registration.fn))
map.set(registration.fn, String(lastId++));
registration.id = map.get(registration.fn);
return registration.id;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
FixturePool,
fixtureParameterNames,
formatPotentiallyInternalLocation,
inheritFixtureNames
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var globals_exports = {};
__export(globals_exports, {
currentTestInfo: () => currentTestInfo,
currentlyLoadingFileSuite: () => currentlyLoadingFileSuite,
isWorkerProcess: () => isWorkerProcess,
setCurrentTestInfo: () => setCurrentTestInfo,
setCurrentlyLoadingFileSuite: () => setCurrentlyLoadingFileSuite,
setIsWorkerProcess: () => setIsWorkerProcess
});
module.exports = __toCommonJS(globals_exports);
let currentTestInfoValue = null;
function setCurrentTestInfo(testInfo) {
currentTestInfoValue = testInfo;
}
function currentTestInfo() {
return currentTestInfoValue;
}
let currentFileSuite;
function setCurrentlyLoadingFileSuite(suite) {
currentFileSuite = suite;
}
function currentlyLoadingFileSuite() {
return currentFileSuite;
}
let _isWorkerProcess = false;
function setIsWorkerProcess() {
_isWorkerProcess = true;
}
function isWorkerProcess() {
return _isWorkerProcess;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
currentTestInfo,
currentlyLoadingFileSuite,
isWorkerProcess,
setCurrentTestInfo,
setCurrentlyLoadingFileSuite,
setIsWorkerProcess
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ipc_exports = {};
__export(ipc_exports, {
serializeConfig: () => serializeConfig,
stdioChunkToParams: () => stdioChunkToParams
});
module.exports = __toCommonJS(ipc_exports);
var import_util = __toESM(require("util"));
var import_compilationCache = require("../transform/compilationCache");
function serializeConfig(config, passCompilationCache) {
const result = {
location: { configDir: config.configDir, resolvedConfigFile: config.config.configFile },
configCLIOverrides: config.configCLIOverrides,
compilationCache: passCompilationCache ? (0, import_compilationCache.serializeCompilationCache)() : void 0
};
try {
result.metadata = JSON.stringify(config.config.metadata);
} catch (error) {
}
return result;
}
function stdioChunkToParams(chunk) {
if (chunk instanceof Uint8Array)
return { buffer: Buffer.from(chunk).toString("base64") };
if (typeof chunk !== "string")
return { text: import_util.default.inspect(chunk) };
return { text: chunk };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
serializeConfig,
stdioChunkToParams
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var poolBuilder_exports = {};
__export(poolBuilder_exports, {
PoolBuilder: () => PoolBuilder
});
module.exports = __toCommonJS(poolBuilder_exports);
var import_fixtures = require("./fixtures");
var import_util = require("../util");
class PoolBuilder {
constructor(type, project) {
this._testTypePools = /* @__PURE__ */ new Map();
this._type = type;
this._project = project;
}
static createForLoader() {
return new PoolBuilder("loader");
}
static createForWorker(project) {
return new PoolBuilder("worker", project);
}
buildPools(suite, testErrors) {
suite.forEachTest((test) => {
const pool = this._buildPoolForTest(test, testErrors);
if (this._type === "loader")
test._poolDigest = pool.digest;
if (this._type === "worker")
test._pool = pool;
});
}
_buildPoolForTest(test, testErrors) {
let pool = this._buildTestTypePool(test._testType, testErrors);
const parents = [];
for (let parent = test.parent; parent; parent = parent.parent)
parents.push(parent);
parents.reverse();
for (const parent of parents) {
if (parent._use.length)
pool = new import_fixtures.FixturePool(parent._use, (e) => this._handleLoadError(e, testErrors), pool, parent._type === "describe");
for (const hook of parent._hooks)
pool.validateFunction(hook.fn, hook.type + " hook", hook.location);
for (const modifier of parent._modifiers)
pool.validateFunction(modifier.fn, modifier.type + " modifier", modifier.location);
}
pool.validateFunction(test.fn, "Test", test.location);
return pool;
}
_buildTestTypePool(testType, testErrors) {
if (!this._testTypePools.has(testType)) {
const optionOverrides = {
overrides: this._project?.project?.use ?? {},
location: { file: `project#${this._project?.id}`, line: 1, column: 1 }
};
const pool = new import_fixtures.FixturePool(testType.fixtures, (e) => this._handleLoadError(e, testErrors), void 0, void 0, optionOverrides);
this._testTypePools.set(testType, pool);
}
return this._testTypePools.get(testType);
}
_handleLoadError(e, testErrors) {
if (testErrors)
testErrors.push(e);
else
throw new Error(`${(0, import_util.formatLocation)(e.location)}: ${e.message}`);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PoolBuilder
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var process_exports = {};
__export(process_exports, {
ProcessRunner: () => ProcessRunner
});
module.exports = __toCommonJS(process_exports);
var import_utils = require("playwright-core/lib/utils");
var import_util = require("../util");
class ProcessRunner {
async gracefullyClose() {
}
dispatchEvent(method, params) {
const response = { method, params };
sendMessageToParent({ method: "__dispatch__", params: response });
}
}
let gracefullyCloseCalled = false;
let forceExitInitiated = false;
sendMessageToParent({ method: "ready" });
process.on("disconnect", () => gracefullyCloseAndExit(true));
process.on("SIGINT", () => {
});
process.on("SIGTERM", () => {
});
let processRunner;
let processName;
const startingEnv = { ...process.env };
process.on("message", async (message) => {
if (message.method === "__init__") {
const { processParams, runnerParams, runnerScript } = message.params;
void (0, import_utils.startProfiling)();
(0, import_utils.setTimeOrigin)(processParams.timeOrigin);
const { create } = require(runnerScript);
processRunner = create(runnerParams);
processName = processParams.processName;
return;
}
if (message.method === "__stop__") {
const keys = /* @__PURE__ */ new Set([...Object.keys(process.env), ...Object.keys(startingEnv)]);
const producedEnv = [...keys].filter((key) => startingEnv[key] !== process.env[key]).map((key) => [key, process.env[key] ?? null]);
sendMessageToParent({ method: "__env_produced__", params: producedEnv });
await gracefullyCloseAndExit(false);
return;
}
if (message.method === "__dispatch__") {
const { id, method, params } = message.params;
try {
const result = await processRunner[method](params);
const response = { id, result };
sendMessageToParent({ method: "__dispatch__", params: response });
} catch (e) {
const response = { id, error: (0, import_util.serializeError)(e) };
sendMessageToParent({ method: "__dispatch__", params: response });
}
}
});
const kForceExitTimeout = +(process.env.PWTEST_FORCE_EXIT_TIMEOUT || 3e4);
async function gracefullyCloseAndExit(forceExit) {
if (forceExit && !forceExitInitiated) {
forceExitInitiated = true;
setTimeout(() => process.exit(0), kForceExitTimeout);
}
if (!gracefullyCloseCalled) {
gracefullyCloseCalled = true;
await processRunner?.gracefullyClose().catch(() => {
});
if (processName)
await (0, import_utils.stopProfiling)(processName).catch(() => {
});
process.exit(0);
}
}
function sendMessageToParent(message) {
try {
process.send(message);
} catch (e) {
try {
JSON.stringify(message);
} catch {
throw e;
}
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ProcessRunner
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var suiteUtils_exports = {};
__export(suiteUtils_exports, {
applyRepeatEachIndex: () => applyRepeatEachIndex,
bindFileSuiteToProject: () => bindFileSuiteToProject,
filterByFocusedLine: () => filterByFocusedLine,
filterOnly: () => filterOnly,
filterSuite: () => filterSuite,
filterTestsRemoveEmptySuites: () => filterTestsRemoveEmptySuites
});
module.exports = __toCommonJS(suiteUtils_exports);
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_util = require("../util");
function filterSuite(suite, suiteFilter, testFilter) {
for (const child of suite.suites) {
if (!suiteFilter(child))
filterSuite(child, suiteFilter, testFilter);
}
const filteredTests = suite.tests.filter(testFilter);
const entries = /* @__PURE__ */ new Set([...suite.suites, ...filteredTests]);
suite._entries = suite._entries.filter((e) => entries.has(e));
}
function filterTestsRemoveEmptySuites(suite, filter) {
const filteredSuites = suite.suites.filter((child) => filterTestsRemoveEmptySuites(child, filter));
const filteredTests = suite.tests.filter(filter);
const entries = /* @__PURE__ */ new Set([...filteredSuites, ...filteredTests]);
suite._entries = suite._entries.filter((e) => entries.has(e));
return !!suite._entries.length;
}
function bindFileSuiteToProject(project, suite) {
const relativeFile = import_path.default.relative(project.project.testDir, suite.location.file);
const fileId = (0, import_utils.calculateSha1)((0, import_utils.toPosixPath)(relativeFile)).slice(0, 20);
const result = suite._deepClone();
result._fileId = fileId;
result.forEachTest((test, suite2) => {
suite2._fileId = fileId;
const [file, ...titles] = test.titlePath();
const testIdExpression = `[project=${project.id}]${(0, import_utils.toPosixPath)(file)}${titles.join("")}`;
const testId = fileId + "-" + (0, import_utils.calculateSha1)(testIdExpression).slice(0, 20);
test.id = testId;
test._projectId = project.id;
let inheritedRetries;
let inheritedTimeout;
for (let parentSuite = suite2; parentSuite; parentSuite = parentSuite.parent) {
if (parentSuite._staticAnnotations.length)
test.annotations.unshift(...parentSuite._staticAnnotations);
if (inheritedRetries === void 0 && parentSuite._retries !== void 0)
inheritedRetries = parentSuite._retries;
if (inheritedTimeout === void 0 && parentSuite._timeout !== void 0)
inheritedTimeout = parentSuite._timeout;
}
test.retries = inheritedRetries ?? project.project.retries;
test.timeout = inheritedTimeout ?? project.project.timeout;
if (test.annotations.some((a) => a.type === "skip" || a.type === "fixme"))
test.expectedStatus = "skipped";
if (test._poolDigest)
test._workerHash = `${project.id}-${test._poolDigest}-0`;
});
return result;
}
function applyRepeatEachIndex(project, fileSuite, repeatEachIndex) {
fileSuite.forEachTest((test, suite) => {
if (repeatEachIndex) {
const [file, ...titles] = test.titlePath();
const testIdExpression = `[project=${project.id}]${(0, import_utils.toPosixPath)(file)}${titles.join("")} (repeat:${repeatEachIndex})`;
const testId = suite._fileId + "-" + (0, import_utils.calculateSha1)(testIdExpression).slice(0, 20);
test.id = testId;
test.repeatEachIndex = repeatEachIndex;
if (test._poolDigest)
test._workerHash = `${project.id}-${test._poolDigest}-${repeatEachIndex}`;
}
});
}
function filterOnly(suite) {
if (!suite._getOnlyItems().length)
return;
const suiteFilter = (suite2) => suite2._only;
const testFilter = (test) => test._only;
return filterSuiteWithOnlySemantics(suite, suiteFilter, testFilter);
}
function filterSuiteWithOnlySemantics(suite, suiteFilter, testFilter) {
const onlySuites = suite.suites.filter((child) => filterSuiteWithOnlySemantics(child, suiteFilter, testFilter) || suiteFilter(child));
const onlyTests = suite.tests.filter(testFilter);
const onlyEntries = /* @__PURE__ */ new Set([...onlySuites, ...onlyTests]);
if (onlyEntries.size) {
suite._entries = suite._entries.filter((e) => onlyEntries.has(e));
return true;
}
return false;
}
function filterByFocusedLine(suite, focusedTestFileLines) {
if (!focusedTestFileLines.length)
return;
const matchers = focusedTestFileLines.map(createFileMatcherFromFilter);
const testFileLineMatches = (testFileName, testLine, testColumn) => matchers.some((m) => m(testFileName, testLine, testColumn));
const suiteFilter = (suite2) => !!suite2.location && testFileLineMatches(suite2.location.file, suite2.location.line, suite2.location.column);
const testFilter = (test) => testFileLineMatches(test.location.file, test.location.line, test.location.column);
return filterSuite(suite, suiteFilter, testFilter);
}
function createFileMatcherFromFilter(filter) {
const fileMatcher = (0, import_util.createFileMatcher)(filter.re || filter.exact || "");
return (testFileName, testLine, testColumn) => fileMatcher(testFileName) && (filter.line === testLine || filter.line === null) && (filter.column === testColumn || filter.column === null);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
applyRepeatEachIndex,
bindFileSuiteToProject,
filterByFocusedLine,
filterOnly,
filterSuite,
filterTestsRemoveEmptySuites
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var test_exports = {};
__export(test_exports, {
Suite: () => Suite,
TestCase: () => TestCase
});
module.exports = __toCommonJS(test_exports);
var import_testType = require("./testType");
var import_teleReceiver = require("../isomorphic/teleReceiver");
class Base {
constructor(title) {
this._only = false;
this._requireFile = "";
this.title = title;
}
}
class Suite extends Base {
constructor(title, type) {
super(title);
this._use = [];
this._entries = [];
this._hooks = [];
// Annotations known statically before running the test, e.g. `test.describe.skip()` or `test.describe({ annotation }, body)`.
this._staticAnnotations = [];
// Explicitly declared tags that are not a part of the title.
this._tags = [];
this._modifiers = [];
this._parallelMode = "none";
this._type = type;
}
get type() {
return this._type;
}
entries() {
return this._entries;
}
get suites() {
return this._entries.filter((entry) => entry instanceof Suite);
}
get tests() {
return this._entries.filter((entry) => entry instanceof TestCase);
}
_addTest(test) {
test.parent = this;
this._entries.push(test);
}
_addSuite(suite) {
suite.parent = this;
this._entries.push(suite);
}
_prependSuite(suite) {
suite.parent = this;
this._entries.unshift(suite);
}
allTests() {
const result = [];
const visit = (suite) => {
for (const entry of suite._entries) {
if (entry instanceof Suite)
visit(entry);
else
result.push(entry);
}
};
visit(this);
return result;
}
_hasTests() {
let result = false;
const visit = (suite) => {
for (const entry of suite._entries) {
if (result)
return;
if (entry instanceof Suite)
visit(entry);
else
result = true;
}
};
visit(this);
return result;
}
titlePath() {
const titlePath = this.parent ? this.parent.titlePath() : [];
if (this.title || this._type !== "describe")
titlePath.push(this.title);
return titlePath;
}
_collectGrepTitlePath(path) {
if (this.parent)
this.parent._collectGrepTitlePath(path);
if (this.title || this._type !== "describe")
path.push(this.title);
path.push(...this._tags);
}
_getOnlyItems() {
const items = [];
if (this._only)
items.push(this);
for (const suite of this.suites)
items.push(...suite._getOnlyItems());
items.push(...this.tests.filter((test) => test._only));
return items;
}
_deepClone() {
const suite = this._clone();
for (const entry of this._entries) {
if (entry instanceof Suite)
suite._addSuite(entry._deepClone());
else
suite._addTest(entry._clone());
}
return suite;
}
_deepSerialize() {
const suite = this._serialize();
suite.entries = [];
for (const entry of this._entries) {
if (entry instanceof Suite)
suite.entries.push(entry._deepSerialize());
else
suite.entries.push(entry._serialize());
}
return suite;
}
static _deepParse(data) {
const suite = Suite._parse(data);
for (const entry of data.entries) {
if (entry.kind === "suite")
suite._addSuite(Suite._deepParse(entry));
else
suite._addTest(TestCase._parse(entry));
}
return suite;
}
forEachTest(visitor) {
for (const entry of this._entries) {
if (entry instanceof Suite)
entry.forEachTest(visitor);
else
visitor(entry, this);
}
}
_serialize() {
return {
kind: "suite",
title: this.title,
type: this._type,
location: this.location,
only: this._only,
requireFile: this._requireFile,
timeout: this._timeout,
retries: this._retries,
staticAnnotations: this._staticAnnotations.slice(),
tags: this._tags.slice(),
modifiers: this._modifiers.slice(),
parallelMode: this._parallelMode,
hooks: this._hooks.map((h) => ({ type: h.type, location: h.location, title: h.title })),
fileId: this._fileId
};
}
static _parse(data) {
const suite = new Suite(data.title, data.type);
suite.location = data.location;
suite._only = data.only;
suite._requireFile = data.requireFile;
suite._timeout = data.timeout;
suite._retries = data.retries;
suite._staticAnnotations = data.staticAnnotations;
suite._tags = data.tags;
suite._modifiers = data.modifiers;
suite._parallelMode = data.parallelMode;
suite._hooks = data.hooks.map((h) => ({ type: h.type, location: h.location, title: h.title, fn: () => {
} }));
suite._fileId = data.fileId;
return suite;
}
_clone() {
const data = this._serialize();
const suite = Suite._parse(data);
suite._use = this._use.slice();
suite._hooks = this._hooks.slice();
suite._fullProject = this._fullProject;
return suite;
}
project() {
return this._fullProject?.project || this.parent?.project();
}
}
class TestCase extends Base {
constructor(title, fn, testType, location) {
super(title);
this.results = [];
this.type = "test";
this.expectedStatus = "passed";
this.timeout = 0;
this.annotations = [];
this.retries = 0;
this.repeatEachIndex = 0;
this.id = "";
this._poolDigest = "";
this._workerHash = "";
this._projectId = "";
// Explicitly declared tags that are not a part of the title.
this._tags = [];
this.fn = fn;
this._testType = testType;
this.location = location;
}
titlePath() {
const titlePath = this.parent ? this.parent.titlePath() : [];
titlePath.push(this.title);
return titlePath;
}
outcome() {
return (0, import_teleReceiver.computeTestCaseOutcome)(this);
}
ok() {
const status = this.outcome();
return status === "expected" || status === "flaky" || status === "skipped";
}
get tags() {
const titleTags = this._grepBaseTitlePath().join(" ").match(/@[\S]+/g) || [];
return [
...titleTags,
...this._tags
];
}
_serialize() {
return {
kind: "test",
id: this.id,
title: this.title,
retries: this.retries,
timeout: this.timeout,
expectedStatus: this.expectedStatus,
location: this.location,
only: this._only,
requireFile: this._requireFile,
poolDigest: this._poolDigest,
workerHash: this._workerHash,
annotations: this.annotations.slice(),
tags: this._tags.slice(),
projectId: this._projectId
};
}
static _parse(data) {
const test = new TestCase(data.title, () => {
}, import_testType.rootTestType, data.location);
test.id = data.id;
test.retries = data.retries;
test.timeout = data.timeout;
test.expectedStatus = data.expectedStatus;
test._only = data.only;
test._requireFile = data.requireFile;
test._poolDigest = data.poolDigest;
test._workerHash = data.workerHash;
test.annotations = data.annotations;
test._tags = data.tags;
test._projectId = data.projectId;
return test;
}
_clone() {
const data = this._serialize();
const test = TestCase._parse(data);
test._testType = this._testType;
test.fn = this.fn;
return test;
}
_appendTestResult() {
const result = {
retry: this.results.length,
parallelIndex: -1,
workerIndex: -1,
duration: 0,
startTime: /* @__PURE__ */ new Date(),
stdout: [],
stderr: [],
attachments: [],
status: "skipped",
steps: [],
errors: [],
annotations: []
};
this.results.push(result);
return result;
}
_grepBaseTitlePath() {
const path = [];
this.parent._collectGrepTitlePath(path);
path.push(this.title);
return path;
}
_grepTitleWithTags() {
const path = this._grepBaseTitlePath();
path.push(...this._tags);
return path.join(" ");
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Suite,
TestCase
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testLoader_exports = {};
__export(testLoader_exports, {
defaultTimeout: () => defaultTimeout,
loadTestFile: () => loadTestFile
});
module.exports = __toCommonJS(testLoader_exports);
var import_path = __toESM(require("path"));
var import_util = __toESM(require("util"));
var esmLoaderHost = __toESM(require("./esmLoaderHost"));
var import_globals = require("./globals");
var import_test = require("./test");
var import_compilationCache = require("../transform/compilationCache");
var import_transform = require("../transform/transform");
var import_util2 = require("../util");
const defaultTimeout = 3e4;
const cachedFileSuites = /* @__PURE__ */ new Map();
async function loadTestFile(file, rootDir, testErrors) {
if (cachedFileSuites.has(file))
return cachedFileSuites.get(file);
const suite = new import_test.Suite(import_path.default.relative(rootDir, file) || import_path.default.basename(file), "file");
suite._requireFile = file;
suite.location = { file, line: 0, column: 0 };
(0, import_globals.setCurrentlyLoadingFileSuite)(suite);
if (!(0, import_globals.isWorkerProcess)()) {
(0, import_compilationCache.startCollectingFileDeps)();
await esmLoaderHost.startCollectingFileDeps();
}
try {
await (0, import_transform.requireOrImport)(file);
cachedFileSuites.set(file, suite);
} catch (e) {
if (!testErrors)
throw e;
testErrors.push(serializeLoadError(file, e));
} finally {
(0, import_globals.setCurrentlyLoadingFileSuite)(void 0);
if (!(0, import_globals.isWorkerProcess)()) {
(0, import_compilationCache.stopCollectingFileDeps)(file);
await esmLoaderHost.stopCollectingFileDeps(file);
}
}
{
const files = /* @__PURE__ */ new Set();
suite.allTests().map((t) => files.add(t.location.file));
if (files.size === 1) {
const mappedFile = files.values().next().value;
if (suite.location.file !== mappedFile) {
if (import_path.default.extname(mappedFile) !== import_path.default.extname(suite.location.file))
suite.location.file = mappedFile;
}
}
}
return suite;
}
function serializeLoadError(file, error) {
if (error instanceof Error) {
const result = (0, import_util2.filterStackTrace)(error);
const loc = error.loc;
result.location = loc ? {
file,
line: loc.line || 0,
column: loc.column || 0
} : void 0;
return result;
}
return { value: import_util.default.inspect(error) };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
defaultTimeout,
loadTestFile
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testType_exports = {};
__export(testType_exports, {
TestTypeImpl: () => TestTypeImpl,
mergeTests: () => mergeTests,
rootTestType: () => rootTestType
});
module.exports = __toCommonJS(testType_exports);
var import_playwright_core = require("playwright-core");
var import_utils = require("playwright-core/lib/utils");
var import_globals = require("./globals");
var import_test = require("./test");
var import_expect = require("../matchers/expect");
var import_transform = require("../transform/transform");
const testTypeSymbol = Symbol("testType");
class TestTypeImpl {
constructor(fixtures) {
this.fixtures = fixtures;
const test = (0, import_transform.wrapFunctionWithLocation)(this._createTest.bind(this, "default"));
test[testTypeSymbol] = this;
test.expect = import_expect.expect;
test.only = (0, import_transform.wrapFunctionWithLocation)(this._createTest.bind(this, "only"));
test.describe = (0, import_transform.wrapFunctionWithLocation)(this._describe.bind(this, "default"));
test.describe.only = (0, import_transform.wrapFunctionWithLocation)(this._describe.bind(this, "only"));
test.describe.configure = (0, import_transform.wrapFunctionWithLocation)(this._configure.bind(this));
test.describe.fixme = (0, import_transform.wrapFunctionWithLocation)(this._describe.bind(this, "fixme"));
test.describe.parallel = (0, import_transform.wrapFunctionWithLocation)(this._describe.bind(this, "parallel"));
test.describe.parallel.only = (0, import_transform.wrapFunctionWithLocation)(this._describe.bind(this, "parallel.only"));
test.describe.serial = (0, import_transform.wrapFunctionWithLocation)(this._describe.bind(this, "serial"));
test.describe.serial.only = (0, import_transform.wrapFunctionWithLocation)(this._describe.bind(this, "serial.only"));
test.describe.skip = (0, import_transform.wrapFunctionWithLocation)(this._describe.bind(this, "skip"));
test.beforeEach = (0, import_transform.wrapFunctionWithLocation)(this._hook.bind(this, "beforeEach"));
test.afterEach = (0, import_transform.wrapFunctionWithLocation)(this._hook.bind(this, "afterEach"));
test.beforeAll = (0, import_transform.wrapFunctionWithLocation)(this._hook.bind(this, "beforeAll"));
test.afterAll = (0, import_transform.wrapFunctionWithLocation)(this._hook.bind(this, "afterAll"));
test.skip = (0, import_transform.wrapFunctionWithLocation)(this._modifier.bind(this, "skip"));
test.fixme = (0, import_transform.wrapFunctionWithLocation)(this._modifier.bind(this, "fixme"));
test.fail = (0, import_transform.wrapFunctionWithLocation)(this._modifier.bind(this, "fail"));
test.fail.only = (0, import_transform.wrapFunctionWithLocation)(this._createTest.bind(this, "fail.only"));
test.slow = (0, import_transform.wrapFunctionWithLocation)(this._modifier.bind(this, "slow"));
test.setTimeout = (0, import_transform.wrapFunctionWithLocation)(this._setTimeout.bind(this));
test.step = this._step.bind(this, "pass");
test.step.skip = this._step.bind(this, "skip");
test.use = (0, import_transform.wrapFunctionWithLocation)(this._use.bind(this));
test.extend = (0, import_transform.wrapFunctionWithLocation)(this._extend.bind(this));
test.info = () => {
const result = (0, import_globals.currentTestInfo)();
if (!result)
throw new Error("test.info() can only be called while test is running");
return result;
};
this.test = test;
}
_currentSuite(location, title) {
const suite = (0, import_globals.currentlyLoadingFileSuite)();
if (!suite) {
throw new Error([
`Playwright Test did not expect ${title} to be called here.`,
`Most common reasons include:`,
`- You are calling ${title} in a configuration file.`,
`- You are calling ${title} in a file that is imported by the configuration file.`,
`- You have two different versions of @playwright/test. This usually happens`,
` when one of the dependencies in your package.json depends on @playwright/test.`
].join("\n"));
}
return suite;
}
_createTest(type, location, title, fnOrDetails, fn) {
throwIfRunningInsideJest();
const suite = this._currentSuite(location, "test()");
if (!suite)
return;
let details;
let body;
if (typeof fnOrDetails === "function") {
body = fnOrDetails;
details = {};
} else {
body = fn;
details = fnOrDetails;
}
const validatedDetails = validateTestDetails(details, location);
const test = new import_test.TestCase(title, body, this, location);
test._requireFile = suite._requireFile;
test.annotations.push(...validatedDetails.annotations);
test._tags.push(...validatedDetails.tags);
suite._addTest(test);
if (type === "only" || type === "fail.only")
test._only = true;
if (type === "skip" || type === "fixme" || type === "fail")
test.annotations.push({ type, location });
else if (type === "fail.only")
test.annotations.push({ type: "fail", location });
}
_describe(type, location, titleOrFn, fnOrDetails, fn) {
throwIfRunningInsideJest();
const suite = this._currentSuite(location, "test.describe()");
if (!suite)
return;
let title;
let body;
let details;
if (typeof titleOrFn === "function") {
title = "";
details = {};
body = titleOrFn;
} else if (typeof fnOrDetails === "function") {
title = titleOrFn;
details = {};
body = fnOrDetails;
} else {
title = titleOrFn;
details = fnOrDetails;
body = fn;
}
const validatedDetails = validateTestDetails(details, location);
const child = new import_test.Suite(title, "describe");
child._requireFile = suite._requireFile;
child.location = location;
child._staticAnnotations.push(...validatedDetails.annotations);
child._tags.push(...validatedDetails.tags);
suite._addSuite(child);
if (type === "only" || type === "serial.only" || type === "parallel.only")
child._only = true;
if (type === "serial" || type === "serial.only")
child._parallelMode = "serial";
if (type === "parallel" || type === "parallel.only")
child._parallelMode = "parallel";
if (type === "skip" || type === "fixme")
child._staticAnnotations.push({ type, location });
for (let parent = suite; parent; parent = parent.parent) {
if (parent._parallelMode === "serial" && child._parallelMode === "parallel")
throw new Error("describe.parallel cannot be nested inside describe.serial");
if (parent._parallelMode === "default" && child._parallelMode === "parallel")
throw new Error("describe.parallel cannot be nested inside describe with default mode");
}
(0, import_globals.setCurrentlyLoadingFileSuite)(child);
body();
(0, import_globals.setCurrentlyLoadingFileSuite)(suite);
}
_hook(name, location, title, fn) {
const suite = this._currentSuite(location, `test.${name}()`);
if (!suite)
return;
if (typeof title === "function") {
fn = title;
title = `${name} hook`;
}
suite._hooks.push({ type: name, fn, title, location });
}
_configure(location, options) {
throwIfRunningInsideJest();
const suite = this._currentSuite(location, `test.describe.configure()`);
if (!suite)
return;
if (options.timeout !== void 0)
suite._timeout = options.timeout;
if (options.retries !== void 0)
suite._retries = options.retries;
if (options.mode !== void 0) {
if (suite._parallelMode !== "none")
throw new Error(`"${suite._parallelMode}" mode is already assigned for the enclosing scope.`);
suite._parallelMode = options.mode;
for (let parent = suite.parent; parent; parent = parent.parent) {
if (parent._parallelMode === "serial" && suite._parallelMode === "parallel")
throw new Error("describe with parallel mode cannot be nested inside describe with serial mode");
if (parent._parallelMode === "default" && suite._parallelMode === "parallel")
throw new Error("describe with parallel mode cannot be nested inside describe with default mode");
}
}
}
_modifier(type, location, ...modifierArgs) {
const suite = (0, import_globals.currentlyLoadingFileSuite)();
if (suite) {
if (typeof modifierArgs[0] === "string" && typeof modifierArgs[1] === "function" && (type === "skip" || type === "fixme" || type === "fail")) {
this._createTest(type, location, modifierArgs[0], modifierArgs[1]);
return;
}
if (typeof modifierArgs[0] === "string" && typeof modifierArgs[1] === "object" && typeof modifierArgs[2] === "function" && (type === "skip" || type === "fixme" || type === "fail")) {
this._createTest(type, location, modifierArgs[0], modifierArgs[1], modifierArgs[2]);
return;
}
if (typeof modifierArgs[0] === "function") {
suite._modifiers.push({ type, fn: modifierArgs[0], location, description: modifierArgs[1] });
} else {
if (modifierArgs.length >= 1 && !modifierArgs[0])
return;
const description = modifierArgs[1];
suite._staticAnnotations.push({ type, description, location });
}
return;
}
const testInfo = (0, import_globals.currentTestInfo)();
if (!testInfo)
throw new Error(`test.${type}() can only be called inside test, describe block or fixture`);
if (typeof modifierArgs[0] === "function")
throw new Error(`test.${type}() with a function can only be called inside describe block`);
testInfo._modifier(type, location, modifierArgs);
}
_setTimeout(location, timeout) {
const suite = (0, import_globals.currentlyLoadingFileSuite)();
if (suite) {
suite._timeout = timeout;
return;
}
const testInfo = (0, import_globals.currentTestInfo)();
if (!testInfo)
throw new Error(`test.setTimeout() can only be called from a test`);
testInfo.setTimeout(timeout);
}
_use(location, fixtures) {
const suite = this._currentSuite(location, `test.use()`);
if (!suite)
return;
suite._use.push({ fixtures, location });
}
async _step(expectation, title, body, options = {}) {
const testInfo = (0, import_globals.currentTestInfo)();
if (!testInfo)
throw new Error(`test.step() can only be called from a test`);
const step = testInfo._addStep({ category: "test.step", title, location: options.location, box: options.box });
return await (0, import_utils.currentZone)().with("stepZone", step).run(async () => {
try {
let result = void 0;
result = await (0, import_utils.raceAgainstDeadline)(async () => {
try {
return await step.info._runStepBody(expectation === "skip", body, step.location);
} catch (e) {
if (result?.timedOut)
testInfo._failWithError(e);
throw e;
}
}, options.timeout ? (0, import_utils.monotonicTime)() + options.timeout : 0);
if (result.timedOut)
throw new import_playwright_core.errors.TimeoutError(`Step timeout of ${options.timeout}ms exceeded.`);
step.complete({});
return result.result;
} catch (error) {
step.complete({ error });
throw error;
}
});
}
_extend(location, fixtures) {
if (fixtures[testTypeSymbol])
throw new Error(`test.extend() accepts fixtures object, not a test object.
Did you mean to call mergeTests()?`);
const fixturesWithLocation = { fixtures, location };
return new TestTypeImpl([...this.fixtures, fixturesWithLocation]).test;
}
}
function throwIfRunningInsideJest() {
if (process.env.JEST_WORKER_ID) {
const packageManagerCommand = (0, import_utils.getPackageManagerExecCommand)();
throw new Error(
`Playwright Test needs to be invoked via '${packageManagerCommand} playwright test' and excluded from Jest test runs.
Creating one directory for Playwright tests and one for Jest is the recommended way of doing it.
See https://playwright.dev/docs/intro for more information about Playwright Test.`
);
}
}
function validateTestDetails(details, location) {
const originalAnnotations = Array.isArray(details.annotation) ? details.annotation : details.annotation ? [details.annotation] : [];
const annotations = originalAnnotations.map((annotation) => ({ ...annotation, location }));
const tags = Array.isArray(details.tag) ? details.tag : details.tag ? [details.tag] : [];
for (const tag of tags) {
if (tag[0] !== "@")
throw new Error(`Tag must start with "@" symbol, got "${tag}" instead.`);
}
return { annotations, tags };
}
const rootTestType = new TestTypeImpl([]);
function mergeTests(...tests) {
let result = rootTestType;
for (const t of tests) {
const testTypeImpl = t[testTypeSymbol];
if (!testTypeImpl)
throw new Error(`mergeTests() accepts "test" functions as parameters.
Did you mean to call test.extend() with fixtures instead?`);
const newFixtures = testTypeImpl.fixtures.filter((theirs) => !result.fixtures.find((ours) => ours.fixtures === theirs.fixtures));
result = new TestTypeImpl([...result.fixtures, ...newFixtures]);
}
return result.test;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestTypeImpl,
mergeTests,
rootTestType
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var fsWatcher_exports = {};
__export(fsWatcher_exports, {
Watcher: () => Watcher
});
module.exports = __toCommonJS(fsWatcher_exports);
var import_utilsBundle = require("./utilsBundle");
class Watcher {
constructor(onChange) {
this._watchedPaths = [];
this._ignoredFolders = [];
this._collector = [];
this._onChange = onChange;
}
async update(watchedPaths, ignoredFolders, reportPending) {
if (JSON.stringify([this._watchedPaths, this._ignoredFolders]) === JSON.stringify([watchedPaths, ignoredFolders]))
return;
if (reportPending)
this._reportEventsIfAny();
this._watchedPaths = watchedPaths;
this._ignoredFolders = ignoredFolders;
void this._fsWatcher?.close();
this._fsWatcher = void 0;
this._collector.length = 0;
clearTimeout(this._throttleTimer);
this._throttleTimer = void 0;
if (!this._watchedPaths.length)
return;
const ignored = [...this._ignoredFolders, "**/node_modules/**"];
this._fsWatcher = import_utilsBundle.chokidar.watch(watchedPaths, { ignoreInitial: true, ignored }).on("all", async (event, file) => {
if (this._throttleTimer)
clearTimeout(this._throttleTimer);
this._collector.push({ event, file });
this._throttleTimer = setTimeout(() => this._reportEventsIfAny(), 250);
});
await new Promise((resolve, reject) => this._fsWatcher.once("ready", resolve).once("error", reject));
}
async close() {
await this._fsWatcher?.close();
}
_reportEventsIfAny() {
if (this._collector.length)
this._onChange(this._collector.slice());
this._collector.length = 0;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Watcher
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var internalsForTest_exports = {};
__export(internalsForTest_exports, {
fileDependencies: () => fileDependencies
});
module.exports = __toCommonJS(internalsForTest_exports);
var import_path = __toESM(require("path"));
var import_compilationCache = require("./transform/compilationCache");
function fileDependencies() {
return Object.fromEntries([...(0, import_compilationCache.fileDependenciesForTest)().entries()].map((entry) => [import_path.default.basename(entry[0]), [...entry[1]].map((f) => import_path.default.basename(f)).sort()]));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
fileDependencies
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var events_exports = {};
__export(events_exports, {
Disposable: () => Disposable,
EventEmitter: () => EventEmitter
});
module.exports = __toCommonJS(events_exports);
var Disposable;
((Disposable2) => {
function disposeAll(disposables) {
for (const disposable of disposables.splice(0))
disposable.dispose();
}
Disposable2.disposeAll = disposeAll;
})(Disposable || (Disposable = {}));
class EventEmitter {
constructor() {
this._listeners = /* @__PURE__ */ new Set();
this.event = (listener, disposables) => {
this._listeners.add(listener);
let disposed = false;
const self = this;
const result = {
dispose() {
if (!disposed) {
disposed = true;
self._listeners.delete(listener);
}
}
};
if (disposables)
disposables.push(result);
return result;
};
}
fire(event) {
const dispatch = !this._deliveryQueue;
if (!this._deliveryQueue)
this._deliveryQueue = [];
for (const listener of this._listeners)
this._deliveryQueue.push({ listener, event });
if (!dispatch)
return;
for (let index = 0; index < this._deliveryQueue.length; index++) {
const { listener, event: event2 } = this._deliveryQueue[index];
listener.call(null, event2);
}
this._deliveryQueue = void 0;
}
dispose() {
this._listeners.clear();
if (this._deliveryQueue)
this._deliveryQueue = [];
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Disposable,
EventEmitter
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var folders_exports = {};
__export(folders_exports, {
artifactsFolderName: () => artifactsFolderName
});
module.exports = __toCommonJS(folders_exports);
function artifactsFolderName(workerIndex) {
return `.playwright-artifacts-${workerIndex}`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
artifactsFolderName
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stringInternPool_exports = {};
__export(stringInternPool_exports, {
JsonStringInternalizer: () => JsonStringInternalizer,
StringInternPool: () => StringInternPool
});
module.exports = __toCommonJS(stringInternPool_exports);
class StringInternPool {
constructor() {
this._stringCache = /* @__PURE__ */ new Map();
}
internString(s) {
let result = this._stringCache.get(s);
if (!result) {
this._stringCache.set(s, s);
result = s;
}
return result;
}
}
class JsonStringInternalizer {
constructor(pool) {
this._pool = pool;
}
traverse(value) {
if (typeof value !== "object")
return;
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
if (typeof value[i] === "string")
value[i] = this.intern(value[i]);
else
this.traverse(value[i]);
}
} else {
for (const name in value) {
if (typeof value[name] === "string")
value[name] = this.intern(value[name]);
else
this.traverse(value[name]);
}
}
}
intern(value) {
return this._pool.internString(value);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
JsonStringInternalizer,
StringInternPool
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var teleReceiver_exports = {};
__export(teleReceiver_exports, {
TeleReporterReceiver: () => TeleReporterReceiver,
TeleSuite: () => TeleSuite,
TeleTestCase: () => TeleTestCase,
TeleTestResult: () => TeleTestResult,
baseFullConfig: () => baseFullConfig,
computeTestCaseOutcome: () => computeTestCaseOutcome,
parseRegexPatterns: () => parseRegexPatterns,
serializeRegexPatterns: () => serializeRegexPatterns
});
module.exports = __toCommonJS(teleReceiver_exports);
class TeleReporterReceiver {
constructor(reporter, options = {}) {
this.isListing = false;
this._tests = /* @__PURE__ */ new Map();
this._rootSuite = new TeleSuite("", "root");
this._options = options;
this._reporter = reporter;
}
reset() {
this._rootSuite._entries = [];
this._tests.clear();
}
dispatch(message) {
const { method, params } = message;
if (method === "onConfigure") {
this._onConfigure(params.config);
return;
}
if (method === "onProject") {
this._onProject(params.project);
return;
}
if (method === "onBegin") {
this._onBegin();
return;
}
if (method === "onTestBegin") {
this._onTestBegin(params.testId, params.result);
return;
}
if (method === "onTestEnd") {
this._onTestEnd(params.test, params.result);
return;
}
if (method === "onStepBegin") {
this._onStepBegin(params.testId, params.resultId, params.step);
return;
}
if (method === "onAttach") {
this._onAttach(params.testId, params.resultId, params.attachments);
return;
}
if (method === "onStepEnd") {
this._onStepEnd(params.testId, params.resultId, params.step);
return;
}
if (method === "onError") {
this._onError(params.error);
return;
}
if (method === "onStdIO") {
this._onStdIO(params.type, params.testId, params.resultId, params.data, params.isBase64);
return;
}
if (method === "onEnd")
return this._onEnd(params.result);
if (method === "onExit")
return this._onExit();
}
_onConfigure(config) {
this._rootDir = config.rootDir;
this._config = this._parseConfig(config);
this._reporter.onConfigure?.(this._config);
}
_onProject(project) {
let projectSuite = this._options.mergeProjects ? this._rootSuite.suites.find((suite) => suite.project().name === project.name) : void 0;
if (!projectSuite) {
projectSuite = new TeleSuite(project.name, "project");
this._rootSuite._addSuite(projectSuite);
}
projectSuite._project = this._parseProject(project);
for (const suite of project.suites)
this._mergeSuiteInto(suite, projectSuite);
}
_onBegin() {
this._reporter.onBegin?.(this._rootSuite);
}
_onTestBegin(testId, payload) {
const test = this._tests.get(testId);
if (this._options.clearPreviousResultsWhenTestBegins)
test.results = [];
const testResult = test._createTestResult(payload.id);
testResult.retry = payload.retry;
testResult.workerIndex = payload.workerIndex;
testResult.parallelIndex = payload.parallelIndex;
testResult.setStartTimeNumber(payload.startTime);
this._reporter.onTestBegin?.(test, testResult);
}
_onTestEnd(testEndPayload, payload) {
const test = this._tests.get(testEndPayload.testId);
test.timeout = testEndPayload.timeout;
test.expectedStatus = testEndPayload.expectedStatus;
const result = test.results.find((r) => r._id === payload.id);
result.duration = payload.duration;
result.status = payload.status;
result.errors = payload.errors;
result.error = result.errors?.[0];
if (!!payload.attachments)
result.attachments = this._parseAttachments(payload.attachments);
if (payload.annotations) {
this._absoluteAnnotationLocationsInplace(payload.annotations);
result.annotations = payload.annotations;
test.annotations = payload.annotations;
}
this._reporter.onTestEnd?.(test, result);
result._stepMap = /* @__PURE__ */ new Map();
}
_onStepBegin(testId, resultId, payload) {
const test = this._tests.get(testId);
const result = test.results.find((r) => r._id === resultId);
const parentStep = payload.parentStepId ? result._stepMap.get(payload.parentStepId) : void 0;
const location = this._absoluteLocation(payload.location);
const step = new TeleTestStep(payload, parentStep, location, result);
if (parentStep)
parentStep.steps.push(step);
else
result.steps.push(step);
result._stepMap.set(payload.id, step);
this._reporter.onStepBegin?.(test, result, step);
}
_onStepEnd(testId, resultId, payload) {
const test = this._tests.get(testId);
const result = test.results.find((r) => r._id === resultId);
const step = result._stepMap.get(payload.id);
step._endPayload = payload;
step.duration = payload.duration;
step.error = payload.error;
this._reporter.onStepEnd?.(test, result, step);
}
_onAttach(testId, resultId, attachments) {
const test = this._tests.get(testId);
const result = test.results.find((r) => r._id === resultId);
result.attachments.push(...attachments.map((a) => ({
name: a.name,
contentType: a.contentType,
path: a.path,
body: a.base64 && globalThis.Buffer ? Buffer.from(a.base64, "base64") : void 0
})));
}
_onError(error) {
this._reporter.onError?.(error);
}
_onStdIO(type, testId, resultId, data, isBase64) {
const chunk = isBase64 ? globalThis.Buffer ? Buffer.from(data, "base64") : atob(data) : data;
const test = testId ? this._tests.get(testId) : void 0;
const result = test && resultId ? test.results.find((r) => r._id === resultId) : void 0;
if (type === "stdout") {
result?.stdout.push(chunk);
this._reporter.onStdOut?.(chunk, test, result);
} else {
result?.stderr.push(chunk);
this._reporter.onStdErr?.(chunk, test, result);
}
}
async _onEnd(result) {
await this._reporter.onEnd?.({
status: result.status,
startTime: new Date(result.startTime),
duration: result.duration
});
}
_onExit() {
return this._reporter.onExit?.();
}
_parseConfig(config) {
const result = { ...baseFullConfig, ...config };
if (this._options.configOverrides) {
result.configFile = this._options.configOverrides.configFile;
result.reportSlowTests = this._options.configOverrides.reportSlowTests;
result.quiet = this._options.configOverrides.quiet;
result.reporter = [...this._options.configOverrides.reporter];
}
return result;
}
_parseProject(project) {
return {
metadata: project.metadata,
name: project.name,
outputDir: this._absolutePath(project.outputDir),
repeatEach: project.repeatEach,
retries: project.retries,
testDir: this._absolutePath(project.testDir),
testIgnore: parseRegexPatterns(project.testIgnore),
testMatch: parseRegexPatterns(project.testMatch),
timeout: project.timeout,
grep: parseRegexPatterns(project.grep),
grepInvert: parseRegexPatterns(project.grepInvert),
dependencies: project.dependencies,
teardown: project.teardown,
snapshotDir: this._absolutePath(project.snapshotDir),
use: project.use
};
}
_parseAttachments(attachments) {
return attachments.map((a) => {
return {
...a,
body: a.base64 && globalThis.Buffer ? Buffer.from(a.base64, "base64") : void 0
};
});
}
_mergeSuiteInto(jsonSuite, parent) {
let targetSuite = parent.suites.find((s) => s.title === jsonSuite.title);
if (!targetSuite) {
targetSuite = new TeleSuite(jsonSuite.title, parent.type === "project" ? "file" : "describe");
parent._addSuite(targetSuite);
}
targetSuite.location = this._absoluteLocation(jsonSuite.location);
jsonSuite.entries.forEach((e) => {
if ("testId" in e)
this._mergeTestInto(e, targetSuite);
else
this._mergeSuiteInto(e, targetSuite);
});
}
_mergeTestInto(jsonTest, parent) {
let targetTest = this._options.mergeTestCases ? parent.tests.find((s) => s.title === jsonTest.title && s.repeatEachIndex === jsonTest.repeatEachIndex) : void 0;
if (!targetTest) {
targetTest = new TeleTestCase(jsonTest.testId, jsonTest.title, this._absoluteLocation(jsonTest.location), jsonTest.repeatEachIndex);
parent._addTest(targetTest);
this._tests.set(targetTest.id, targetTest);
}
this._updateTest(jsonTest, targetTest);
}
_updateTest(payload, test) {
test.id = payload.testId;
test.location = this._absoluteLocation(payload.location);
test.retries = payload.retries;
test.tags = payload.tags ?? [];
test.annotations = payload.annotations ?? [];
this._absoluteAnnotationLocationsInplace(test.annotations);
return test;
}
_absoluteAnnotationLocationsInplace(annotations) {
for (const annotation of annotations) {
if (annotation.location)
annotation.location = this._absoluteLocation(annotation.location);
}
}
_absoluteLocation(location) {
if (!location)
return location;
return {
...location,
file: this._absolutePath(location.file)
};
}
_absolutePath(relativePath) {
if (relativePath === void 0)
return;
return this._options.resolvePath ? this._options.resolvePath(this._rootDir, relativePath) : this._rootDir + "/" + relativePath;
}
}
class TeleSuite {
constructor(title, type) {
this._entries = [];
this._requireFile = "";
this._parallelMode = "none";
this.title = title;
this._type = type;
}
get type() {
return this._type;
}
get suites() {
return this._entries.filter((e) => e.type !== "test");
}
get tests() {
return this._entries.filter((e) => e.type === "test");
}
entries() {
return this._entries;
}
allTests() {
const result = [];
const visit = (suite) => {
for (const entry of suite.entries()) {
if (entry.type === "test")
result.push(entry);
else
visit(entry);
}
};
visit(this);
return result;
}
titlePath() {
const titlePath = this.parent ? this.parent.titlePath() : [];
if (this.title || this._type !== "describe")
titlePath.push(this.title);
return titlePath;
}
project() {
return this._project ?? this.parent?.project();
}
_addTest(test) {
test.parent = this;
this._entries.push(test);
}
_addSuite(suite) {
suite.parent = this;
this._entries.push(suite);
}
}
class TeleTestCase {
constructor(id, title, location, repeatEachIndex) {
this.fn = () => {
};
this.results = [];
this.type = "test";
this.expectedStatus = "passed";
this.timeout = 0;
this.annotations = [];
this.retries = 0;
this.tags = [];
this.repeatEachIndex = 0;
this.id = id;
this.title = title;
this.location = location;
this.repeatEachIndex = repeatEachIndex;
}
titlePath() {
const titlePath = this.parent ? this.parent.titlePath() : [];
titlePath.push(this.title);
return titlePath;
}
outcome() {
return computeTestCaseOutcome(this);
}
ok() {
const status = this.outcome();
return status === "expected" || status === "flaky" || status === "skipped";
}
_createTestResult(id) {
const result = new TeleTestResult(this.results.length, id);
this.results.push(result);
return result;
}
}
class TeleTestStep {
constructor(payload, parentStep, location, result) {
this.duration = -1;
this.steps = [];
this._startTime = 0;
this.title = payload.title;
this.category = payload.category;
this.location = location;
this.parent = parentStep;
this._startTime = payload.startTime;
this._result = result;
}
titlePath() {
const parentPath = this.parent?.titlePath() || [];
return [...parentPath, this.title];
}
get startTime() {
return new Date(this._startTime);
}
set startTime(value) {
this._startTime = +value;
}
get attachments() {
return this._endPayload?.attachments?.map((index) => this._result.attachments[index]) ?? [];
}
get annotations() {
return this._endPayload?.annotations ?? [];
}
}
class TeleTestResult {
constructor(retry, id) {
this.parallelIndex = -1;
this.workerIndex = -1;
this.duration = -1;
this.stdout = [];
this.stderr = [];
this.attachments = [];
this.annotations = [];
this.status = "skipped";
this.steps = [];
this.errors = [];
this._stepMap = /* @__PURE__ */ new Map();
this._startTime = 0;
this.retry = retry;
this._id = id;
}
setStartTimeNumber(startTime) {
this._startTime = startTime;
}
get startTime() {
return new Date(this._startTime);
}
set startTime(value) {
this._startTime = +value;
}
}
const baseFullConfig = {
forbidOnly: false,
fullyParallel: false,
globalSetup: null,
globalTeardown: null,
globalTimeout: 0,
grep: /.*/,
grepInvert: null,
maxFailures: 0,
metadata: {},
preserveOutput: "always",
projects: [],
reporter: [[process.env.CI ? "dot" : "list"]],
reportSlowTests: {
max: 5,
threshold: 3e5
/* 5 minutes */
},
configFile: "",
rootDir: "",
quiet: false,
shard: null,
updateSnapshots: "missing",
updateSourceMethod: "patch",
version: "",
workers: 0,
webServer: null
};
function serializeRegexPatterns(patterns) {
if (!Array.isArray(patterns))
patterns = [patterns];
return patterns.map((s) => {
if (typeof s === "string")
return { s };
return { r: { source: s.source, flags: s.flags } };
});
}
function parseRegexPatterns(patterns) {
return patterns.map((p) => {
if (p.s !== void 0)
return p.s;
return new RegExp(p.r.source, p.r.flags);
});
}
function computeTestCaseOutcome(test) {
let skipped = 0;
let didNotRun = 0;
let expected = 0;
let interrupted = 0;
let unexpected = 0;
for (const result of test.results) {
if (result.status === "interrupted") {
++interrupted;
} else if (result.status === "skipped" && test.expectedStatus === "skipped") {
++skipped;
} else if (result.status === "skipped") {
++didNotRun;
} else if (result.status === test.expectedStatus) {
++expected;
} else {
++unexpected;
}
}
if (expected === 0 && unexpected === 0)
return "skipped";
if (unexpected === 0)
return "expected";
if (expected === 0 && skipped === 0)
return "unexpected";
return "flaky";
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TeleReporterReceiver,
TeleSuite,
TeleTestCase,
TeleTestResult,
baseFullConfig,
computeTestCaseOutcome,
parseRegexPatterns,
serializeRegexPatterns
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var teleSuiteUpdater_exports = {};
__export(teleSuiteUpdater_exports, {
TeleSuiteUpdater: () => TeleSuiteUpdater
});
module.exports = __toCommonJS(teleSuiteUpdater_exports);
var import_teleReceiver = require("./teleReceiver");
var import_testTree = require("./testTree");
class TeleSuiteUpdater {
constructor(options) {
this.loadErrors = [];
this.progress = {
total: 0,
passed: 0,
failed: 0,
skipped: 0
};
this._lastRunTestCount = 0;
this._receiver = new import_teleReceiver.TeleReporterReceiver(this._createReporter(), {
mergeProjects: true,
mergeTestCases: true,
resolvePath: (rootDir, relativePath) => rootDir + options.pathSeparator + relativePath,
clearPreviousResultsWhenTestBegins: true
});
this._options = options;
}
_createReporter() {
return {
version: () => "v2",
onConfigure: (c) => {
this.config = c;
this._lastRunReceiver = new import_teleReceiver.TeleReporterReceiver({
version: () => "v2",
onBegin: (suite) => {
this._lastRunTestCount = suite.allTests().length;
this._lastRunReceiver = void 0;
}
}, {
mergeProjects: true,
mergeTestCases: false,
resolvePath: (rootDir, relativePath) => rootDir + this._options.pathSeparator + relativePath
});
},
onBegin: (suite) => {
if (!this.rootSuite)
this.rootSuite = suite;
if (this._testResultsSnapshot) {
for (const test of this.rootSuite.allTests())
test.results = this._testResultsSnapshot?.get(test.id) || test.results;
this._testResultsSnapshot = void 0;
}
this.progress.total = this._lastRunTestCount;
this.progress.passed = 0;
this.progress.failed = 0;
this.progress.skipped = 0;
this._options.onUpdate(true);
},
onEnd: () => {
this._options.onUpdate(true);
},
onTestBegin: (test, testResult) => {
testResult[import_testTree.statusEx] = "running";
this._options.onUpdate();
},
onTestEnd: (test, testResult) => {
if (test.outcome() === "skipped")
++this.progress.skipped;
else if (test.outcome() === "unexpected")
++this.progress.failed;
else
++this.progress.passed;
testResult[import_testTree.statusEx] = testResult.status;
this._options.onUpdate();
},
onError: (error) => this._handleOnError(error),
printsToStdio: () => false
};
}
processGlobalReport(report) {
const receiver = new import_teleReceiver.TeleReporterReceiver({
version: () => "v2",
onConfigure: (c) => {
this.config = c;
},
onError: (error) => this._handleOnError(error)
});
for (const message of report)
void receiver.dispatch(message);
}
processListReport(report) {
const tests = this.rootSuite?.allTests() || [];
this._testResultsSnapshot = new Map(tests.map((test) => [test.id, test.results]));
this._receiver.reset();
for (const message of report)
void this._receiver.dispatch(message);
}
processTestReportEvent(message) {
this._lastRunReceiver?.dispatch(message)?.catch(() => {
});
this._receiver.dispatch(message)?.catch(() => {
});
}
_handleOnError(error) {
this.loadErrors.push(error);
this._options.onError?.(error);
this._options.onUpdate();
}
asModel() {
return {
rootSuite: this.rootSuite || new import_teleReceiver.TeleSuite("", "root"),
config: this.config,
loadErrors: this.loadErrors,
progress: this.progress
};
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TeleSuiteUpdater
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testServerConnection_exports = {};
__export(testServerConnection_exports, {
TestServerConnection: () => TestServerConnection,
WebSocketTestServerTransport: () => WebSocketTestServerTransport
});
module.exports = __toCommonJS(testServerConnection_exports);
var events = __toESM(require("./events"));
class WebSocketTestServerTransport {
constructor(url) {
this._ws = new WebSocket(url);
}
onmessage(listener) {
this._ws.addEventListener("message", (event) => listener(event.data.toString()));
}
onopen(listener) {
this._ws.addEventListener("open", listener);
}
onerror(listener) {
this._ws.addEventListener("error", listener);
}
onclose(listener) {
this._ws.addEventListener("close", listener);
}
send(data) {
this._ws.send(data);
}
close() {
this._ws.close();
}
}
class TestServerConnection {
constructor(transport) {
this._onCloseEmitter = new events.EventEmitter();
this._onReportEmitter = new events.EventEmitter();
this._onStdioEmitter = new events.EventEmitter();
this._onTestFilesChangedEmitter = new events.EventEmitter();
this._onLoadTraceRequestedEmitter = new events.EventEmitter();
this._lastId = 0;
this._callbacks = /* @__PURE__ */ new Map();
this._isClosed = false;
this.onClose = this._onCloseEmitter.event;
this.onReport = this._onReportEmitter.event;
this.onStdio = this._onStdioEmitter.event;
this.onTestFilesChanged = this._onTestFilesChangedEmitter.event;
this.onLoadTraceRequested = this._onLoadTraceRequestedEmitter.event;
this._transport = transport;
this._transport.onmessage((data) => {
const message = JSON.parse(data);
const { id, result, error, method, params } = message;
if (id) {
const callback = this._callbacks.get(id);
if (!callback)
return;
this._callbacks.delete(id);
if (error)
callback.reject(new Error(error));
else
callback.resolve(result);
} else {
this._dispatchEvent(method, params);
}
});
const pingInterval = setInterval(() => this._sendMessage("ping").catch(() => {
}), 3e4);
this._connectedPromise = new Promise((f, r) => {
this._transport.onopen(f);
this._transport.onerror(r);
});
this._transport.onclose(() => {
this._isClosed = true;
this._onCloseEmitter.fire();
clearInterval(pingInterval);
});
}
isClosed() {
return this._isClosed;
}
async _sendMessage(method, params) {
const logForTest = globalThis.__logForTest;
logForTest?.({ method, params });
await this._connectedPromise;
const id = ++this._lastId;
const message = { id, method, params };
this._transport.send(JSON.stringify(message));
return new Promise((resolve, reject) => {
this._callbacks.set(id, { resolve, reject });
});
}
_sendMessageNoReply(method, params) {
this._sendMessage(method, params).catch(() => {
});
}
_dispatchEvent(method, params) {
if (method === "report")
this._onReportEmitter.fire(params);
else if (method === "stdio")
this._onStdioEmitter.fire(params);
else if (method === "testFilesChanged")
this._onTestFilesChangedEmitter.fire(params);
else if (method === "loadTraceRequested")
this._onLoadTraceRequestedEmitter.fire(params);
}
async initialize(params) {
await this._sendMessage("initialize", params);
}
async ping(params) {
await this._sendMessage("ping", params);
}
async pingNoReply(params) {
this._sendMessageNoReply("ping", params);
}
async watch(params) {
await this._sendMessage("watch", params);
}
watchNoReply(params) {
this._sendMessageNoReply("watch", params);
}
async open(params) {
await this._sendMessage("open", params);
}
openNoReply(params) {
this._sendMessageNoReply("open", params);
}
async resizeTerminal(params) {
await this._sendMessage("resizeTerminal", params);
}
resizeTerminalNoReply(params) {
this._sendMessageNoReply("resizeTerminal", params);
}
async checkBrowsers(params) {
return await this._sendMessage("checkBrowsers", params);
}
async installBrowsers(params) {
await this._sendMessage("installBrowsers", params);
}
async runGlobalSetup(params) {
return await this._sendMessage("runGlobalSetup", params);
}
async runGlobalTeardown(params) {
return await this._sendMessage("runGlobalTeardown", params);
}
async startDevServer(params) {
return await this._sendMessage("startDevServer", params);
}
async stopDevServer(params) {
return await this._sendMessage("stopDevServer", params);
}
async clearCache(params) {
return await this._sendMessage("clearCache", params);
}
async listFiles(params) {
return await this._sendMessage("listFiles", params);
}
async listTests(params) {
return await this._sendMessage("listTests", params);
}
async runTests(params) {
return await this._sendMessage("runTests", params);
}
async findRelatedTestFiles(params) {
return await this._sendMessage("findRelatedTestFiles", params);
}
async stopTests(params) {
await this._sendMessage("stopTests", params);
}
stopTestsNoReply(params) {
this._sendMessageNoReply("stopTests", params);
}
async closeGracefully(params) {
await this._sendMessage("closeGracefully", params);
}
close() {
try {
this._transport.close();
} catch {
}
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestServerConnection,
WebSocketTestServerTransport
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testServerInterface_exports = {};
module.exports = __toCommonJS(testServerInterface_exports);
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testTree_exports = {};
__export(testTree_exports, {
TestTree: () => TestTree,
collectTestIds: () => collectTestIds,
sortAndPropagateStatus: () => sortAndPropagateStatus,
statusEx: () => statusEx
});
module.exports = __toCommonJS(testTree_exports);
class TestTree {
constructor(rootFolder, rootSuite, loadErrors, projectFilters, pathSeparator, hideFiles) {
this._treeItemById = /* @__PURE__ */ new Map();
this._treeItemByTestId = /* @__PURE__ */ new Map();
const filterProjects = projectFilters && [...projectFilters.values()].some(Boolean);
this.pathSeparator = pathSeparator;
this.rootItem = {
kind: "group",
subKind: "folder",
id: rootFolder,
title: "",
location: { file: "", line: 0, column: 0 },
duration: 0,
parent: void 0,
children: [],
status: "none",
hasLoadErrors: false
};
this._treeItemById.set(rootFolder, this.rootItem);
const visitSuite = (project, parentSuite, parentGroup, mode) => {
for (const suite of mode === "tests" ? [] : parentSuite.suites) {
if (!suite.title) {
visitSuite(project, suite, parentGroup, "all");
continue;
}
let group = parentGroup.children.find((item) => item.kind === "group" && item.title === suite.title);
if (!group) {
group = {
kind: "group",
subKind: "describe",
id: "suite:" + parentSuite.titlePath().join("") + "" + suite.title,
// account for anonymous suites
title: suite.title,
location: suite.location,
duration: 0,
parent: parentGroup,
children: [],
status: "none",
hasLoadErrors: false
};
this._addChild(parentGroup, group);
}
visitSuite(project, suite, group, "all");
}
for (const test of mode === "suites" ? [] : parentSuite.tests) {
const title = test.title;
let testCaseItem = parentGroup.children.find((t) => t.kind !== "group" && t.title === title);
if (!testCaseItem) {
testCaseItem = {
kind: "case",
id: "test:" + test.titlePath().join(""),
title,
parent: parentGroup,
children: [],
tests: [],
location: test.location,
duration: 0,
status: "none",
project: void 0,
test: void 0,
tags: test.tags
};
this._addChild(parentGroup, testCaseItem);
}
const result = test.results[0];
let status = "none";
if (result?.[statusEx] === "scheduled")
status = "scheduled";
else if (result?.[statusEx] === "running")
status = "running";
else if (result?.status === "skipped")
status = "skipped";
else if (result?.status === "interrupted")
status = "none";
else if (result && test.outcome() !== "expected")
status = "failed";
else if (result && test.outcome() === "expected")
status = "passed";
testCaseItem.tests.push(test);
const testItem = {
kind: "test",
id: test.id,
title: project.name,
location: test.location,
test,
parent: testCaseItem,
children: [],
status,
duration: test.results.length ? Math.max(0, test.results[0].duration) : 0,
project
};
this._addChild(testCaseItem, testItem);
this._treeItemByTestId.set(test.id, testItem);
testCaseItem.duration = testCaseItem.children.reduce((a, b) => a + b.duration, 0);
}
};
for (const projectSuite of rootSuite?.suites || []) {
if (filterProjects && !projectFilters.get(projectSuite.title))
continue;
for (const fileSuite of projectSuite.suites) {
if (hideFiles) {
visitSuite(projectSuite.project(), fileSuite, this.rootItem, "suites");
if (fileSuite.tests.length) {
const defaultDescribeItem = this._defaultDescribeItem();
visitSuite(projectSuite.project(), fileSuite, defaultDescribeItem, "tests");
}
} else {
const fileItem = this._fileItem(fileSuite.location.file.split(pathSeparator), true);
visitSuite(projectSuite.project(), fileSuite, fileItem, "all");
}
}
}
for (const loadError of loadErrors) {
if (!loadError.location)
continue;
const fileItem = this._fileItem(loadError.location.file.split(pathSeparator), true);
fileItem.hasLoadErrors = true;
}
}
_addChild(parent, child) {
parent.children.push(child);
child.parent = parent;
this._treeItemById.set(child.id, child);
}
filterTree(filterText, statusFilters, runningTestIds) {
const tokens = filterText.trim().toLowerCase().split(" ");
const filtersStatuses = [...statusFilters.values()].some(Boolean);
const filter = (testCase) => {
const titleWithTags = [...testCase.tests[0].titlePath(), ...testCase.tests[0].tags].join(" ").toLowerCase();
if (!tokens.every((token) => titleWithTags.includes(token)) && !testCase.tests.some((t) => runningTestIds?.has(t.id)))
return false;
testCase.children = testCase.children.filter((test) => {
return !filtersStatuses || runningTestIds?.has(test.test.id) || statusFilters.get(test.status);
});
testCase.tests = testCase.children.map((c) => c.test);
return !!testCase.children.length;
};
const visit = (treeItem) => {
const newChildren = [];
for (const child of treeItem.children) {
if (child.kind === "case") {
if (filter(child))
newChildren.push(child);
} else {
visit(child);
if (child.children.length || child.hasLoadErrors)
newChildren.push(child);
}
}
treeItem.children = newChildren;
};
visit(this.rootItem);
}
_fileItem(filePath, isFile) {
if (filePath.length === 0)
return this.rootItem;
const fileName = filePath.join(this.pathSeparator);
const existingFileItem = this._treeItemById.get(fileName);
if (existingFileItem)
return existingFileItem;
const parentFileItem = this._fileItem(filePath.slice(0, filePath.length - 1), false);
const fileItem = {
kind: "group",
subKind: isFile ? "file" : "folder",
id: fileName,
title: filePath[filePath.length - 1],
location: { file: fileName, line: 0, column: 0 },
duration: 0,
parent: parentFileItem,
children: [],
status: "none",
hasLoadErrors: false
};
this._addChild(parentFileItem, fileItem);
return fileItem;
}
_defaultDescribeItem() {
let defaultDescribeItem = this._treeItemById.get("<anonymous>");
if (!defaultDescribeItem) {
defaultDescribeItem = {
kind: "group",
subKind: "describe",
id: "<anonymous>",
title: "<anonymous>",
location: { file: "", line: 0, column: 0 },
duration: 0,
parent: this.rootItem,
children: [],
status: "none",
hasLoadErrors: false
};
this._addChild(this.rootItem, defaultDescribeItem);
}
return defaultDescribeItem;
}
sortAndPropagateStatus() {
sortAndPropagateStatus(this.rootItem);
}
flattenForSingleProject() {
const visit = (treeItem) => {
if (treeItem.kind === "case" && treeItem.children.length === 1) {
treeItem.project = treeItem.children[0].project;
treeItem.test = treeItem.children[0].test;
treeItem.children = [];
this._treeItemByTestId.set(treeItem.test.id, treeItem);
} else {
treeItem.children.forEach(visit);
}
};
visit(this.rootItem);
}
shortenRoot() {
let shortRoot = this.rootItem;
while (shortRoot.children.length === 1 && shortRoot.children[0].kind === "group" && shortRoot.children[0].subKind === "folder")
shortRoot = shortRoot.children[0];
shortRoot.location = this.rootItem.location;
this.rootItem = shortRoot;
}
testIds() {
const result = /* @__PURE__ */ new Set();
const visit = (treeItem) => {
if (treeItem.kind === "case")
treeItem.tests.forEach((t) => result.add(t.id));
treeItem.children.forEach(visit);
};
visit(this.rootItem);
return result;
}
fileNames() {
const result = /* @__PURE__ */ new Set();
const visit = (treeItem) => {
if (treeItem.kind === "group" && treeItem.subKind === "file")
result.add(treeItem.id);
else
treeItem.children.forEach(visit);
};
visit(this.rootItem);
return [...result];
}
flatTreeItems() {
const result = [];
const visit = (treeItem) => {
result.push(treeItem);
treeItem.children.forEach(visit);
};
visit(this.rootItem);
return result;
}
treeItemById(id) {
return this._treeItemById.get(id);
}
collectTestIds(treeItem) {
return treeItem ? collectTestIds(treeItem) : /* @__PURE__ */ new Set();
}
}
function sortAndPropagateStatus(treeItem) {
for (const child of treeItem.children)
sortAndPropagateStatus(child);
if (treeItem.kind === "group") {
treeItem.children.sort((a, b) => {
const fc = a.location.file.localeCompare(b.location.file);
return fc || a.location.line - b.location.line;
});
}
let allPassed = treeItem.children.length > 0;
let allSkipped = treeItem.children.length > 0;
let hasFailed = false;
let hasRunning = false;
let hasScheduled = false;
for (const child of treeItem.children) {
allSkipped = allSkipped && child.status === "skipped";
allPassed = allPassed && (child.status === "passed" || child.status === "skipped");
hasFailed = hasFailed || child.status === "failed";
hasRunning = hasRunning || child.status === "running";
hasScheduled = hasScheduled || child.status === "scheduled";
}
if (hasRunning)
treeItem.status = "running";
else if (hasScheduled)
treeItem.status = "scheduled";
else if (hasFailed)
treeItem.status = "failed";
else if (allSkipped)
treeItem.status = "skipped";
else if (allPassed)
treeItem.status = "passed";
}
function collectTestIds(treeItem) {
const testIds = /* @__PURE__ */ new Set();
const visit = (treeItem2) => {
if (treeItem2.kind === "case")
treeItem2.tests.map((t) => t.id).forEach((id) => testIds.add(id));
else if (treeItem2.kind === "test")
testIds.add(treeItem2.id);
else
treeItem2.children?.forEach(visit);
};
visit(treeItem);
return testIds;
}
const statusEx = Symbol("statusEx");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestTree,
collectTestIds,
sortAndPropagateStatus,
statusEx
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var types_d_exports = {};
module.exports = __toCommonJS(types_d_exports);
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var loaderMain_exports = {};
__export(loaderMain_exports, {
LoaderMain: () => LoaderMain,
create: () => create
});
module.exports = __toCommonJS(loaderMain_exports);
var import_configLoader = require("../common/configLoader");
var import_esmLoaderHost = require("../common/esmLoaderHost");
var import_poolBuilder = require("../common/poolBuilder");
var import_process = require("../common/process");
var import_testLoader = require("../common/testLoader");
var import_compilationCache = require("../transform/compilationCache");
class LoaderMain extends import_process.ProcessRunner {
constructor(serializedConfig) {
super();
this._poolBuilder = import_poolBuilder.PoolBuilder.createForLoader();
this._serializedConfig = serializedConfig;
}
_config() {
if (!this._configPromise)
this._configPromise = (0, import_configLoader.deserializeConfig)(this._serializedConfig);
return this._configPromise;
}
async loadTestFile(params) {
const testErrors = [];
const config = await this._config();
const fileSuite = await (0, import_testLoader.loadTestFile)(params.file, config.config.rootDir, testErrors);
this._poolBuilder.buildPools(fileSuite);
return { fileSuite: fileSuite._deepSerialize(), testErrors };
}
async getCompilationCacheFromLoader() {
await (0, import_esmLoaderHost.incorporateCompilationCache)();
return (0, import_compilationCache.serializeCompilationCache)();
}
}
const create = (config) => new LoaderMain(config);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
LoaderMain,
create
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var matcherHint_exports = {};
__export(matcherHint_exports, {
ExpectError: () => ExpectError,
callLogText: () => callLogText,
formatMatcherMessage: () => formatMatcherMessage,
isJestError: () => isJestError
});
module.exports = __toCommonJS(matcherHint_exports);
var import_utils = require("playwright-core/lib/utils");
var import_expectBundle = require("../common/expectBundle");
function formatMatcherMessage(state, details) {
const receiver = details.receiver ?? (details.locator ? "locator" : "page");
let message = (0, import_expectBundle.DIM_COLOR)("expect(") + (0, import_expectBundle.RECEIVED_COLOR)(receiver) + (0, import_expectBundle.DIM_COLOR)(")" + (state.promise ? "." + state.promise : "") + (state.isNot ? ".not" : "") + ".") + details.matcherName + (0, import_expectBundle.DIM_COLOR)("(") + (0, import_expectBundle.EXPECTED_COLOR)(details.expectation) + (0, import_expectBundle.DIM_COLOR)(")") + " failed\n\n";
const diffLines = details.printedDiff?.split("\n");
if (diffLines?.length === 2) {
details.printedExpected = diffLines[0];
details.printedReceived = diffLines[1];
details.printedDiff = void 0;
}
const align = !details.errorMessage && details.printedExpected?.startsWith("Expected:") && (!details.printedReceived || details.printedReceived.startsWith("Received:"));
if (details.locator)
message += `Locator: ${align ? " " : ""}${String(details.locator)}
`;
if (details.printedExpected)
message += details.printedExpected + "\n";
if (details.printedReceived)
message += details.printedReceived + "\n";
if (details.timedOut && details.timeout)
message += `Timeout: ${align ? " " : ""}${details.timeout}ms
`;
if (details.printedDiff)
message += details.printedDiff + "\n";
if (details.errorMessage) {
message += details.errorMessage;
if (!details.errorMessage.endsWith("\n"))
message += "\n";
}
message += callLogText(details.log);
return message;
}
class ExpectError extends Error {
constructor(jestError, customMessage, stackFrames) {
super("");
this.name = jestError.name;
this.message = jestError.message;
this.matcherResult = jestError.matcherResult;
if (customMessage)
this.message = customMessage + "\n\n" + this.message;
this.stack = this.name + ": " + this.message + "\n" + (0, import_utils.stringifyStackFrames)(stackFrames).join("\n");
}
}
function isJestError(e) {
return e instanceof Error && "matcherResult" in e;
}
const callLogText = (log) => {
if (!log || !log.some((l) => !!l))
return "";
return `
Call log:
${(0, import_expectBundle.DIM_COLOR)(log.join("\n"))}
`;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ExpectError,
callLogText,
formatMatcherMessage,
isJestError
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var matchers_exports = {};
__export(matchers_exports, {
toBeAttached: () => toBeAttached,
toBeChecked: () => toBeChecked,
toBeDisabled: () => toBeDisabled,
toBeEditable: () => toBeEditable,
toBeEmpty: () => toBeEmpty,
toBeEnabled: () => toBeEnabled,
toBeFocused: () => toBeFocused,
toBeHidden: () => toBeHidden,
toBeInViewport: () => toBeInViewport,
toBeOK: () => toBeOK,
toBeVisible: () => toBeVisible,
toContainClass: () => toContainClass,
toContainText: () => toContainText,
toHaveAccessibleDescription: () => toHaveAccessibleDescription,
toHaveAccessibleErrorMessage: () => toHaveAccessibleErrorMessage,
toHaveAccessibleName: () => toHaveAccessibleName,
toHaveAttribute: () => toHaveAttribute,
toHaveCSS: () => toHaveCSS,
toHaveClass: () => toHaveClass,
toHaveCount: () => toHaveCount,
toHaveId: () => toHaveId,
toHaveJSProperty: () => toHaveJSProperty,
toHaveRole: () => toHaveRole,
toHaveText: () => toHaveText,
toHaveTitle: () => toHaveTitle,
toHaveURL: () => toHaveURL,
toHaveValue: () => toHaveValue,
toHaveValues: () => toHaveValues,
toPass: () => toPass
});
module.exports = __toCommonJS(matchers_exports);
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_util = require("../util");
var import_toBeTruthy = require("./toBeTruthy");
var import_toEqual = require("./toEqual");
var import_toHaveURL = require("./toHaveURL");
var import_toMatchText = require("./toMatchText");
var import_config = require("../common/config");
var import_globals = require("../common/globals");
var import_testInfo = require("../worker/testInfo");
var import_matcherHint = require("./matcherHint");
function toBeAttached(locator, options) {
const attached = !options || options.attached === void 0 || options.attached;
const expected = attached ? "attached" : "detached";
const arg = attached ? "" : "{ attached: false }";
return import_toBeTruthy.toBeTruthy.call(this, "toBeAttached", locator, "Locator", expected, arg, async (isNot, timeout) => {
return await locator._expect(attached ? "to.be.attached" : "to.be.detached", { isNot, timeout });
}, options);
}
function toBeChecked(locator, options) {
const checked = options?.checked;
const indeterminate = options?.indeterminate;
const expectedValue = {
checked,
indeterminate
};
let expected;
let arg;
if (options?.indeterminate) {
expected = "indeterminate";
arg = `{ indeterminate: true }`;
} else {
expected = options?.checked === false ? "unchecked" : "checked";
arg = options?.checked === false ? `{ checked: false }` : "";
}
return import_toBeTruthy.toBeTruthy.call(this, "toBeChecked", locator, "Locator", expected, arg, async (isNot, timeout) => {
return await locator._expect("to.be.checked", { isNot, timeout, expectedValue });
}, options);
}
function toBeDisabled(locator, options) {
return import_toBeTruthy.toBeTruthy.call(this, "toBeDisabled", locator, "Locator", "disabled", "", async (isNot, timeout) => {
return await locator._expect("to.be.disabled", { isNot, timeout });
}, options);
}
function toBeEditable(locator, options) {
const editable = !options || options.editable === void 0 || options.editable;
const expected = editable ? "editable" : "readOnly";
const arg = editable ? "" : "{ editable: false }";
return import_toBeTruthy.toBeTruthy.call(this, "toBeEditable", locator, "Locator", expected, arg, async (isNot, timeout) => {
return await locator._expect(editable ? "to.be.editable" : "to.be.readonly", { isNot, timeout });
}, options);
}
function toBeEmpty(locator, options) {
return import_toBeTruthy.toBeTruthy.call(this, "toBeEmpty", locator, "Locator", "empty", "", async (isNot, timeout) => {
return await locator._expect("to.be.empty", { isNot, timeout });
}, options);
}
function toBeEnabled(locator, options) {
const enabled = !options || options.enabled === void 0 || options.enabled;
const expected = enabled ? "enabled" : "disabled";
const arg = enabled ? "" : "{ enabled: false }";
return import_toBeTruthy.toBeTruthy.call(this, "toBeEnabled", locator, "Locator", expected, arg, async (isNot, timeout) => {
return await locator._expect(enabled ? "to.be.enabled" : "to.be.disabled", { isNot, timeout });
}, options);
}
function toBeFocused(locator, options) {
return import_toBeTruthy.toBeTruthy.call(this, "toBeFocused", locator, "Locator", "focused", "", async (isNot, timeout) => {
return await locator._expect("to.be.focused", { isNot, timeout });
}, options);
}
function toBeHidden(locator, options) {
return import_toBeTruthy.toBeTruthy.call(this, "toBeHidden", locator, "Locator", "hidden", "", async (isNot, timeout) => {
return await locator._expect("to.be.hidden", { isNot, timeout });
}, options);
}
function toBeVisible(locator, options) {
const visible = !options || options.visible === void 0 || options.visible;
const expected = visible ? "visible" : "hidden";
const arg = visible ? "" : "{ visible: false }";
return import_toBeTruthy.toBeTruthy.call(this, "toBeVisible", locator, "Locator", expected, arg, async (isNot, timeout) => {
return await locator._expect(visible ? "to.be.visible" : "to.be.hidden", { isNot, timeout });
}, options);
}
function toBeInViewport(locator, options) {
return import_toBeTruthy.toBeTruthy.call(this, "toBeInViewport", locator, "Locator", "in viewport", "", async (isNot, timeout) => {
return await locator._expect("to.be.in.viewport", { isNot, expectedNumber: options?.ratio, timeout });
}, options);
}
function toContainText(locator, expected, options = {}) {
if (Array.isArray(expected)) {
return import_toEqual.toEqual.call(this, "toContainText", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected, { matchSubstring: true, normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
return await locator._expect("to.contain.text.array", { expectedText, isNot, useInnerText: options.useInnerText, timeout });
}, expected, { ...options, contains: true });
} else {
return import_toMatchText.toMatchText.call(this, "toContainText", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { matchSubstring: true, normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
return await locator._expect("to.have.text", { expectedText, isNot, useInnerText: options.useInnerText, timeout });
}, expected, { ...options, matchSubstring: true });
}
}
function toHaveAccessibleDescription(locator, expected, options) {
return import_toMatchText.toMatchText.call(this, "toHaveAccessibleDescription", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase, normalizeWhiteSpace: true });
return await locator._expect("to.have.accessible.description", { expectedText, isNot, timeout });
}, expected, options);
}
function toHaveAccessibleName(locator, expected, options) {
return import_toMatchText.toMatchText.call(this, "toHaveAccessibleName", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase, normalizeWhiteSpace: true });
return await locator._expect("to.have.accessible.name", { expectedText, isNot, timeout });
}, expected, options);
}
function toHaveAccessibleErrorMessage(locator, expected, options) {
return import_toMatchText.toMatchText.call(this, "toHaveAccessibleErrorMessage", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase, normalizeWhiteSpace: true });
return await locator._expect("to.have.accessible.error.message", { expectedText, isNot, timeout });
}, expected, options);
}
function toHaveAttribute(locator, name, expected, options) {
if (!options) {
if (typeof expected === "object" && !(0, import_utils.isRegExp)(expected)) {
options = expected;
expected = void 0;
}
}
if (expected === void 0) {
return import_toBeTruthy.toBeTruthy.call(this, "toHaveAttribute", locator, "Locator", "have attribute", "", async (isNot, timeout) => {
return await locator._expect("to.have.attribute", { expressionArg: name, isNot, timeout });
}, options);
}
return import_toMatchText.toMatchText.call(this, "toHaveAttribute", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase });
return await locator._expect("to.have.attribute.value", { expressionArg: name, expectedText, isNot, timeout });
}, expected, options);
}
function toHaveClass(locator, expected, options) {
if (Array.isArray(expected)) {
return import_toEqual.toEqual.call(this, "toHaveClass", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected);
return await locator._expect("to.have.class.array", { expectedText, isNot, timeout });
}, expected, options);
} else {
return import_toMatchText.toMatchText.call(this, "toHaveClass", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
return await locator._expect("to.have.class", { expectedText, isNot, timeout });
}, expected, options);
}
}
function toContainClass(locator, expected, options) {
if (Array.isArray(expected)) {
if (expected.some((e) => (0, import_utils.isRegExp)(e)))
throw new Error(`"expected" argument in toContainClass cannot contain RegExp values`);
return import_toEqual.toEqual.call(this, "toContainClass", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected);
return await locator._expect("to.contain.class.array", { expectedText, isNot, timeout });
}, expected, options);
} else {
if ((0, import_utils.isRegExp)(expected))
throw new Error(`"expected" argument in toContainClass cannot be a RegExp value`);
return import_toMatchText.toMatchText.call(this, "toContainClass", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
return await locator._expect("to.contain.class", { expectedText, isNot, timeout });
}, expected, options);
}
}
function toHaveCount(locator, expected, options) {
return import_toEqual.toEqual.call(this, "toHaveCount", locator, "Locator", async (isNot, timeout) => {
return await locator._expect("to.have.count", { expectedNumber: expected, isNot, timeout });
}, expected, options);
}
function toHaveCSS(locator, name, expected, options) {
return import_toMatchText.toMatchText.call(this, "toHaveCSS", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
return await locator._expect("to.have.css", { expressionArg: name, expectedText, isNot, timeout });
}, expected, options);
}
function toHaveId(locator, expected, options) {
return import_toMatchText.toMatchText.call(this, "toHaveId", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
return await locator._expect("to.have.id", { expectedText, isNot, timeout });
}, expected, options);
}
function toHaveJSProperty(locator, name, expected, options) {
return import_toEqual.toEqual.call(this, "toHaveJSProperty", locator, "Locator", async (isNot, timeout) => {
return await locator._expect("to.have.property", { expressionArg: name, expectedValue: expected, isNot, timeout });
}, expected, options);
}
function toHaveRole(locator, expected, options) {
if (!(0, import_utils.isString)(expected))
throw new Error(`"role" argument in toHaveRole must be a string`);
return import_toMatchText.toMatchText.call(this, "toHaveRole", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
return await locator._expect("to.have.role", { expectedText, isNot, timeout });
}, expected, options);
}
function toHaveText(locator, expected, options = {}) {
if (Array.isArray(expected)) {
return import_toEqual.toEqual.call(this, "toHaveText", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected, { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
return await locator._expect("to.have.text.array", { expectedText, isNot, useInnerText: options?.useInnerText, timeout });
}, expected, options);
} else {
return import_toMatchText.toMatchText.call(this, "toHaveText", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
return await locator._expect("to.have.text", { expectedText, isNot, useInnerText: options?.useInnerText, timeout });
}, expected, options);
}
}
function toHaveValue(locator, expected, options) {
return import_toMatchText.toMatchText.call(this, "toHaveValue", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
return await locator._expect("to.have.value", { expectedText, isNot, timeout });
}, expected, options);
}
function toHaveValues(locator, expected, options) {
return import_toEqual.toEqual.call(this, "toHaveValues", locator, "Locator", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected);
return await locator._expect("to.have.values", { expectedText, isNot, timeout });
}, expected, options);
}
function toHaveTitle(page, expected, options = {}) {
return import_toMatchText.toMatchText.call(this, "toHaveTitle", page, "Page", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { normalizeWhiteSpace: true });
return await page.mainFrame()._expect("to.have.title", { expectedText, isNot, timeout });
}, expected, options);
}
function toHaveURL(page, expected, options) {
if (typeof expected === "function")
return import_toHaveURL.toHaveURLWithPredicate.call(this, page, expected, options);
const baseURL = page.context()._options.baseURL;
expected = typeof expected === "string" ? (0, import_utils.constructURLBasedOnBaseURL)(baseURL, expected) : expected;
return import_toMatchText.toMatchText.call(this, "toHaveURL", page, "Page", async (isNot, timeout) => {
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase });
return await page.mainFrame()._expect("to.have.url", { expectedText, isNot, timeout });
}, expected, options);
}
async function toBeOK(response) {
const matcherName = "toBeOK";
(0, import_util.expectTypes)(response, ["APIResponse"], matcherName);
const contentType = response.headers()["content-type"];
const isTextEncoding = contentType && (0, import_utils.isTextualMimeType)(contentType);
const [log, text] = this.isNot === response.ok() ? await Promise.all([
response._fetchLog(),
isTextEncoding ? response.text() : null
]) : [];
const message = () => (0, import_matcherHint.formatMatcherMessage)(this, {
matcherName,
receiver: "response",
expectation: "",
log
}) + (text === null ? "" : `
Response text:
${import_utils2.colors.dim(text?.substring(0, 1e3) || "")}`);
const pass = response.ok();
return { message, pass };
}
async function toPass(callback, options = {}) {
const testInfo = (0, import_globals.currentTestInfo)();
const timeout = (0, import_config.takeFirst)(options.timeout, testInfo?._projectInternal.expect?.toPass?.timeout, 0);
const intervals = (0, import_config.takeFirst)(options.intervals, testInfo?._projectInternal.expect?.toPass?.intervals, [100, 250, 500, 1e3]);
const { deadline, timeoutMessage } = testInfo ? testInfo._deadlineForMatcher(timeout) : import_testInfo.TestInfoImpl._defaultDeadlineForMatcher(timeout);
const result = await (0, import_utils.pollAgainstDeadline)(async () => {
if (testInfo && (0, import_globals.currentTestInfo)() !== testInfo)
return { continuePolling: false, result: void 0 };
try {
await callback();
return { continuePolling: !!this.isNot, result: void 0 };
} catch (e) {
return { continuePolling: !this.isNot, result: e };
}
}, deadline, intervals);
if (result.timedOut) {
const message = result.result ? [
result.result.message,
"",
`Call Log:`,
`- ${timeoutMessage}`
].join("\n") : timeoutMessage;
return { message: () => message, pass: !!this.isNot };
}
return { pass: !this.isNot, message: () => "" };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toBeAttached,
toBeChecked,
toBeDisabled,
toBeEditable,
toBeEmpty,
toBeEnabled,
toBeFocused,
toBeHidden,
toBeInViewport,
toBeOK,
toBeVisible,
toContainClass,
toContainText,
toHaveAccessibleDescription,
toHaveAccessibleErrorMessage,
toHaveAccessibleName,
toHaveAttribute,
toHaveCSS,
toHaveClass,
toHaveCount,
toHaveId,
toHaveJSProperty,
toHaveRole,
toHaveText,
toHaveTitle,
toHaveURL,
toHaveValue,
toHaveValues,
toPass
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var toBeTruthy_exports = {};
__export(toBeTruthy_exports, {
toBeTruthy: () => toBeTruthy
});
module.exports = __toCommonJS(toBeTruthy_exports);
var import_util = require("../util");
var import_matcherHint = require("./matcherHint");
async function toBeTruthy(matcherName, locator, receiverType, expected, arg, query, options = {}) {
(0, import_util.expectTypes)(locator, [receiverType], matcherName);
const timeout = options.timeout ?? this.timeout;
const { matches: pass, log, timedOut, received, errorMessage } = await query(!!this.isNot, timeout);
if (pass === !this.isNot) {
return {
name: matcherName,
message: () => "",
pass,
expected
};
}
let printedReceived;
let printedExpected;
if (pass) {
printedExpected = `Expected: not ${expected}`;
printedReceived = errorMessage ? "" : `Received: ${expected}`;
} else {
printedExpected = `Expected: ${expected}`;
printedReceived = errorMessage ? "" : `Received: ${received}`;
}
const message = () => {
return (0, import_matcherHint.formatMatcherMessage)(this, {
matcherName,
expectation: arg,
locator,
timeout,
timedOut,
printedExpected,
printedReceived,
errorMessage,
log
});
};
return {
message,
pass,
actual: received,
name: matcherName,
expected,
log,
timeout: timedOut ? timeout : void 0
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toBeTruthy
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var toEqual_exports = {};
__export(toEqual_exports, {
toEqual: () => toEqual
});
module.exports = __toCommonJS(toEqual_exports);
var import_utils = require("playwright-core/lib/utils");
var import_util = require("../util");
var import_matcherHint = require("./matcherHint");
const EXPECTED_LABEL = "Expected";
const RECEIVED_LABEL = "Received";
async function toEqual(matcherName, locator, receiverType, query, expected, options = {}) {
(0, import_util.expectTypes)(locator, [receiverType], matcherName);
const timeout = options.timeout ?? this.timeout;
const { matches: pass, received, log, timedOut, errorMessage } = await query(!!this.isNot, timeout);
if (pass === !this.isNot) {
return {
name: matcherName,
message: () => "",
pass,
expected
};
}
let printedReceived;
let printedExpected;
let printedDiff;
if (pass) {
printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;
printedReceived = errorMessage ? "" : `Received: ${this.utils.printReceived(received)}`;
} else if (errorMessage) {
printedExpected = `Expected: ${this.utils.printExpected(expected)}`;
} else if (Array.isArray(expected) && Array.isArray(received)) {
const normalizedExpected = expected.map((exp, index) => {
const rec = received[index];
if ((0, import_utils.isRegExp)(exp))
return exp.test(rec) ? rec : exp;
return exp;
});
printedDiff = this.utils.printDiffOrStringify(
normalizedExpected,
received,
EXPECTED_LABEL,
RECEIVED_LABEL,
false
);
} else {
printedDiff = this.utils.printDiffOrStringify(
expected,
received,
EXPECTED_LABEL,
RECEIVED_LABEL,
false
);
}
const message = () => {
return (0, import_matcherHint.formatMatcherMessage)(this, {
matcherName,
expectation: "expected",
locator,
timeout,
timedOut,
printedExpected,
printedReceived,
printedDiff,
errorMessage,
log
});
};
return {
actual: received,
expected,
message,
name: matcherName,
pass,
log,
timeout: timedOut ? timeout : void 0
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toEqual
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var toHaveURL_exports = {};
__export(toHaveURL_exports, {
toHaveURLWithPredicate: () => toHaveURLWithPredicate
});
module.exports = __toCommonJS(toHaveURL_exports);
var import_utils = require("playwright-core/lib/utils");
var import_expect = require("./expect");
var import_matcherHint = require("./matcherHint");
var import_expectBundle = require("../common/expectBundle");
async function toHaveURLWithPredicate(page, expected, options) {
const matcherName = "toHaveURL";
const timeout = options?.timeout ?? this.timeout;
const baseURL = page.context()._options.baseURL;
let conditionSucceeded = false;
let lastCheckedURLString = void 0;
try {
await page.mainFrame().waitForURL(
(url) => {
lastCheckedURLString = url.toString();
if (options?.ignoreCase) {
return !this.isNot === (0, import_utils.urlMatches)(
baseURL?.toLocaleLowerCase(),
lastCheckedURLString.toLocaleLowerCase(),
expected
);
}
return !this.isNot === (0, import_utils.urlMatches)(baseURL, lastCheckedURLString, expected);
},
{ timeout }
);
conditionSucceeded = true;
} catch (e) {
conditionSucceeded = false;
}
if (conditionSucceeded)
return { name: matcherName, pass: !this.isNot, message: () => "" };
return {
name: matcherName,
pass: this.isNot,
message: () => toHaveURLMessage(
this,
matcherName,
expected,
lastCheckedURLString,
this.isNot,
true,
timeout
),
actual: lastCheckedURLString,
timeout
};
}
function toHaveURLMessage(state, matcherName, expected, received, pass, timedOut, timeout) {
const receivedString = received || "";
let printedReceived;
let printedExpected;
let printedDiff;
if (typeof expected === "function") {
printedExpected = `Expected: predicate to ${!state.isNot ? "succeed" : "fail"}`;
printedReceived = `Received: ${(0, import_expectBundle.printReceived)(receivedString)}`;
} else {
if (pass) {
printedExpected = `Expected pattern: not ${state.utils.printExpected(expected)}`;
const formattedReceived = (0, import_expect.printReceivedStringContainExpectedResult)(receivedString, null);
printedReceived = `Received string: ${formattedReceived}`;
} else {
const labelExpected = `Expected ${typeof expected === "string" ? "string" : "pattern"}`;
printedDiff = state.utils.printDiffOrStringify(expected, receivedString, labelExpected, "Received string", false);
}
}
return (0, import_matcherHint.formatMatcherMessage)(state, {
matcherName,
expectation: "expected",
timeout,
timedOut,
printedExpected,
printedReceived,
printedDiff
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toHaveURLWithPredicate
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var toMatchAriaSnapshot_exports = {};
__export(toMatchAriaSnapshot_exports, {
toMatchAriaSnapshot: () => toMatchAriaSnapshot
});
module.exports = __toCommonJS(toMatchAriaSnapshot_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_matcherHint = require("./matcherHint");
var import_util = require("../util");
var import_expect = require("./expect");
var import_globals = require("../common/globals");
async function toMatchAriaSnapshot(locator, expectedParam, options = {}) {
const matcherName = "toMatchAriaSnapshot";
const testInfo = (0, import_globals.currentTestInfo)();
if (!testInfo)
throw new Error(`toMatchAriaSnapshot() must be called during the test`);
if (testInfo._projectInternal.ignoreSnapshots)
return { pass: !this.isNot, message: () => "", name: "toMatchAriaSnapshot", expected: "" };
const updateSnapshots = testInfo.config.updateSnapshots;
let expected;
let timeout;
let expectedPath;
if ((0, import_utils.isString)(expectedParam)) {
expected = expectedParam;
timeout = options.timeout ?? this.timeout;
} else {
const legacyPath = testInfo._resolveSnapshotPaths("aria", expectedParam?.name, "dontUpdateSnapshotIndex", ".yml").absoluteSnapshotPath;
expectedPath = testInfo._resolveSnapshotPaths("aria", expectedParam?.name, "updateSnapshotIndex").absoluteSnapshotPath;
if (!await (0, import_util.fileExistsAsync)(expectedPath) && await (0, import_util.fileExistsAsync)(legacyPath))
expectedPath = legacyPath;
expected = await import_fs.default.promises.readFile(expectedPath, "utf8").catch(() => "");
timeout = expectedParam?.timeout ?? this.timeout;
}
const generateMissingBaseline = updateSnapshots === "missing" && !expected;
if (generateMissingBaseline) {
if (this.isNot) {
const message2 = `Matchers using ".not" can't generate new baselines`;
return { pass: this.isNot, message: () => message2, name: "toMatchAriaSnapshot" };
} else {
expected = `- none "Generating new baseline"`;
}
}
expected = unshift(expected);
const { matches: pass, received, log, timedOut, errorMessage } = await locator._expect("to.match.aria", { expectedValue: expected, isNot: this.isNot, timeout });
const typedReceived = received;
const message = () => {
let printedExpected;
let printedReceived;
let printedDiff;
if (errorMessage) {
printedExpected = `Expected: ${this.isNot ? "not " : ""}${this.utils.printExpected(expected)}`;
} else if (pass) {
const receivedString = (0, import_expect.printReceivedStringContainExpectedSubstring)(typedReceived.raw, typedReceived.raw.indexOf(expected), expected.length);
printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;
printedReceived = `Received: ${receivedString}`;
} else {
printedDiff = this.utils.printDiffOrStringify(expected, typedReceived.raw, "Expected", "Received", false);
}
return (0, import_matcherHint.formatMatcherMessage)(this, {
matcherName,
expectation: "expected",
locator,
timeout,
timedOut,
printedExpected,
printedReceived,
printedDiff,
errorMessage,
log
});
};
if (errorMessage)
return { pass: this.isNot, message, name: "toMatchAriaSnapshot", expected };
if (!this.isNot) {
if (updateSnapshots === "all" || updateSnapshots === "changed" && pass === this.isNot || generateMissingBaseline) {
if (expectedPath) {
await import_fs.default.promises.mkdir(import_path.default.dirname(expectedPath), { recursive: true });
await import_fs.default.promises.writeFile(expectedPath, typedReceived.regex, "utf8");
const relativePath = import_path.default.relative(process.cwd(), expectedPath);
if (updateSnapshots === "missing") {
const message2 = `A snapshot doesn't exist at ${relativePath}, writing actual.`;
testInfo._hasNonRetriableError = true;
testInfo._failWithError(new Error(message2));
} else {
const message2 = `A snapshot is generated at ${relativePath}.`;
console.log(message2);
}
return { pass: true, message: () => "", name: "toMatchAriaSnapshot" };
} else {
const suggestedRebaseline = `\`
${(0, import_utils.escapeTemplateString)(indent(typedReceived.regex, "{indent} "))}
{indent}\``;
if (updateSnapshots === "missing") {
const message2 = "A snapshot is not provided, generating new baseline.";
testInfo._hasNonRetriableError = true;
testInfo._failWithError(new Error(message2));
}
return { pass: false, message: () => "", name: "toMatchAriaSnapshot", suggestedRebaseline };
}
}
}
return {
name: matcherName,
expected,
message,
pass,
actual: received,
log,
timeout: timedOut ? timeout : void 0
};
}
function unshift(snapshot) {
const lines = snapshot.split("\n");
let whitespacePrefixLength = 100;
for (const line of lines) {
if (!line.trim())
continue;
const match = line.match(/^(\s*)/);
if (match && match[1].length < whitespacePrefixLength)
whitespacePrefixLength = match[1].length;
}
return lines.filter((t) => t.trim()).map((line) => line.substring(whitespacePrefixLength)).join("\n");
}
function indent(snapshot, indent2) {
return snapshot.split("\n").map((line) => indent2 + line).join("\n");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toMatchAriaSnapshot
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var toMatchSnapshot_exports = {};
__export(toMatchSnapshot_exports, {
toHaveScreenshot: () => toHaveScreenshot,
toHaveScreenshotStepTitle: () => toHaveScreenshotStepTitle,
toMatchSnapshot: () => toMatchSnapshot
});
module.exports = __toCommonJS(toMatchSnapshot_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_util = require("../util");
var import_matcherHint = require("./matcherHint");
var import_globals = require("../common/globals");
const NonConfigProperties = [
"clip",
"fullPage",
"mask",
"maskColor",
"omitBackground",
"timeout"
];
class SnapshotHelper {
constructor(testInfo, matcherName, locator, anonymousSnapshotExtension, configOptions, nameOrOptions, optOptions) {
let name;
if (Array.isArray(nameOrOptions) || typeof nameOrOptions === "string") {
name = nameOrOptions;
this.options = { ...optOptions };
} else {
const { name: nameFromOptions, ...options } = nameOrOptions;
this.options = options;
name = nameFromOptions;
}
this.name = Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
const resolvedPaths = testInfo._resolveSnapshotPaths(matcherName === "toHaveScreenshot" ? "screenshot" : "snapshot", name, "updateSnapshotIndex", anonymousSnapshotExtension);
this.expectedPath = resolvedPaths.absoluteSnapshotPath;
this.attachmentBaseName = resolvedPaths.relativeOutputPath;
const outputBasePath = testInfo._getOutputPath(resolvedPaths.relativeOutputPath);
this.legacyExpectedPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-expected");
this.previousPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-previous");
this.actualPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-actual");
this.diffPath = (0, import_util.addSuffixToFilePath)(outputBasePath, "-diff");
const filteredConfigOptions = { ...configOptions };
for (const prop of NonConfigProperties)
delete filteredConfigOptions[prop];
this.options = {
...filteredConfigOptions,
...this.options
};
if (this.options._comparator) {
this.options.comparator = this.options._comparator;
delete this.options._comparator;
}
if (this.options.maxDiffPixels !== void 0 && this.options.maxDiffPixels < 0)
throw new Error("`maxDiffPixels` option value must be non-negative integer");
if (this.options.maxDiffPixelRatio !== void 0 && (this.options.maxDiffPixelRatio < 0 || this.options.maxDiffPixelRatio > 1))
throw new Error("`maxDiffPixelRatio` option value must be between 0 and 1");
this.matcherName = matcherName;
this.locator = locator;
this.updateSnapshots = testInfo.config.updateSnapshots;
this.mimeType = import_utilsBundle.mime.getType(import_path.default.basename(this.expectedPath)) ?? "application/octet-stream";
this.comparator = (0, import_utils.getComparator)(this.mimeType);
this.testInfo = testInfo;
this.kind = this.mimeType.startsWith("image/") ? "Screenshot" : "Snapshot";
}
createMatcherResult(message, pass, log) {
const unfiltered = {
name: this.matcherName,
expected: this.expectedPath,
actual: this.actualPath,
diff: this.diffPath,
pass,
message: () => message,
log
};
return Object.fromEntries(Object.entries(unfiltered).filter(([_, v]) => v !== void 0));
}
handleMissingNegated() {
const isWriteMissingMode = this.updateSnapshots !== "none";
const message = `A snapshot doesn't exist at ${this.expectedPath}${isWriteMissingMode ? `, matchers using ".not" won't write them automatically.` : "."}`;
return this.createMatcherResult(message, true);
}
handleDifferentNegated() {
return this.createMatcherResult("", false);
}
handleMatchingNegated() {
const message = [
import_utils2.colors.red(`${this.kind} comparison failed:`),
"",
indent("Expected result should be different from the actual one.", " ")
].join("\n");
return this.createMatcherResult(message, true);
}
handleMissing(actual, step) {
const isWriteMissingMode = this.updateSnapshots !== "none";
if (isWriteMissingMode)
writeFileSync(this.expectedPath, actual);
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-expected"), contentType: this.mimeType, path: this.expectedPath });
writeFileSync(this.actualPath, actual);
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-actual"), contentType: this.mimeType, path: this.actualPath });
const message = `A snapshot doesn't exist at ${this.expectedPath}${isWriteMissingMode ? ", writing actual." : "."}`;
if (this.updateSnapshots === "all" || this.updateSnapshots === "changed") {
console.log(message);
return this.createMatcherResult(message, true);
}
if (this.updateSnapshots === "missing") {
this.testInfo._hasNonRetriableError = true;
this.testInfo._failWithError(new Error(message));
return this.createMatcherResult("", true);
}
return this.createMatcherResult(message, false);
}
handleDifferent(actual, expected, previous, diff, header, diffError, log, step) {
const output = [`${header}${indent(diffError, " ")}`];
if (this.name) {
output.push("");
output.push(` Snapshot: ${this.name}`);
}
if (expected !== void 0) {
writeFileSync(this.legacyExpectedPath, expected);
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-expected"), contentType: this.mimeType, path: this.expectedPath });
}
if (previous !== void 0) {
writeFileSync(this.previousPath, previous);
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-previous"), contentType: this.mimeType, path: this.previousPath });
}
if (actual !== void 0) {
writeFileSync(this.actualPath, actual);
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-actual"), contentType: this.mimeType, path: this.actualPath });
}
if (diff !== void 0) {
writeFileSync(this.diffPath, diff);
step?._attachToStep({ name: (0, import_util.addSuffixToFilePath)(this.attachmentBaseName, "-diff"), contentType: this.mimeType, path: this.diffPath });
}
if (log?.length)
output.push((0, import_matcherHint.callLogText)(log));
else
output.push("");
return this.createMatcherResult(output.join("\n"), false, log);
}
handleMatching() {
return this.createMatcherResult("", true);
}
}
function toMatchSnapshot(received, nameOrOptions = {}, optOptions = {}) {
const testInfo = (0, import_globals.currentTestInfo)();
if (!testInfo)
throw new Error(`toMatchSnapshot() must be called during the test`);
if (received instanceof Promise)
throw new Error("An unresolved Promise was passed to toMatchSnapshot(), make sure to resolve it by adding await to it.");
if (testInfo._projectInternal.ignoreSnapshots)
return { pass: !this.isNot, message: () => "", name: "toMatchSnapshot", expected: nameOrOptions };
const configOptions = testInfo._projectInternal.expect?.toMatchSnapshot || {};
const helper = new SnapshotHelper(
testInfo,
"toMatchSnapshot",
void 0,
"." + determineFileExtension(received),
configOptions,
nameOrOptions,
optOptions
);
if (this.isNot) {
if (!import_fs.default.existsSync(helper.expectedPath))
return helper.handleMissingNegated();
const isDifferent = !!helper.comparator(received, import_fs.default.readFileSync(helper.expectedPath), helper.options);
return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
}
if (!import_fs.default.existsSync(helper.expectedPath))
return helper.handleMissing(received, this._stepInfo);
const expected = import_fs.default.readFileSync(helper.expectedPath);
if (helper.updateSnapshots === "all") {
if (!(0, import_utils.compareBuffersOrStrings)(received, expected))
return helper.handleMatching();
writeFileSync(helper.expectedPath, received);
console.log(helper.expectedPath + " is not the same, writing actual.");
return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
}
if (helper.updateSnapshots === "changed") {
const result2 = helper.comparator(received, expected, helper.options);
if (!result2)
return helper.handleMatching();
writeFileSync(helper.expectedPath, received);
console.log(helper.expectedPath + " does not match, writing actual.");
return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
}
const result = helper.comparator(received, expected, helper.options);
if (!result)
return helper.handleMatching();
const header = (0, import_matcherHint.formatMatcherMessage)(this, { matcherName: "toMatchSnapshot", receiver: (0, import_utils.isString)(received) ? "string" : "Buffer", expectation: "expected" });
return helper.handleDifferent(received, expected, void 0, result.diff, header, result.errorMessage, void 0, this._stepInfo);
}
function toHaveScreenshotStepTitle(nameOrOptions = {}, optOptions = {}) {
let name;
if (typeof nameOrOptions === "object" && !Array.isArray(nameOrOptions))
name = nameOrOptions.name;
else
name = nameOrOptions;
return Array.isArray(name) ? name.join(import_path.default.sep) : name || "";
}
async function toHaveScreenshot(pageOrLocator, nameOrOptions = {}, optOptions = {}) {
const testInfo = (0, import_globals.currentTestInfo)();
if (!testInfo)
throw new Error(`toHaveScreenshot() must be called during the test`);
if (testInfo._projectInternal.ignoreSnapshots)
return { pass: !this.isNot, message: () => "", name: "toHaveScreenshot", expected: nameOrOptions };
(0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
const [page, locator] = pageOrLocator.constructor.name === "Page" ? [pageOrLocator, void 0] : [pageOrLocator.page(), pageOrLocator];
const configOptions = testInfo._projectInternal.expect?.toHaveScreenshot || {};
const helper = new SnapshotHelper(testInfo, "toHaveScreenshot", locator, void 0, configOptions, nameOrOptions, optOptions);
if (!helper.expectedPath.toLowerCase().endsWith(".png"))
throw new Error(`Screenshot name "${import_path.default.basename(helper.expectedPath)}" must have '.png' extension`);
(0, import_util.expectTypes)(pageOrLocator, ["Page", "Locator"], "toHaveScreenshot");
const style = await loadScreenshotStyles(helper.options.stylePath);
const timeout = helper.options.timeout ?? this.timeout;
const expectScreenshotOptions = {
locator,
animations: helper.options.animations ?? "disabled",
caret: helper.options.caret ?? "hide",
clip: helper.options.clip,
fullPage: helper.options.fullPage,
mask: helper.options.mask,
maskColor: helper.options.maskColor,
omitBackground: helper.options.omitBackground,
scale: helper.options.scale ?? "css",
style,
isNot: !!this.isNot,
timeout,
comparator: helper.options.comparator,
maxDiffPixels: helper.options.maxDiffPixels,
maxDiffPixelRatio: helper.options.maxDiffPixelRatio,
threshold: helper.options.threshold
};
const hasSnapshot = import_fs.default.existsSync(helper.expectedPath);
if (this.isNot) {
if (!hasSnapshot)
return helper.handleMissingNegated();
expectScreenshotOptions.expected = await import_fs.default.promises.readFile(helper.expectedPath);
const isDifferent = !(await page._expectScreenshot(expectScreenshotOptions)).errorMessage;
return isDifferent ? helper.handleDifferentNegated() : helper.handleMatchingNegated();
}
if (helper.updateSnapshots === "none" && !hasSnapshot)
return helper.createMatcherResult(`A snapshot doesn't exist at ${helper.expectedPath}.`, false);
if (!hasSnapshot) {
const { actual: actual2, previous: previous2, diff: diff2, errorMessage: errorMessage2, log: log2, timedOut: timedOut2 } = await page._expectScreenshot(expectScreenshotOptions);
if (errorMessage2) {
const header2 = (0, import_matcherHint.formatMatcherMessage)(this, { matcherName: "toHaveScreenshot", locator, expectation: "expected", timeout, timedOut: timedOut2 });
return helper.handleDifferent(actual2, void 0, previous2, diff2, header2, errorMessage2, log2, this._stepInfo);
}
return helper.handleMissing(actual2, this._stepInfo);
}
const expected = await import_fs.default.promises.readFile(helper.expectedPath);
expectScreenshotOptions.expected = helper.updateSnapshots === "all" ? void 0 : expected;
const { actual, previous, diff, errorMessage, log, timedOut } = await page._expectScreenshot(expectScreenshotOptions);
const writeFiles = (actualBuffer) => {
writeFileSync(helper.expectedPath, actualBuffer);
writeFileSync(helper.actualPath, actualBuffer);
console.log(helper.expectedPath + " is re-generated, writing actual.");
return helper.createMatcherResult(helper.expectedPath + " running with --update-snapshots, writing actual.", true);
};
if (!errorMessage) {
if (helper.updateSnapshots === "all" && actual && (0, import_utils.compareBuffersOrStrings)(actual, expected)) {
console.log(helper.expectedPath + " is re-generated, writing actual.");
return writeFiles(actual);
}
return helper.handleMatching();
}
if (helper.updateSnapshots === "changed" || helper.updateSnapshots === "all") {
if (actual)
return writeFiles(actual);
let header2 = (0, import_matcherHint.formatMatcherMessage)(this, { matcherName: "toHaveScreenshot", locator, expectation: "expected", timeout, timedOut });
header2 += " Failed to re-generate expected.\n";
return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header2, errorMessage, log, this._stepInfo);
}
const header = (0, import_matcherHint.formatMatcherMessage)(this, { matcherName: "toHaveScreenshot", locator, expectation: "expected", timeout, timedOut });
return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header, errorMessage, log, this._stepInfo);
}
function writeFileSync(aPath, content) {
import_fs.default.mkdirSync(import_path.default.dirname(aPath), { recursive: true });
import_fs.default.writeFileSync(aPath, content);
}
function indent(lines, tab) {
return lines.replace(/^(?=.+$)/gm, tab);
}
function determineFileExtension(file) {
if (typeof file === "string")
return "txt";
if (compareMagicBytes(file, [137, 80, 78, 71, 13, 10, 26, 10]))
return "png";
if (compareMagicBytes(file, [255, 216, 255]))
return "jpg";
return "dat";
}
function compareMagicBytes(file, magicBytes) {
return Buffer.compare(Buffer.from(magicBytes), file.slice(0, magicBytes.length)) === 0;
}
async function loadScreenshotStyles(stylePath) {
if (!stylePath)
return;
const stylePaths = Array.isArray(stylePath) ? stylePath : [stylePath];
const styles = await Promise.all(stylePaths.map(async (stylePath2) => {
const text = await import_fs.default.promises.readFile(stylePath2, "utf8");
return text.trim();
}));
return styles.join("\n").trim() || void 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toHaveScreenshot,
toHaveScreenshotStepTitle,
toMatchSnapshot
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var toMatchText_exports = {};
__export(toMatchText_exports, {
toMatchText: () => toMatchText
});
module.exports = __toCommonJS(toMatchText_exports);
var import_util = require("../util");
var import_expect = require("./expect");
var import_matcherHint = require("./matcherHint");
var import_expectBundle = require("../common/expectBundle");
async function toMatchText(matcherName, receiver, receiverType, query, expected, options = {}) {
(0, import_util.expectTypes)(receiver, [receiverType], matcherName);
const locator = receiverType === "Locator" ? receiver : void 0;
if (!(typeof expected === "string") && !(expected && typeof expected.test === "function")) {
const errorMessage2 = `Error: ${(0, import_expectBundle.EXPECTED_COLOR)("expected")} value must be a string or regular expression
${this.utils.printWithType("Expected", expected, this.utils.printExpected)}`;
throw new Error((0, import_matcherHint.formatMatcherMessage)(this, { locator, matcherName, expectation: "expected", errorMessage: errorMessage2 }));
}
const timeout = options.timeout ?? this.timeout;
const { matches: pass, received, log, timedOut, errorMessage } = await query(!!this.isNot, timeout);
if (pass === !this.isNot) {
return {
name: matcherName,
message: () => "",
pass,
expected
};
}
const expectedSuffix = typeof expected === "string" ? options.matchSubstring ? " substring" : "" : " pattern";
const receivedSuffix = typeof expected === "string" ? options.matchSubstring ? " string" : "" : " string";
const receivedString = received || "";
let printedReceived;
let printedExpected;
let printedDiff;
if (pass) {
if (typeof expected === "string") {
printedExpected = `Expected${expectedSuffix}: not ${this.utils.printExpected(expected)}`;
if (!errorMessage) {
const formattedReceived = (0, import_expect.printReceivedStringContainExpectedSubstring)(receivedString, receivedString.indexOf(expected), expected.length);
printedReceived = `Received${receivedSuffix}: ${formattedReceived}`;
}
} else {
printedExpected = `Expected${expectedSuffix}: not ${this.utils.printExpected(expected)}`;
if (!errorMessage) {
const formattedReceived = (0, import_expect.printReceivedStringContainExpectedResult)(receivedString, typeof expected.exec === "function" ? expected.exec(receivedString) : null);
printedReceived = `Received${receivedSuffix}: ${formattedReceived}`;
}
}
} else {
if (errorMessage)
printedExpected = `Expected${expectedSuffix}: ${this.utils.printExpected(expected)}`;
else
printedDiff = this.utils.printDiffOrStringify(expected, receivedString, `Expected${expectedSuffix}`, `Received${receivedSuffix}`, false);
}
const message = () => {
return (0, import_matcherHint.formatMatcherMessage)(this, {
matcherName,
expectation: "expected",
locator,
timeout,
timedOut,
printedExpected,
printedReceived,
printedDiff,
log,
errorMessage
});
};
return {
name: matcherName,
expected,
message,
pass,
actual: received,
log,
timeout: timedOut ? timeout : void 0
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toMatchText
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var actions_d_exports = {};
module.exports = __toCommonJS(actions_d_exports);
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var browserContextFactory_exports = {};
__export(browserContextFactory_exports, {
SharedContextFactory: () => SharedContextFactory,
contextFactory: () => contextFactory
});
module.exports = __toCommonJS(browserContextFactory_exports);
var import_crypto = __toESM(require("crypto"));
var import_fs = __toESM(require("fs"));
var import_net = __toESM(require("net"));
var import_path = __toESM(require("path"));
var playwright = __toESM(require("playwright-core"));
var import_registry = require("playwright-core/lib/server/registry/index");
var import_server = require("playwright-core/lib/server");
var import_log = require("../log");
var import_config = require("./config");
var import_server2 = require("../sdk/server");
function contextFactory(config) {
if (config.sharedBrowserContext)
return SharedContextFactory.create(config);
if (config.browser.remoteEndpoint)
return new RemoteContextFactory(config);
if (config.browser.cdpEndpoint)
return new CdpContextFactory(config);
if (config.browser.isolated)
return new IsolatedContextFactory(config);
return new PersistentContextFactory(config);
}
class BaseContextFactory {
constructor(name, config) {
this._logName = name;
this.config = config;
}
async _obtainBrowser(clientInfo) {
if (this._browserPromise)
return this._browserPromise;
(0, import_log.testDebug)(`obtain browser (${this._logName})`);
this._browserPromise = this._doObtainBrowser(clientInfo);
void this._browserPromise.then((browser) => {
browser.on("disconnected", () => {
this._browserPromise = void 0;
});
}).catch(() => {
this._browserPromise = void 0;
});
return this._browserPromise;
}
async _doObtainBrowser(clientInfo) {
throw new Error("Not implemented");
}
async createContext(clientInfo) {
(0, import_log.testDebug)(`create browser context (${this._logName})`);
const browser = await this._obtainBrowser(clientInfo);
const browserContext = await this._doCreateContext(browser);
await addInitScript(browserContext, this.config.browser.initScript);
return {
browserContext,
close: (afterClose) => this._closeBrowserContext(browserContext, browser, afterClose)
};
}
async _doCreateContext(browser) {
throw new Error("Not implemented");
}
async _closeBrowserContext(browserContext, browser, afterClose) {
(0, import_log.testDebug)(`close browser context (${this._logName})`);
if (browser.contexts().length === 1)
this._browserPromise = void 0;
await browserContext.close().catch(import_log.logUnhandledError);
await afterClose();
if (browser.contexts().length === 0) {
(0, import_log.testDebug)(`close browser (${this._logName})`);
await browser.close().catch(import_log.logUnhandledError);
}
}
}
class IsolatedContextFactory extends BaseContextFactory {
constructor(config) {
super("isolated", config);
}
async _doObtainBrowser(clientInfo) {
await injectCdpPort(this.config.browser);
const browserType = playwright[this.config.browser.browserName];
const tracesDir = await computeTracesDir(this.config, clientInfo);
if (tracesDir && this.config.saveTrace)
await startTraceServer(this.config, tracesDir);
return browserType.launch({
tracesDir,
...this.config.browser.launchOptions,
handleSIGINT: false,
handleSIGTERM: false
}).catch((error) => {
if (error.message.includes("Executable doesn't exist"))
throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`);
throw error;
});
}
async _doCreateContext(browser) {
return browser.newContext(this.config.browser.contextOptions);
}
}
class CdpContextFactory extends BaseContextFactory {
constructor(config) {
super("cdp", config);
}
async _doObtainBrowser() {
return playwright.chromium.connectOverCDP(this.config.browser.cdpEndpoint, { headers: this.config.browser.cdpHeaders });
}
async _doCreateContext(browser) {
return this.config.browser.isolated ? await browser.newContext() : browser.contexts()[0];
}
}
class RemoteContextFactory extends BaseContextFactory {
constructor(config) {
super("remote", config);
}
async _doObtainBrowser() {
const url = new URL(this.config.browser.remoteEndpoint);
url.searchParams.set("browser", this.config.browser.browserName);
if (this.config.browser.launchOptions)
url.searchParams.set("launch-options", JSON.stringify(this.config.browser.launchOptions));
return playwright[this.config.browser.browserName].connect(String(url));
}
async _doCreateContext(browser) {
return browser.newContext();
}
}
class PersistentContextFactory {
constructor(config) {
this.name = "persistent";
this.description = "Create a new persistent browser context";
this._userDataDirs = /* @__PURE__ */ new Set();
this.config = config;
}
async createContext(clientInfo) {
await injectCdpPort(this.config.browser);
(0, import_log.testDebug)("create browser context (persistent)");
const userDataDir = this.config.browser.userDataDir ?? await this._createUserDataDir(clientInfo);
const tracesDir = await computeTracesDir(this.config, clientInfo);
if (tracesDir && this.config.saveTrace)
await startTraceServer(this.config, tracesDir);
this._userDataDirs.add(userDataDir);
(0, import_log.testDebug)("lock user data dir", userDataDir);
const browserType = playwright[this.config.browser.browserName];
for (let i = 0; i < 5; i++) {
const launchOptions = {
tracesDir,
...this.config.browser.launchOptions,
...this.config.browser.contextOptions,
handleSIGINT: false,
handleSIGTERM: false,
ignoreDefaultArgs: [
"--disable-extensions"
],
assistantMode: true
};
try {
const browserContext = await browserType.launchPersistentContext(userDataDir, launchOptions);
await addInitScript(browserContext, this.config.browser.initScript);
const close = (afterClose) => this._closeBrowserContext(browserContext, userDataDir, afterClose);
return { browserContext, close };
} catch (error) {
if (error.message.includes("Executable doesn't exist"))
throw new Error(`Browser specified in your config is not installed. Either install it (likely) or change the config.`);
if (error.message.includes("ProcessSingleton") || error.message.includes("Invalid URL")) {
await new Promise((resolve) => setTimeout(resolve, 1e3));
continue;
}
throw error;
}
}
throw new Error(`Browser is already in use for ${userDataDir}, use --isolated to run multiple instances of the same browser`);
}
async _closeBrowserContext(browserContext, userDataDir, afterClose) {
(0, import_log.testDebug)("close browser context (persistent)");
(0, import_log.testDebug)("release user data dir", userDataDir);
await browserContext.close().catch(() => {
});
await afterClose();
this._userDataDirs.delete(userDataDir);
(0, import_log.testDebug)("close browser context complete (persistent)");
}
async _createUserDataDir(clientInfo) {
const dir = process.env.PWMCP_PROFILES_DIR_FOR_TEST ?? import_registry.registryDirectory;
const browserToken = this.config.browser.launchOptions?.channel ?? this.config.browser?.browserName;
const rootPath = (0, import_server2.firstRootPath)(clientInfo);
const rootPathToken = rootPath ? `-${createHash(rootPath)}` : "";
const result = import_path.default.join(dir, `mcp-${browserToken}${rootPathToken}`);
await import_fs.default.promises.mkdir(result, { recursive: true });
return result;
}
}
async function injectCdpPort(browserConfig) {
if (browserConfig.browserName === "chromium")
browserConfig.launchOptions.cdpPort = await findFreePort();
}
async function findFreePort() {
return new Promise((resolve, reject) => {
const server = import_net.default.createServer();
server.listen(0, () => {
const { port } = server.address();
server.close(() => resolve(port));
});
server.on("error", reject);
});
}
async function startTraceServer(config, tracesDir) {
if (!config.saveTrace)
return;
const server = await (0, import_server.startTraceViewerServer)();
const urlPrefix = server.urlPrefix("human-readable");
const url = urlPrefix + "/trace/index.html?trace=" + tracesDir + "/trace.json";
console.error("\nTrace viewer listening on " + url);
}
function createHash(data) {
return import_crypto.default.createHash("sha256").update(data).digest("hex").slice(0, 7);
}
async function addInitScript(browserContext, initScript) {
for (const scriptPath of initScript ?? [])
await browserContext.addInitScript({ path: import_path.default.resolve(scriptPath) });
}
class SharedContextFactory {
static create(config) {
if (SharedContextFactory._instance)
throw new Error("SharedContextFactory already exists");
const baseConfig = { ...config, sharedBrowserContext: false };
const baseFactory = contextFactory(baseConfig);
SharedContextFactory._instance = new SharedContextFactory(baseFactory);
return SharedContextFactory._instance;
}
constructor(baseFactory) {
this._baseFactory = baseFactory;
}
async createContext(clientInfo, abortSignal, toolName) {
if (!this._contextPromise) {
(0, import_log.testDebug)("create shared browser context");
this._contextPromise = this._baseFactory.createContext(clientInfo, abortSignal, toolName);
}
const { browserContext } = await this._contextPromise;
(0, import_log.testDebug)(`shared context client connected`);
return {
browserContext,
close: async () => {
(0, import_log.testDebug)(`shared context client disconnected`);
}
};
}
static async dispose() {
await SharedContextFactory._instance?._dispose();
}
async _dispose() {
const contextPromise = this._contextPromise;
this._contextPromise = void 0;
if (!contextPromise)
return;
const { close } = await contextPromise;
await close(async () => {
});
}
}
async function computeTracesDir(config, clientInfo) {
if (!config.saveTrace && !config.capabilities?.includes("tracing"))
return;
return await (0, import_config.outputFile)(config, clientInfo, `traces`, { origin: "code", reason: "Collecting trace" });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
SharedContextFactory,
contextFactory
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var browserServerBackend_exports = {};
__export(browserServerBackend_exports, {
BrowserServerBackend: () => BrowserServerBackend
});
module.exports = __toCommonJS(browserServerBackend_exports);
var import_context = require("./context");
var import_log = require("../log");
var import_response = require("./response");
var import_sessionLog = require("./sessionLog");
var import_tools = require("./tools");
var import_tool = require("../sdk/tool");
class BrowserServerBackend {
constructor(config, factory) {
this._config = config;
this._browserContextFactory = factory;
this._tools = (0, import_tools.filteredTools)(config);
}
async initialize(server, clientInfo) {
this._sessionLog = this._config.saveSession ? await import_sessionLog.SessionLog.create(this._config, clientInfo) : void 0;
this._context = new import_context.Context({
config: this._config,
browserContextFactory: this._browserContextFactory,
sessionLog: this._sessionLog,
clientInfo
});
}
async listTools() {
return this._tools.map((tool) => (0, import_tool.toMcpTool)(tool.schema));
}
async callTool(name, rawArguments) {
const tool = this._tools.find((tool2) => tool2.schema.name === name);
if (!tool)
throw new Error(`Tool "${name}" not found`);
const parsedArguments = tool.schema.inputSchema.parse(rawArguments || {});
const context = this._context;
const response = new import_response.Response(context, name, parsedArguments);
response.logBegin();
context.setRunningTool(name);
try {
await tool.handle(context, parsedArguments, response);
await response.finish();
this._sessionLog?.logResponse(response);
} catch (error) {
response.addError(String(error));
} finally {
context.setRunningTool(void 0);
}
response.logEnd();
return response.serialize();
}
serverClosed() {
void this._context?.dispose().catch(import_log.logUnhandledError);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BrowserServerBackend
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var codegen_exports = {};
__export(codegen_exports, {
escapeWithQuotes: () => escapeWithQuotes,
formatObject: () => formatObject,
quote: () => quote
});
module.exports = __toCommonJS(codegen_exports);
function escapeWithQuotes(text, char = "'") {
const stringified = JSON.stringify(text);
const escapedText = stringified.substring(1, stringified.length - 1).replace(/\\"/g, '"');
if (char === "'")
return char + escapedText.replace(/[']/g, "\\'") + char;
if (char === '"')
return char + escapedText.replace(/["]/g, '\\"') + char;
if (char === "`")
return char + escapedText.replace(/[`]/g, "\\`") + char;
throw new Error("Invalid escape char");
}
function quote(text) {
return escapeWithQuotes(text, "'");
}
function formatObject(value, indent = " ", mode = "multiline") {
if (typeof value === "string")
return quote(value);
if (Array.isArray(value))
return `[${value.map((o) => formatObject(o)).join(", ")}]`;
if (typeof value === "object") {
const keys = Object.keys(value).filter((key) => value[key] !== void 0).sort();
if (!keys.length)
return "{}";
const tokens = [];
for (const key of keys)
tokens.push(`${key}: ${formatObject(value[key])}`);
if (mode === "multiline")
return `{
${tokens.join(`,
${indent}`)}
}`;
return `{ ${tokens.join(", ")} }`;
}
return String(value);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
escapeWithQuotes,
formatObject,
quote
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var config_exports = {};
__export(config_exports, {
commaSeparatedList: () => commaSeparatedList,
configFromCLIOptions: () => configFromCLIOptions,
defaultConfig: () => defaultConfig,
dotenvFileLoader: () => dotenvFileLoader,
headerParser: () => headerParser,
numberParser: () => numberParser,
outputDir: () => outputDir,
outputFile: () => outputFile,
resolutionParser: () => resolutionParser,
resolveCLIConfig: () => resolveCLIConfig,
resolveConfig: () => resolveConfig,
semicolonSeparatedList: () => semicolonSeparatedList
});
module.exports = __toCommonJS(config_exports);
var import_fs = __toESM(require("fs"));
var import_os = __toESM(require("os"));
var import_path = __toESM(require("path"));
var import_playwright_core = require("playwright-core");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_util = require("../../util");
var import_server = require("../sdk/server");
const defaultConfig = {
browser: {
browserName: "chromium",
launchOptions: {
channel: "chrome",
headless: import_os.default.platform() === "linux" && !process.env.DISPLAY,
chromiumSandbox: true
},
contextOptions: {
viewport: null
}
},
network: {
allowedOrigins: void 0,
blockedOrigins: void 0
},
server: {},
saveTrace: false,
timeouts: {
action: 5e3,
navigation: 6e4
}
};
async function resolveConfig(config) {
return mergeConfig(defaultConfig, config);
}
async function resolveCLIConfig(cliOptions) {
const configInFile = await loadConfig(cliOptions.config);
const envOverrides = configFromEnv();
const cliOverrides = configFromCLIOptions(cliOptions);
let result = defaultConfig;
result = mergeConfig(result, configInFile);
result = mergeConfig(result, envOverrides);
result = mergeConfig(result, cliOverrides);
await validateConfig(result);
return result;
}
async function validateConfig(config) {
if (config.browser.initScript) {
for (const script of config.browser.initScript) {
if (!await (0, import_util.fileExistsAsync)(script))
throw new Error(`Init script file does not exist: ${script}`);
}
}
if (config.sharedBrowserContext && config.saveVideo)
throw new Error("saveVideo is not supported when sharedBrowserContext is true");
}
function configFromCLIOptions(cliOptions) {
let browserName;
let channel;
switch (cliOptions.browser) {
case "chrome":
case "chrome-beta":
case "chrome-canary":
case "chrome-dev":
case "chromium":
case "msedge":
case "msedge-beta":
case "msedge-canary":
case "msedge-dev":
browserName = "chromium";
channel = cliOptions.browser;
break;
case "firefox":
browserName = "firefox";
break;
case "webkit":
browserName = "webkit";
break;
}
const launchOptions = {
channel,
executablePath: cliOptions.executablePath,
headless: cliOptions.headless
};
if (cliOptions.sandbox === false)
launchOptions.chromiumSandbox = false;
if (cliOptions.proxyServer) {
launchOptions.proxy = {
server: cliOptions.proxyServer
};
if (cliOptions.proxyBypass)
launchOptions.proxy.bypass = cliOptions.proxyBypass;
}
if (cliOptions.device && cliOptions.cdpEndpoint)
throw new Error("Device emulation is not supported with cdpEndpoint.");
const contextOptions = cliOptions.device ? import_playwright_core.devices[cliOptions.device] : {};
if (cliOptions.storageState)
contextOptions.storageState = cliOptions.storageState;
if (cliOptions.userAgent)
contextOptions.userAgent = cliOptions.userAgent;
if (cliOptions.viewportSize)
contextOptions.viewport = cliOptions.viewportSize;
if (cliOptions.ignoreHttpsErrors)
contextOptions.ignoreHTTPSErrors = true;
if (cliOptions.blockServiceWorkers)
contextOptions.serviceWorkers = "block";
if (cliOptions.grantPermissions)
contextOptions.permissions = cliOptions.grantPermissions;
if (cliOptions.saveVideo) {
contextOptions.recordVideo = {
// Videos are moved to output directory on saveAs.
dir: tmpDir(),
size: cliOptions.saveVideo
};
}
const result = {
browser: {
browserName,
isolated: cliOptions.isolated,
userDataDir: cliOptions.userDataDir,
launchOptions,
contextOptions,
cdpEndpoint: cliOptions.cdpEndpoint,
cdpHeaders: cliOptions.cdpHeader,
initScript: cliOptions.initScript
},
server: {
port: cliOptions.port,
host: cliOptions.host,
allowedHosts: cliOptions.allowedHosts
},
capabilities: cliOptions.caps,
network: {
allowedOrigins: cliOptions.allowedOrigins,
blockedOrigins: cliOptions.blockedOrigins
},
saveSession: cliOptions.saveSession,
saveTrace: cliOptions.saveTrace,
saveVideo: cliOptions.saveVideo,
secrets: cliOptions.secrets,
sharedBrowserContext: cliOptions.sharedBrowserContext,
outputDir: cliOptions.outputDir,
imageResponses: cliOptions.imageResponses,
timeouts: {
action: cliOptions.timeoutAction,
navigation: cliOptions.timeoutNavigation
}
};
return result;
}
function configFromEnv() {
const options = {};
options.allowedHosts = commaSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_HOSTNAMES);
options.allowedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_ALLOWED_ORIGINS);
options.blockedOrigins = semicolonSeparatedList(process.env.PLAYWRIGHT_MCP_BLOCKED_ORIGINS);
options.blockServiceWorkers = envToBoolean(process.env.PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERS);
options.browser = envToString(process.env.PLAYWRIGHT_MCP_BROWSER);
options.caps = commaSeparatedList(process.env.PLAYWRIGHT_MCP_CAPS);
options.cdpEndpoint = envToString(process.env.PLAYWRIGHT_MCP_CDP_ENDPOINT);
options.cdpHeader = headerParser(process.env.PLAYWRIGHT_MCP_CDP_HEADERS, {});
options.config = envToString(process.env.PLAYWRIGHT_MCP_CONFIG);
options.device = envToString(process.env.PLAYWRIGHT_MCP_DEVICE);
options.executablePath = envToString(process.env.PLAYWRIGHT_MCP_EXECUTABLE_PATH);
options.grantPermissions = commaSeparatedList(process.env.PLAYWRIGHT_MCP_GRANT_PERMISSIONS);
options.headless = envToBoolean(process.env.PLAYWRIGHT_MCP_HEADLESS);
options.host = envToString(process.env.PLAYWRIGHT_MCP_HOST);
options.ignoreHttpsErrors = envToBoolean(process.env.PLAYWRIGHT_MCP_IGNORE_HTTPS_ERRORS);
const initScript = envToString(process.env.PLAYWRIGHT_MCP_INIT_SCRIPT);
if (initScript)
options.initScript = [initScript];
options.isolated = envToBoolean(process.env.PLAYWRIGHT_MCP_ISOLATED);
if (process.env.PLAYWRIGHT_MCP_IMAGE_RESPONSES === "omit")
options.imageResponses = "omit";
options.sandbox = envToBoolean(process.env.PLAYWRIGHT_MCP_SANDBOX);
options.outputDir = envToString(process.env.PLAYWRIGHT_MCP_OUTPUT_DIR);
options.port = numberParser(process.env.PLAYWRIGHT_MCP_PORT);
options.proxyBypass = envToString(process.env.PLAYWRIGHT_MCP_PROXY_BYPASS);
options.proxyServer = envToString(process.env.PLAYWRIGHT_MCP_PROXY_SERVER);
options.saveTrace = envToBoolean(process.env.PLAYWRIGHT_MCP_SAVE_TRACE);
options.saveVideo = resolutionParser("--save-video", process.env.PLAYWRIGHT_MCP_SAVE_VIDEO);
options.secrets = dotenvFileLoader(process.env.PLAYWRIGHT_MCP_SECRETS_FILE);
options.storageState = envToString(process.env.PLAYWRIGHT_MCP_STORAGE_STATE);
options.timeoutAction = numberParser(process.env.PLAYWRIGHT_MCP_TIMEOUT_ACTION);
options.timeoutNavigation = numberParser(process.env.PLAYWRIGHT_MCP_TIMEOUT_NAVIGATION);
options.userAgent = envToString(process.env.PLAYWRIGHT_MCP_USER_AGENT);
options.userDataDir = envToString(process.env.PLAYWRIGHT_MCP_USER_DATA_DIR);
options.viewportSize = resolutionParser("--viewport-size", process.env.PLAYWRIGHT_MCP_VIEWPORT_SIZE);
return configFromCLIOptions(options);
}
async function loadConfig(configFile) {
if (!configFile)
return {};
try {
return JSON.parse(await import_fs.default.promises.readFile(configFile, "utf8"));
} catch (error) {
throw new Error(`Failed to load config file: ${configFile}, ${error}`);
}
}
function tmpDir() {
return import_path.default.join(process.env.PW_TMPDIR_FOR_TEST ?? import_os.default.tmpdir(), "playwright-mcp-output");
}
function outputDir(config, clientInfo) {
const rootPath = (0, import_server.firstRootPath)(clientInfo);
return config.outputDir ?? (rootPath ? import_path.default.join(rootPath, ".playwright-mcp") : void 0) ?? import_path.default.join(tmpDir(), String(clientInfo.timestamp));
}
async function outputFile(config, clientInfo, fileName, options) {
const file = await resolveFile(config, clientInfo, fileName, options);
(0, import_utilsBundle.debug)("pw:mcp:file")(options.reason, file);
return file;
}
async function resolveFile(config, clientInfo, fileName, options) {
const dir = outputDir(config, clientInfo);
if (options.origin === "code")
return import_path.default.resolve(dir, fileName);
if (options.origin === "llm") {
fileName = fileName.split("\\").join("/");
const resolvedFile = import_path.default.resolve(dir, fileName);
if (!resolvedFile.startsWith(import_path.default.resolve(dir) + import_path.default.sep))
throw new Error(`Resolved file path for ${fileName} is outside of the output directory`);
return resolvedFile;
}
return import_path.default.join(dir, sanitizeForFilePath(fileName));
}
function pickDefined(obj) {
return Object.fromEntries(
Object.entries(obj ?? {}).filter(([_, v]) => v !== void 0)
);
}
function mergeConfig(base, overrides) {
const browser = {
...pickDefined(base.browser),
...pickDefined(overrides.browser),
browserName: overrides.browser?.browserName ?? base.browser?.browserName ?? "chromium",
isolated: overrides.browser?.isolated ?? base.browser?.isolated ?? false,
launchOptions: {
...pickDefined(base.browser?.launchOptions),
...pickDefined(overrides.browser?.launchOptions),
...{ assistantMode: true }
},
contextOptions: {
...pickDefined(base.browser?.contextOptions),
...pickDefined(overrides.browser?.contextOptions)
}
};
if (browser.browserName !== "chromium" && browser.launchOptions)
delete browser.launchOptions.channel;
return {
...pickDefined(base),
...pickDefined(overrides),
browser,
network: {
...pickDefined(base.network),
...pickDefined(overrides.network)
},
server: {
...pickDefined(base.server),
...pickDefined(overrides.server)
},
timeouts: {
...pickDefined(base.timeouts),
...pickDefined(overrides.timeouts)
}
};
}
function semicolonSeparatedList(value) {
if (!value)
return void 0;
return value.split(";").map((v) => v.trim());
}
function commaSeparatedList(value) {
if (!value)
return void 0;
return value.split(",").map((v) => v.trim());
}
function dotenvFileLoader(value) {
if (!value)
return void 0;
return import_utilsBundle.dotenv.parse(import_fs.default.readFileSync(value, "utf8"));
}
function numberParser(value) {
if (!value)
return void 0;
return +value;
}
function resolutionParser(name, value) {
if (!value)
return void 0;
if (value.includes("x")) {
const [width, height] = value.split("x").map((v) => +v);
if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0)
throw new Error(`Invalid resolution format: use ${name}="800x600"`);
return { width, height };
}
if (value.includes(",")) {
const [width, height] = value.split(",").map((v) => +v);
if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0)
throw new Error(`Invalid resolution format: use ${name}="800x600"`);
return { width, height };
}
throw new Error(`Invalid resolution format: use ${name}="800x600"`);
}
function headerParser(arg, previous) {
if (!arg)
return previous || {};
const result = previous || {};
const [name, value] = arg.split(":").map((v) => v.trim());
result[name] = value;
return result;
}
function envToBoolean(value) {
if (value === "true" || value === "1")
return true;
if (value === "false" || value === "0")
return false;
return void 0;
}
function envToString(value) {
return value ? value.trim() : void 0;
}
function sanitizeForFilePath(s) {
const sanitize = (s2) => s2.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, "-");
const separator = s.lastIndexOf(".");
if (separator === -1)
return sanitize(s);
return sanitize(s.substring(0, separator)) + "." + sanitize(s.substring(separator + 1));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
commaSeparatedList,
configFromCLIOptions,
defaultConfig,
dotenvFileLoader,
headerParser,
numberParser,
outputDir,
outputFile,
resolutionParser,
resolveCLIConfig,
resolveConfig,
semicolonSeparatedList
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var context_exports = {};
__export(context_exports, {
Context: () => Context,
InputRecorder: () => InputRecorder
});
module.exports = __toCommonJS(context_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_log = require("../log");
var import_tab = require("./tab");
var import_config = require("./config");
var codegen = __toESM(require("./codegen"));
var import_utils = require("./tools/utils");
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
class Context {
constructor(options) {
this._tabs = [];
this._abortController = new AbortController();
this.config = options.config;
this.sessionLog = options.sessionLog;
this.options = options;
this._browserContextFactory = options.browserContextFactory;
this._clientInfo = options.clientInfo;
testDebug("create context");
Context._allContexts.add(this);
}
static {
this._allContexts = /* @__PURE__ */ new Set();
}
static async disposeAll() {
await Promise.all([...Context._allContexts].map((context) => context.dispose()));
}
tabs() {
return this._tabs;
}
currentTab() {
return this._currentTab;
}
currentTabOrDie() {
if (!this._currentTab)
throw new Error('No open pages available. Use the "browser_navigate" tool to navigate to a page first.');
return this._currentTab;
}
async newTab() {
const { browserContext } = await this._ensureBrowserContext();
const page = await browserContext.newPage();
this._currentTab = this._tabs.find((t) => t.page === page);
return this._currentTab;
}
async selectTab(index) {
const tab = this._tabs[index];
if (!tab)
throw new Error(`Tab ${index} not found`);
await tab.page.bringToFront();
this._currentTab = tab;
return tab;
}
async ensureTab() {
const { browserContext } = await this._ensureBrowserContext();
if (!this._currentTab)
await browserContext.newPage();
return this._currentTab;
}
async closeTab(index) {
const tab = index === void 0 ? this._currentTab : this._tabs[index];
if (!tab)
throw new Error(`Tab ${index} not found`);
const url = tab.page.url();
await tab.page.close();
return url;
}
async outputFile(fileName, options) {
return (0, import_config.outputFile)(this.config, this._clientInfo, fileName, options);
}
_onPageCreated(page) {
const tab = new import_tab.Tab(this, page, (tab2) => this._onPageClosed(tab2));
this._tabs.push(tab);
if (!this._currentTab)
this._currentTab = tab;
}
_onPageClosed(tab) {
const index = this._tabs.indexOf(tab);
if (index === -1)
return;
this._tabs.splice(index, 1);
if (this._currentTab === tab)
this._currentTab = this._tabs[Math.min(index, this._tabs.length - 1)];
if (!this._tabs.length)
void this.closeBrowserContext();
}
async closeBrowserContext() {
if (!this._closeBrowserContextPromise)
this._closeBrowserContextPromise = this._closeBrowserContextImpl().catch(import_log.logUnhandledError);
await this._closeBrowserContextPromise;
this._closeBrowserContextPromise = void 0;
}
isRunningTool() {
return this._runningToolName !== void 0;
}
setRunningTool(name) {
this._runningToolName = name;
}
async _closeBrowserContextImpl() {
if (!this._browserContextPromise)
return;
testDebug("close context");
const promise = this._browserContextPromise;
this._browserContextPromise = void 0;
await promise.then(async ({ browserContext, close }) => {
if (this.config.saveTrace)
await browserContext.tracing.stop();
const videos = this.config.saveVideo ? browserContext.pages().map((page) => page.video()).filter((video) => !!video) : [];
await close(async () => {
for (const video of videos) {
const name = await this.outputFile((0, import_utils.dateAsFileName)("webm"), { origin: "code", reason: "Saving video" });
await import_fs.default.promises.mkdir(import_path.default.dirname(name), { recursive: true });
const p = await video.path();
if (import_fs.default.existsSync(p)) {
try {
await import_fs.default.promises.rename(p, name);
} catch (e) {
if (e.code !== "EXDEV")
(0, import_log.logUnhandledError)(e);
try {
await import_fs.default.promises.copyFile(p, name);
await import_fs.default.promises.unlink(p);
} catch (e2) {
(0, import_log.logUnhandledError)(e2);
}
}
}
}
});
});
}
async dispose() {
this._abortController.abort("MCP context disposed");
await this.closeBrowserContext();
Context._allContexts.delete(this);
}
async _setupRequestInterception(context) {
if (this.config.network?.allowedOrigins?.length) {
await context.route("**", (route) => route.abort("blockedbyclient"));
for (const origin of this.config.network.allowedOrigins)
await context.route(originOrHostGlob(origin), (route) => route.continue());
}
if (this.config.network?.blockedOrigins?.length) {
for (const origin of this.config.network.blockedOrigins)
await context.route(originOrHostGlob(origin), (route) => route.abort("blockedbyclient"));
}
}
async ensureBrowserContext() {
const { browserContext } = await this._ensureBrowserContext();
return browserContext;
}
_ensureBrowserContext() {
if (!this._browserContextPromise) {
this._browserContextPromise = this._setupBrowserContext();
this._browserContextPromise.catch(() => {
this._browserContextPromise = void 0;
});
}
return this._browserContextPromise;
}
async _setupBrowserContext() {
if (this._closeBrowserContextPromise)
throw new Error("Another browser context is being closed.");
const result = await this._browserContextFactory.createContext(this._clientInfo, this._abortController.signal, this._runningToolName);
const { browserContext } = result;
await this._setupRequestInterception(browserContext);
if (this.sessionLog)
await InputRecorder.create(this, browserContext);
for (const page of browserContext.pages())
this._onPageCreated(page);
browserContext.on("page", (page) => this._onPageCreated(page));
if (this.config.saveTrace) {
await browserContext.tracing.start({
name: "trace-" + Date.now(),
screenshots: true,
snapshots: true,
_live: true
});
}
return result;
}
lookupSecret(secretName) {
if (!this.config.secrets?.[secretName])
return { value: secretName, code: codegen.quote(secretName) };
return {
value: this.config.secrets[secretName],
code: `process.env['${secretName}']`
};
}
}
function originOrHostGlob(originOrHost) {
try {
const url = new URL(originOrHost);
if (url.origin !== "null")
return `${url.origin}/**`;
} catch {
}
return `*://${originOrHost}/**`;
}
class InputRecorder {
constructor(context, browserContext) {
this._context = context;
this._browserContext = browserContext;
}
static async create(context, browserContext) {
const recorder = new InputRecorder(context, browserContext);
await recorder._initialize();
return recorder;
}
async _initialize() {
const sessionLog = this._context.sessionLog;
await this._browserContext._enableRecorder({
mode: "recording",
recorderMode: "api"
}, {
actionAdded: (page, data, code) => {
if (this._context.isRunningTool())
return;
const tab = import_tab.Tab.forPage(page);
if (tab)
sessionLog.logUserAction(data.action, tab, code, false);
},
actionUpdated: (page, data, code) => {
if (this._context.isRunningTool())
return;
const tab = import_tab.Tab.forPage(page);
if (tab)
sessionLog.logUserAction(data.action, tab, code, true);
},
signalAdded: (page, data) => {
if (this._context.isRunningTool())
return;
if (data.signal.name !== "navigation")
return;
const tab = import_tab.Tab.forPage(page);
const navigateAction = {
name: "navigate",
url: data.signal.url,
signals: []
};
if (tab)
sessionLog.logUserAction(navigateAction, tab, `await page.goto('${data.signal.url}');`, false);
}
});
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Context,
InputRecorder
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var response_exports = {};
__export(response_exports, {
Response: () => Response,
parseResponse: () => parseResponse,
requestDebug: () => requestDebug
});
module.exports = __toCommonJS(response_exports);
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_tab = require("./tab");
const requestDebug = (0, import_utilsBundle.debug)("pw:mcp:request");
class Response {
constructor(context, toolName, toolArgs) {
this._result = [];
this._code = [];
this._images = [];
this._includeSnapshot = false;
this._includeTabs = false;
this._context = context;
this.toolName = toolName;
this.toolArgs = toolArgs;
}
addResult(result) {
this._result.push(result);
}
addError(error) {
this._result.push(error);
this._isError = true;
}
isError() {
return this._isError;
}
result() {
return this._result.join("\n");
}
addCode(code) {
this._code.push(code);
}
code() {
return this._code.join("\n");
}
addImage(image) {
this._images.push(image);
}
images() {
return this._images;
}
setIncludeSnapshot() {
this._includeSnapshot = true;
}
setIncludeTabs() {
this._includeTabs = true;
}
async finish() {
if (this._includeSnapshot && this._context.currentTab())
this._tabSnapshot = await this._context.currentTabOrDie().captureSnapshot();
for (const tab of this._context.tabs())
await tab.updateTitle();
}
tabSnapshot() {
return this._tabSnapshot;
}
logBegin() {
if (requestDebug.enabled)
requestDebug(this.toolName, this.toolArgs);
}
logEnd() {
if (requestDebug.enabled)
requestDebug(this.serialize({ omitSnapshot: true, omitBlobs: true }));
}
serialize(options = {}) {
const response = [];
if (this._result.length) {
response.push("### Result");
response.push(this._result.join("\n"));
response.push("");
}
if (this._code.length) {
response.push(`### Ran Playwright code
\`\`\`js
${this._code.join("\n")}
\`\`\``);
response.push("");
}
if (this._includeSnapshot || this._includeTabs)
response.push(...renderTabsMarkdown(this._context.tabs(), this._includeTabs));
if (this._tabSnapshot?.modalStates.length) {
response.push(...(0, import_tab.renderModalStates)(this._context, this._tabSnapshot.modalStates));
response.push("");
} else if (this._tabSnapshot) {
response.push(renderTabSnapshot(this._tabSnapshot, options));
response.push("");
}
const content = [
{ type: "text", text: response.join("\n") }
];
if (this._context.config.imageResponses !== "omit") {
for (const image of this._images)
content.push({ type: "image", data: options.omitBlobs ? "<blob>" : image.data.toString("base64"), mimeType: image.contentType });
}
this._redactSecrets(content);
return { content, isError: this._isError };
}
_redactSecrets(content) {
if (!this._context.config.secrets)
return;
for (const item of content) {
if (item.type !== "text")
continue;
for (const [secretName, secretValue] of Object.entries(this._context.config.secrets))
item.text = item.text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
}
}
}
function renderTabSnapshot(tabSnapshot, options = {}) {
const lines = [];
if (tabSnapshot.consoleMessages.length) {
lines.push(`### New console messages`);
for (const message of tabSnapshot.consoleMessages)
lines.push(`- ${trim(message.toString(), 100)}`);
lines.push("");
}
if (tabSnapshot.downloads.length) {
lines.push(`### Downloads`);
for (const entry of tabSnapshot.downloads) {
if (entry.finished)
lines.push(`- Downloaded file ${entry.download.suggestedFilename()} to ${entry.outputFile}`);
else
lines.push(`- Downloading file ${entry.download.suggestedFilename()} ...`);
}
lines.push("");
}
lines.push(`### Page state`);
lines.push(`- Page URL: ${tabSnapshot.url}`);
lines.push(`- Page Title: ${tabSnapshot.title}`);
lines.push(`- Page Snapshot:`);
lines.push("```yaml");
lines.push(options.omitSnapshot ? "<snapshot>" : tabSnapshot.ariaSnapshot);
lines.push("```");
return lines.join("\n");
}
function renderTabsMarkdown(tabs, force = false) {
if (tabs.length === 1 && !force)
return [];
if (!tabs.length) {
return [
"### Open tabs",
'No open tabs. Use the "browser_navigate" tool to navigate to a page first.',
""
];
}
const lines = ["### Open tabs"];
for (let i = 0; i < tabs.length; i++) {
const tab = tabs[i];
const current = tab.isCurrentTab() ? " (current)" : "";
lines.push(`- ${i}:${current} [${tab.lastTitle()}] (${tab.page.url()})`);
}
lines.push("");
return lines;
}
function trim(text, maxLength) {
if (text.length <= maxLength)
return text;
return text.slice(0, maxLength) + "...";
}
function parseSections(text) {
const sections = /* @__PURE__ */ new Map();
const sectionHeaders = text.split(/^### /m).slice(1);
for (const section of sectionHeaders) {
const firstNewlineIndex = section.indexOf("\n");
if (firstNewlineIndex === -1)
continue;
const sectionName = section.substring(0, firstNewlineIndex);
const sectionContent = section.substring(firstNewlineIndex + 1).trim();
sections.set(sectionName, sectionContent);
}
return sections;
}
function parseResponse(response) {
if (response.content?.[0].type !== "text")
return void 0;
const text = response.content[0].text;
const sections = parseSections(text);
const result = sections.get("Result");
const code = sections.get("Ran Playwright code");
const tabs = sections.get("Open tabs");
const pageState = sections.get("Page state");
const consoleMessages = sections.get("New console messages");
const modalState = sections.get("Modal state");
const downloads = sections.get("Downloads");
const codeNoFrame = code?.replace(/^```js\n/, "").replace(/\n```$/, "");
const isError = response.isError;
const attachments = response.content.slice(1);
return {
result,
code: codeNoFrame,
tabs,
pageState,
consoleMessages,
modalState,
downloads,
isError,
attachments
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Response,
parseResponse,
requestDebug
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var sessionLog_exports = {};
__export(sessionLog_exports, {
SessionLog: () => SessionLog
});
module.exports = __toCommonJS(sessionLog_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_log = require("../log");
var import_config = require("./config");
class SessionLog {
constructor(sessionFolder) {
this._ordinal = 0;
this._pendingEntries = [];
this._sessionFileQueue = Promise.resolve();
this._folder = sessionFolder;
this._file = import_path.default.join(this._folder, "session.md");
}
static async create(config, clientInfo) {
const sessionFolder = await (0, import_config.outputFile)(config, clientInfo, `session-${Date.now()}`, { origin: "code", reason: "Saving session" });
await import_fs.default.promises.mkdir(sessionFolder, { recursive: true });
console.error(`Session: ${sessionFolder}`);
return new SessionLog(sessionFolder);
}
logResponse(response) {
const entry = {
timestamp: performance.now(),
toolCall: {
toolName: response.toolName,
toolArgs: response.toolArgs,
result: response.result(),
isError: response.isError()
},
code: response.code(),
tabSnapshot: response.tabSnapshot()
};
this._appendEntry(entry);
}
logUserAction(action, tab, code, isUpdate) {
code = code.trim();
if (isUpdate) {
const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
if (lastEntry?.userAction?.name === action.name) {
lastEntry.userAction = action;
lastEntry.code = code;
return;
}
}
if (action.name === "navigate") {
const lastEntry = this._pendingEntries[this._pendingEntries.length - 1];
if (lastEntry?.tabSnapshot?.url === action.url)
return;
}
const entry = {
timestamp: performance.now(),
userAction: action,
code,
tabSnapshot: {
url: tab.page.url(),
title: "",
ariaSnapshot: action.ariaSnapshot || "",
modalStates: [],
consoleMessages: [],
downloads: []
}
};
this._appendEntry(entry);
}
_appendEntry(entry) {
this._pendingEntries.push(entry);
if (this._flushEntriesTimeout)
clearTimeout(this._flushEntriesTimeout);
this._flushEntriesTimeout = setTimeout(() => this._flushEntries(), 1e3);
}
async _flushEntries() {
clearTimeout(this._flushEntriesTimeout);
const entries = this._pendingEntries;
this._pendingEntries = [];
const lines = [""];
for (const entry of entries) {
const ordinal = (++this._ordinal).toString().padStart(3, "0");
if (entry.toolCall) {
lines.push(
`### Tool call: ${entry.toolCall.toolName}`,
`- Args`,
"```json",
JSON.stringify(entry.toolCall.toolArgs, null, 2),
"```"
);
if (entry.toolCall.result) {
lines.push(
entry.toolCall.isError ? `- Error` : `- Result`,
"```",
entry.toolCall.result,
"```"
);
}
}
if (entry.userAction) {
const actionData = { ...entry.userAction };
delete actionData.ariaSnapshot;
delete actionData.selector;
delete actionData.signals;
lines.push(
`### User action: ${entry.userAction.name}`,
`- Args`,
"```json",
JSON.stringify(actionData, null, 2),
"```"
);
}
if (entry.code) {
lines.push(
`- Code`,
"```js",
entry.code,
"```"
);
}
if (entry.tabSnapshot) {
const fileName = `${ordinal}.snapshot.yml`;
import_fs.default.promises.writeFile(import_path.default.join(this._folder, fileName), entry.tabSnapshot.ariaSnapshot).catch(import_log.logUnhandledError);
lines.push(`- Snapshot: ${fileName}`);
}
lines.push("", "");
}
this._sessionFileQueue = this._sessionFileQueue.then(() => import_fs.default.promises.appendFile(this._file, lines.join("\n")));
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
SessionLog
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tab_exports = {};
__export(tab_exports, {
Tab: () => Tab,
TabEvents: () => TabEvents,
renderModalStates: () => renderModalStates
});
module.exports = __toCommonJS(tab_exports);
var import_events = require("events");
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("./tools/utils");
var import_log = require("../log");
var import_dialogs = require("./tools/dialogs");
var import_files = require("./tools/files");
const TabEvents = {
modalState: "modalState"
};
class Tab extends import_events.EventEmitter {
constructor(context, page, onPageClose) {
super();
this._lastTitle = "about:blank";
this._consoleMessages = [];
this._recentConsoleMessages = [];
this._requests = /* @__PURE__ */ new Set();
this._modalStates = [];
this._downloads = [];
this.context = context;
this.page = page;
this._onPageClose = onPageClose;
page.on("console", (event) => this._handleConsoleMessage(messageToConsoleMessage(event)));
page.on("pageerror", (error) => this._handleConsoleMessage(pageErrorToConsoleMessage(error)));
page.on("request", (request) => this._requests.add(request));
page.on("close", () => this._onClose());
page.on("filechooser", (chooser) => {
this.setModalState({
type: "fileChooser",
description: "File chooser",
fileChooser: chooser,
clearedBy: import_files.uploadFile.schema.name
});
});
page.on("dialog", (dialog) => this._dialogShown(dialog));
page.on("download", (download) => {
void this._downloadStarted(download);
});
page.setDefaultNavigationTimeout(this.context.config.timeouts.navigation);
page.setDefaultTimeout(this.context.config.timeouts.action);
page[tabSymbol] = this;
this._initializedPromise = this._initialize();
}
static forPage(page) {
return page[tabSymbol];
}
static async collectConsoleMessages(page) {
const result = [];
const messages = await page.consoleMessages().catch(() => []);
for (const message of messages)
result.push(messageToConsoleMessage(message));
const errors = await page.pageErrors().catch(() => []);
for (const error of errors)
result.push(pageErrorToConsoleMessage(error));
return result;
}
async _initialize() {
for (const message of await Tab.collectConsoleMessages(this.page))
this._handleConsoleMessage(message);
const requests = await this.page.requests().catch(() => []);
for (const request of requests)
this._requests.add(request);
}
modalStates() {
return this._modalStates;
}
setModalState(modalState) {
this._modalStates.push(modalState);
this.emit(TabEvents.modalState, modalState);
}
clearModalState(modalState) {
this._modalStates = this._modalStates.filter((state) => state !== modalState);
}
modalStatesMarkdown() {
return renderModalStates(this.context, this.modalStates());
}
_dialogShown(dialog) {
this.setModalState({
type: "dialog",
description: `"${dialog.type()}" dialog with message "${dialog.message()}"`,
dialog,
clearedBy: import_dialogs.handleDialog.schema.name
});
}
async _downloadStarted(download) {
const entry = {
download,
finished: false,
outputFile: await this.context.outputFile(download.suggestedFilename(), { origin: "web", reason: "Saving download" })
};
this._downloads.push(entry);
await download.saveAs(entry.outputFile);
entry.finished = true;
}
_clearCollectedArtifacts() {
this._consoleMessages.length = 0;
this._recentConsoleMessages.length = 0;
this._requests.clear();
}
_handleConsoleMessage(message) {
this._consoleMessages.push(message);
this._recentConsoleMessages.push(message);
}
_onClose() {
this._clearCollectedArtifacts();
this._onPageClose(this);
}
async updateTitle() {
await this._raceAgainstModalStates(async () => {
this._lastTitle = await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.title());
});
}
lastTitle() {
return this._lastTitle;
}
isCurrentTab() {
return this === this.context.currentTab();
}
async waitForLoadState(state, options) {
await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForLoadState(state, options).catch(import_log.logUnhandledError));
}
async navigate(url) {
this._clearCollectedArtifacts();
const downloadEvent = (0, import_utils2.callOnPageNoTrace)(this.page, (page) => page.waitForEvent("download").catch(import_log.logUnhandledError));
try {
await this.page.goto(url, { waitUntil: "domcontentloaded" });
} catch (_e) {
const e = _e;
const mightBeDownload = e.message.includes("net::ERR_ABORTED") || e.message.includes("Download is starting");
if (!mightBeDownload)
throw e;
const download = await Promise.race([
downloadEvent,
new Promise((resolve) => setTimeout(resolve, 3e3))
]);
if (!download)
throw e;
await new Promise((resolve) => setTimeout(resolve, 500));
return;
}
await this.waitForLoadState("load", { timeout: 5e3 });
}
async consoleMessages(type) {
await this._initializedPromise;
return this._consoleMessages.filter((message) => type ? message.type === type : true);
}
async requests() {
await this._initializedPromise;
return this._requests;
}
async captureSnapshot() {
let tabSnapshot;
const modalStates = await this._raceAgainstModalStates(async () => {
const snapshot = await this.page._snapshotForAI();
tabSnapshot = {
url: this.page.url(),
title: await this.page.title(),
ariaSnapshot: snapshot,
modalStates: [],
consoleMessages: [],
downloads: this._downloads
};
});
if (tabSnapshot) {
tabSnapshot.consoleMessages = this._recentConsoleMessages;
this._recentConsoleMessages = [];
}
return tabSnapshot ?? {
url: this.page.url(),
title: "",
ariaSnapshot: "",
modalStates,
consoleMessages: [],
downloads: []
};
}
_javaScriptBlocked() {
return this._modalStates.some((state) => state.type === "dialog");
}
async _raceAgainstModalStates(action) {
if (this.modalStates().length)
return this.modalStates();
const promise = new import_utils.ManualPromise();
const listener = (modalState) => promise.resolve([modalState]);
this.once(TabEvents.modalState, listener);
return await Promise.race([
action().then(() => {
this.off(TabEvents.modalState, listener);
return [];
}),
promise
]);
}
async waitForCompletion(callback) {
await this._raceAgainstModalStates(() => (0, import_utils2.waitForCompletion)(this, callback));
}
async refLocator(params) {
return (await this.refLocators([params]))[0];
}
async refLocators(params) {
const snapshot = await this.page._snapshotForAI();
return params.map((param) => {
if (!snapshot.includes(`[ref=${param.ref}]`))
throw new Error(`Ref ${param.ref} not found in the current page snapshot. Try capturing new snapshot.`);
return this.page.locator(`aria-ref=${param.ref}`).describe(param.element);
});
}
async waitForTimeout(time) {
if (this._javaScriptBlocked()) {
await new Promise((f) => setTimeout(f, time));
return;
}
await (0, import_utils2.callOnPageNoTrace)(this.page, (page) => {
return page.evaluate(() => new Promise((f) => setTimeout(f, 1e3)));
});
}
}
function messageToConsoleMessage(message) {
return {
type: message.type(),
text: message.text(),
toString: () => `[${message.type().toUpperCase()}] ${message.text()} @ ${message.location().url}:${message.location().lineNumber}`
};
}
function pageErrorToConsoleMessage(errorOrValue) {
if (errorOrValue instanceof Error) {
return {
type: "error",
text: errorOrValue.message,
toString: () => errorOrValue.stack || errorOrValue.message
};
}
return {
type: "error",
text: String(errorOrValue),
toString: () => String(errorOrValue)
};
}
function renderModalStates(context, modalStates) {
const result = ["### Modal state"];
if (modalStates.length === 0)
result.push("- There is no modal state present");
for (const state of modalStates)
result.push(`- [${state.description}]: can be handled by the "${state.clearedBy}" tool`);
return result;
}
const tabSymbol = Symbol("tabSymbol");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Tab,
TabEvents,
renderModalStates
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tools_exports = {};
__export(tools_exports, {
browserTools: () => browserTools,
filteredTools: () => filteredTools
});
module.exports = __toCommonJS(tools_exports);
var import_common = __toESM(require("./tools/common"));
var import_console = __toESM(require("./tools/console"));
var import_dialogs = __toESM(require("./tools/dialogs"));
var import_evaluate = __toESM(require("./tools/evaluate"));
var import_files = __toESM(require("./tools/files"));
var import_form = __toESM(require("./tools/form"));
var import_install = __toESM(require("./tools/install"));
var import_keyboard = __toESM(require("./tools/keyboard"));
var import_mouse = __toESM(require("./tools/mouse"));
var import_navigate = __toESM(require("./tools/navigate"));
var import_network = __toESM(require("./tools/network"));
var import_pdf = __toESM(require("./tools/pdf"));
var import_snapshot = __toESM(require("./tools/snapshot"));
var import_screenshot = __toESM(require("./tools/screenshot"));
var import_tabs = __toESM(require("./tools/tabs"));
var import_tracing = __toESM(require("./tools/tracing"));
var import_wait = __toESM(require("./tools/wait"));
var import_verify = __toESM(require("./tools/verify"));
const browserTools = [
...import_common.default,
...import_console.default,
...import_dialogs.default,
...import_evaluate.default,
...import_files.default,
...import_form.default,
...import_install.default,
...import_keyboard.default,
...import_navigate.default,
...import_network.default,
...import_mouse.default,
...import_pdf.default,
...import_screenshot.default,
...import_snapshot.default,
...import_tabs.default,
...import_tracing.default,
...import_wait.default,
...import_verify.default
];
function filteredTools(config) {
return browserTools.filter((tool) => tool.capability.startsWith("core") || config.capabilities?.includes(tool.capability));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
browserTools,
filteredTools
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var common_exports = {};
__export(common_exports, {
default: () => common_default
});
module.exports = __toCommonJS(common_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const close = (0, import_tool.defineTool)({
capability: "core",
schema: {
name: "browser_close",
title: "Close browser",
description: "Close the page",
inputSchema: import_bundle.z.object({}),
type: "action"
},
handle: async (context, params, response) => {
await context.closeBrowserContext();
response.setIncludeTabs();
response.addCode(`await page.close()`);
}
});
const resize = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_resize",
title: "Resize browser window",
description: "Resize the browser window",
inputSchema: import_bundle.z.object({
width: import_bundle.z.number().describe("Width of the browser window"),
height: import_bundle.z.number().describe("Height of the browser window")
}),
type: "action"
},
handle: async (tab, params, response) => {
response.addCode(`await page.setViewportSize({ width: ${params.width}, height: ${params.height} });`);
await tab.waitForCompletion(async () => {
await tab.page.setViewportSize({ width: params.width, height: params.height });
});
}
});
var common_default = [
close,
resize
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var console_exports = {};
__export(console_exports, {
default: () => console_default
});
module.exports = __toCommonJS(console_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const console = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_console_messages",
title: "Get console messages",
description: "Returns all console messages",
inputSchema: import_bundle.z.object({
onlyErrors: import_bundle.z.boolean().optional().describe("Only return error messages")
}),
type: "readOnly"
},
handle: async (tab, params, response) => {
const messages = await tab.consoleMessages(params.onlyErrors ? "error" : void 0);
messages.map((message) => response.addResult(message.toString()));
}
});
var console_default = [
console
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var dialogs_exports = {};
__export(dialogs_exports, {
default: () => dialogs_default,
handleDialog: () => handleDialog
});
module.exports = __toCommonJS(dialogs_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const handleDialog = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_handle_dialog",
title: "Handle a dialog",
description: "Handle a dialog",
inputSchema: import_bundle.z.object({
accept: import_bundle.z.boolean().describe("Whether to accept the dialog."),
promptText: import_bundle.z.string().optional().describe("The text of the prompt in case of a prompt dialog.")
}),
type: "action"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
const dialogState = tab.modalStates().find((state) => state.type === "dialog");
if (!dialogState)
throw new Error("No dialog visible");
tab.clearModalState(dialogState);
await tab.waitForCompletion(async () => {
if (params.accept)
await dialogState.dialog.accept(params.promptText);
else
await dialogState.dialog.dismiss();
});
},
clearsModalState: "dialog"
});
var dialogs_default = [
handleDialog
];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
handleDialog
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var evaluate_exports = {};
__export(evaluate_exports, {
default: () => evaluate_default
});
module.exports = __toCommonJS(evaluate_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
var javascript = __toESM(require("../codegen"));
var import_utils = require("./utils");
const evaluateSchema = import_bundle.z.object({
function: import_bundle.z.string().describe("() => { /* code */ } or (element) => { /* code */ } when element is provided"),
element: import_bundle.z.string().optional().describe("Human-readable element description used to obtain permission to interact with the element"),
ref: import_bundle.z.string().optional().describe("Exact target element reference from the page snapshot")
});
const evaluate = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_evaluate",
title: "Evaluate JavaScript",
description: "Evaluate JavaScript expression on page or element",
inputSchema: evaluateSchema,
type: "action"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
let locator;
if (params.ref && params.element) {
locator = await tab.refLocator({ ref: params.ref, element: params.element });
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.evaluate(${javascript.quote(params.function)});`);
} else {
response.addCode(`await page.evaluate(${javascript.quote(params.function)});`);
}
await tab.waitForCompletion(async () => {
const receiver = locator ?? tab.page;
const result = await receiver._evaluateFunction(params.function);
response.addResult(JSON.stringify(result, null, 2) || "undefined");
});
}
});
var evaluate_default = [
evaluate
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var files_exports = {};
__export(files_exports, {
default: () => files_default,
uploadFile: () => uploadFile
});
module.exports = __toCommonJS(files_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const uploadFile = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_file_upload",
title: "Upload files",
description: "Upload one or multiple files",
inputSchema: import_bundle.z.object({
paths: import_bundle.z.array(import_bundle.z.string()).optional().describe("The absolute paths to the files to upload. Can be single file or multiple files. If omitted, file chooser is cancelled.")
}),
type: "action"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
const modalState = tab.modalStates().find((state) => state.type === "fileChooser");
if (!modalState)
throw new Error("No file chooser visible");
response.addCode(`await fileChooser.setFiles(${JSON.stringify(params.paths)})`);
tab.clearModalState(modalState);
await tab.waitForCompletion(async () => {
if (params.paths)
await modalState.fileChooser.setFiles(params.paths);
});
},
clearsModalState: "fileChooser"
});
var files_default = [
uploadFile
];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
uploadFile
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var form_exports = {};
__export(form_exports, {
default: () => form_default
});
module.exports = __toCommonJS(form_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
var import_utils = require("./utils");
var codegen = __toESM(require("../codegen"));
const fillForm = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_fill_form",
title: "Fill form",
description: "Fill multiple form fields",
inputSchema: import_bundle.z.object({
fields: import_bundle.z.array(import_bundle.z.object({
name: import_bundle.z.string().describe("Human-readable field name"),
type: import_bundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the field"),
ref: import_bundle.z.string().describe("Exact target field reference from the page snapshot"),
value: import_bundle.z.string().describe("Value to fill in the field. If the field is a checkbox, the value should be `true` or `false`. If the field is a combobox, the value should be the text of the option.")
})).describe("Fields to fill in")
}),
type: "input"
},
handle: async (tab, params, response) => {
for (const field of params.fields) {
const locator = await tab.refLocator({ element: field.name, ref: field.ref });
const locatorSource = `await page.${await (0, import_utils.generateLocator)(locator)}`;
if (field.type === "textbox" || field.type === "slider") {
const secret = tab.context.lookupSecret(field.value);
await locator.fill(secret.value);
response.addCode(`${locatorSource}.fill(${secret.code});`);
} else if (field.type === "checkbox" || field.type === "radio") {
await locator.setChecked(field.value === "true");
response.addCode(`${locatorSource}.setChecked(${field.value});`);
} else if (field.type === "combobox") {
await locator.selectOption({ label: field.value });
response.addCode(`${locatorSource}.selectOption(${codegen.quote(field.value)});`);
}
}
}
});
var form_default = [
fillForm
];
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var install_exports = {};
__export(install_exports, {
default: () => install_default
});
module.exports = __toCommonJS(install_exports);
var import_child_process = require("child_process");
var import_path = __toESM(require("path"));
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const install = (0, import_tool.defineTool)({
capability: "core-install",
schema: {
name: "browser_install",
title: "Install the browser specified in the config",
description: "Install the browser specified in the config. Call this if you get an error about the browser not being installed.",
inputSchema: import_bundle.z.object({}),
type: "action"
},
handle: async (context, params, response) => {
const channel = context.config.browser?.launchOptions?.channel ?? context.config.browser?.browserName ?? "chrome";
const cliPath = import_path.default.join(require.resolve("playwright/package.json"), "../cli.js");
const child = (0, import_child_process.fork)(cliPath, ["install", channel], {
stdio: "pipe"
});
const output = [];
child.stdout?.on("data", (data) => output.push(data.toString()));
child.stderr?.on("data", (data) => output.push(data.toString()));
await new Promise((resolve, reject) => {
child.on("close", (code) => {
if (code === 0)
resolve();
else
reject(new Error(`Failed to install browser: ${output.join("")}`));
});
});
response.setIncludeTabs();
}
});
var install_default = [
install
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var keyboard_exports = {};
__export(keyboard_exports, {
default: () => keyboard_default
});
module.exports = __toCommonJS(keyboard_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
var import_snapshot = require("./snapshot");
var import_utils = require("./utils");
const pressKey = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_press_key",
title: "Press a key",
description: "Press a key on the keyboard",
inputSchema: import_bundle.z.object({
key: import_bundle.z.string().describe("Name of the key to press or a character to generate, such as `ArrowLeft` or `a`")
}),
type: "input"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
response.addCode(`// Press ${params.key}`);
response.addCode(`await page.keyboard.press('${params.key}');`);
await tab.waitForCompletion(async () => {
await tab.page.keyboard.press(params.key);
});
}
});
const typeSchema = import_snapshot.elementSchema.extend({
text: import_bundle.z.string().describe("Text to type into the element"),
submit: import_bundle.z.boolean().optional().describe("Whether to submit entered text (press Enter after)"),
slowly: import_bundle.z.boolean().optional().describe("Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.")
});
const type = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_type",
title: "Type text",
description: "Type text into editable element",
inputSchema: typeSchema,
type: "input"
},
handle: async (tab, params, response) => {
const locator = await tab.refLocator(params);
const secret = tab.context.lookupSecret(params.text);
await tab.waitForCompletion(async () => {
if (params.slowly) {
response.setIncludeSnapshot();
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.pressSequentially(${secret.code});`);
await locator.pressSequentially(secret.value);
} else {
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.fill(${secret.code});`);
await locator.fill(secret.value);
}
if (params.submit) {
response.setIncludeSnapshot();
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.press('Enter');`);
await locator.press("Enter");
}
});
}
});
var keyboard_default = [
pressKey,
type
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var mouse_exports = {};
__export(mouse_exports, {
default: () => mouse_default
});
module.exports = __toCommonJS(mouse_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const elementSchema = import_bundle.z.object({
element: import_bundle.z.string().describe("Human-readable element description used to obtain permission to interact with the element")
});
const mouseMove = (0, import_tool.defineTabTool)({
capability: "vision",
schema: {
name: "browser_mouse_move_xy",
title: "Move mouse",
description: "Move mouse to a given position",
inputSchema: elementSchema.extend({
x: import_bundle.z.number().describe("X coordinate"),
y: import_bundle.z.number().describe("Y coordinate")
}),
type: "input"
},
handle: async (tab, params, response) => {
response.addCode(`// Move mouse to (${params.x}, ${params.y})`);
response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
await tab.waitForCompletion(async () => {
await tab.page.mouse.move(params.x, params.y);
});
}
});
const mouseClick = (0, import_tool.defineTabTool)({
capability: "vision",
schema: {
name: "browser_mouse_click_xy",
title: "Click",
description: "Click left mouse button at a given position",
inputSchema: elementSchema.extend({
x: import_bundle.z.number().describe("X coordinate"),
y: import_bundle.z.number().describe("Y coordinate")
}),
type: "input"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
response.addCode(`// Click mouse at coordinates (${params.x}, ${params.y})`);
response.addCode(`await page.mouse.move(${params.x}, ${params.y});`);
response.addCode(`await page.mouse.down();`);
response.addCode(`await page.mouse.up();`);
await tab.waitForCompletion(async () => {
await tab.page.mouse.move(params.x, params.y);
await tab.page.mouse.down();
await tab.page.mouse.up();
});
}
});
const mouseDrag = (0, import_tool.defineTabTool)({
capability: "vision",
schema: {
name: "browser_mouse_drag_xy",
title: "Drag mouse",
description: "Drag left mouse button to a given position",
inputSchema: elementSchema.extend({
startX: import_bundle.z.number().describe("Start X coordinate"),
startY: import_bundle.z.number().describe("Start Y coordinate"),
endX: import_bundle.z.number().describe("End X coordinate"),
endY: import_bundle.z.number().describe("End Y coordinate")
}),
type: "input"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
response.addCode(`// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`);
response.addCode(`await page.mouse.move(${params.startX}, ${params.startY});`);
response.addCode(`await page.mouse.down();`);
response.addCode(`await page.mouse.move(${params.endX}, ${params.endY});`);
response.addCode(`await page.mouse.up();`);
await tab.waitForCompletion(async () => {
await tab.page.mouse.move(params.startX, params.startY);
await tab.page.mouse.down();
await tab.page.mouse.move(params.endX, params.endY);
await tab.page.mouse.up();
});
}
});
var mouse_default = [
mouseMove,
mouseClick,
mouseDrag
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var navigate_exports = {};
__export(navigate_exports, {
default: () => navigate_default
});
module.exports = __toCommonJS(navigate_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const navigate = (0, import_tool.defineTool)({
capability: "core",
schema: {
name: "browser_navigate",
title: "Navigate to a URL",
description: "Navigate to a URL",
inputSchema: import_bundle.z.object({
url: import_bundle.z.string().describe("The URL to navigate to")
}),
type: "action"
},
handle: async (context, params, response) => {
const tab = await context.ensureTab();
await tab.navigate(params.url);
response.setIncludeSnapshot();
response.addCode(`await page.goto('${params.url}');`);
}
});
const goBack = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_navigate_back",
title: "Go back",
description: "Go back to the previous page",
inputSchema: import_bundle.z.object({}),
type: "action"
},
handle: async (tab, params, response) => {
await tab.page.goBack();
response.setIncludeSnapshot();
response.addCode(`await page.goBack();`);
}
});
var navigate_default = [
navigate,
goBack
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var network_exports = {};
__export(network_exports, {
default: () => network_default
});
module.exports = __toCommonJS(network_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const requests = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_network_requests",
title: "List network requests",
description: "Returns all network requests since loading the page",
inputSchema: import_bundle.z.object({}),
type: "readOnly"
},
handle: async (tab, params, response) => {
const requests2 = await tab.requests();
for (const request of requests2)
response.addResult(await renderRequest(request));
}
});
async function renderRequest(request) {
const result = [];
result.push(`[${request.method().toUpperCase()}] ${request.url()}`);
const hasResponse = request._hasResponse;
if (hasResponse) {
const response = await request.response();
if (response)
result.push(`=> [${response.status()}] ${response.statusText()}`);
}
return result.join(" ");
}
var network_default = [
requests
];
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var pdf_exports = {};
__export(pdf_exports, {
default: () => pdf_default
});
module.exports = __toCommonJS(pdf_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
var javascript = __toESM(require("../codegen"));
var import_utils = require("./utils");
const pdfSchema = import_bundle.z.object({
filename: import_bundle.z.string().optional().describe("File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified.")
});
const pdf = (0, import_tool.defineTabTool)({
capability: "pdf",
schema: {
name: "browser_pdf_save",
title: "Save as PDF",
description: "Save page as PDF",
inputSchema: pdfSchema,
type: "readOnly"
},
handle: async (tab, params, response) => {
const fileName = await tab.context.outputFile(params.filename ?? (0, import_utils.dateAsFileName)("pdf"), { origin: "llm", reason: "Saving PDF" });
response.addCode(`await page.pdf(${javascript.formatObject({ path: fileName })});`);
response.addResult(`Saved page as ${fileName}`);
await tab.page.pdf({ path: fileName });
}
});
var pdf_default = [
pdf
];
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var screenshot_exports = {};
__export(screenshot_exports, {
default: () => screenshot_default
});
module.exports = __toCommonJS(screenshot_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
var javascript = __toESM(require("../codegen"));
var import_utils = require("./utils");
const screenshotSchema = import_bundle.z.object({
type: import_bundle.z.enum(["png", "jpeg"]).default("png").describe("Image format for the screenshot. Default is png."),
filename: import_bundle.z.string().optional().describe("File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified."),
element: import_bundle.z.string().optional().describe("Human-readable element description used to obtain permission to screenshot the element. If not provided, the screenshot will be taken of viewport. If element is provided, ref must be provided too."),
ref: import_bundle.z.string().optional().describe("Exact target element reference from the page snapshot. If not provided, the screenshot will be taken of viewport. If ref is provided, element must be provided too."),
fullPage: import_bundle.z.boolean().optional().describe("When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Cannot be used with element screenshots.")
});
const screenshot = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_take_screenshot",
title: "Take a screenshot",
description: `Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.`,
inputSchema: screenshotSchema,
type: "readOnly"
},
handle: async (tab, params, response) => {
if (!!params.element !== !!params.ref)
throw new Error("Both element and ref must be provided or neither.");
if (params.fullPage && params.ref)
throw new Error("fullPage cannot be used with element screenshots.");
const fileType = params.type || "png";
const fileName = await tab.context.outputFile(params.filename ?? (0, import_utils.dateAsFileName)(fileType), { origin: "llm", reason: "Saving screenshot" });
const options = {
type: fileType,
quality: fileType === "png" ? void 0 : 90,
scale: "css",
path: fileName,
...params.fullPage !== void 0 && { fullPage: params.fullPage }
};
const isElementScreenshot = params.element && params.ref;
const screenshotTarget = isElementScreenshot ? params.element : params.fullPage ? "full page" : "viewport";
response.addCode(`// Screenshot ${screenshotTarget} and save it as ${fileName}`);
const locator = params.ref ? await tab.refLocator({ element: params.element || "", ref: params.ref }) : null;
if (locator)
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.screenshot(${javascript.formatObject(options)});`);
else
response.addCode(`await page.screenshot(${javascript.formatObject(options)});`);
const buffer = locator ? await locator.screenshot(options) : await tab.page.screenshot(options);
response.addResult(`Took the ${screenshotTarget} screenshot and saved it as ${fileName}`);
if (!params.fullPage) {
response.addImage({
contentType: fileType === "png" ? "image/png" : "image/jpeg",
data: buffer
});
}
}
});
var screenshot_default = [
screenshot
];
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var snapshot_exports = {};
__export(snapshot_exports, {
default: () => snapshot_default,
elementSchema: () => elementSchema
});
module.exports = __toCommonJS(snapshot_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
var javascript = __toESM(require("../codegen"));
var import_utils = require("./utils");
const snapshot = (0, import_tool.defineTool)({
capability: "core",
schema: {
name: "browser_snapshot",
title: "Page snapshot",
description: "Capture accessibility snapshot of the current page, this is better than screenshot",
inputSchema: import_bundle.z.object({}),
type: "readOnly"
},
handle: async (context, params, response) => {
await context.ensureTab();
response.setIncludeSnapshot();
}
});
const elementSchema = import_bundle.z.object({
element: import_bundle.z.string().describe("Human-readable element description used to obtain permission to interact with the element"),
ref: import_bundle.z.string().describe("Exact target element reference from the page snapshot")
});
const clickSchema = elementSchema.extend({
doubleClick: import_bundle.z.boolean().optional().describe("Whether to perform a double click instead of a single click"),
button: import_bundle.z.enum(["left", "right", "middle"]).optional().describe("Button to click, defaults to left"),
modifiers: import_bundle.z.array(import_bundle.z.enum(["Alt", "Control", "ControlOrMeta", "Meta", "Shift"])).optional().describe("Modifier keys to press")
});
const click = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_click",
title: "Click",
description: "Perform click on a web page",
inputSchema: clickSchema,
type: "input"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
const locator = await tab.refLocator(params);
const options = {
button: params.button,
modifiers: params.modifiers
};
const formatted = javascript.formatObject(options, " ", "oneline");
const optionsAttr = formatted !== "{}" ? formatted : "";
if (params.doubleClick)
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.dblclick(${optionsAttr});`);
else
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.click(${optionsAttr});`);
await tab.waitForCompletion(async () => {
if (params.doubleClick)
await locator.dblclick(options);
else
await locator.click(options);
});
}
});
const drag = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_drag",
title: "Drag mouse",
description: "Perform drag and drop between two elements",
inputSchema: import_bundle.z.object({
startElement: import_bundle.z.string().describe("Human-readable source element description used to obtain the permission to interact with the element"),
startRef: import_bundle.z.string().describe("Exact source element reference from the page snapshot"),
endElement: import_bundle.z.string().describe("Human-readable target element description used to obtain the permission to interact with the element"),
endRef: import_bundle.z.string().describe("Exact target element reference from the page snapshot")
}),
type: "input"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
const [startLocator, endLocator] = await tab.refLocators([
{ ref: params.startRef, element: params.startElement },
{ ref: params.endRef, element: params.endElement }
]);
await tab.waitForCompletion(async () => {
await startLocator.dragTo(endLocator);
});
response.addCode(`await page.${await (0, import_utils.generateLocator)(startLocator)}.dragTo(page.${await (0, import_utils.generateLocator)(endLocator)});`);
}
});
const hover = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_hover",
title: "Hover mouse",
description: "Hover over element on page",
inputSchema: elementSchema,
type: "input"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
const locator = await tab.refLocator(params);
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.hover();`);
await tab.waitForCompletion(async () => {
await locator.hover();
});
}
});
const selectOptionSchema = elementSchema.extend({
values: import_bundle.z.array(import_bundle.z.string()).describe("Array of values to select in the dropdown. This can be a single value or multiple values.")
});
const selectOption = (0, import_tool.defineTabTool)({
capability: "core",
schema: {
name: "browser_select_option",
title: "Select option",
description: "Select an option in a dropdown",
inputSchema: selectOptionSchema,
type: "input"
},
handle: async (tab, params, response) => {
response.setIncludeSnapshot();
const locator = await tab.refLocator(params);
response.addCode(`await page.${await (0, import_utils.generateLocator)(locator)}.selectOption(${javascript.formatObject(params.values)});`);
await tab.waitForCompletion(async () => {
await locator.selectOption(params.values);
});
}
});
const pickLocator = (0, import_tool.defineTabTool)({
capability: "testing",
schema: {
name: "browser_generate_locator",
title: "Create locator for element",
description: "Generate locator for the given element to use in tests",
inputSchema: elementSchema,
type: "readOnly"
},
handle: async (tab, params, response) => {
const locator = await tab.refLocator(params);
response.addResult(await (0, import_utils.generateLocator)(locator));
}
});
var snapshot_default = [
snapshot,
click,
drag,
hover,
selectOption,
pickLocator
];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
elementSchema
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tabs_exports = {};
__export(tabs_exports, {
default: () => tabs_default
});
module.exports = __toCommonJS(tabs_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const browserTabs = (0, import_tool.defineTool)({
capability: "core-tabs",
schema: {
name: "browser_tabs",
title: "Manage tabs",
description: "List, create, close, or select a browser tab.",
inputSchema: import_bundle.z.object({
action: import_bundle.z.enum(["list", "new", "close", "select"]).describe("Operation to perform"),
index: import_bundle.z.number().optional().describe("Tab index, used for close/select. If omitted for close, current tab is closed.")
}),
type: "action"
},
handle: async (context, params, response) => {
switch (params.action) {
case "list": {
await context.ensureTab();
response.setIncludeTabs();
return;
}
case "new": {
await context.newTab();
response.setIncludeTabs();
return;
}
case "close": {
await context.closeTab(params.index);
response.setIncludeSnapshot();
return;
}
case "select": {
if (params.index === void 0)
throw new Error("Tab index is required");
await context.selectTab(params.index);
response.setIncludeSnapshot();
return;
}
}
}
});
var tabs_default = [
browserTabs
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tool_exports = {};
__export(tool_exports, {
defineTabTool: () => defineTabTool,
defineTool: () => defineTool
});
module.exports = __toCommonJS(tool_exports);
function defineTool(tool) {
return tool;
}
function defineTabTool(tool) {
return {
...tool,
handle: async (context, params, response) => {
const tab = await context.ensureTab();
const modalStates = tab.modalStates().map((state) => state.type);
if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.
` + tab.modalStatesMarkdown().join("\n"));
else if (!tool.clearsModalState && modalStates.length)
response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.
` + tab.modalStatesMarkdown().join("\n"));
else
return tool.handle(tab, params, response);
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
defineTabTool,
defineTool
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tracing_exports = {};
__export(tracing_exports, {
default: () => tracing_default
});
module.exports = __toCommonJS(tracing_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const tracingStart = (0, import_tool.defineTool)({
capability: "tracing",
schema: {
name: "browser_start_tracing",
title: "Start tracing",
description: "Start trace recording",
inputSchema: import_bundle.z.object({}),
type: "readOnly"
},
handle: async (context, params, response) => {
const browserContext = await context.ensureBrowserContext();
const tracesDir = await context.outputFile(`traces`, { origin: "code", reason: "Collecting trace" });
const name = "trace-" + Date.now();
await browserContext.tracing.start({
name,
screenshots: true,
snapshots: true,
_live: true
});
const traceLegend = `- Action log: ${tracesDir}/${name}.trace
- Network log: ${tracesDir}/${name}.network
- Resources with content by sha1: ${tracesDir}/resources`;
response.addResult(`Tracing started, saving to ${tracesDir}.
${traceLegend}`);
browserContext.tracing[traceLegendSymbol] = traceLegend;
}
});
const tracingStop = (0, import_tool.defineTool)({
capability: "tracing",
schema: {
name: "browser_stop_tracing",
title: "Stop tracing",
description: "Stop trace recording",
inputSchema: import_bundle.z.object({}),
type: "readOnly"
},
handle: async (context, params, response) => {
const browserContext = await context.ensureBrowserContext();
await browserContext.tracing.stop();
const traceLegend = browserContext.tracing[traceLegendSymbol];
response.addResult(`Tracing stopped.
${traceLegend}`);
}
});
var tracing_default = [
tracingStart,
tracingStop
];
const traceLegendSymbol = Symbol("tracesDir");
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var utils_exports = {};
__export(utils_exports, {
callOnPageNoTrace: () => callOnPageNoTrace,
dateAsFileName: () => dateAsFileName,
generateLocator: () => generateLocator,
waitForCompletion: () => waitForCompletion
});
module.exports = __toCommonJS(utils_exports);
var import_utils = require("playwright-core/lib/utils");
async function waitForCompletion(tab, callback) {
const requests = /* @__PURE__ */ new Set();
let frameNavigated = false;
let waitCallback = () => {
};
const waitBarrier = new Promise((f) => {
waitCallback = f;
});
const responseListener = (request) => {
requests.delete(request);
if (!requests.size)
waitCallback();
};
const requestListener = (request) => {
requests.add(request);
void request.response().then(() => responseListener(request)).catch(() => {
});
};
const frameNavigateListener = (frame) => {
if (frame.parentFrame())
return;
frameNavigated = true;
dispose();
clearTimeout(timeout);
void tab.waitForLoadState("load").then(waitCallback);
};
const onTimeout = () => {
dispose();
waitCallback();
};
tab.page.on("request", requestListener);
tab.page.on("requestfailed", responseListener);
tab.page.on("framenavigated", frameNavigateListener);
const timeout = setTimeout(onTimeout, 1e4);
const dispose = () => {
tab.page.off("request", requestListener);
tab.page.off("requestfailed", responseListener);
tab.page.off("framenavigated", frameNavigateListener);
clearTimeout(timeout);
};
try {
const result = await callback();
if (!requests.size && !frameNavigated)
waitCallback();
await waitBarrier;
await tab.waitForTimeout(1e3);
return result;
} finally {
dispose();
}
}
async function generateLocator(locator) {
try {
const { resolvedSelector } = await locator._resolveSelector();
return (0, import_utils.asLocator)("javascript", resolvedSelector);
} catch (e) {
throw new Error("Ref not found, likely because element was removed. Use browser_snapshot to see what elements are currently on the page.");
}
}
async function callOnPageNoTrace(page, callback) {
return await page._wrapApiCall(() => callback(page), { internal: true });
}
function dateAsFileName(extension) {
const date = /* @__PURE__ */ new Date();
return `page-${date.toISOString().replace(/[:.]/g, "-")}.${extension}`;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
callOnPageNoTrace,
dateAsFileName,
generateLocator,
waitForCompletion
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var verify_exports = {};
__export(verify_exports, {
default: () => verify_default
});
module.exports = __toCommonJS(verify_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
var javascript = __toESM(require("../codegen"));
var import_utils = require("./utils");
const verifyElement = (0, import_tool.defineTabTool)({
capability: "testing",
schema: {
name: "browser_verify_element_visible",
title: "Verify element visible",
description: "Verify element is visible on the page",
inputSchema: import_bundle.z.object({
role: import_bundle.z.string().describe('ROLE of the element. Can be found in the snapshot like this: `- {ROLE} "Accessible Name":`'),
accessibleName: import_bundle.z.string().describe('ACCESSIBLE_NAME of the element. Can be found in the snapshot like this: `- role "{ACCESSIBLE_NAME}"`')
}),
type: "assertion"
},
handle: async (tab, params, response) => {
const locator = tab.page.getByRole(params.role, { name: params.accessibleName });
if (await locator.count() === 0) {
response.addError(`Element with role "${params.role}" and accessible name "${params.accessibleName}" not found`);
return;
}
response.addCode(`await expect(page.getByRole(${javascript.escapeWithQuotes(params.role)}, { name: ${javascript.escapeWithQuotes(params.accessibleName)} })).toBeVisible();`);
response.addResult("Done");
}
});
const verifyText = (0, import_tool.defineTabTool)({
capability: "testing",
schema: {
name: "browser_verify_text_visible",
title: "Verify text visible",
description: `Verify text is visible on the page. Prefer ${verifyElement.schema.name} if possible.`,
inputSchema: import_bundle.z.object({
text: import_bundle.z.string().describe('TEXT to verify. Can be found in the snapshot like this: `- role "Accessible Name": {TEXT}` or like this: `- text: {TEXT}`')
}),
type: "assertion"
},
handle: async (tab, params, response) => {
const locator = tab.page.getByText(params.text).filter({ visible: true });
if (await locator.count() === 0) {
response.addError("Text not found");
return;
}
response.addCode(`await expect(page.getByText(${javascript.escapeWithQuotes(params.text)})).toBeVisible();`);
response.addResult("Done");
}
});
const verifyList = (0, import_tool.defineTabTool)({
capability: "testing",
schema: {
name: "browser_verify_list_visible",
title: "Verify list visible",
description: "Verify list is visible on the page",
inputSchema: import_bundle.z.object({
element: import_bundle.z.string().describe("Human-readable list description"),
ref: import_bundle.z.string().describe("Exact target element reference that points to the list"),
items: import_bundle.z.array(import_bundle.z.string()).describe("Items to verify")
}),
type: "assertion"
},
handle: async (tab, params, response) => {
const locator = await tab.refLocator({ ref: params.ref, element: params.element });
const itemTexts = [];
for (const item of params.items) {
const itemLocator = locator.getByText(item);
if (await itemLocator.count() === 0) {
response.addError(`Item "${item}" not found`);
return;
}
itemTexts.push(await itemLocator.textContent());
}
const ariaSnapshot = `\`
- list:
${itemTexts.map((t) => ` - listitem: ${javascript.escapeWithQuotes(t, '"')}`).join("\n")}
\``;
response.addCode(`await expect(page.locator('body')).toMatchAriaSnapshot(${ariaSnapshot});`);
response.addResult("Done");
}
});
const verifyValue = (0, import_tool.defineTabTool)({
capability: "testing",
schema: {
name: "browser_verify_value",
title: "Verify value",
description: "Verify element value",
inputSchema: import_bundle.z.object({
type: import_bundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the element"),
element: import_bundle.z.string().describe("Human-readable element description"),
ref: import_bundle.z.string().describe("Exact target element reference that points to the element"),
value: import_bundle.z.string().describe('Value to verify. For checkbox, use "true" or "false".')
}),
type: "assertion"
},
handle: async (tab, params, response) => {
const locator = await tab.refLocator({ ref: params.ref, element: params.element });
const locatorSource = `page.${await (0, import_utils.generateLocator)(locator)}`;
if (params.type === "textbox" || params.type === "slider" || params.type === "combobox") {
const value = await locator.inputValue();
if (value !== params.value) {
response.addError(`Expected value "${params.value}", but got "${value}"`);
return;
}
response.addCode(`await expect(${locatorSource}).toHaveValue(${javascript.quote(params.value)});`);
} else if (params.type === "checkbox" || params.type === "radio") {
const value = await locator.isChecked();
if (value !== (params.value === "true")) {
response.addError(`Expected value "${params.value}", but got "${value}"`);
return;
}
const matcher = value ? "toBeChecked" : "not.toBeChecked";
response.addCode(`await expect(${locatorSource}).${matcher}();`);
}
response.addResult("Done");
}
});
var verify_default = [
verifyElement,
verifyText,
verifyList,
verifyValue
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var wait_exports = {};
__export(wait_exports, {
default: () => wait_default
});
module.exports = __toCommonJS(wait_exports);
var import_bundle = require("../../sdk/bundle");
var import_tool = require("./tool");
const wait = (0, import_tool.defineTool)({
capability: "core",
schema: {
name: "browser_wait_for",
title: "Wait for",
description: "Wait for text to appear or disappear or a specified time to pass",
inputSchema: import_bundle.z.object({
time: import_bundle.z.number().optional().describe("The time to wait in seconds"),
text: import_bundle.z.string().optional().describe("The text to wait for"),
textGone: import_bundle.z.string().optional().describe("The text to wait for to disappear")
}),
type: "assertion"
},
handle: async (context, params, response) => {
if (!params.text && !params.textGone && !params.time)
throw new Error("Either time, text or textGone must be provided");
if (params.time) {
response.addCode(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
await new Promise((f) => setTimeout(f, Math.min(3e4, params.time * 1e3)));
}
const tab = context.currentTabOrDie();
const locator = params.text ? tab.page.getByText(params.text).first() : void 0;
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : void 0;
if (goneLocator) {
response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
await goneLocator.waitFor({ state: "hidden" });
}
if (locator) {
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
await locator.waitFor({ state: "visible" });
}
response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
response.setIncludeSnapshot();
}
});
var wait_default = [
wait
];
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var watchdog_exports = {};
__export(watchdog_exports, {
setupExitWatchdog: () => setupExitWatchdog
});
module.exports = __toCommonJS(watchdog_exports);
var import_browserContextFactory = require("./browserContextFactory");
var import_context = require("./context");
function setupExitWatchdog() {
let isExiting = false;
const handleExit = async () => {
if (isExiting)
return;
isExiting = true;
setTimeout(() => process.exit(0), 15e3);
await import_context.Context.disposeAll();
await import_browserContextFactory.SharedContextFactory.dispose();
process.exit(0);
};
process.stdin.on("close", handleExit);
process.on("SIGINT", handleExit);
process.on("SIGTERM", handleExit);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
setupExitWatchdog
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var config_d_exports = {};
module.exports = __toCommonJS(config_d_exports);
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var cdpRelay_exports = {};
__export(cdpRelay_exports, {
CDPRelayServer: () => CDPRelayServer
});
module.exports = __toCommonJS(cdpRelay_exports);
var import_child_process = require("child_process");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_registry = require("playwright-core/lib/server/registry/index");
var import_utils = require("playwright-core/lib/utils");
var import_http2 = require("../sdk/http");
var import_log = require("../log");
var protocol = __toESM(require("./protocol"));
const debugLogger = (0, import_utilsBundle.debug)("pw:mcp:relay");
class CDPRelayServer {
constructor(server, browserChannel, userDataDir, executablePath) {
this._playwrightConnection = null;
this._extensionConnection = null;
this._nextSessionId = 1;
this._wsHost = (0, import_http2.httpAddressToString)(server.address()).replace(/^http/, "ws");
this._browserChannel = browserChannel;
this._userDataDir = userDataDir;
this._executablePath = executablePath;
const uuid = crypto.randomUUID();
this._cdpPath = `/cdp/${uuid}`;
this._extensionPath = `/extension/${uuid}`;
this._resetExtensionConnection();
this._wss = new import_utilsBundle.wsServer({ server });
this._wss.on("connection", this._onConnection.bind(this));
}
cdpEndpoint() {
return `${this._wsHost}${this._cdpPath}`;
}
extensionEndpoint() {
return `${this._wsHost}${this._extensionPath}`;
}
async ensureExtensionConnectionForMCPContext(clientInfo, abortSignal, toolName) {
debugLogger("Ensuring extension connection for MCP context");
if (this._extensionConnection)
return;
this._connectBrowser(clientInfo, toolName);
debugLogger("Waiting for incoming extension connection");
await Promise.race([
this._extensionConnectionPromise,
new Promise((_, reject) => setTimeout(() => {
reject(new Error(`Extension connection timeout. Make sure the "Playwright MCP Bridge" extension is installed. See https://github.com/microsoft/playwright-mcp/blob/main/extension/README.md for installation instructions.`));
}, process.env.PWMCP_TEST_CONNECTION_TIMEOUT ? parseInt(process.env.PWMCP_TEST_CONNECTION_TIMEOUT, 10) : 5e3)),
new Promise((_, reject) => abortSignal.addEventListener("abort", reject))
]);
debugLogger("Extension connection established");
}
_connectBrowser(clientInfo, toolName) {
const mcpRelayEndpoint = `${this._wsHost}${this._extensionPath}`;
const url = new URL("chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html");
url.searchParams.set("mcpRelayUrl", mcpRelayEndpoint);
const client = {
name: clientInfo.name,
version: clientInfo.version
};
url.searchParams.set("client", JSON.stringify(client));
url.searchParams.set("protocolVersion", process.env.PWMCP_TEST_PROTOCOL_VERSION ?? protocol.VERSION.toString());
if (toolName)
url.searchParams.set("newTab", String(toolName === "browser_navigate"));
const token = process.env.PLAYWRIGHT_MCP_EXTENSION_TOKEN;
if (token)
url.searchParams.set("token", token);
const href = url.toString();
let executablePath = this._executablePath;
if (!executablePath) {
const executableInfo = import_registry.registry.findExecutable(this._browserChannel);
if (!executableInfo)
throw new Error(`Unsupported channel: "${this._browserChannel}"`);
executablePath = executableInfo.executablePath("javascript");
if (!executablePath)
throw new Error(`"${this._browserChannel}" executable not found. Make sure it is installed at a standard location.`);
}
const args = [];
if (this._userDataDir)
args.push(`--user-data-dir=${this._userDataDir}`);
args.push(href);
(0, import_child_process.spawn)(executablePath, args, {
windowsHide: true,
detached: true,
shell: false,
stdio: "ignore"
});
}
stop() {
this.closeConnections("Server stopped");
this._wss.close();
}
closeConnections(reason) {
this._closePlaywrightConnection(reason);
this._closeExtensionConnection(reason);
}
_onConnection(ws2, request) {
const url = new URL(`http://localhost${request.url}`);
debugLogger(`New connection to ${url.pathname}`);
if (url.pathname === this._cdpPath) {
this._handlePlaywrightConnection(ws2);
} else if (url.pathname === this._extensionPath) {
this._handleExtensionConnection(ws2);
} else {
debugLogger(`Invalid path: ${url.pathname}`);
ws2.close(4004, "Invalid path");
}
}
_handlePlaywrightConnection(ws2) {
if (this._playwrightConnection) {
debugLogger("Rejecting second Playwright connection");
ws2.close(1e3, "Another CDP client already connected");
return;
}
this._playwrightConnection = ws2;
ws2.on("message", async (data) => {
try {
const message = JSON.parse(data.toString());
await this._handlePlaywrightMessage(message);
} catch (error) {
debugLogger(`Error while handling Playwright message
${data.toString()}
`, error);
}
});
ws2.on("close", () => {
if (this._playwrightConnection !== ws2)
return;
this._playwrightConnection = null;
this._closeExtensionConnection("Playwright client disconnected");
debugLogger("Playwright WebSocket closed");
});
ws2.on("error", (error) => {
debugLogger("Playwright WebSocket error:", error);
});
debugLogger("Playwright MCP connected");
}
_closeExtensionConnection(reason) {
this._extensionConnection?.close(reason);
this._extensionConnectionPromise.reject(new Error(reason));
this._resetExtensionConnection();
}
_resetExtensionConnection() {
this._connectedTabInfo = void 0;
this._extensionConnection = null;
this._extensionConnectionPromise = new import_utils.ManualPromise();
void this._extensionConnectionPromise.catch(import_log.logUnhandledError);
}
_closePlaywrightConnection(reason) {
if (this._playwrightConnection?.readyState === import_utilsBundle.ws.OPEN)
this._playwrightConnection.close(1e3, reason);
this._playwrightConnection = null;
}
_handleExtensionConnection(ws2) {
if (this._extensionConnection) {
ws2.close(1e3, "Another extension connection already established");
return;
}
this._extensionConnection = new ExtensionConnection(ws2);
this._extensionConnection.onclose = (c, reason) => {
debugLogger("Extension WebSocket closed:", reason, c === this._extensionConnection);
if (this._extensionConnection !== c)
return;
this._resetExtensionConnection();
this._closePlaywrightConnection(`Extension disconnected: ${reason}`);
};
this._extensionConnection.onmessage = this._handleExtensionMessage.bind(this);
this._extensionConnectionPromise.resolve();
}
_handleExtensionMessage(method, params) {
switch (method) {
case "forwardCDPEvent":
const sessionId = params.sessionId || this._connectedTabInfo?.sessionId;
this._sendToPlaywright({
sessionId,
method: params.method,
params: params.params
});
break;
}
}
async _handlePlaywrightMessage(message) {
debugLogger("\u2190 Playwright:", `${message.method} (id=${message.id})`);
const { id, sessionId, method, params } = message;
try {
const result = await this._handleCDPCommand(method, params, sessionId);
this._sendToPlaywright({ id, sessionId, result });
} catch (e) {
debugLogger("Error in the extension:", e);
this._sendToPlaywright({
id,
sessionId,
error: { message: e.message }
});
}
}
async _handleCDPCommand(method, params, sessionId) {
switch (method) {
case "Browser.getVersion": {
return {
protocolVersion: "1.3",
product: "Chrome/Extension-Bridge",
userAgent: "CDP-Bridge-Server/1.0.0"
};
}
case "Browser.setDownloadBehavior": {
return {};
}
case "Target.setAutoAttach": {
if (sessionId)
break;
const { targetInfo } = await this._extensionConnection.send("attachToTab", {});
this._connectedTabInfo = {
targetInfo,
sessionId: `pw-tab-${this._nextSessionId++}`
};
debugLogger("Simulating auto-attach");
this._sendToPlaywright({
method: "Target.attachedToTarget",
params: {
sessionId: this._connectedTabInfo.sessionId,
targetInfo: {
...this._connectedTabInfo.targetInfo,
attached: true
},
waitingForDebugger: false
}
});
return {};
}
case "Target.getTargetInfo": {
return this._connectedTabInfo?.targetInfo;
}
}
return await this._forwardToExtension(method, params, sessionId);
}
async _forwardToExtension(method, params, sessionId) {
if (!this._extensionConnection)
throw new Error("Extension not connected");
if (this._connectedTabInfo?.sessionId === sessionId)
sessionId = void 0;
return await this._extensionConnection.send("forwardCDPCommand", { sessionId, method, params });
}
_sendToPlaywright(message) {
debugLogger("\u2192 Playwright:", `${message.method ?? `response(id=${message.id})`}`);
this._playwrightConnection?.send(JSON.stringify(message));
}
}
class ExtensionConnection {
constructor(ws2) {
this._callbacks = /* @__PURE__ */ new Map();
this._lastId = 0;
this._ws = ws2;
this._ws.on("message", this._onMessage.bind(this));
this._ws.on("close", this._onClose.bind(this));
this._ws.on("error", this._onError.bind(this));
}
async send(method, params) {
if (this._ws.readyState !== import_utilsBundle.ws.OPEN)
throw new Error(`Unexpected WebSocket state: ${this._ws.readyState}`);
const id = ++this._lastId;
this._ws.send(JSON.stringify({ id, method, params }));
const error = new Error(`Protocol error: ${method}`);
return new Promise((resolve, reject) => {
this._callbacks.set(id, { resolve, reject, error });
});
}
close(message) {
debugLogger("closing extension connection:", message);
if (this._ws.readyState === import_utilsBundle.ws.OPEN)
this._ws.close(1e3, message);
}
_onMessage(event) {
const eventData = event.toString();
let parsedJson;
try {
parsedJson = JSON.parse(eventData);
} catch (e) {
debugLogger(`<closing ws> Closing websocket due to malformed JSON. eventData=${eventData} e=${e?.message}`);
this._ws.close();
return;
}
try {
this._handleParsedMessage(parsedJson);
} catch (e) {
debugLogger(`<closing ws> Closing websocket due to failed onmessage callback. eventData=${eventData} e=${e?.message}`);
this._ws.close();
}
}
_handleParsedMessage(object) {
if (object.id && this._callbacks.has(object.id)) {
const callback = this._callbacks.get(object.id);
this._callbacks.delete(object.id);
if (object.error) {
const error = callback.error;
error.message = object.error;
callback.reject(error);
} else {
callback.resolve(object.result);
}
} else if (object.id) {
debugLogger("\u2190 Extension: unexpected response", object);
} else {
this.onmessage?.(object.method, object.params);
}
}
_onClose(event) {
debugLogger(`<ws closed> code=${event.code} reason=${event.reason}`);
this._dispose();
this.onclose?.(this, event.reason);
}
_onError(event) {
debugLogger(`<ws error> message=${event.message} type=${event.type} target=${event.target}`);
this._dispose();
}
_dispose() {
for (const callback of this._callbacks.values())
callback.reject(new Error("WebSocket closed"));
this._callbacks.clear();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CDPRelayServer
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var extensionContextFactory_exports = {};
__export(extensionContextFactory_exports, {
ExtensionContextFactory: () => ExtensionContextFactory
});
module.exports = __toCommonJS(extensionContextFactory_exports);
var playwright = __toESM(require("playwright-core"));
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_http = require("../sdk/http");
var import_cdpRelay = require("./cdpRelay");
const debugLogger = (0, import_utilsBundle.debug)("pw:mcp:relay");
class ExtensionContextFactory {
constructor(browserChannel, userDataDir, executablePath) {
this._browserChannel = browserChannel;
this._userDataDir = userDataDir;
this._executablePath = executablePath;
}
async createContext(clientInfo, abortSignal, toolName) {
const browser = await this._obtainBrowser(clientInfo, abortSignal, toolName);
return {
browserContext: browser.contexts()[0],
close: async () => {
debugLogger("close() called for browser context");
await browser.close();
}
};
}
async _obtainBrowser(clientInfo, abortSignal, toolName) {
const relay = await this._startRelay(abortSignal);
await relay.ensureExtensionConnectionForMCPContext(clientInfo, abortSignal, toolName);
return await playwright.chromium.connectOverCDP(relay.cdpEndpoint());
}
async _startRelay(abortSignal) {
const httpServer = await (0, import_http.startHttpServer)({});
if (abortSignal.aborted) {
httpServer.close();
throw new Error(abortSignal.reason);
}
const cdpRelayServer = new import_cdpRelay.CDPRelayServer(httpServer, this._browserChannel, this._userDataDir, this._executablePath);
abortSignal.addEventListener("abort", () => cdpRelayServer.stop());
debugLogger(`CDP relay server started, extension endpoint: ${cdpRelayServer.extensionEndpoint()}.`);
return cdpRelayServer;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ExtensionContextFactory
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var protocol_exports = {};
__export(protocol_exports, {
VERSION: () => VERSION
});
module.exports = __toCommonJS(protocol_exports);
const VERSION = 1;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
VERSION
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var mcp_exports = {};
__export(mcp_exports, {
createConnection: () => createConnection
});
module.exports = __toCommonJS(mcp_exports);
var import_browserServerBackend = require("./browser/browserServerBackend");
var import_config = require("./browser/config");
var import_browserContextFactory = require("./browser/browserContextFactory");
var mcpServer = __toESM(require("./sdk/server"));
const packageJSON = require("../../package.json");
async function createConnection(userConfig = {}, contextGetter) {
const config = await (0, import_config.resolveConfig)(userConfig);
const factory = contextGetter ? new SimpleBrowserContextFactory(contextGetter) : (0, import_browserContextFactory.contextFactory)(config);
return mcpServer.createServer("Playwright", packageJSON.version, new import_browserServerBackend.BrowserServerBackend(config, factory), false);
}
class SimpleBrowserContextFactory {
constructor(contextGetter) {
this.name = "custom";
this.description = "Connect to a browser using a custom context getter";
this._contextGetter = contextGetter;
}
async createContext() {
const browserContext = await this._contextGetter();
return {
browserContext,
close: () => browserContext.close()
};
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createConnection
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var log_exports = {};
__export(log_exports, {
logUnhandledError: () => logUnhandledError,
testDebug: () => testDebug
});
module.exports = __toCommonJS(log_exports);
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
const errorDebug = (0, import_utilsBundle.debug)("pw:mcp:error");
function logUnhandledError(error) {
errorDebug(error);
}
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
logUnhandledError,
testDebug
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var program_exports = {};
__export(program_exports, {
decorateCommand: () => decorateCommand
});
module.exports = __toCommonJS(program_exports);
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var mcpServer = __toESM(require("./sdk/server"));
var import_config = require("./browser/config");
var import_watchdog = require("./browser/watchdog");
var import_browserContextFactory = require("./browser/browserContextFactory");
var import_proxyBackend = require("./sdk/proxyBackend");
var import_browserServerBackend = require("./browser/browserServerBackend");
var import_extensionContextFactory = require("./extension/extensionContextFactory");
function decorateCommand(command, version) {
command.option("--allowed-hosts <hosts...>", "comma-separated list of hosts this server is allowed to serve from. Defaults to the host the server is bound to. Pass '*' to disable the host check.", import_config.commaSeparatedList).option("--allowed-origins <origins>", "semicolon-separated list of origins to allow the browser to request. Default is to allow all.", import_config.semicolonSeparatedList).option("--blocked-origins <origins>", "semicolon-separated list of origins to block the browser from requesting. Blocklist is evaluated before allowlist. If used without the allowlist, requests not matching the blocklist are still allowed.", import_config.semicolonSeparatedList).option("--block-service-workers", "block service workers").option("--browser <browser>", "browser or chrome channel to use, possible values: chrome, firefox, webkit, msedge.").option("--caps <caps>", "comma-separated list of additional capabilities to enable, possible values: vision, pdf.", import_config.commaSeparatedList).option("--cdp-endpoint <endpoint>", "CDP endpoint to connect to.").option("--cdp-header <headers...>", "CDP headers to send with the connect request, multiple can be specified.", import_config.headerParser).option("--config <path>", "path to the configuration file.").option("--device <device>", 'device to emulate, for example: "iPhone 15"').option("--executable-path <path>", "path to the browser executable.").option("--extension", 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').option("--grant-permissions <permissions...>", 'List of permissions to grant to the browser context, for example "geolocation", "clipboard-read", "clipboard-write".', import_config.commaSeparatedList).option("--headless", "run browser in headless mode, headed by default").option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.").option("--ignore-https-errors", "ignore https errors").option("--init-script <path...>", "path to JavaScript file to add as an initialization script. The script will be evaluated in every page before any of the page's scripts. Can be specified multiple times.").option("--isolated", "keep the browser profile in memory, do not save it to disk.").option("--image-responses <mode>", 'whether to send image responses to the client. Can be "allow" or "omit", Defaults to "allow".').option("--no-sandbox", "disable the sandbox for all process types that are normally sandboxed.").option("--output-dir <path>", "path to the directory for output files.").option("--port <port>", "port to listen on for SSE transport.").option("--proxy-bypass <bypass>", 'comma-separated domains to bypass proxy, for example ".com,chromium.org,.domain.com"').option("--proxy-server <proxy>", 'specify proxy server, for example "http://myproxy:3128" or "socks5://myproxy:8080"').option("--save-session", "Whether to save the Playwright MCP session into the output directory.").option("--save-trace", "Whether to save the Playwright Trace of the session into the output directory.").option("--save-video <size>", 'Whether to save the video of the session into the output directory. For example "--save-video=800x600"', import_config.resolutionParser.bind(null, "--save-video")).option("--secrets <path>", "path to a file containing secrets in the dotenv format", import_config.dotenvFileLoader).option("--shared-browser-context", "reuse the same browser context between all connected HTTP clients.").option("--storage-state <path>", "path to the storage state file for isolated sessions.").option("--timeout-action <timeout>", "specify action timeout in milliseconds, defaults to 5000ms", import_config.numberParser).option("--timeout-navigation <timeout>", "specify navigation timeout in milliseconds, defaults to 60000ms", import_config.numberParser).option("--user-agent <ua string>", "specify user agent string").option("--user-data-dir <path>", "path to the user data directory. If not specified, a temporary directory will be created.").option("--viewport-size <size>", 'specify browser viewport size in pixels, for example "1280x720"', import_config.resolutionParser.bind(null, "--viewport-size")).addOption(new import_utilsBundle.ProgramOption("--connect-tool", "Allow to switch between different browser connection methods.").hideHelp()).addOption(new import_utilsBundle.ProgramOption("--vision", "Legacy option, use --caps=vision instead").hideHelp()).action(async (options) => {
(0, import_watchdog.setupExitWatchdog)();
if (options.vision) {
console.error("The --vision option is deprecated, use --caps=vision instead");
options.caps = "vision";
}
const config = await (0, import_config.resolveCLIConfig)(options);
const browserContextFactory = (0, import_browserContextFactory.contextFactory)(config);
const extensionContextFactory = new import_extensionContextFactory.ExtensionContextFactory(config.browser.launchOptions.channel || "chrome", config.browser.userDataDir, config.browser.launchOptions.executablePath);
if (options.extension) {
const serverBackendFactory = {
name: "Playwright w/ extension",
nameInConfig: "playwright-extension",
version,
create: () => new import_browserServerBackend.BrowserServerBackend(config, extensionContextFactory)
};
await mcpServer.start(serverBackendFactory, config.server);
return;
}
if (options.connectTool) {
const providers = [
{
name: "default",
description: "Starts standalone browser",
connect: () => mcpServer.wrapInProcess(new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory))
},
{
name: "extension",
description: "Connect to a browser using the Playwright MCP extension",
connect: () => mcpServer.wrapInProcess(new import_browserServerBackend.BrowserServerBackend(config, extensionContextFactory))
}
];
const factory2 = {
name: "Playwright w/ switch",
nameInConfig: "playwright-switch",
version,
create: () => new import_proxyBackend.ProxyBackend(providers)
};
await mcpServer.start(factory2, config.server);
return;
}
const factory = {
name: "Playwright",
nameInConfig: "playwright",
version,
create: () => new import_browserServerBackend.BrowserServerBackend(config, browserContextFactory)
};
await mcpServer.start(factory, config.server);
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
decorateCommand
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var bundle_exports = {};
__export(bundle_exports, {
CallToolRequestSchema: () => CallToolRequestSchema,
Client: () => Client,
ListRootsRequestSchema: () => ListRootsRequestSchema,
ListToolsRequestSchema: () => ListToolsRequestSchema,
PingRequestSchema: () => PingRequestSchema,
ProgressNotificationSchema: () => ProgressNotificationSchema,
SSEClientTransport: () => SSEClientTransport,
SSEServerTransport: () => SSEServerTransport,
Server: () => Server,
StdioClientTransport: () => StdioClientTransport,
StdioServerTransport: () => StdioServerTransport,
StreamableHTTPClientTransport: () => StreamableHTTPClientTransport,
StreamableHTTPServerTransport: () => StreamableHTTPServerTransport,
z: () => z,
zodToJsonSchema: () => zodToJsonSchema
});
module.exports = __toCommonJS(bundle_exports);
var bundle = __toESM(require("../../mcpBundleImpl"));
const zodToJsonSchema = bundle.zodToJsonSchema;
const Client = bundle.Client;
const Server = bundle.Server;
const SSEClientTransport = bundle.SSEClientTransport;
const SSEServerTransport = bundle.SSEServerTransport;
const StdioClientTransport = bundle.StdioClientTransport;
const StdioServerTransport = bundle.StdioServerTransport;
const StreamableHTTPServerTransport = bundle.StreamableHTTPServerTransport;
const StreamableHTTPClientTransport = bundle.StreamableHTTPClientTransport;
const CallToolRequestSchema = bundle.CallToolRequestSchema;
const ListRootsRequestSchema = bundle.ListRootsRequestSchema;
const ProgressNotificationSchema = bundle.ProgressNotificationSchema;
const ListToolsRequestSchema = bundle.ListToolsRequestSchema;
const PingRequestSchema = bundle.PingRequestSchema;
const z = bundle.z;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CallToolRequestSchema,
Client,
ListRootsRequestSchema,
ListToolsRequestSchema,
PingRequestSchema,
ProgressNotificationSchema,
SSEClientTransport,
SSEServerTransport,
Server,
StdioClientTransport,
StdioServerTransport,
StreamableHTTPClientTransport,
StreamableHTTPServerTransport,
z,
zodToJsonSchema
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var exports_exports = {};
module.exports = __toCommonJS(exports_exports);
__reExport(exports_exports, require("./inProcessTransport"), module.exports);
__reExport(exports_exports, require("./proxyBackend"), module.exports);
__reExport(exports_exports, require("./server"), module.exports);
__reExport(exports_exports, require("./tool"), module.exports);
__reExport(exports_exports, require("./http"), module.exports);
__reExport(exports_exports, require("./mdb"), module.exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
...require("./inProcessTransport"),
...require("./proxyBackend"),
...require("./server"),
...require("./tool"),
...require("./http"),
...require("./mdb")
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var http_exports = {};
__export(http_exports, {
httpAddressToString: () => httpAddressToString,
installHttpTransport: () => installHttpTransport,
startHttpServer: () => startHttpServer
});
module.exports = __toCommonJS(http_exports);
var import_assert = __toESM(require("assert"));
var import_http = __toESM(require("http"));
var import_crypto = __toESM(require("crypto"));
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var mcpBundle = __toESM(require("./bundle"));
var mcpServer = __toESM(require("./server"));
const testDebug = (0, import_utilsBundle.debug)("pw:mcp:test");
async function startHttpServer(config, abortSignal) {
const { host, port } = config;
const httpServer = import_http.default.createServer();
decorateServer(httpServer);
await new Promise((resolve, reject) => {
httpServer.on("error", reject);
abortSignal?.addEventListener("abort", () => {
httpServer.close();
reject(new Error("Aborted"));
});
httpServer.listen(port, host, () => {
resolve();
httpServer.removeListener("error", reject);
});
});
return httpServer;
}
function httpAddressToString(address) {
(0, import_assert.default)(address, "Could not bind server socket");
if (typeof address === "string")
return address;
const resolvedPort = address.port;
let resolvedHost = address.family === "IPv4" ? address.address : `[${address.address}]`;
if (resolvedHost === "0.0.0.0" || resolvedHost === "[::]")
resolvedHost = "localhost";
return `http://${resolvedHost}:${resolvedPort}`;
}
async function installHttpTransport(httpServer, serverBackendFactory, allowedHosts) {
const url = httpAddressToString(httpServer.address());
const host = new URL(url).host;
allowedHosts = (allowedHosts || [host]).map((h) => h.toLowerCase());
const allowAnyHost = allowedHosts.includes("*");
const sseSessions = /* @__PURE__ */ new Map();
const streamableSessions = /* @__PURE__ */ new Map();
httpServer.on("request", async (req, res) => {
if (!allowAnyHost) {
const host2 = req.headers.host?.toLowerCase();
if (!host2) {
res.statusCode = 400;
return res.end("Missing host");
}
if (!allowedHosts.includes(host2)) {
res.statusCode = 403;
return res.end("Access is only allowed at " + allowedHosts.join(", "));
}
}
const url2 = new URL(`http://localhost${req.url}`);
if (url2.pathname === "/killkillkill" && req.method === "GET") {
res.statusCode = 200;
res.end("Killing process");
process.emit("SIGINT");
return;
}
if (url2.pathname.startsWith("/sse"))
await handleSSE(serverBackendFactory, req, res, url2, sseSessions);
else
await handleStreamable(serverBackendFactory, req, res, streamableSessions);
});
}
async function handleSSE(serverBackendFactory, req, res, url, sessions) {
if (req.method === "POST") {
const sessionId = url.searchParams.get("sessionId");
if (!sessionId) {
res.statusCode = 400;
return res.end("Missing sessionId");
}
const transport = sessions.get(sessionId);
if (!transport) {
res.statusCode = 404;
return res.end("Session not found");
}
return await transport.handlePostMessage(req, res);
} else if (req.method === "GET") {
const transport = new mcpBundle.SSEServerTransport("/sse", res);
sessions.set(transport.sessionId, transport);
testDebug(`create SSE session: ${transport.sessionId}`);
await mcpServer.connect(serverBackendFactory, transport, false);
res.on("close", () => {
testDebug(`delete SSE session: ${transport.sessionId}`);
sessions.delete(transport.sessionId);
});
return;
}
res.statusCode = 405;
res.end("Method not allowed");
}
async function handleStreamable(serverBackendFactory, req, res, sessions) {
const sessionId = req.headers["mcp-session-id"];
if (sessionId) {
const transport = sessions.get(sessionId);
if (!transport) {
res.statusCode = 404;
res.end("Session not found");
return;
}
return await transport.handleRequest(req, res);
}
if (req.method === "POST") {
const transport = new mcpBundle.StreamableHTTPServerTransport({
sessionIdGenerator: () => import_crypto.default.randomUUID(),
onsessioninitialized: async (sessionId2) => {
testDebug(`create http session: ${transport.sessionId}`);
await mcpServer.connect(serverBackendFactory, transport, true);
sessions.set(sessionId2, transport);
}
});
transport.onclose = () => {
if (!transport.sessionId)
return;
sessions.delete(transport.sessionId);
testDebug(`delete http session: ${transport.sessionId}`);
};
await transport.handleRequest(req, res);
return;
}
res.statusCode = 400;
res.end("Invalid request");
}
function decorateServer(server) {
const sockets = /* @__PURE__ */ new Set();
server.on("connection", (socket) => {
sockets.add(socket);
socket.once("close", () => sockets.delete(socket));
});
const close = server.close;
server.close = (callback) => {
for (const socket of sockets)
socket.destroy();
sockets.clear();
return close.call(server, callback);
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
httpAddressToString,
installHttpTransport,
startHttpServer
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var inProcessTransport_exports = {};
__export(inProcessTransport_exports, {
InProcessTransport: () => InProcessTransport
});
module.exports = __toCommonJS(inProcessTransport_exports);
class InProcessTransport {
constructor(server) {
this._connected = false;
this._server = server;
this._serverTransport = new InProcessServerTransport(this);
}
async start() {
if (this._connected)
throw new Error("InprocessTransport already started!");
await this._server.connect(this._serverTransport);
this._connected = true;
}
async send(message, options) {
if (!this._connected)
throw new Error("Transport not connected");
this._serverTransport._receiveFromClient(message);
}
async close() {
if (this._connected) {
this._connected = false;
this.onclose?.();
this._serverTransport.onclose?.();
}
}
_receiveFromServer(message, extra) {
this.onmessage?.(message, extra);
}
}
class InProcessServerTransport {
constructor(clientTransport) {
this._clientTransport = clientTransport;
}
async start() {
}
async send(message, options) {
this._clientTransport._receiveFromServer(message);
}
async close() {
this.onclose?.();
}
_receiveFromClient(message) {
this.onmessage?.(message);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
InProcessTransport
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var mdb_exports = {};
__export(mdb_exports, {
MDBBackend: () => MDBBackend,
runMainBackend: () => runMainBackend,
runOnPauseBackendLoop: () => runOnPauseBackendLoop
});
module.exports = __toCommonJS(mdb_exports);
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_utils = require("playwright-core/lib/utils");
var import_tool = require("./tool");
var mcpBundle = __toESM(require("./bundle"));
var mcpServer = __toESM(require("./server"));
var mcpHttp = __toESM(require("./http"));
const mdbDebug = (0, import_utilsBundle.debug)("pw:mcp:mdb");
const errorsDebug = (0, import_utilsBundle.debug)("pw:mcp:errors");
const z = mcpBundle.z;
class MDBBackend {
constructor(mainBackend) {
this._progress = [];
this._mainBackend = mainBackend;
this._progressCallback = (params) => {
if (params.message)
this._progress.push({ type: "text", text: params.message });
};
}
async initialize(server, clientInfo) {
if (!this._clientInfo) {
this._clientInfo = clientInfo;
await this._mainBackend.initialize?.(server, clientInfo);
}
}
async listTools() {
return await this._mainBackend.listTools();
}
async callTool(name, args) {
if (name === pushToolsSchema.name) {
await this._createOnPauseClient(pushToolsSchema.inputSchema.parse(args || {}));
return { content: [{ type: "text", text: "Tools pushed" }] };
}
if (this._onPauseClient?.tools.find((tool) => tool.name === name)) {
const result2 = await this._onPauseClient.client.callTool({
name,
arguments: args
});
await this._mainBackend.afterCallTool?.(name, args, result2);
return result2;
}
await this._onPauseClient?.transport.terminateSession().catch(errorsDebug);
await this._onPauseClient?.client.close().catch(errorsDebug);
this._onPauseClient = void 0;
const resultPromise = new import_utils.ManualPromise();
const interruptPromise = new import_utils.ManualPromise();
this._interruptPromise = interruptPromise;
this._mainBackend.callTool(name, args, this._progressCallback).then((result2) => {
resultPromise.resolve(result2);
}).catch((e) => {
resultPromise.resolve({ content: [{ type: "text", text: String(e) }], isError: true });
});
const result = await Promise.race([interruptPromise, resultPromise]);
if (interruptPromise.isDone())
mdbDebug("client call intercepted", result);
else
mdbDebug("client call result", result);
result.content.unshift(...this._progress);
this._progress.length = 0;
return result;
}
async _createOnPauseClient(params) {
if (this._onPauseClient)
await this._onPauseClient.client.close().catch(errorsDebug);
this._onPauseClient = await this._createClient(params.mcpUrl);
this._interruptPromise?.resolve({
content: [{
type: "text",
text: params.introMessage || ""
}]
});
this._interruptPromise = void 0;
}
async _createClient(url) {
const client = new mcpBundle.Client({ name: "Interrupting client", version: "0.0.0" }, { capabilities: { roots: {} } });
client.setRequestHandler(mcpBundle.ListRootsRequestSchema, () => ({ roots: this._clientInfo?.roots || [] }));
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
client.setNotificationHandler(mcpBundle.ProgressNotificationSchema, (notification) => {
if (notification.method === "notifications/progress") {
const { message } = notification.params;
if (message)
this._progress.push({ type: "text", text: message });
}
});
const transport = new mcpBundle.StreamableHTTPClientTransport(new URL(url));
await client.connect(transport);
const { tools } = await client.listTools();
return { client, tools, transport };
}
}
const pushToolsSchema = (0, import_tool.defineToolSchema)({
name: "mdb_push_tools",
title: "Push MCP tools to the tools stack",
description: "Push MCP tools to the tools stack",
inputSchema: z.object({
mcpUrl: z.string(),
introMessage: z.string().optional()
}),
type: "readOnly"
});
async function runMainBackend(backendFactory, options) {
const mdbBackend = new MDBBackend(backendFactory.create());
const factory = {
...backendFactory,
create: () => mdbBackend
};
const url = await startAsHttp(factory, { port: options?.port || 0 });
process.env.PLAYWRIGHT_DEBUGGER_MCP = url;
if (options?.port !== void 0)
return url;
await mcpServer.connect(factory, new mcpBundle.StdioServerTransport(), false);
}
async function runOnPauseBackendLoop(backend, introMessage) {
const wrappedBackend = new ServerBackendWithCloseListener(backend);
const factory = {
name: "on-pause-backend",
nameInConfig: "on-pause-backend",
version: "0.0.0",
create: () => wrappedBackend
};
const httpServer = await mcpHttp.startHttpServer({ port: 0 });
await mcpHttp.installHttpTransport(httpServer, factory);
const url = mcpHttp.httpAddressToString(httpServer.address());
const client = new mcpBundle.Client({ name: "Pushing client", version: "0.0.0" });
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
const transport = new mcpBundle.StreamableHTTPClientTransport(new URL(process.env.PLAYWRIGHT_DEBUGGER_MCP));
await client.connect(transport);
const pushToolsResult = await client.callTool({
name: pushToolsSchema.name,
arguments: {
mcpUrl: url,
introMessage
}
});
if (pushToolsResult.isError)
errorsDebug("Failed to push tools", pushToolsResult.content);
await transport.terminateSession();
await client.close();
await wrappedBackend.waitForClosed();
httpServer.close();
}
async function startAsHttp(backendFactory, options) {
const httpServer = await mcpHttp.startHttpServer(options);
await mcpHttp.installHttpTransport(httpServer, backendFactory);
return mcpHttp.httpAddressToString(httpServer.address());
}
class ServerBackendWithCloseListener {
constructor(backend) {
this._serverClosedPromise = new import_utils.ManualPromise();
this._backend = backend;
}
async initialize(server, clientInfo) {
await this._backend.initialize?.(server, clientInfo);
}
async listTools() {
return this._backend.listTools();
}
async callTool(name, args, progress) {
return this._backend.callTool(name, args, progress);
}
serverClosed(server) {
this._backend.serverClosed?.(server);
this._serverClosedPromise.resolve();
}
async waitForClosed() {
await this._serverClosedPromise;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MDBBackend,
runMainBackend,
runOnPauseBackendLoop
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var proxyBackend_exports = {};
__export(proxyBackend_exports, {
ProxyBackend: () => ProxyBackend
});
module.exports = __toCommonJS(proxyBackend_exports);
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var mcpBundle = __toESM(require("./bundle"));
const errorsDebug = (0, import_utilsBundle.debug)("pw:mcp:errors");
const { z, zodToJsonSchema } = mcpBundle;
class ProxyBackend {
constructor(mcpProviders) {
this._mcpProviders = mcpProviders;
this._contextSwitchTool = this._defineContextSwitchTool();
}
async initialize(server, clientInfo) {
this._clientInfo = clientInfo;
}
async listTools() {
const currentClient = await this._ensureCurrentClient();
const response = await currentClient.listTools();
if (this._mcpProviders.length === 1)
return response.tools;
return [
...response.tools,
this._contextSwitchTool
];
}
async callTool(name, args) {
if (name === this._contextSwitchTool.name)
return this._callContextSwitchTool(args);
const currentClient = await this._ensureCurrentClient();
return await currentClient.callTool({
name,
arguments: args
});
}
serverClosed() {
void this._currentClient?.close().catch(errorsDebug);
}
async _callContextSwitchTool(params) {
try {
const factory = this._mcpProviders.find((factory2) => factory2.name === params.name);
if (!factory)
throw new Error("Unknown connection method: " + params.name);
await this._setCurrentClient(factory);
return {
content: [{ type: "text", text: "### Result\nSuccessfully changed connection method.\n" }]
};
} catch (error) {
return {
content: [{ type: "text", text: `### Result
Error: ${error}
` }],
isError: true
};
}
}
_defineContextSwitchTool() {
return {
name: "browser_connect",
description: [
"Connect to a browser using one of the available methods:",
...this._mcpProviders.map((factory) => `- "${factory.name}": ${factory.description}`)
].join("\n"),
inputSchema: zodToJsonSchema(z.object({
name: z.enum(this._mcpProviders.map((factory) => factory.name)).default(this._mcpProviders[0].name).describe("The method to use to connect to the browser")
}), { strictUnions: true }),
annotations: {
title: "Connect to a browser context",
readOnlyHint: true,
openWorldHint: false
}
};
}
async _ensureCurrentClient() {
if (this._currentClient)
return this._currentClient;
return await this._setCurrentClient(this._mcpProviders[0]);
}
async _setCurrentClient(factory) {
await this._currentClient?.close();
this._currentClient = void 0;
const client = new mcpBundle.Client({ name: "Playwright MCP Proxy", version: "0.0.0" });
client.registerCapabilities({
roots: {
listRoots: true
}
});
client.setRequestHandler(mcpBundle.ListRootsRequestSchema, () => ({ roots: this._clientInfo?.roots || [] }));
client.setRequestHandler(mcpBundle.PingRequestSchema, () => ({}));
const transport = await factory.connect();
await client.connect(transport);
this._currentClient = client;
return client;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ProxyBackend
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var server_exports = {};
__export(server_exports, {
connect: () => connect,
createServer: () => createServer,
firstRootPath: () => firstRootPath,
start: () => start,
wrapInProcess: () => wrapInProcess
});
module.exports = __toCommonJS(server_exports);
var import_url = require("url");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var mcpBundle = __toESM(require("./bundle"));
var import_http = require("./http");
var import_inProcessTransport = require("./inProcessTransport");
const serverDebug = (0, import_utilsBundle.debug)("pw:mcp:server");
async function connect(factory, transport, runHeartbeat) {
const server = createServer(factory.name, factory.version, factory.create(), runHeartbeat);
await server.connect(transport);
}
async function wrapInProcess(backend) {
const server = createServer("Internal", "0.0.0", backend, false);
return new import_inProcessTransport.InProcessTransport(server);
}
function createServer(name, version, backend, runHeartbeat) {
const server = new mcpBundle.Server({ name, version }, {
capabilities: {
tools: {}
}
});
server.setRequestHandler(mcpBundle.ListToolsRequestSchema, async () => {
serverDebug("listTools");
const tools = await backend.listTools();
return { tools };
});
let initializePromise;
server.setRequestHandler(mcpBundle.CallToolRequestSchema, async (request, extra) => {
serverDebug("callTool", request);
const progressToken = request.params._meta?.progressToken;
let progressCounter = 0;
const progress = progressToken ? (params) => {
extra.sendNotification({
method: "notifications/progress",
params: {
progressToken,
progress: params.progress ?? ++progressCounter,
total: params.total,
message: params.message
}
}).catch(serverDebug);
} : () => {
};
try {
if (!initializePromise)
initializePromise = initializeServer(server, backend, runHeartbeat);
await initializePromise;
return mergeTextParts(await backend.callTool(request.params.name, request.params.arguments || {}, progress));
} catch (error) {
return {
content: [{ type: "text", text: "### Result\n" + String(error) }],
isError: true
};
}
});
addServerListener(server, "close", () => backend.serverClosed?.(server));
return server;
}
const initializeServer = async (server, backend, runHeartbeat) => {
const capabilities = server.getClientCapabilities();
let clientRoots = [];
if (capabilities?.roots) {
const { roots } = await server.listRoots().catch((e) => {
serverDebug(e);
return { roots: [] };
});
clientRoots = roots;
}
const clientInfo = {
name: server.getClientVersion()?.name ?? "unknown",
version: server.getClientVersion()?.version ?? "unknown",
roots: clientRoots,
timestamp: Date.now()
};
await backend.initialize?.(server, clientInfo);
if (runHeartbeat)
startHeartbeat(server);
};
const startHeartbeat = (server) => {
const beat = () => {
Promise.race([
server.ping(),
new Promise((_, reject) => setTimeout(() => reject(new Error("ping timeout")), 5e3))
]).then(() => {
setTimeout(beat, 3e3);
}).catch(() => {
void server.close();
});
};
beat();
};
function addServerListener(server, event, listener) {
const oldListener = server[`on${event}`];
server[`on${event}`] = () => {
oldListener?.();
listener();
};
}
async function start(serverBackendFactory, options) {
if (options.port === void 0) {
await connect(serverBackendFactory, new mcpBundle.StdioServerTransport(), false);
return;
}
const httpServer = await (0, import_http.startHttpServer)(options);
const url = (0, import_http.httpAddressToString)(httpServer.address());
await (0, import_http.installHttpTransport)(httpServer, serverBackendFactory, options.allowedHosts);
const mcpConfig = { mcpServers: {} };
mcpConfig.mcpServers[serverBackendFactory.nameInConfig] = {
url: `${url}/mcp`
};
const message = [
`Listening on ${url}`,
"Put this in your client config:",
JSON.stringify(mcpConfig, void 0, 2),
"For legacy SSE transport support, you can use the /sse endpoint instead."
].join("\n");
console.error(message);
}
function firstRootPath(clientInfo) {
if (clientInfo.roots.length === 0)
return void 0;
const firstRootUri = clientInfo.roots[0]?.uri;
const url = firstRootUri ? new URL(firstRootUri) : void 0;
return url ? (0, import_url.fileURLToPath)(url) : void 0;
}
function mergeTextParts(result) {
const content = [];
const testParts = [];
for (const part of result.content) {
if (part.type === "text") {
testParts.push(part.text);
continue;
}
if (testParts.length > 0) {
content.push({ type: "text", text: testParts.join("\n") });
testParts.length = 0;
}
content.push(part);
}
if (testParts.length > 0)
content.push({ type: "text", text: testParts.join("\n") });
return {
...result,
content
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
connect,
createServer,
firstRootPath,
start,
wrapInProcess
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tool_exports = {};
__export(tool_exports, {
defineToolSchema: () => defineToolSchema,
toMcpTool: () => toMcpTool
});
module.exports = __toCommonJS(tool_exports);
var import_bundle = require("../sdk/bundle");
const typesWithIntent = ["action", "assertion", "input"];
function toMcpTool(tool, options) {
const inputSchema = options?.addIntent && typesWithIntent.includes(tool.type) ? tool.inputSchema.extend({
intent: import_bundle.z.string().describe("The intent of the call, for example the test step description plan idea")
}) : tool.inputSchema;
const readOnly = tool.type === "readOnly" || tool.type === "assertion";
return {
name: tool.name,
description: tool.description,
inputSchema: (0, import_bundle.zodToJsonSchema)(inputSchema, { strictUnions: true }),
annotations: {
title: tool.title,
readOnlyHint: readOnly,
destructiveHint: !readOnly,
openWorldHint: true
}
};
}
function defineToolSchema(tool) {
return tool;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
defineToolSchema,
toMcpTool
});

Sorry, the diff of this file is too big to display

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var gitCommitInfoPlugin_exports = {};
__export(gitCommitInfoPlugin_exports, {
addGitCommitInfoPlugin: () => addGitCommitInfoPlugin
});
module.exports = __toCommonJS(gitCommitInfoPlugin_exports);
var fs = __toESM(require("fs"));
var import_utils = require("playwright-core/lib/utils");
const GIT_OPERATIONS_TIMEOUT_MS = 3e3;
const addGitCommitInfoPlugin = (fullConfig) => {
fullConfig.plugins.push({ factory: gitCommitInfoPlugin.bind(null, fullConfig) });
};
function print(s, ...args) {
console.log("GitCommitInfo: " + s, ...args);
}
function debug(s, ...args) {
if (!process.env.DEBUG_GIT_COMMIT_INFO)
return;
print(s, ...args);
}
const gitCommitInfoPlugin = (fullConfig) => {
return {
name: "playwright:git-commit-info",
setup: async (config, configDir) => {
const metadata = config.metadata;
const ci = await ciInfo();
if (!metadata.ci && ci) {
debug("ci info", ci);
metadata.ci = ci;
}
if (fullConfig.captureGitInfo?.commit || fullConfig.captureGitInfo?.commit === void 0 && ci) {
const git = await gitCommitInfo(configDir).catch((e) => print("failed to get git commit info", e));
if (git) {
debug("commit info", git);
metadata.gitCommit = git;
}
}
if (fullConfig.captureGitInfo?.diff || fullConfig.captureGitInfo?.diff === void 0 && ci) {
const diffResult = await gitDiff(configDir, ci).catch((e) => print("failed to get git diff", e));
if (diffResult) {
debug(`diff length ${diffResult.length}`);
metadata.gitDiff = diffResult;
}
}
}
};
};
async function ciInfo() {
if (process.env.GITHUB_ACTIONS) {
let pr;
try {
const json = JSON.parse(await fs.promises.readFile(process.env.GITHUB_EVENT_PATH, "utf8"));
pr = { title: json.pull_request.title, number: json.pull_request.number, baseHash: json.pull_request.base.sha };
} catch {
}
return {
commitHref: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/commit/${process.env.GITHUB_SHA}`,
commitHash: process.env.GITHUB_SHA,
prHref: pr ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/pull/${pr.number}` : void 0,
prTitle: pr?.title,
prBaseHash: pr?.baseHash,
buildHref: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
};
}
if (process.env.GITLAB_CI) {
return {
commitHref: `${process.env.CI_PROJECT_URL}/-/commit/${process.env.CI_COMMIT_SHA}`,
commitHash: process.env.CI_COMMIT_SHA,
buildHref: process.env.CI_JOB_URL,
branch: process.env.CI_COMMIT_REF_NAME
};
}
if (process.env.JENKINS_URL && process.env.BUILD_URL) {
return {
commitHref: process.env.BUILD_URL,
commitHash: process.env.GIT_COMMIT,
branch: process.env.GIT_BRANCH
};
}
}
async function gitCommitInfo(gitDir) {
const separator = `---786eec917292---`;
const tokens = [
"%H",
// commit hash
"%h",
// abbreviated commit hash
"%s",
// subject
"%B",
// raw body (unwrapped subject and body)
"%an",
// author name
"%ae",
// author email
"%at",
// author date, UNIX timestamp
"%cn",
// committer name
"%ce",
// committer email
"%ct",
// committer date, UNIX timestamp
""
// branch
];
const output = await runGit(`git log -1 --pretty=format:"${tokens.join(separator)}" && git rev-parse --abbrev-ref HEAD`, gitDir);
if (!output)
return void 0;
const [hash, shortHash, subject, body, authorName, authorEmail, authorTime, committerName, committerEmail, committerTime, branch] = output.split(separator);
return {
shortHash,
hash,
subject,
body,
author: {
name: authorName,
email: authorEmail,
time: +authorTime * 1e3
},
committer: {
name: committerName,
email: committerEmail,
time: +committerTime * 1e3
},
branch: branch.trim()
};
}
async function gitDiff(gitDir, ci) {
const diffLimit = 1e5;
if (ci?.prBaseHash) {
await runGit(`git fetch origin ${ci.prBaseHash} --depth=1 --no-auto-maintenance --no-auto-gc --no-tags --no-recurse-submodules`, gitDir);
const diff2 = await runGit(`git diff ${ci.prBaseHash} HEAD`, gitDir);
if (diff2)
return diff2.substring(0, diffLimit);
}
if (ci)
return;
const uncommitted = await runGit("git diff", gitDir);
if (uncommitted === void 0) {
return;
}
if (uncommitted)
return uncommitted.substring(0, diffLimit);
const diff = await runGit("git diff HEAD~1", gitDir);
return diff?.substring(0, diffLimit);
}
async function runGit(command, cwd) {
debug(`running "${command}"`);
const start = (0, import_utils.monotonicTime)();
const result = await (0, import_utils.spawnAsync)(
command,
[],
{ stdio: "pipe", cwd, timeout: GIT_OPERATIONS_TIMEOUT_MS, shell: true }
);
if ((0, import_utils.monotonicTime)() - start > GIT_OPERATIONS_TIMEOUT_MS) {
print(`timeout of ${GIT_OPERATIONS_TIMEOUT_MS}ms exceeded while running "${command}"`);
return;
}
if (result.code)
debug(`failure, code=${result.code}
${result.stderr}`);
else
debug(`success`);
return result.code ? void 0 : result.stdout.trim();
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addGitCommitInfoPlugin
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var plugins_exports = {};
__export(plugins_exports, {
webServer: () => import_webServerPlugin.webServer
});
module.exports = __toCommonJS(plugins_exports);
var import_webServerPlugin = require("./webServerPlugin");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
webServer
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var webServerPlugin_exports = {};
__export(webServerPlugin_exports, {
WebServerPlugin: () => WebServerPlugin,
webServer: () => webServer,
webServerPluginsForConfig: () => webServerPluginsForConfig
});
module.exports = __toCommonJS(webServerPlugin_exports);
var import_net = __toESM(require("net"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
const DEFAULT_ENVIRONMENT_VARIABLES = {
"BROWSER": "none",
// Disable that create-react-app will open the page in the browser
"FORCE_COLOR": "1",
"DEBUG_COLORS": "1"
};
const debugWebServer = (0, import_utilsBundle.debug)("pw:webserver");
class WebServerPlugin {
constructor(options, checkPortOnly) {
this.name = "playwright:webserver";
this._options = options;
this._checkPortOnly = checkPortOnly;
}
async setup(config, configDir, reporter) {
this._reporter = reporter;
this._isAvailableCallback = this._options.url ? getIsAvailableFunction(this._options.url, this._checkPortOnly, !!this._options.ignoreHTTPSErrors, this._reporter.onStdErr?.bind(this._reporter)) : void 0;
this._options.cwd = this._options.cwd ? import_path.default.resolve(configDir, this._options.cwd) : configDir;
try {
await this._startProcess();
await this._waitForProcess();
} catch (error) {
await this.teardown();
throw error;
}
}
async teardown() {
debugWebServer(`Terminating the WebServer`);
await this._killProcess?.();
debugWebServer(`Terminated the WebServer`);
}
async _startProcess() {
let processExitedReject = (error) => {
};
this._processExitedPromise = new Promise((_, reject) => processExitedReject = reject);
const isAlreadyAvailable = await this._isAvailableCallback?.();
if (isAlreadyAvailable) {
debugWebServer(`WebServer is already available`);
if (this._options.reuseExistingServer)
return;
const port = new URL(this._options.url).port;
throw new Error(`${this._options.url ?? `http://localhost${port ? ":" + port : ""}`} is already used, make sure that nothing is running on the port/url or set reuseExistingServer:true in config.webServer.`);
}
if (!this._options.command)
throw new Error("config.webServer.command cannot be empty");
debugWebServer(`Starting WebServer process ${this._options.command}...`);
const { launchedProcess, gracefullyClose } = await (0, import_utils.launchProcess)({
command: this._options.command,
env: {
...DEFAULT_ENVIRONMENT_VARIABLES,
...process.env,
...this._options.env
},
cwd: this._options.cwd,
stdio: "stdin",
shell: true,
attemptToGracefullyClose: async () => {
if (process.platform === "win32")
throw new Error("Graceful shutdown is not supported on Windows");
if (!this._options.gracefulShutdown)
throw new Error("skip graceful shutdown");
const { signal, timeout = 0 } = this._options.gracefulShutdown;
process.kill(-launchedProcess.pid, signal);
return new Promise((resolve, reject) => {
const timer = timeout !== 0 ? setTimeout(() => reject(new Error(`process didn't close gracefully within timeout`)), timeout) : void 0;
launchedProcess.once("close", (...args) => {
clearTimeout(timer);
resolve();
});
});
},
log: () => {
},
onExit: (code) => processExitedReject(new Error(code ? `Process from config.webServer was not able to start. Exit code: ${code}` : "Process from config.webServer exited early.")),
tempDirectories: []
});
this._killProcess = gracefullyClose;
debugWebServer(`Process started`);
launchedProcess.stderr.on("data", (data) => {
if (debugWebServer.enabled || (this._options.stderr === "pipe" || !this._options.stderr))
this._reporter.onStdErr?.(prefixOutputLines(data.toString(), this._options.name));
});
launchedProcess.stdout.on("data", (data) => {
if (debugWebServer.enabled || this._options.stdout === "pipe")
this._reporter.onStdOut?.(prefixOutputLines(data.toString(), this._options.name));
});
}
async _waitForProcess() {
if (!this._isAvailableCallback) {
this._processExitedPromise.catch(() => {
});
return;
}
debugWebServer(`Waiting for availability...`);
const launchTimeout = this._options.timeout || 60 * 1e3;
const cancellationToken = { canceled: false };
const { timedOut } = await Promise.race([
(0, import_utils.raceAgainstDeadline)(() => waitFor(this._isAvailableCallback, cancellationToken), (0, import_utils.monotonicTime)() + launchTimeout),
this._processExitedPromise
]);
cancellationToken.canceled = true;
if (timedOut)
throw new Error(`Timed out waiting ${launchTimeout}ms from config.webServer.`);
debugWebServer(`WebServer available`);
}
}
async function isPortUsed(port) {
const innerIsPortUsed = (host) => new Promise((resolve) => {
const conn = import_net.default.connect(port, host).on("error", () => {
resolve(false);
}).on("connect", () => {
conn.end();
resolve(true);
});
});
return await innerIsPortUsed("127.0.0.1") || await innerIsPortUsed("::1");
}
async function waitFor(waitFn, cancellationToken) {
const logScale = [100, 250, 500];
while (!cancellationToken.canceled) {
const connected = await waitFn();
if (connected)
return;
const delay = logScale.shift() || 1e3;
debugWebServer(`Waiting ${delay}ms`);
await new Promise((x) => setTimeout(x, delay));
}
}
function getIsAvailableFunction(url, checkPortOnly, ignoreHTTPSErrors, onStdErr) {
const urlObject = new URL(url);
if (!checkPortOnly)
return () => (0, import_utils.isURLAvailable)(urlObject, ignoreHTTPSErrors, debugWebServer, onStdErr);
const port = urlObject.port;
return () => isPortUsed(+port);
}
const webServer = (options) => {
return new WebServerPlugin(options, false);
};
const webServerPluginsForConfig = (config) => {
const shouldSetBaseUrl = !!config.config.webServer;
const webServerPlugins = [];
for (const webServerConfig of config.webServers) {
if (webServerConfig.port && webServerConfig.url)
throw new Error(`Either 'port' or 'url' should be specified in config.webServer.`);
let url;
if (webServerConfig.port || webServerConfig.url) {
url = webServerConfig.url || `http://localhost:${webServerConfig.port}`;
if (shouldSetBaseUrl && !webServerConfig.url)
process.env.PLAYWRIGHT_TEST_BASE_URL = url;
}
webServerPlugins.push(new WebServerPlugin({ ...webServerConfig, url }, webServerConfig.port !== void 0));
}
return webServerPlugins;
};
function prefixOutputLines(output, prefixName = "WebServer") {
const lastIsNewLine = output[output.length - 1] === "\n";
let lines = output.split("\n");
if (lastIsNewLine)
lines.pop();
lines = lines.map((line) => import_utils2.colors.dim(`[${prefixName}] `) + line);
if (lastIsNewLine)
lines.push("");
return lines.join("\n");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
WebServerPlugin,
webServer,
webServerPluginsForConfig
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var base_exports = {};
__export(base_exports, {
TerminalReporter: () => TerminalReporter,
fitToWidth: () => fitToWidth,
formatError: () => formatError,
formatFailure: () => formatFailure,
formatResultFailure: () => formatResultFailure,
formatRetry: () => formatRetry,
internalScreen: () => internalScreen,
kOutputSymbol: () => kOutputSymbol,
nonTerminalScreen: () => nonTerminalScreen,
prepareErrorStack: () => prepareErrorStack,
relativeFilePath: () => relativeFilePath,
resolveOutputFile: () => resolveOutputFile,
separator: () => separator,
stepSuffix: () => stepSuffix,
terminalScreen: () => terminalScreen
});
module.exports = __toCommonJS(base_exports);
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_utils2 = require("playwright-core/lib/utils");
var import_util = require("../util");
var import_utilsBundle2 = require("../utilsBundle");
const kOutputSymbol = Symbol("output");
const DEFAULT_TTY_WIDTH = 100;
const DEFAULT_TTY_HEIGHT = 40;
const originalProcessStdout = process.stdout;
const originalProcessStderr = process.stderr;
const terminalScreen = (() => {
let isTTY = !!originalProcessStdout.isTTY;
let ttyWidth = originalProcessStdout.columns || 0;
let ttyHeight = originalProcessStdout.rows || 0;
if (process.env.PLAYWRIGHT_FORCE_TTY === "false" || process.env.PLAYWRIGHT_FORCE_TTY === "0") {
isTTY = false;
ttyWidth = 0;
ttyHeight = 0;
} else if (process.env.PLAYWRIGHT_FORCE_TTY === "true" || process.env.PLAYWRIGHT_FORCE_TTY === "1") {
isTTY = true;
ttyWidth = originalProcessStdout.columns || DEFAULT_TTY_WIDTH;
ttyHeight = originalProcessStdout.rows || DEFAULT_TTY_HEIGHT;
} else if (process.env.PLAYWRIGHT_FORCE_TTY) {
isTTY = true;
const sizeMatch = process.env.PLAYWRIGHT_FORCE_TTY.match(/^(\d+)x(\d+)$/);
if (sizeMatch) {
ttyWidth = +sizeMatch[1];
ttyHeight = +sizeMatch[2];
} else {
ttyWidth = +process.env.PLAYWRIGHT_FORCE_TTY;
ttyHeight = DEFAULT_TTY_HEIGHT;
}
if (isNaN(ttyWidth))
ttyWidth = DEFAULT_TTY_WIDTH;
if (isNaN(ttyHeight))
ttyHeight = DEFAULT_TTY_HEIGHT;
}
let useColors = isTTY;
if (process.env.DEBUG_COLORS === "0" || process.env.DEBUG_COLORS === "false" || process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false")
useColors = false;
else if (process.env.DEBUG_COLORS || process.env.FORCE_COLOR)
useColors = true;
const colors = useColors ? import_utils2.colors : import_utils2.noColors;
return {
resolveFiles: "cwd",
isTTY,
ttyWidth,
ttyHeight,
colors,
stdout: originalProcessStdout,
stderr: originalProcessStderr
};
})();
const nonTerminalScreen = {
colors: terminalScreen.colors,
isTTY: false,
ttyWidth: 0,
ttyHeight: 0,
resolveFiles: "rootDir"
};
const internalScreen = {
colors: import_utils2.colors,
isTTY: false,
ttyWidth: 0,
ttyHeight: 0,
resolveFiles: "rootDir"
};
class TerminalReporter {
constructor(options = {}) {
this.totalTestCount = 0;
this.fileDurations = /* @__PURE__ */ new Map();
this._fatalErrors = [];
this._failureCount = 0;
this.screen = options.screen ?? terminalScreen;
this._options = options;
}
version() {
return "v2";
}
onConfigure(config) {
this.config = config;
}
onBegin(suite) {
this.suite = suite;
this.totalTestCount = suite.allTests().length;
}
onStdOut(chunk, test, result) {
this._appendOutput({ chunk, type: "stdout" }, result);
}
onStdErr(chunk, test, result) {
this._appendOutput({ chunk, type: "stderr" }, result);
}
_appendOutput(output, result) {
if (!result)
return;
result[kOutputSymbol] = result[kOutputSymbol] || [];
result[kOutputSymbol].push(output);
}
onTestEnd(test, result) {
if (result.status !== "skipped" && result.status !== test.expectedStatus)
++this._failureCount;
const projectName = test.titlePath()[1];
const relativePath = relativeTestPath(this.screen, this.config, test);
const fileAndProject = (projectName ? `[${projectName}] \u203A ` : "") + relativePath;
const entry = this.fileDurations.get(fileAndProject) || { duration: 0, workers: /* @__PURE__ */ new Set() };
entry.duration += result.duration;
entry.workers.add(result.workerIndex);
this.fileDurations.set(fileAndProject, entry);
}
onError(error) {
this._fatalErrors.push(error);
}
async onEnd(result) {
this.result = result;
}
fitToScreen(line, prefix) {
if (!this.screen.ttyWidth) {
return line;
}
return fitToWidth(line, this.screen.ttyWidth, prefix);
}
generateStartingMessage() {
const jobs = this.config.metadata.actualWorkers ?? this.config.workers;
const shardDetails = this.config.shard ? `, shard ${this.config.shard.current} of ${this.config.shard.total}` : "";
if (!this.totalTestCount)
return "";
return "\n" + this.screen.colors.dim("Running ") + this.totalTestCount + this.screen.colors.dim(` test${this.totalTestCount !== 1 ? "s" : ""} using `) + jobs + this.screen.colors.dim(` worker${jobs !== 1 ? "s" : ""}${shardDetails}`);
}
getSlowTests() {
if (!this.config.reportSlowTests)
return [];
const fileDurations = [...this.fileDurations.entries()].filter(([key, value]) => value.workers.size === 1).map(([key, value]) => [key, value.duration]);
fileDurations.sort((a, b) => b[1] - a[1]);
const count = Math.min(fileDurations.length, this.config.reportSlowTests.max || Number.POSITIVE_INFINITY);
const threshold = this.config.reportSlowTests.threshold;
return fileDurations.filter(([, duration]) => duration > threshold).slice(0, count);
}
generateSummaryMessage({ didNotRun, skipped, expected, interrupted, unexpected, flaky, fatalErrors }) {
const tokens = [];
if (unexpected.length) {
tokens.push(this.screen.colors.red(` ${unexpected.length} failed`));
for (const test of unexpected)
tokens.push(this.screen.colors.red(this.formatTestHeader(test, { indent: " " })));
}
if (interrupted.length) {
tokens.push(this.screen.colors.yellow(` ${interrupted.length} interrupted`));
for (const test of interrupted)
tokens.push(this.screen.colors.yellow(this.formatTestHeader(test, { indent: " " })));
}
if (flaky.length) {
tokens.push(this.screen.colors.yellow(` ${flaky.length} flaky`));
for (const test of flaky)
tokens.push(this.screen.colors.yellow(this.formatTestHeader(test, { indent: " " })));
}
if (skipped)
tokens.push(this.screen.colors.yellow(` ${skipped} skipped`));
if (didNotRun)
tokens.push(this.screen.colors.yellow(` ${didNotRun} did not run`));
if (expected)
tokens.push(this.screen.colors.green(` ${expected} passed`) + this.screen.colors.dim(` (${(0, import_utilsBundle.ms)(this.result.duration)})`));
if (fatalErrors.length && expected + unexpected.length + interrupted.length + flaky.length > 0)
tokens.push(this.screen.colors.red(` ${fatalErrors.length === 1 ? "1 error was not a part of any test" : fatalErrors.length + " errors were not a part of any test"}, see above for details`));
return tokens.join("\n");
}
generateSummary() {
let didNotRun = 0;
let skipped = 0;
let expected = 0;
const interrupted = [];
const interruptedToPrint = [];
const unexpected = [];
const flaky = [];
this.suite.allTests().forEach((test) => {
switch (test.outcome()) {
case "skipped": {
if (test.results.some((result) => result.status === "interrupted")) {
if (test.results.some((result) => !!result.error))
interruptedToPrint.push(test);
interrupted.push(test);
} else if (!test.results.length || test.expectedStatus !== "skipped") {
++didNotRun;
} else {
++skipped;
}
break;
}
case "expected":
++expected;
break;
case "unexpected":
unexpected.push(test);
break;
case "flaky":
flaky.push(test);
break;
}
});
const failuresToPrint = [...unexpected, ...flaky, ...interruptedToPrint];
return {
didNotRun,
skipped,
expected,
interrupted,
unexpected,
flaky,
failuresToPrint,
fatalErrors: this._fatalErrors
};
}
epilogue(full) {
const summary = this.generateSummary();
const summaryMessage = this.generateSummaryMessage(summary);
if (full && summary.failuresToPrint.length && !this._options.omitFailures)
this._printFailures(summary.failuresToPrint);
this._printSlowTests();
this._printSummary(summaryMessage);
}
_printFailures(failures) {
this.writeLine("");
failures.forEach((test, index) => {
this.writeLine(this.formatFailure(test, index + 1));
});
}
_printSlowTests() {
const slowTests = this.getSlowTests();
slowTests.forEach(([file, duration]) => {
this.writeLine(this.screen.colors.yellow(" Slow test file: ") + file + this.screen.colors.yellow(` (${(0, import_utilsBundle.ms)(duration)})`));
});
if (slowTests.length)
this.writeLine(this.screen.colors.yellow(" Consider running tests from slow files in parallel. See: https://playwright.dev/docs/test-parallel"));
}
_printSummary(summary) {
if (summary.trim())
this.writeLine(summary);
}
willRetry(test) {
return test.outcome() === "unexpected" && test.results.length <= test.retries;
}
formatTestTitle(test, step) {
return formatTestTitle(this.screen, this.config, test, step, this._options);
}
formatTestHeader(test, options = {}) {
return formatTestHeader(this.screen, this.config, test, { ...options, includeTestId: this._options.includeTestId });
}
formatFailure(test, index) {
return formatFailure(this.screen, this.config, test, index, this._options);
}
formatError(error) {
return formatError(this.screen, error);
}
writeLine(line) {
this.screen.stdout?.write(line ? line + "\n" : "\n");
}
}
function formatFailure(screen, config, test, index, options) {
const lines = [];
const header = formatTestHeader(screen, config, test, { indent: " ", index, mode: "error", includeTestId: options?.includeTestId });
lines.push(screen.colors.red(header));
for (const result of test.results) {
const resultLines = [];
const errors = formatResultFailure(screen, test, result, " ");
if (!errors.length)
continue;
if (result.retry) {
resultLines.push("");
resultLines.push(screen.colors.gray(separator(screen, ` Retry #${result.retry}`)));
}
resultLines.push(...errors.map((error) => "\n" + error.message));
const attachmentGroups = groupAttachments(result.attachments);
for (let i = 0; i < attachmentGroups.length; ++i) {
const attachment = attachmentGroups[i];
if (attachment.name === "error-context" && attachment.path) {
resultLines.push("");
resultLines.push(screen.colors.dim(` Error Context: ${relativeFilePath(screen, config, attachment.path)}`));
continue;
}
if (attachment.name.startsWith("_"))
continue;
const hasPrintableContent = attachment.contentType.startsWith("text/");
if (!attachment.path && !hasPrintableContent)
continue;
resultLines.push("");
resultLines.push(screen.colors.dim(separator(screen, ` attachment #${i + 1}: ${screen.colors.bold(attachment.name)} (${attachment.contentType})`)));
if (attachment.actual?.path) {
if (attachment.expected?.path) {
const expectedPath = relativeFilePath(screen, config, attachment.expected.path);
resultLines.push(screen.colors.dim(` Expected: ${expectedPath}`));
}
const actualPath = relativeFilePath(screen, config, attachment.actual.path);
resultLines.push(screen.colors.dim(` Received: ${actualPath}`));
if (attachment.previous?.path) {
const previousPath = relativeFilePath(screen, config, attachment.previous.path);
resultLines.push(screen.colors.dim(` Previous: ${previousPath}`));
}
if (attachment.diff?.path) {
const diffPath = relativeFilePath(screen, config, attachment.diff.path);
resultLines.push(screen.colors.dim(` Diff: ${diffPath}`));
}
} else if (attachment.path) {
const relativePath = relativeFilePath(screen, config, attachment.path);
resultLines.push(screen.colors.dim(` ${relativePath}`));
if (attachment.name === "trace") {
const packageManagerCommand = (0, import_utils.getPackageManagerExecCommand)();
resultLines.push(screen.colors.dim(` Usage:`));
resultLines.push("");
resultLines.push(screen.colors.dim(` ${packageManagerCommand} playwright show-trace ${quotePathIfNeeded(relativePath)}`));
resultLines.push("");
}
} else {
if (attachment.contentType.startsWith("text/") && attachment.body) {
let text = attachment.body.toString();
if (text.length > 300)
text = text.slice(0, 300) + "...";
for (const line of text.split("\n"))
resultLines.push(screen.colors.dim(` ${line}`));
}
}
resultLines.push(screen.colors.dim(separator(screen, " ")));
}
lines.push(...resultLines);
}
lines.push("");
return lines.join("\n");
}
function formatRetry(screen, result) {
const retryLines = [];
if (result.retry) {
retryLines.push("");
retryLines.push(screen.colors.gray(separator(screen, ` Retry #${result.retry}`)));
}
return retryLines;
}
function quotePathIfNeeded(path2) {
if (/\s/.test(path2))
return `"${path2}"`;
return path2;
}
function formatResultFailure(screen, test, result, initialIndent) {
const errorDetails = [];
if (result.status === "passed" && test.expectedStatus === "failed") {
errorDetails.push({
message: indent(screen.colors.red(`Expected to fail, but passed.`), initialIndent)
});
}
if (result.status === "interrupted") {
errorDetails.push({
message: indent(screen.colors.red(`Test was interrupted.`), initialIndent)
});
}
for (const error of result.errors) {
const formattedError = formatError(screen, error);
errorDetails.push({
message: indent(formattedError.message, initialIndent),
location: formattedError.location
});
}
return errorDetails;
}
function relativeFilePath(screen, config, file) {
if (screen.resolveFiles === "cwd")
return import_path.default.relative(process.cwd(), file);
return import_path.default.relative(config.rootDir, file);
}
function relativeTestPath(screen, config, test) {
return relativeFilePath(screen, config, test.location.file);
}
function stepSuffix(step) {
const stepTitles = step ? step.titlePath() : [];
return stepTitles.map((t) => t.split("\n")[0]).map((t) => " \u203A " + t).join("");
}
function formatTestTitle(screen, config, test, step, options = {}) {
const [, projectName, , ...titles] = test.titlePath();
const location = `${relativeTestPath(screen, config, test)}:${test.location.line}:${test.location.column}`;
const testId = options.includeTestId ? `[id=${test.id}] ` : "";
const projectLabel = options.includeTestId ? `project=` : "";
const projectTitle = projectName ? `[${projectLabel}${projectName}] \u203A ` : "";
const testTitle = `${testId}${projectTitle}${location} \u203A ${titles.join(" \u203A ")}`;
const extraTags = test.tags.filter((t) => !testTitle.includes(t));
return `${testTitle}${stepSuffix(step)}${extraTags.length ? " " + extraTags.join(" ") : ""}`;
}
function formatTestHeader(screen, config, test, options = {}) {
const title = formatTestTitle(screen, config, test, void 0, options);
const header = `${options.indent || ""}${options.index ? options.index + ") " : ""}${title}`;
let fullHeader = header;
if (options.mode === "error") {
const stepPaths = /* @__PURE__ */ new Set();
for (const result of test.results.filter((r) => !!r.errors.length)) {
const stepPath = [];
const visit = (steps) => {
const errors = steps.filter((s) => s.error);
if (errors.length > 1)
return;
if (errors.length === 1 && errors[0].category === "test.step") {
stepPath.push(errors[0].title);
visit(errors[0].steps);
}
};
visit(result.steps);
stepPaths.add(["", ...stepPath].join(" \u203A "));
}
fullHeader = header + (stepPaths.size === 1 ? stepPaths.values().next().value : "");
}
return separator(screen, fullHeader);
}
function formatError(screen, error) {
const message = error.message || error.value || "";
const stack = error.stack;
if (!stack && !error.location)
return { message };
const tokens = [];
const parsedStack = stack ? prepareErrorStack(stack) : void 0;
tokens.push(parsedStack?.message || message);
if (error.snippet) {
let snippet = error.snippet;
if (!screen.colors.enabled)
snippet = (0, import_util.stripAnsiEscapes)(snippet);
tokens.push("");
tokens.push(snippet);
}
if (parsedStack && parsedStack.stackLines.length)
tokens.push(screen.colors.dim(parsedStack.stackLines.join("\n")));
let location = error.location;
if (parsedStack && !location)
location = parsedStack.location;
if (error.cause)
tokens.push(screen.colors.dim("[cause]: ") + formatError(screen, error.cause).message);
return {
location,
message: tokens.join("\n")
};
}
function separator(screen, text = "") {
if (text)
text += " ";
const columns = Math.min(100, screen.ttyWidth || 100);
return text + screen.colors.dim("\u2500".repeat(Math.max(0, columns - (0, import_util.stripAnsiEscapes)(text).length)));
}
function indent(lines, tab) {
return lines.replace(/^(?=.+$)/gm, tab);
}
function prepareErrorStack(stack) {
return (0, import_utils.parseErrorStack)(stack, import_path.default.sep, !!process.env.PWDEBUGIMPL);
}
function characterWidth(c) {
return import_utilsBundle2.getEastAsianWidth.eastAsianWidth(c.codePointAt(0));
}
function stringWidth(v) {
let width = 0;
for (const { segment } of new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(v))
width += characterWidth(segment);
return width;
}
function suffixOfWidth(v, width) {
const segments = [...new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(v)];
let suffixBegin = v.length;
for (const { segment, index } of segments.reverse()) {
const segmentWidth = stringWidth(segment);
if (segmentWidth > width)
break;
width -= segmentWidth;
suffixBegin = index;
}
return v.substring(suffixBegin);
}
function fitToWidth(line, width, prefix) {
const prefixLength = prefix ? (0, import_util.stripAnsiEscapes)(prefix).length : 0;
width -= prefixLength;
if (stringWidth(line) <= width)
return line;
const parts = line.split(import_util.ansiRegex);
const taken = [];
for (let i = parts.length - 1; i >= 0; i--) {
if (i % 2) {
taken.push(parts[i]);
} else {
let part = suffixOfWidth(parts[i], width);
const wasTruncated = part.length < parts[i].length;
if (wasTruncated && parts[i].length > 0) {
part = "\u2026" + suffixOfWidth(parts[i], width - 1);
}
taken.push(part);
width -= stringWidth(part);
}
}
return taken.reverse().join("");
}
function resolveFromEnv(name) {
const value = process.env[name];
if (value)
return import_path.default.resolve(process.cwd(), value);
return void 0;
}
function resolveOutputFile(reporterName, options) {
const name = reporterName.toUpperCase();
let outputFile = resolveFromEnv(`PLAYWRIGHT_${name}_OUTPUT_FILE`);
if (!outputFile && options.outputFile)
outputFile = import_path.default.resolve(options.configDir, options.outputFile);
if (outputFile)
return { outputFile };
let outputDir = resolveFromEnv(`PLAYWRIGHT_${name}_OUTPUT_DIR`);
if (!outputDir && options.outputDir)
outputDir = import_path.default.resolve(options.configDir, options.outputDir);
if (!outputDir && options.default)
outputDir = (0, import_util.resolveReporterOutputPath)(options.default.outputDir, options.configDir, void 0);
if (!outputDir)
outputDir = options.configDir;
const reportName = process.env[`PLAYWRIGHT_${name}_OUTPUT_NAME`] ?? options.fileName ?? options.default?.fileName;
if (!reportName)
return void 0;
outputFile = import_path.default.resolve(outputDir, reportName);
return { outputFile, outputDir };
}
function groupAttachments(attachments) {
const result = [];
const attachmentsByPrefix = /* @__PURE__ */ new Map();
for (const attachment of attachments) {
if (!attachment.path) {
result.push(attachment);
continue;
}
const match = attachment.name.match(/^(.*)-(expected|actual|diff|previous)(\.[^.]+)?$/);
if (!match) {
result.push(attachment);
continue;
}
const [, name, category] = match;
let group = attachmentsByPrefix.get(name);
if (!group) {
group = { ...attachment, name };
attachmentsByPrefix.set(name, group);
result.push(group);
}
if (category === "expected")
group.expected = attachment;
else if (category === "actual")
group.actual = attachment;
else if (category === "diff")
group.diff = attachment;
else if (category === "previous")
group.previous = attachment;
}
return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TerminalReporter,
fitToWidth,
formatError,
formatFailure,
formatResultFailure,
formatRetry,
internalScreen,
kOutputSymbol,
nonTerminalScreen,
prepareErrorStack,
relativeFilePath,
resolveOutputFile,
separator,
stepSuffix,
terminalScreen
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var blob_exports = {};
__export(blob_exports, {
BlobReporter: () => BlobReporter,
currentBlobReportVersion: () => currentBlobReportVersion
});
module.exports = __toCommonJS(blob_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_stream = require("stream");
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_zipBundle = require("playwright-core/lib/zipBundle");
var import_base = require("./base");
var import_teleEmitter = require("./teleEmitter");
const currentBlobReportVersion = 2;
class BlobReporter extends import_teleEmitter.TeleReporterEmitter {
constructor(options) {
super((message) => this._messages.push(message));
this._messages = [];
this._attachments = [];
this._options = options;
if (this._options.fileName && !this._options.fileName.endsWith(".zip"))
throw new Error(`Blob report file name must end with .zip extension: ${this._options.fileName}`);
this._salt = (0, import_utils2.createGuid)();
}
onConfigure(config) {
const metadata = {
version: currentBlobReportVersion,
userAgent: (0, import_utils2.getUserAgent)(),
name: process.env.PWTEST_BOT_NAME,
shard: config.shard ?? void 0,
pathSeparator: import_path.default.sep
};
this._messages.push({
method: "onBlobReportMetadata",
params: metadata
});
this._config = config;
super.onConfigure(config);
}
async onEnd(result) {
await super.onEnd(result);
const zipFileName = await this._prepareOutputFile();
const zipFile = new import_zipBundle.yazl.ZipFile();
const zipFinishPromise = new import_utils2.ManualPromise();
const finishPromise = zipFinishPromise.catch((e) => {
throw new Error(`Failed to write report ${zipFileName}: ` + e.message);
});
zipFile.on("error", (error) => zipFinishPromise.reject(error));
zipFile.outputStream.pipe(import_fs.default.createWriteStream(zipFileName)).on("close", () => {
zipFinishPromise.resolve(void 0);
}).on("error", (error) => zipFinishPromise.reject(error));
for (const { originalPath, zipEntryPath } of this._attachments) {
if (!import_fs.default.statSync(originalPath, { throwIfNoEntry: false })?.isFile())
continue;
zipFile.addFile(originalPath, zipEntryPath);
}
const lines = this._messages.map((m) => JSON.stringify(m) + "\n");
const content = import_stream.Readable.from(lines);
zipFile.addReadStream(content, "report.jsonl");
zipFile.end();
await finishPromise;
}
async _prepareOutputFile() {
const { outputFile, outputDir } = (0, import_base.resolveOutputFile)("BLOB", {
...this._options,
default: {
fileName: this._defaultReportName(this._config),
outputDir: "blob-report"
}
});
if (!process.env.PWTEST_BLOB_DO_NOT_REMOVE)
await (0, import_utils.removeFolders)([outputDir]);
await import_fs.default.promises.mkdir(import_path.default.dirname(outputFile), { recursive: true });
return outputFile;
}
_defaultReportName(config) {
let reportName = "report";
if (this._options._commandHash)
reportName += "-" + (0, import_utils.sanitizeForFilePath)(this._options._commandHash);
if (config.shard) {
const paddedNumber = `${config.shard.current}`.padStart(`${config.shard.total}`.length, "0");
reportName = `${reportName}-${paddedNumber}`;
}
return `${reportName}.zip`;
}
_serializeAttachments(attachments) {
return super._serializeAttachments(attachments).map((attachment) => {
if (!attachment.path)
return attachment;
const sha1 = (0, import_utils2.calculateSha1)(attachment.path + this._salt);
const extension = import_utilsBundle.mime.getExtension(attachment.contentType) || "dat";
const newPath = `resources/${sha1}.${extension}`;
this._attachments.push({ originalPath: attachment.path, zipEntryPath: newPath });
return {
...attachment,
path: newPath
};
});
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BlobReporter,
currentBlobReportVersion
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var dot_exports = {};
__export(dot_exports, {
default: () => dot_default
});
module.exports = __toCommonJS(dot_exports);
var import_base = require("./base");
class DotReporter extends import_base.TerminalReporter {
constructor() {
super(...arguments);
this._counter = 0;
}
onBegin(suite) {
super.onBegin(suite);
this.writeLine(this.generateStartingMessage());
}
onStdOut(chunk, test, result) {
super.onStdOut(chunk, test, result);
if (!this.config.quiet)
this.screen.stdout.write(chunk);
}
onStdErr(chunk, test, result) {
super.onStdErr(chunk, test, result);
if (!this.config.quiet)
this.screen.stderr.write(chunk);
}
onTestEnd(test, result) {
super.onTestEnd(test, result);
if (this._counter === 80) {
this.screen.stdout.write("\n");
this._counter = 0;
}
++this._counter;
if (result.status === "skipped") {
this.screen.stdout.write(this.screen.colors.yellow("\xB0"));
return;
}
if (this.willRetry(test)) {
this.screen.stdout.write(this.screen.colors.gray("\xD7"));
return;
}
switch (test.outcome()) {
case "expected":
this.screen.stdout.write(this.screen.colors.green("\xB7"));
break;
case "unexpected":
this.screen.stdout.write(this.screen.colors.red(result.status === "timedOut" ? "T" : "F"));
break;
case "flaky":
this.screen.stdout.write(this.screen.colors.yellow("\xB1"));
break;
}
}
onError(error) {
super.onError(error);
this.writeLine("\n" + this.formatError(error).message);
this._counter = 0;
}
async onEnd(result) {
await super.onEnd(result);
this.screen.stdout.write("\n");
this.epilogue(true);
}
}
var dot_default = DotReporter;
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var empty_exports = {};
__export(empty_exports, {
default: () => empty_default
});
module.exports = __toCommonJS(empty_exports);
class EmptyReporter {
version() {
return "v2";
}
printsToStdio() {
return false;
}
}
var empty_default = EmptyReporter;
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var github_exports = {};
__export(github_exports, {
GitHubReporter: () => GitHubReporter,
default: () => github_default
});
module.exports = __toCommonJS(github_exports);
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_base = require("./base");
var import_util = require("../util");
class GitHubLogger {
_log(message, type = "notice", options = {}) {
message = message.replace(/\n/g, "%0A");
const configs = Object.entries(options).map(([key, option]) => `${key}=${option}`).join(",");
process.stdout.write((0, import_util.stripAnsiEscapes)(`::${type} ${configs}::${message}
`));
}
debug(message, options) {
this._log(message, "debug", options);
}
error(message, options) {
this._log(message, "error", options);
}
notice(message, options) {
this._log(message, "notice", options);
}
warning(message, options) {
this._log(message, "warning", options);
}
}
class GitHubReporter extends import_base.TerminalReporter {
constructor(options = {}) {
super(options);
this.githubLogger = new GitHubLogger();
this.screen = { ...this.screen, colors: import_utils.noColors };
}
printsToStdio() {
return false;
}
async onEnd(result) {
await super.onEnd(result);
this._printAnnotations();
}
onError(error) {
const errorMessage = this.formatError(error).message;
this.githubLogger.error(errorMessage);
}
_printAnnotations() {
const summary = this.generateSummary();
const summaryMessage = this.generateSummaryMessage(summary);
if (summary.failuresToPrint.length)
this._printFailureAnnotations(summary.failuresToPrint);
this._printSlowTestAnnotations();
this._printSummaryAnnotation(summaryMessage);
}
_printSlowTestAnnotations() {
this.getSlowTests().forEach(([file, duration]) => {
const filePath = workspaceRelativePath(import_path.default.join(process.cwd(), file));
this.githubLogger.warning(`${filePath} took ${(0, import_utilsBundle.ms)(duration)}`, {
title: "Slow Test",
file: filePath
});
});
}
_printSummaryAnnotation(summary) {
this.githubLogger.notice(summary, {
title: "\u{1F3AD} Playwright Run Summary"
});
}
_printFailureAnnotations(failures) {
failures.forEach((test, index) => {
const title = this.formatTestTitle(test);
const header = this.formatTestHeader(test, { indent: " ", index: index + 1, mode: "error" });
for (const result of test.results) {
const errors = (0, import_base.formatResultFailure)(this.screen, test, result, " ");
for (const error of errors) {
const options = {
file: workspaceRelativePath(error.location?.file || test.location.file),
title
};
if (error.location) {
options.line = error.location.line;
options.col = error.location.column;
}
const message = [header, ...(0, import_base.formatRetry)(this.screen, result), error.message].join("\n");
this.githubLogger.error(message, options);
}
}
});
}
}
function workspaceRelativePath(filePath) {
return import_path.default.relative(process.env["GITHUB_WORKSPACE"] ?? "", filePath);
}
var github_default = GitHubReporter;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
GitHubReporter
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var html_exports = {};
__export(html_exports, {
default: () => html_default,
showHTMLReport: () => showHTMLReport,
startHtmlReportServer: () => startHtmlReportServer
});
module.exports = __toCommonJS(html_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_stream = require("stream");
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_utilsBundle2 = require("playwright-core/lib/utilsBundle");
var import_zipBundle = require("playwright-core/lib/zipBundle");
var import_base = require("./base");
var import_babelBundle = require("../transform/babelBundle");
var import_util = require("../util");
const htmlReportOptions = ["always", "never", "on-failure"];
const isHtmlReportOption = (type) => {
return htmlReportOptions.includes(type);
};
class HtmlReporter {
constructor(options) {
this._topLevelErrors = [];
this._options = options;
}
version() {
return "v2";
}
printsToStdio() {
return false;
}
onConfigure(config) {
this.config = config;
}
onBegin(suite) {
const { outputFolder, open: open2, attachmentsBaseURL, host, port } = this._resolveOptions();
this._outputFolder = outputFolder;
this._open = open2;
this._host = host;
this._port = port;
this._attachmentsBaseURL = attachmentsBaseURL;
const reportedWarnings = /* @__PURE__ */ new Set();
for (const project of this.config.projects) {
if (this._isSubdirectory(outputFolder, project.outputDir) || this._isSubdirectory(project.outputDir, outputFolder)) {
const key = outputFolder + "|" + project.outputDir;
if (reportedWarnings.has(key))
continue;
reportedWarnings.add(key);
writeLine(import_utils2.colors.red(`Configuration Error: HTML reporter output folder clashes with the tests output folder:`));
writeLine(`
html reporter folder: ${import_utils2.colors.bold(outputFolder)}
test results folder: ${import_utils2.colors.bold(project.outputDir)}`);
writeLine("");
writeLine(`HTML reporter will clear its output directory prior to being generated, which will lead to the artifact loss.
`);
}
}
this.suite = suite;
}
_resolveOptions() {
const outputFolder = reportFolderFromEnv() ?? (0, import_util.resolveReporterOutputPath)("playwright-report", this._options.configDir, this._options.outputFolder);
return {
outputFolder,
open: getHtmlReportOptionProcessEnv() || this._options.open || "on-failure",
attachmentsBaseURL: process.env.PLAYWRIGHT_HTML_ATTACHMENTS_BASE_URL || this._options.attachmentsBaseURL || "data/",
host: process.env.PLAYWRIGHT_HTML_HOST || this._options.host,
port: process.env.PLAYWRIGHT_HTML_PORT ? +process.env.PLAYWRIGHT_HTML_PORT : this._options.port
};
}
_isSubdirectory(parentDir, dir) {
const relativePath = import_path.default.relative(parentDir, dir);
return !!relativePath && !relativePath.startsWith("..") && !import_path.default.isAbsolute(relativePath);
}
onError(error) {
this._topLevelErrors.push(error);
}
async onEnd(result) {
const projectSuites = this.suite.suites;
await (0, import_utils.removeFolders)([this._outputFolder]);
let noSnippets;
if (process.env.PLAYWRIGHT_HTML_NO_SNIPPETS === "false" || process.env.PLAYWRIGHT_HTML_NO_SNIPPETS === "0")
noSnippets = false;
else if (process.env.PLAYWRIGHT_HTML_NO_SNIPPETS)
noSnippets = true;
noSnippets = noSnippets || this._options.noSnippets;
let noCopyPrompt;
if (process.env.PLAYWRIGHT_HTML_NO_COPY_PROMPT === "false" || process.env.PLAYWRIGHT_HTML_NO_COPY_PROMPT === "0")
noCopyPrompt = false;
else if (process.env.PLAYWRIGHT_HTML_NO_COPY_PROMPT)
noCopyPrompt = true;
noCopyPrompt = noCopyPrompt || this._options.noCopyPrompt;
const builder = new HtmlBuilder(this.config, this._outputFolder, this._attachmentsBaseURL, {
title: process.env.PLAYWRIGHT_HTML_TITLE || this._options.title,
noSnippets,
noCopyPrompt
});
this._buildResult = await builder.build(this.config.metadata, projectSuites, result, this._topLevelErrors);
}
async onExit() {
if (process.env.CI || !this._buildResult)
return;
const { ok, singleTestId } = this._buildResult;
const shouldOpen = !this._options._isTestServer && (this._open === "always" || !ok && this._open === "on-failure");
if (shouldOpen) {
await showHTMLReport(this._outputFolder, this._host, this._port, singleTestId);
} else if (this._options._mode === "test" && !this._options._isTestServer) {
const packageManagerCommand = (0, import_utils.getPackageManagerExecCommand)();
const relativeReportPath = this._outputFolder === standaloneDefaultFolder() ? "" : " " + import_path.default.relative(process.cwd(), this._outputFolder);
const hostArg = this._host ? ` --host ${this._host}` : "";
const portArg = this._port ? ` --port ${this._port}` : "";
writeLine("");
writeLine("To open last HTML report run:");
writeLine(import_utils2.colors.cyan(`
${packageManagerCommand} playwright show-report${relativeReportPath}${hostArg}${portArg}
`));
}
}
}
function reportFolderFromEnv() {
const envValue = process.env.PLAYWRIGHT_HTML_OUTPUT_DIR || process.env.PLAYWRIGHT_HTML_REPORT;
return envValue ? import_path.default.resolve(envValue) : void 0;
}
function getHtmlReportOptionProcessEnv() {
const htmlOpenEnv = process.env.PLAYWRIGHT_HTML_OPEN || process.env.PW_TEST_HTML_REPORT_OPEN;
if (!htmlOpenEnv)
return void 0;
if (!isHtmlReportOption(htmlOpenEnv)) {
writeLine(import_utils2.colors.red(`Configuration Error: HTML reporter Invalid value for PLAYWRIGHT_HTML_OPEN: ${htmlOpenEnv}. Valid values are: ${htmlReportOptions.join(", ")}`));
return void 0;
}
return htmlOpenEnv;
}
function standaloneDefaultFolder() {
return reportFolderFromEnv() ?? (0, import_util.resolveReporterOutputPath)("playwright-report", process.cwd(), void 0);
}
async function showHTMLReport(reportFolder, host = "localhost", port, testId) {
const folder = reportFolder ?? standaloneDefaultFolder();
try {
(0, import_utils.assert)(import_fs.default.statSync(folder).isDirectory());
} catch (e) {
writeLine(import_utils2.colors.red(`No report found at "${folder}"`));
(0, import_utils.gracefullyProcessExitDoNotHang)(1);
return;
}
const server = startHtmlReportServer(folder);
await server.start({ port, host, preferredPort: port ? void 0 : 9323 });
let url = server.urlPrefix("human-readable");
writeLine("");
writeLine(import_utils2.colors.cyan(` Serving HTML report at ${url}. Press Ctrl+C to quit.`));
if (testId)
url += `#?testId=${testId}`;
url = url.replace("0.0.0.0", "localhost");
await (0, import_utilsBundle.open)(url, { wait: true }).catch(() => {
});
await new Promise(() => {
});
}
function startHtmlReportServer(folder) {
const server = new import_utils.HttpServer();
server.routePrefix("/", (request, response) => {
let relativePath = new URL("http://localhost" + request.url).pathname;
if (relativePath.startsWith("/trace/file")) {
const url = new URL("http://localhost" + request.url);
try {
return server.serveFile(request, response, url.searchParams.get("path"));
} catch (e) {
return false;
}
}
if (relativePath.endsWith("/stall.js"))
return true;
if (relativePath === "/")
relativePath = "/index.html";
const absolutePath = import_path.default.join(folder, ...relativePath.split("/"));
return server.serveFile(request, response, absolutePath);
});
return server;
}
class HtmlBuilder {
constructor(config, outputDir, attachmentsBaseURL, options) {
this._stepsInFile = new import_utils.MultiMap();
this._hasTraces = false;
this._config = config;
this._reportFolder = outputDir;
this._options = options;
import_fs.default.mkdirSync(this._reportFolder, { recursive: true });
this._dataZipFile = new import_zipBundle.yazl.ZipFile();
this._attachmentsBaseURL = attachmentsBaseURL;
}
async build(metadata, projectSuites, result, topLevelErrors) {
const data = /* @__PURE__ */ new Map();
for (const projectSuite of projectSuites) {
const projectName = projectSuite.project().name;
for (const fileSuite of projectSuite.suites) {
const fileName = this._relativeLocation(fileSuite.location).file;
this._createEntryForSuite(data, projectName, fileSuite, fileName, true);
}
}
if (!this._options.noSnippets)
createSnippets(this._stepsInFile);
let ok = true;
for (const [fileId, { testFile, testFileSummary }] of data) {
const stats = testFileSummary.stats;
for (const test of testFileSummary.tests) {
if (test.outcome === "expected")
++stats.expected;
if (test.outcome === "skipped")
++stats.skipped;
if (test.outcome === "unexpected")
++stats.unexpected;
if (test.outcome === "flaky")
++stats.flaky;
++stats.total;
}
stats.ok = stats.unexpected + stats.flaky === 0;
if (!stats.ok)
ok = false;
const testCaseSummaryComparator = (t1, t2) => {
const w1 = (t1.outcome === "unexpected" ? 1e3 : 0) + (t1.outcome === "flaky" ? 1 : 0);
const w2 = (t2.outcome === "unexpected" ? 1e3 : 0) + (t2.outcome === "flaky" ? 1 : 0);
return w2 - w1;
};
testFileSummary.tests.sort(testCaseSummaryComparator);
this._addDataFile(fileId + ".json", testFile);
}
const htmlReport = {
metadata,
startTime: result.startTime.getTime(),
duration: result.duration,
files: [...data.values()].map((e) => e.testFileSummary),
projectNames: projectSuites.map((r) => r.project().name),
stats: { ...[...data.values()].reduce((a, e) => addStats(a, e.testFileSummary.stats), emptyStats()) },
errors: topLevelErrors.map((error) => (0, import_base.formatError)(import_base.internalScreen, error).message),
options: this._options
};
htmlReport.files.sort((f1, f2) => {
const w1 = f1.stats.unexpected * 1e3 + f1.stats.flaky;
const w2 = f2.stats.unexpected * 1e3 + f2.stats.flaky;
return w2 - w1;
});
this._addDataFile("report.json", htmlReport);
let singleTestId;
if (htmlReport.stats.total === 1) {
const testFile = data.values().next().value.testFile;
singleTestId = testFile.tests[0].testId;
}
if (process.env.PW_HMR === "1") {
const redirectFile = import_path.default.join(this._reportFolder, "index.html");
await this._writeReportData(redirectFile);
async function redirect() {
const hmrURL = new URL("http://localhost:44224");
const popup = window.open(hmrURL);
const listener = (evt) => {
if (evt.source === popup && evt.data === "ready") {
const element = document.getElementById("playwrightReportBase64");
popup.postMessage(element?.textContent ?? "", hmrURL.origin);
window.removeEventListener("message", listener);
window.close();
}
};
window.addEventListener("message", listener);
}
import_fs.default.appendFileSync(redirectFile, `<script>(${redirect.toString()})()</script>`);
return { ok, singleTestId };
}
const appFolder = import_path.default.join(require.resolve("playwright-core"), "..", "lib", "vite", "htmlReport");
await (0, import_utils.copyFileAndMakeWritable)(import_path.default.join(appFolder, "index.html"), import_path.default.join(this._reportFolder, "index.html"));
if (this._hasTraces) {
const traceViewerFolder = import_path.default.join(require.resolve("playwright-core"), "..", "lib", "vite", "traceViewer");
const traceViewerTargetFolder = import_path.default.join(this._reportFolder, "trace");
const traceViewerAssetsTargetFolder = import_path.default.join(traceViewerTargetFolder, "assets");
import_fs.default.mkdirSync(traceViewerAssetsTargetFolder, { recursive: true });
for (const file of import_fs.default.readdirSync(traceViewerFolder)) {
if (file.endsWith(".map") || file.includes("watch") || file.includes("assets"))
continue;
await (0, import_utils.copyFileAndMakeWritable)(import_path.default.join(traceViewerFolder, file), import_path.default.join(traceViewerTargetFolder, file));
}
for (const file of import_fs.default.readdirSync(import_path.default.join(traceViewerFolder, "assets"))) {
if (file.endsWith(".map") || file.includes("xtermModule"))
continue;
await (0, import_utils.copyFileAndMakeWritable)(import_path.default.join(traceViewerFolder, "assets", file), import_path.default.join(traceViewerAssetsTargetFolder, file));
}
}
await this._writeReportData(import_path.default.join(this._reportFolder, "index.html"));
return { ok, singleTestId };
}
async _writeReportData(filePath) {
import_fs.default.appendFileSync(filePath, '<script id="playwrightReportBase64" type="application/zip">data:application/zip;base64,');
await new Promise((f) => {
this._dataZipFile.end(void 0, () => {
this._dataZipFile.outputStream.pipe(new Base64Encoder()).pipe(import_fs.default.createWriteStream(filePath, { flags: "a" })).on("close", f);
});
});
import_fs.default.appendFileSync(filePath, "</script>");
}
_addDataFile(fileName, data) {
this._dataZipFile.addBuffer(Buffer.from(JSON.stringify(data)), fileName);
}
_createEntryForSuite(data, projectName, suite, fileName, deep) {
const fileId = (0, import_utils.calculateSha1)(fileName).slice(0, 20);
let fileEntry = data.get(fileId);
if (!fileEntry) {
fileEntry = {
testFile: { fileId, fileName, tests: [] },
testFileSummary: { fileId, fileName, tests: [], stats: emptyStats() }
};
data.set(fileId, fileEntry);
}
const { testFile, testFileSummary } = fileEntry;
const testEntries = [];
this._processSuite(suite, projectName, [], deep, testEntries);
for (const test of testEntries) {
testFile.tests.push(test.testCase);
testFileSummary.tests.push(test.testCaseSummary);
}
}
_processSuite(suite, projectName, path2, deep, outTests) {
const newPath = [...path2, suite.title];
suite.entries().forEach((e) => {
if (e.type === "test")
outTests.push(this._createTestEntry(e, projectName, newPath));
else if (deep)
this._processSuite(e, projectName, newPath, deep, outTests);
});
}
_createTestEntry(test, projectName, path2) {
const duration = test.results.reduce((a, r) => a + r.duration, 0);
const location = this._relativeLocation(test.location);
path2 = path2.slice(1).filter((path3) => path3.length > 0);
const results = test.results.map((r) => this._createTestResult(test, r));
return {
testCase: {
testId: test.id,
title: test.title,
projectName,
location,
duration,
annotations: this._serializeAnnotations(test.annotations),
tags: test.tags,
outcome: test.outcome(),
path: path2,
results,
ok: test.outcome() === "expected" || test.outcome() === "flaky"
},
testCaseSummary: {
testId: test.id,
title: test.title,
projectName,
location,
duration,
annotations: this._serializeAnnotations(test.annotations),
tags: test.tags,
outcome: test.outcome(),
path: path2,
ok: test.outcome() === "expected" || test.outcome() === "flaky",
results: results.map((result) => {
return { attachments: result.attachments.map((a) => ({ name: a.name, contentType: a.contentType, path: a.path })) };
})
}
};
}
_serializeAttachments(attachments) {
let lastAttachment;
return attachments.map((a) => {
if (a.name === "trace")
this._hasTraces = true;
if ((a.name === "stdout" || a.name === "stderr") && a.contentType === "text/plain") {
if (lastAttachment && lastAttachment.name === a.name && lastAttachment.contentType === a.contentType) {
lastAttachment.body += (0, import_util.stripAnsiEscapes)(a.body);
return null;
}
a.body = (0, import_util.stripAnsiEscapes)(a.body);
lastAttachment = a;
return a;
}
if (a.path) {
let fileName = a.path;
try {
const buffer = import_fs.default.readFileSync(a.path);
const sha1 = (0, import_utils.calculateSha1)(buffer) + import_path.default.extname(a.path);
fileName = this._attachmentsBaseURL + sha1;
import_fs.default.mkdirSync(import_path.default.join(this._reportFolder, "data"), { recursive: true });
import_fs.default.writeFileSync(import_path.default.join(this._reportFolder, "data", sha1), buffer);
} catch (e) {
}
return {
name: a.name,
contentType: a.contentType,
path: fileName,
body: a.body
};
}
if (a.body instanceof Buffer) {
if (isTextContentType(a.contentType)) {
const charset = a.contentType.match(/charset=(.*)/)?.[1];
try {
const body = a.body.toString(charset || "utf-8");
return {
name: a.name,
contentType: a.contentType,
body
};
} catch (e) {
}
}
import_fs.default.mkdirSync(import_path.default.join(this._reportFolder, "data"), { recursive: true });
const extension = (0, import_utils.sanitizeForFilePath)(import_path.default.extname(a.name).replace(/^\./, "")) || import_utilsBundle2.mime.getExtension(a.contentType) || "dat";
const sha1 = (0, import_utils.calculateSha1)(a.body) + "." + extension;
import_fs.default.writeFileSync(import_path.default.join(this._reportFolder, "data", sha1), a.body);
return {
name: a.name,
contentType: a.contentType,
path: this._attachmentsBaseURL + sha1
};
}
return {
name: a.name,
contentType: a.contentType,
body: a.body
};
}).filter(Boolean);
}
_serializeAnnotations(annotations) {
return annotations.map((a) => ({
type: a.type,
description: a.description === void 0 ? void 0 : String(a.description),
location: a.location ? {
file: a.location.file,
line: a.location.line,
column: a.location.column
} : void 0
}));
}
_createTestResult(test, result) {
return {
duration: result.duration,
startTime: result.startTime.toISOString(),
retry: result.retry,
steps: dedupeSteps(result.steps).map((s) => this._createTestStep(s, result)),
errors: (0, import_base.formatResultFailure)(import_base.internalScreen, test, result, "").map((error) => {
return {
message: error.message,
codeframe: error.location ? createErrorCodeframe(error.message, error.location) : void 0
};
}),
status: result.status,
annotations: this._serializeAnnotations(result.annotations),
attachments: this._serializeAttachments([
...result.attachments,
...result.stdout.map((m) => stdioAttachment(m, "stdout")),
...result.stderr.map((m) => stdioAttachment(m, "stderr"))
])
};
}
_createTestStep(dedupedStep, result) {
const { step, duration, count } = dedupedStep;
const skipped = dedupedStep.step.annotations?.find((a) => a.type === "skip");
let title = step.title;
if (skipped)
title = `${title} (skipped${skipped.description ? ": " + skipped.description : ""})`;
const testStep = {
title,
startTime: step.startTime.toISOString(),
duration,
steps: dedupeSteps(step.steps).map((s) => this._createTestStep(s, result)),
attachments: step.attachments.map((s) => {
const index = result.attachments.indexOf(s);
if (index === -1)
throw new Error("Unexpected, attachment not found");
return index;
}),
location: this._relativeLocation(step.location),
error: step.error?.message,
count,
skipped: !!skipped
};
if (step.location)
this._stepsInFile.set(step.location.file, testStep);
return testStep;
}
_relativeLocation(location) {
if (!location)
return void 0;
const file = (0, import_utils.toPosixPath)(import_path.default.relative(this._config.rootDir, location.file));
return {
file,
line: location.line,
column: location.column
};
}
}
const emptyStats = () => {
return {
total: 0,
expected: 0,
unexpected: 0,
flaky: 0,
skipped: 0,
ok: true
};
};
const addStats = (stats, delta) => {
stats.total += delta.total;
stats.skipped += delta.skipped;
stats.expected += delta.expected;
stats.unexpected += delta.unexpected;
stats.flaky += delta.flaky;
stats.ok = stats.ok && delta.ok;
return stats;
};
class Base64Encoder extends import_stream.Transform {
_transform(chunk, encoding, callback) {
if (this._remainder) {
chunk = Buffer.concat([this._remainder, chunk]);
this._remainder = void 0;
}
const remaining = chunk.length % 3;
if (remaining) {
this._remainder = chunk.slice(chunk.length - remaining);
chunk = chunk.slice(0, chunk.length - remaining);
}
chunk = chunk.toString("base64");
this.push(Buffer.from(chunk));
callback();
}
_flush(callback) {
if (this._remainder)
this.push(Buffer.from(this._remainder.toString("base64")));
callback();
}
}
function isTextContentType(contentType) {
return contentType.startsWith("text/") || contentType.startsWith("application/json");
}
function stdioAttachment(chunk, type) {
return {
name: type,
contentType: "text/plain",
body: typeof chunk === "string" ? chunk : chunk.toString("utf-8")
};
}
function dedupeSteps(steps) {
const result = [];
let lastResult = void 0;
for (const step of steps) {
const canDedupe = !step.error && step.duration >= 0 && step.location?.file && !step.steps.length;
const lastStep = lastResult?.step;
if (canDedupe && lastResult && lastStep && step.category === lastStep.category && step.title === lastStep.title && step.location?.file === lastStep.location?.file && step.location?.line === lastStep.location?.line && step.location?.column === lastStep.location?.column) {
++lastResult.count;
lastResult.duration += step.duration;
continue;
}
lastResult = { step, count: 1, duration: step.duration };
result.push(lastResult);
if (!canDedupe)
lastResult = void 0;
}
return result;
}
function createSnippets(stepsInFile) {
for (const file of stepsInFile.keys()) {
let source;
try {
source = import_fs.default.readFileSync(file, "utf-8") + "\n//";
} catch (e) {
continue;
}
const lines = source.split("\n").length;
const highlighted = (0, import_babelBundle.codeFrameColumns)(source, { start: { line: lines, column: 1 } }, { highlightCode: true, linesAbove: lines, linesBelow: 0 });
const highlightedLines = highlighted.split("\n");
const lineWithArrow = highlightedLines[highlightedLines.length - 1];
for (const step of stepsInFile.get(file)) {
if (step.location.line < 2 || step.location.line >= lines)
continue;
const snippetLines = highlightedLines.slice(step.location.line - 2, step.location.line + 1);
const index = lineWithArrow.indexOf("^");
const shiftedArrow = lineWithArrow.slice(0, index) + " ".repeat(step.location.column - 1) + lineWithArrow.slice(index);
snippetLines.splice(2, 0, shiftedArrow);
step.snippet = snippetLines.join("\n");
}
}
}
function createErrorCodeframe(message, location) {
let source;
try {
source = import_fs.default.readFileSync(location.file, "utf-8") + "\n//";
} catch (e) {
return;
}
return (0, import_babelBundle.codeFrameColumns)(
source,
{
start: {
line: location.line,
column: location.column
}
},
{
highlightCode: false,
linesAbove: 100,
linesBelow: 100,
message: (0, import_util.stripAnsiEscapes)(message).split("\n")[0] || void 0
}
);
}
function writeLine(line) {
process.stdout.write(line + "\n");
}
var html_default = HtmlReporter;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
showHTMLReport,
startHtmlReportServer
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var internalReporter_exports = {};
__export(internalReporter_exports, {
InternalReporter: () => InternalReporter
});
module.exports = __toCommonJS(internalReporter_exports);
var import_fs = __toESM(require("fs"));
var import_utils = require("playwright-core/lib/utils");
var import_base = require("./base");
var import_multiplexer = require("./multiplexer");
var import_test = require("../common/test");
var import_babelBundle = require("../transform/babelBundle");
var import_reporterV2 = require("./reporterV2");
class InternalReporter {
constructor(reporters) {
this._didBegin = false;
this._reporter = new import_multiplexer.Multiplexer(reporters.map(import_reporterV2.wrapReporterAsV2));
}
version() {
return "v2";
}
onConfigure(config) {
this._config = config;
this._startTime = /* @__PURE__ */ new Date();
this._monotonicStartTime = (0, import_utils.monotonicTime)();
this._reporter.onConfigure?.(config);
}
onBegin(suite) {
this._didBegin = true;
this._reporter.onBegin?.(suite);
}
onTestBegin(test, result) {
this._reporter.onTestBegin?.(test, result);
}
onStdOut(chunk, test, result) {
this._reporter.onStdOut?.(chunk, test, result);
}
onStdErr(chunk, test, result) {
this._reporter.onStdErr?.(chunk, test, result);
}
onTestEnd(test, result) {
this._addSnippetToTestErrors(test, result);
this._reporter.onTestEnd?.(test, result);
}
async onEnd(result) {
if (!this._didBegin) {
this.onBegin(new import_test.Suite("", "root"));
}
return await this._reporter.onEnd?.({
...result,
startTime: this._startTime,
duration: (0, import_utils.monotonicTime)() - this._monotonicStartTime
});
}
async onExit() {
await this._reporter.onExit?.();
}
onError(error) {
addLocationAndSnippetToError(this._config, error);
this._reporter.onError?.(error);
}
onStepBegin(test, result, step) {
this._reporter.onStepBegin?.(test, result, step);
}
onStepEnd(test, result, step) {
this._addSnippetToStepError(test, step);
this._reporter.onStepEnd?.(test, result, step);
}
printsToStdio() {
return this._reporter.printsToStdio ? this._reporter.printsToStdio() : true;
}
_addSnippetToTestErrors(test, result) {
for (const error of result.errors)
addLocationAndSnippetToError(this._config, error, test.location.file);
}
_addSnippetToStepError(test, step) {
if (step.error)
addLocationAndSnippetToError(this._config, step.error, test.location.file);
}
}
function addLocationAndSnippetToError(config, error, file) {
if (error.stack && !error.location)
error.location = (0, import_base.prepareErrorStack)(error.stack).location;
const location = error.location;
if (!location)
return;
try {
const tokens = [];
const source = import_fs.default.readFileSync(location.file, "utf8");
const codeFrame = (0, import_babelBundle.codeFrameColumns)(source, { start: location }, { highlightCode: true });
if (!file || import_fs.default.realpathSync(file) !== location.file) {
tokens.push(import_base.internalScreen.colors.gray(` at `) + `${(0, import_base.relativeFilePath)(import_base.internalScreen, config, location.file)}:${location.line}`);
tokens.push("");
}
tokens.push(codeFrame);
error.snippet = tokens.join("\n");
} catch (e) {
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
InternalReporter
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var json_exports = {};
__export(json_exports, {
default: () => json_default,
serializePatterns: () => serializePatterns
});
module.exports = __toCommonJS(json_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_base = require("./base");
var import_config = require("../common/config");
class JSONReporter {
constructor(options) {
this._errors = [];
this._resolvedOutputFile = (0, import_base.resolveOutputFile)("JSON", options)?.outputFile;
}
version() {
return "v2";
}
printsToStdio() {
return !this._resolvedOutputFile;
}
onConfigure(config) {
this.config = config;
}
onBegin(suite) {
this.suite = suite;
}
onError(error) {
this._errors.push(error);
}
async onEnd(result) {
await outputReport(this._serializeReport(result), this._resolvedOutputFile);
}
_serializeReport(result) {
const report = {
config: {
...removePrivateFields(this.config),
rootDir: (0, import_utils.toPosixPath)(this.config.rootDir),
projects: this.config.projects.map((project) => {
return {
outputDir: (0, import_utils.toPosixPath)(project.outputDir),
repeatEach: project.repeatEach,
retries: project.retries,
metadata: project.metadata,
id: (0, import_config.getProjectId)(project),
name: project.name,
testDir: (0, import_utils.toPosixPath)(project.testDir),
testIgnore: serializePatterns(project.testIgnore),
testMatch: serializePatterns(project.testMatch),
timeout: project.timeout
};
})
},
suites: this._mergeSuites(this.suite.suites),
errors: this._errors,
stats: {
startTime: result.startTime.toISOString(),
duration: result.duration,
expected: 0,
skipped: 0,
unexpected: 0,
flaky: 0
}
};
for (const test of this.suite.allTests())
++report.stats[test.outcome()];
return report;
}
_mergeSuites(suites) {
const fileSuites = new import_utils.MultiMap();
for (const projectSuite of suites) {
const projectId = (0, import_config.getProjectId)(projectSuite.project());
const projectName = projectSuite.project().name;
for (const fileSuite of projectSuite.suites) {
const file = fileSuite.location.file;
const serialized = this._serializeSuite(projectId, projectName, fileSuite);
if (serialized)
fileSuites.set(file, serialized);
}
}
const results = [];
for (const [, suites2] of fileSuites) {
const result = {
title: suites2[0].title,
file: suites2[0].file,
column: 0,
line: 0,
specs: []
};
for (const suite of suites2)
this._mergeTestsFromSuite(result, suite);
results.push(result);
}
return results;
}
_relativeLocation(location) {
if (!location)
return { file: "", line: 0, column: 0 };
return {
file: (0, import_utils.toPosixPath)(import_path.default.relative(this.config.rootDir, location.file)),
line: location.line,
column: location.column
};
}
_locationMatches(s1, s2) {
return s1.file === s2.file && s1.line === s2.line && s1.column === s2.column;
}
_mergeTestsFromSuite(to, from) {
for (const fromSuite of from.suites || []) {
const toSuite = (to.suites || []).find((s) => s.title === fromSuite.title && this._locationMatches(s, fromSuite));
if (toSuite) {
this._mergeTestsFromSuite(toSuite, fromSuite);
} else {
if (!to.suites)
to.suites = [];
to.suites.push(fromSuite);
}
}
for (const spec of from.specs || []) {
const toSpec = to.specs.find((s) => s.title === spec.title && s.file === (0, import_utils.toPosixPath)(import_path.default.relative(this.config.rootDir, spec.file)) && s.line === spec.line && s.column === spec.column);
if (toSpec)
toSpec.tests.push(...spec.tests);
else
to.specs.push(spec);
}
}
_serializeSuite(projectId, projectName, suite) {
if (!suite.allTests().length)
return null;
const suites = suite.suites.map((suite2) => this._serializeSuite(projectId, projectName, suite2)).filter((s) => s);
return {
title: suite.title,
...this._relativeLocation(suite.location),
specs: suite.tests.map((test) => this._serializeTestSpec(projectId, projectName, test)),
suites: suites.length ? suites : void 0
};
}
_serializeTestSpec(projectId, projectName, test) {
return {
title: test.title,
ok: test.ok(),
tags: test.tags.map((tag) => tag.substring(1)),
// Strip '@'.
tests: [this._serializeTest(projectId, projectName, test)],
id: test.id,
...this._relativeLocation(test.location)
};
}
_serializeTest(projectId, projectName, test) {
return {
timeout: test.timeout,
annotations: test.annotations,
expectedStatus: test.expectedStatus,
projectId,
projectName,
results: test.results.map((r) => this._serializeTestResult(r, test)),
status: test.outcome()
};
}
_serializeTestResult(result, test) {
const steps = result.steps.filter((s) => s.category === "test.step");
const jsonResult = {
workerIndex: result.workerIndex,
parallelIndex: result.parallelIndex,
status: result.status,
duration: result.duration,
error: result.error,
errors: result.errors.map((e) => this._serializeError(e)),
stdout: result.stdout.map((s) => stdioEntry(s)),
stderr: result.stderr.map((s) => stdioEntry(s)),
retry: result.retry,
steps: steps.length ? steps.map((s) => this._serializeTestStep(s)) : void 0,
startTime: result.startTime.toISOString(),
annotations: result.annotations,
attachments: result.attachments.map((a) => ({
name: a.name,
contentType: a.contentType,
path: a.path,
body: a.body?.toString("base64")
}))
};
if (result.error?.stack)
jsonResult.errorLocation = (0, import_base.prepareErrorStack)(result.error.stack).location;
return jsonResult;
}
_serializeError(error) {
return (0, import_base.formatError)(import_base.nonTerminalScreen, error);
}
_serializeTestStep(step) {
const steps = step.steps.filter((s) => s.category === "test.step");
return {
title: step.title,
duration: step.duration,
error: step.error,
steps: steps.length ? steps.map((s) => this._serializeTestStep(s)) : void 0
};
}
}
async function outputReport(report, resolvedOutputFile) {
const reportString = JSON.stringify(report, void 0, 2);
if (resolvedOutputFile) {
await import_fs.default.promises.mkdir(import_path.default.dirname(resolvedOutputFile), { recursive: true });
await import_fs.default.promises.writeFile(resolvedOutputFile, reportString);
} else {
console.log(reportString);
}
}
function stdioEntry(s) {
if (typeof s === "string")
return { text: s };
return { buffer: s.toString("base64") };
}
function removePrivateFields(config) {
return Object.fromEntries(Object.entries(config).filter(([name, value]) => !name.startsWith("_")));
}
function serializePatterns(patterns) {
if (!Array.isArray(patterns))
patterns = [patterns];
return patterns.map((s) => s.toString());
}
var json_default = JSONReporter;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
serializePatterns
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var junit_exports = {};
__export(junit_exports, {
default: () => junit_default
});
module.exports = __toCommonJS(junit_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_base = require("./base");
var import_util = require("../util");
class JUnitReporter {
constructor(options) {
this.totalTests = 0;
this.totalFailures = 0;
this.totalSkipped = 0;
this.stripANSIControlSequences = false;
this.includeProjectInTestName = false;
this.stripANSIControlSequences = (0, import_utils.getAsBooleanFromENV)("PLAYWRIGHT_JUNIT_STRIP_ANSI", !!options.stripANSIControlSequences);
this.includeProjectInTestName = (0, import_utils.getAsBooleanFromENV)("PLAYWRIGHT_JUNIT_INCLUDE_PROJECT_IN_TEST_NAME", !!options.includeProjectInTestName);
this.configDir = options.configDir;
this.resolvedOutputFile = (0, import_base.resolveOutputFile)("JUNIT", options)?.outputFile;
}
version() {
return "v2";
}
printsToStdio() {
return !this.resolvedOutputFile;
}
onConfigure(config) {
this.config = config;
}
onBegin(suite) {
this.suite = suite;
this.timestamp = /* @__PURE__ */ new Date();
}
async onEnd(result) {
const children = [];
for (const projectSuite of this.suite.suites) {
for (const fileSuite of projectSuite.suites)
children.push(await this._buildTestSuite(projectSuite.title, fileSuite));
}
const tokens = [];
const self = this;
const root = {
name: "testsuites",
attributes: {
id: process.env[`PLAYWRIGHT_JUNIT_SUITE_ID`] || "",
name: process.env[`PLAYWRIGHT_JUNIT_SUITE_NAME`] || "",
tests: self.totalTests,
failures: self.totalFailures,
skipped: self.totalSkipped,
errors: 0,
time: result.duration / 1e3
},
children
};
serializeXML(root, tokens, this.stripANSIControlSequences);
const reportString = tokens.join("\n");
if (this.resolvedOutputFile) {
await import_fs.default.promises.mkdir(import_path.default.dirname(this.resolvedOutputFile), { recursive: true });
await import_fs.default.promises.writeFile(this.resolvedOutputFile, reportString);
} else {
console.log(reportString);
}
}
async _buildTestSuite(projectName, suite) {
let tests = 0;
let skipped = 0;
let failures = 0;
let duration = 0;
const children = [];
const testCaseNamePrefix = projectName && this.includeProjectInTestName ? `[${projectName}] ` : "";
for (const test of suite.allTests()) {
++tests;
if (test.outcome() === "skipped")
++skipped;
if (!test.ok())
++failures;
for (const result of test.results)
duration += result.duration;
await this._addTestCase(suite.title, testCaseNamePrefix, test, children);
}
this.totalTests += tests;
this.totalSkipped += skipped;
this.totalFailures += failures;
const entry = {
name: "testsuite",
attributes: {
name: suite.title,
timestamp: this.timestamp.toISOString(),
hostname: projectName,
tests,
failures,
skipped,
time: duration / 1e3,
errors: 0
},
children
};
return entry;
}
async _addTestCase(suiteName, namePrefix, test, entries) {
const entry = {
name: "testcase",
attributes: {
// Skip root, project, file
name: namePrefix + test.titlePath().slice(3).join(" \u203A "),
// filename
classname: suiteName,
time: test.results.reduce((acc, value) => acc + value.duration, 0) / 1e3
},
children: []
};
entries.push(entry);
const properties = {
name: "properties",
children: []
};
for (const annotation of test.annotations) {
const property = {
name: "property",
attributes: {
name: annotation.type,
value: annotation?.description ? annotation.description : ""
}
};
properties.children?.push(property);
}
if (properties.children?.length)
entry.children.push(properties);
if (test.outcome() === "skipped") {
entry.children.push({ name: "skipped" });
return;
}
if (!test.ok()) {
entry.children.push({
name: "failure",
attributes: {
message: `${import_path.default.basename(test.location.file)}:${test.location.line}:${test.location.column} ${test.title}`,
type: "FAILURE"
},
text: (0, import_util.stripAnsiEscapes)((0, import_base.formatFailure)(import_base.nonTerminalScreen, this.config, test))
});
}
const systemOut = [];
const systemErr = [];
for (const result of test.results) {
systemOut.push(...result.stdout.map((item) => item.toString()));
systemErr.push(...result.stderr.map((item) => item.toString()));
for (const attachment of result.attachments) {
if (!attachment.path)
continue;
let attachmentPath = import_path.default.relative(this.configDir, attachment.path);
try {
if (this.resolvedOutputFile)
attachmentPath = import_path.default.relative(import_path.default.dirname(this.resolvedOutputFile), attachment.path);
} catch {
systemOut.push(`
Warning: Unable to make attachment path ${attachment.path} relative to report output file ${this.resolvedOutputFile}`);
}
try {
await import_fs.default.promises.access(attachment.path);
systemOut.push(`
[[ATTACHMENT|${attachmentPath}]]
`);
} catch {
systemErr.push(`
Warning: attachment ${attachmentPath} is missing`);
}
}
}
if (systemOut.length)
entry.children.push({ name: "system-out", text: systemOut.join("") });
if (systemErr.length)
entry.children.push({ name: "system-err", text: systemErr.join("") });
}
}
function serializeXML(entry, tokens, stripANSIControlSequences) {
const attrs = [];
for (const [name, value] of Object.entries(entry.attributes || {}))
attrs.push(`${name}="${escape(String(value), stripANSIControlSequences, false)}"`);
tokens.push(`<${entry.name}${attrs.length ? " " : ""}${attrs.join(" ")}>`);
for (const child of entry.children || [])
serializeXML(child, tokens, stripANSIControlSequences);
if (entry.text)
tokens.push(escape(entry.text, stripANSIControlSequences, true));
tokens.push(`</${entry.name}>`);
}
const discouragedXMLCharacters = /[\u0000-\u0008\u000b-\u000c\u000e-\u001f\u007f-\u0084\u0086-\u009f]/g;
function escape(text, stripANSIControlSequences, isCharacterData) {
if (stripANSIControlSequences)
text = (0, import_util.stripAnsiEscapes)(text);
if (isCharacterData) {
text = "<![CDATA[" + text.replace(/]]>/g, "]]&gt;") + "]]>";
} else {
const escapeRe = /[&"'<>]/g;
text = text.replace(escapeRe, (c) => ({ "&": "&amp;", '"': "&quot;", "'": "&apos;", "<": "&lt;", ">": "&gt;" })[c]);
}
text = text.replace(discouragedXMLCharacters, "");
return text;
}
var junit_default = JUnitReporter;
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var line_exports = {};
__export(line_exports, {
default: () => line_default
});
module.exports = __toCommonJS(line_exports);
var import_base = require("./base");
class LineReporter extends import_base.TerminalReporter {
constructor() {
super(...arguments);
this._current = 0;
this._failures = 0;
this._didBegin = false;
}
onBegin(suite) {
super.onBegin(suite);
const startingMessage = this.generateStartingMessage();
if (startingMessage) {
this.writeLine(startingMessage);
this.writeLine();
}
this._didBegin = true;
}
onStdOut(chunk, test, result) {
super.onStdOut(chunk, test, result);
this._dumpToStdio(test, chunk, this.screen.stdout);
}
onStdErr(chunk, test, result) {
super.onStdErr(chunk, test, result);
this._dumpToStdio(test, chunk, this.screen.stderr);
}
_dumpToStdio(test, chunk, stream) {
if (this.config.quiet)
return;
if (!process.env.PW_TEST_DEBUG_REPORTERS)
stream.write(`\x1B[1A\x1B[2K`);
if (test && this._lastTest !== test) {
const title = this.screen.colors.dim(this.formatTestTitle(test));
stream.write(this.fitToScreen(title) + `
`);
this._lastTest = test;
}
stream.write(chunk);
if (chunk[chunk.length - 1] !== "\n")
this.writeLine();
this.writeLine();
}
onTestBegin(test, result) {
++this._current;
this._updateLine(test, result, void 0);
}
onStepBegin(test, result, step) {
if (this.screen.isTTY && step.category === "test.step")
this._updateLine(test, result, step);
}
onStepEnd(test, result, step) {
if (this.screen.isTTY && step.category === "test.step")
this._updateLine(test, result, step.parent);
}
onTestEnd(test, result) {
super.onTestEnd(test, result);
if (!this.willRetry(test) && (test.outcome() === "flaky" || test.outcome() === "unexpected" || result.status === "interrupted")) {
if (!process.env.PW_TEST_DEBUG_REPORTERS)
this.screen.stdout.write(`\x1B[1A\x1B[2K`);
this.writeLine(this.formatFailure(test, ++this._failures));
this.writeLine();
}
}
_updateLine(test, result, step) {
const retriesPrefix = this.totalTestCount < this._current ? ` (retries)` : ``;
const prefix = `[${this._current}/${this.totalTestCount}]${retriesPrefix} `;
const currentRetrySuffix = result.retry ? this.screen.colors.yellow(` (retry #${result.retry})`) : "";
const title = this.formatTestTitle(test, step) + currentRetrySuffix;
if (process.env.PW_TEST_DEBUG_REPORTERS)
this.screen.stdout.write(`${prefix + title}
`);
else
this.screen.stdout.write(`\x1B[1A\x1B[2K${prefix + this.fitToScreen(title, prefix)}
`);
}
onError(error) {
super.onError(error);
const message = this.formatError(error).message + "\n";
if (!process.env.PW_TEST_DEBUG_REPORTERS && this._didBegin)
this.screen.stdout.write(`\x1B[1A\x1B[2K`);
this.screen.stdout.write(message);
this.writeLine();
}
async onEnd(result) {
if (!process.env.PW_TEST_DEBUG_REPORTERS && this._didBegin)
this.screen.stdout.write(`\x1B[1A\x1B[2K`);
await super.onEnd(result);
this.epilogue(false);
}
}
var line_default = LineReporter;
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var list_exports = {};
__export(list_exports, {
default: () => list_default
});
module.exports = __toCommonJS(list_exports);
var import_utils = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_base = require("./base");
var import_util = require("../util");
const DOES_NOT_SUPPORT_UTF8_IN_TERMINAL = process.platform === "win32" && process.env.TERM_PROGRAM !== "vscode" && !process.env.WT_SESSION;
const POSITIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? "ok" : "\u2713";
const NEGATIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? "x" : "\u2718";
class ListReporter extends import_base.TerminalReporter {
constructor(options) {
super(options);
this._lastRow = 0;
this._lastColumn = 0;
this._testRows = /* @__PURE__ */ new Map();
this._stepRows = /* @__PURE__ */ new Map();
this._resultIndex = /* @__PURE__ */ new Map();
this._stepIndex = /* @__PURE__ */ new Map();
this._needNewLine = false;
this._printSteps = (0, import_utils.getAsBooleanFromENV)("PLAYWRIGHT_LIST_PRINT_STEPS", options?.printSteps);
this._prefixStdio = options?.prefixStdio;
}
onBegin(suite) {
super.onBegin(suite);
const startingMessage = this.generateStartingMessage();
if (startingMessage) {
this.writeLine(startingMessage);
this.writeLine("");
}
}
onTestBegin(test, result) {
const index = String(this._resultIndex.size + 1);
this._resultIndex.set(result, index);
if (!this.screen.isTTY)
return;
this._maybeWriteNewLine();
this._testRows.set(test, this._lastRow);
const prefix = this._testPrefix(index, "");
const line = this.screen.colors.dim(this.formatTestTitle(test)) + this._retrySuffix(result);
this._appendLine(line, prefix);
}
onStdOut(chunk, test, result) {
super.onStdOut(chunk, test, result);
this._dumpToStdio(test, chunk, this.screen.stdout, "out");
}
onStdErr(chunk, test, result) {
super.onStdErr(chunk, test, result);
this._dumpToStdio(test, chunk, this.screen.stderr, "err");
}
getStepIndex(testIndex, result, step) {
if (this._stepIndex.has(step))
return this._stepIndex.get(step);
const ordinal = (result[lastStepOrdinalSymbol] || 0) + 1;
result[lastStepOrdinalSymbol] = ordinal;
const stepIndex = `${testIndex}.${ordinal}`;
this._stepIndex.set(step, stepIndex);
return stepIndex;
}
onStepBegin(test, result, step) {
if (step.category !== "test.step")
return;
const testIndex = this._resultIndex.get(result) || "";
if (!this.screen.isTTY)
return;
if (this._printSteps) {
this._maybeWriteNewLine();
this._stepRows.set(step, this._lastRow);
const prefix = this._testPrefix(this.getStepIndex(testIndex, result, step), "");
const line = test.title + this.screen.colors.dim((0, import_base.stepSuffix)(step));
this._appendLine(line, prefix);
} else {
this._updateOrAppendLine(this._testRows, test, this.screen.colors.dim(this.formatTestTitle(test, step)) + this._retrySuffix(result), this._testPrefix(testIndex, ""));
}
}
onStepEnd(test, result, step) {
if (step.category !== "test.step")
return;
const testIndex = this._resultIndex.get(result) || "";
if (!this._printSteps) {
if (this.screen.isTTY)
this._updateOrAppendLine(this._testRows, test, this.screen.colors.dim(this.formatTestTitle(test, step.parent)) + this._retrySuffix(result), this._testPrefix(testIndex, ""));
return;
}
const index = this.getStepIndex(testIndex, result, step);
const title = this.screen.isTTY ? test.title + this.screen.colors.dim((0, import_base.stepSuffix)(step)) : this.formatTestTitle(test, step);
const prefix = this._testPrefix(index, "");
let text = "";
if (step.error)
text = this.screen.colors.red(title);
else
text = title;
text += this.screen.colors.dim(` (${(0, import_utilsBundle.ms)(step.duration)})`);
this._updateOrAppendLine(this._stepRows, step, text, prefix);
}
_maybeWriteNewLine() {
if (this._needNewLine) {
this._needNewLine = false;
this.screen.stdout.write("\n");
++this._lastRow;
this._lastColumn = 0;
}
}
_updateLineCountAndNewLineFlagForOutput(text) {
this._needNewLine = text[text.length - 1] !== "\n";
if (!this.screen.ttyWidth)
return;
for (const ch of text) {
if (ch === "\n") {
this._lastColumn = 0;
++this._lastRow;
continue;
}
++this._lastColumn;
if (this._lastColumn > this.screen.ttyWidth) {
this._lastColumn = 0;
++this._lastRow;
}
}
}
_dumpToStdio(test, chunk, stream, stdio) {
if (this.config.quiet)
return;
const text = chunk.toString("utf-8");
this._updateLineCountAndNewLineFlagForOutput(text);
if (this._prefixStdio)
stream.write(`[${stdio}] ${chunk}`);
else
stream.write(chunk);
}
onTestEnd(test, result) {
super.onTestEnd(test, result);
const title = this.formatTestTitle(test);
let prefix = "";
let text = "";
let index = this._resultIndex.get(result);
if (!index) {
index = String(this._resultIndex.size + 1);
this._resultIndex.set(result, index);
}
if (result.status === "skipped") {
prefix = this._testPrefix(index, this.screen.colors.green("-"));
text = this.screen.colors.cyan(title) + this._retrySuffix(result);
} else {
const statusMark = result.status === "passed" ? POSITIVE_STATUS_MARK : NEGATIVE_STATUS_MARK;
if (result.status === test.expectedStatus) {
prefix = this._testPrefix(index, this.screen.colors.green(statusMark));
text = title;
} else {
prefix = this._testPrefix(index, this.screen.colors.red(statusMark));
text = this.screen.colors.red(title);
}
text += this._retrySuffix(result) + this.screen.colors.dim(` (${(0, import_utilsBundle.ms)(result.duration)})`);
}
this._updateOrAppendLine(this._testRows, test, text, prefix);
}
_updateOrAppendLine(entityRowNumbers, entity, text, prefix) {
const row = entityRowNumbers.get(entity);
if (row !== void 0 && this.screen.isTTY && this._lastRow - row < this.screen.ttyHeight) {
this._updateLine(row, text, prefix);
} else {
this._maybeWriteNewLine();
entityRowNumbers.set(entity, this._lastRow);
this._appendLine(text, prefix);
}
}
_appendLine(text, prefix) {
const line = prefix + this.fitToScreen(text, prefix);
if (process.env.PW_TEST_DEBUG_REPORTERS) {
this.screen.stdout.write("#" + this._lastRow + " : " + line + "\n");
} else {
this.screen.stdout.write(line);
this.screen.stdout.write("\n");
}
++this._lastRow;
this._lastColumn = 0;
}
_updateLine(row, text, prefix) {
const line = prefix + this.fitToScreen(text, prefix);
if (process.env.PW_TEST_DEBUG_REPORTERS)
this.screen.stdout.write("#" + row + " : " + line + "\n");
else
this._updateLineForTTY(row, line);
}
_updateLineForTTY(row, line) {
if (row !== this._lastRow)
this.screen.stdout.write(`\x1B[${this._lastRow - row}A`);
this.screen.stdout.write("\x1B[2K\x1B[0G");
this.screen.stdout.write(line);
if (row !== this._lastRow)
this.screen.stdout.write(`\x1B[${this._lastRow - row}E`);
}
_testPrefix(index, statusMark) {
const statusMarkLength = (0, import_util.stripAnsiEscapes)(statusMark).length;
const indexLength = Math.ceil(Math.log10(this.totalTestCount + 1));
return " " + statusMark + " ".repeat(3 - statusMarkLength) + this.screen.colors.dim(index.padStart(indexLength) + " ");
}
_retrySuffix(result) {
return result.retry ? this.screen.colors.yellow(` (retry #${result.retry})`) : "";
}
onError(error) {
super.onError(error);
this._maybeWriteNewLine();
const message = this.formatError(error).message + "\n";
this._updateLineCountAndNewLineFlagForOutput(message);
this.screen.stdout.write(message);
}
async onEnd(result) {
await super.onEnd(result);
this.screen.stdout.write("\n");
this.epilogue(true);
}
}
const lastStepOrdinalSymbol = Symbol("lastStepOrdinal");
var list_default = ListReporter;
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var listModeReporter_exports = {};
__export(listModeReporter_exports, {
default: () => listModeReporter_default
});
module.exports = __toCommonJS(listModeReporter_exports);
var import_path = __toESM(require("path"));
var import_base = require("./base");
class ListModeReporter {
constructor(options = {}) {
this._options = options;
this.screen = options?.screen ?? import_base.terminalScreen;
}
version() {
return "v2";
}
onConfigure(config) {
this.config = config;
}
onBegin(suite) {
this._writeLine(`Listing tests:`);
const tests = suite.allTests();
const files = /* @__PURE__ */ new Set();
for (const test of tests) {
const [, projectName, , ...titles] = test.titlePath();
const location = `${import_path.default.relative(this.config.rootDir, test.location.file)}:${test.location.line}:${test.location.column}`;
const testId = this._options.includeTestId ? `[id=${test.id}] ` : "";
const projectLabel = this._options.includeTestId ? `project=` : "";
const projectTitle = projectName ? `[${projectLabel}${projectName}] \u203A ` : "";
this._writeLine(` ${testId}${projectTitle}${location} \u203A ${titles.join(" \u203A ")}`);
files.add(test.location.file);
}
this._writeLine(`Total: ${tests.length} ${tests.length === 1 ? "test" : "tests"} in ${files.size} ${files.size === 1 ? "file" : "files"}`);
}
onError(error) {
this.screen.stderr.write("\n" + (0, import_base.formatError)(import_base.terminalScreen, error).message + "\n");
}
_writeLine(line) {
this.screen.stdout.write(line + "\n");
}
}
var listModeReporter_default = ListModeReporter;
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var markdown_exports = {};
__export(markdown_exports, {
default: () => markdown_default
});
module.exports = __toCommonJS(markdown_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
class MarkdownReporter {
constructor(options) {
this._fatalErrors = [];
this._options = options;
}
printsToStdio() {
return false;
}
onBegin(config, suite) {
this._config = config;
this._suite = suite;
}
onError(error) {
this._fatalErrors.push(error);
}
async onEnd(result) {
const summary = this._generateSummary();
const lines = [];
if (this._fatalErrors.length)
lines.push(`**${this._fatalErrors.length} fatal errors, not part of any test**`);
if (summary.unexpected.length) {
lines.push(`**${summary.unexpected.length} failed**`);
this._printTestList(":x:", summary.unexpected, lines);
}
if (summary.flaky.length) {
lines.push(`<details>`);
lines.push(`<summary><b>${summary.flaky.length} flaky</b></summary>`);
this._printTestList(":warning:", summary.flaky, lines, " <br/>");
lines.push(`</details>`);
lines.push(``);
}
if (summary.interrupted.length) {
lines.push(`<details>`);
lines.push(`<summary><b>${summary.interrupted.length} interrupted</b></summary>`);
this._printTestList(":warning:", summary.interrupted, lines, " <br/>");
lines.push(`</details>`);
lines.push(``);
}
const skipped = summary.skipped ? `, ${summary.skipped} skipped` : "";
const didNotRun = summary.didNotRun ? `, ${summary.didNotRun} did not run` : "";
lines.push(`**${summary.expected} passed${skipped}${didNotRun}**`);
lines.push(``);
await this.publishReport(lines.join("\n"));
}
async publishReport(report) {
const maybeRelativeFile = this._options.outputFile || "report.md";
const reportFile = import_path.default.resolve(this._options.configDir, maybeRelativeFile);
await import_fs.default.promises.mkdir(import_path.default.dirname(reportFile), { recursive: true });
await import_fs.default.promises.writeFile(reportFile, report);
}
_generateSummary() {
let didNotRun = 0;
let skipped = 0;
let expected = 0;
const interrupted = [];
const interruptedToPrint = [];
const unexpected = [];
const flaky = [];
this._suite.allTests().forEach((test) => {
switch (test.outcome()) {
case "skipped": {
if (test.results.some((result) => result.status === "interrupted")) {
if (test.results.some((result) => !!result.error))
interruptedToPrint.push(test);
interrupted.push(test);
} else if (!test.results.length || test.expectedStatus !== "skipped") {
++didNotRun;
} else {
++skipped;
}
break;
}
case "expected":
++expected;
break;
case "unexpected":
unexpected.push(test);
break;
case "flaky":
flaky.push(test);
break;
}
});
return {
didNotRun,
skipped,
expected,
interrupted,
unexpected,
flaky
};
}
_printTestList(prefix, tests, lines, suffix) {
for (const test of tests)
lines.push(`${prefix} ${formatTestTitle(this._config.rootDir, test)}${suffix || ""}`);
lines.push(``);
}
}
function formatTestTitle(rootDir, test) {
const [, projectName, , ...titles] = test.titlePath();
const relativeTestPath = import_path.default.relative(rootDir, test.location.file);
const location = `${relativeTestPath}:${test.location.line}`;
const projectTitle = projectName ? `[${projectName}] \u203A ` : "";
const testTitle = `${projectTitle}${location} \u203A ${titles.join(" \u203A ")}`;
const extraTags = test.tags.filter((t) => !testTitle.includes(t));
const formattedTags = extraTags.map((t) => `\`${t}\``).join(" ");
return `${testTitle}${extraTags.length ? " " + formattedTags : ""}`;
}
var markdown_default = MarkdownReporter;
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var merge_exports = {};
__export(merge_exports, {
createMergedReport: () => createMergedReport
});
module.exports = __toCommonJS(merge_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_blob = require("./blob");
var import_multiplexer = require("./multiplexer");
var import_stringInternPool = require("../isomorphic/stringInternPool");
var import_teleReceiver = require("../isomorphic/teleReceiver");
var import_reporters = require("../runner/reporters");
var import_util = require("../util");
async function createMergedReport(config, dir, reporterDescriptions, rootDirOverride) {
const reporters = await (0, import_reporters.createReporters)(config, "merge", false, reporterDescriptions);
const multiplexer = new import_multiplexer.Multiplexer(reporters);
const stringPool = new import_stringInternPool.StringInternPool();
let printStatus = () => {
};
if (!multiplexer.printsToStdio()) {
printStatus = printStatusToStdout;
printStatus(`merging reports from ${dir}`);
}
const shardFiles = await sortedShardFiles(dir);
if (shardFiles.length === 0)
throw new Error(`No report files found in ${dir}`);
const eventData = await mergeEvents(dir, shardFiles, stringPool, printStatus, rootDirOverride);
const pathSeparator = rootDirOverride ? import_path.default.sep : eventData.pathSeparatorFromMetadata ?? import_path.default.sep;
const receiver = new import_teleReceiver.TeleReporterReceiver(multiplexer, {
mergeProjects: false,
mergeTestCases: false,
resolvePath: (rootDir, relativePath) => stringPool.internString(rootDir + pathSeparator + relativePath),
configOverrides: config.config
});
printStatus(`processing test events`);
const dispatchEvents = async (events) => {
for (const event of events) {
if (event.method === "onEnd")
printStatus(`building final report`);
await receiver.dispatch(event);
if (event.method === "onEnd")
printStatus(`finished building report`);
}
};
await dispatchEvents(eventData.prologue);
for (const { reportFile, eventPatchers, metadata } of eventData.reports) {
const reportJsonl = await import_fs.default.promises.readFile(reportFile);
const events = parseTestEvents(reportJsonl);
new import_stringInternPool.JsonStringInternalizer(stringPool).traverse(events);
eventPatchers.patchers.push(new AttachmentPathPatcher(dir));
if (metadata.name)
eventPatchers.patchers.push(new GlobalErrorPatcher(metadata.name));
eventPatchers.patchEvents(events);
await dispatchEvents(events);
}
await dispatchEvents(eventData.epilogue);
}
const commonEventNames = ["onBlobReportMetadata", "onConfigure", "onProject", "onBegin", "onEnd"];
const commonEvents = new Set(commonEventNames);
const commonEventRegex = new RegExp(`${commonEventNames.join("|")}`);
function parseCommonEvents(reportJsonl) {
return splitBufferLines(reportJsonl).map((line) => line.toString("utf8")).filter((line) => commonEventRegex.test(line)).map((line) => JSON.parse(line)).filter((event) => commonEvents.has(event.method));
}
function parseTestEvents(reportJsonl) {
return splitBufferLines(reportJsonl).map((line) => line.toString("utf8")).filter((line) => line.length).map((line) => JSON.parse(line)).filter((event) => !commonEvents.has(event.method));
}
function splitBufferLines(buffer) {
const lines = [];
let start = 0;
while (start < buffer.length) {
const end = buffer.indexOf(10, start);
if (end === -1) {
lines.push(buffer.slice(start));
break;
}
lines.push(buffer.slice(start, end));
start = end + 1;
}
return lines;
}
async function extractAndParseReports(dir, shardFiles, internalizer, printStatus) {
const shardEvents = [];
await import_fs.default.promises.mkdir(import_path.default.join(dir, "resources"), { recursive: true });
const reportNames = new UniqueFileNameGenerator();
for (const file of shardFiles) {
const absolutePath = import_path.default.join(dir, file);
printStatus(`extracting: ${(0, import_util.relativeFilePath)(absolutePath)}`);
const zipFile = new import_utils.ZipFile(absolutePath);
const entryNames = await zipFile.entries();
for (const entryName of entryNames.sort()) {
let fileName = import_path.default.join(dir, entryName);
const content = await zipFile.read(entryName);
if (entryName.endsWith(".jsonl")) {
fileName = reportNames.makeUnique(fileName);
let parsedEvents = parseCommonEvents(content);
internalizer.traverse(parsedEvents);
const metadata = findMetadata(parsedEvents, file);
parsedEvents = modernizer.modernize(metadata.version, parsedEvents);
shardEvents.push({
file,
localPath: fileName,
metadata,
parsedEvents
});
}
await import_fs.default.promises.writeFile(fileName, content);
}
zipFile.close();
}
return shardEvents;
}
function findMetadata(events, file) {
if (events[0]?.method !== "onBlobReportMetadata")
throw new Error(`No metadata event found in ${file}`);
const metadata = events[0].params;
if (metadata.version > import_blob.currentBlobReportVersion)
throw new Error(`Blob report ${file} was created with a newer version of Playwright.`);
return metadata;
}
async function mergeEvents(dir, shardReportFiles, stringPool, printStatus, rootDirOverride) {
const internalizer = new import_stringInternPool.JsonStringInternalizer(stringPool);
const configureEvents = [];
const projectEvents = [];
const endEvents = [];
const blobs = await extractAndParseReports(dir, shardReportFiles, internalizer, printStatus);
blobs.sort((a, b) => {
const nameA = a.metadata.name ?? "";
const nameB = b.metadata.name ?? "";
if (nameA !== nameB)
return nameA.localeCompare(nameB);
const shardA = a.metadata.shard?.current ?? 0;
const shardB = b.metadata.shard?.current ?? 0;
if (shardA !== shardB)
return shardA - shardB;
return a.file.localeCompare(b.file);
});
printStatus(`merging events`);
const reports = [];
const globalTestIdSet = /* @__PURE__ */ new Set();
for (let i = 0; i < blobs.length; ++i) {
const { parsedEvents, metadata, localPath } = blobs[i];
const eventPatchers = new JsonEventPatchers();
eventPatchers.patchers.push(new IdsPatcher(
stringPool,
metadata.name,
String(i),
globalTestIdSet
));
if (rootDirOverride)
eventPatchers.patchers.push(new PathSeparatorPatcher(metadata.pathSeparator));
eventPatchers.patchEvents(parsedEvents);
for (const event of parsedEvents) {
if (event.method === "onConfigure")
configureEvents.push(event);
else if (event.method === "onProject")
projectEvents.push(event);
else if (event.method === "onEnd")
endEvents.push(event);
}
reports.push({
eventPatchers,
reportFile: localPath,
metadata
});
}
return {
prologue: [
mergeConfigureEvents(configureEvents, rootDirOverride),
...projectEvents,
{ method: "onBegin", params: void 0 }
],
reports,
epilogue: [
mergeEndEvents(endEvents),
{ method: "onExit", params: void 0 }
],
pathSeparatorFromMetadata: blobs[0]?.metadata.pathSeparator
};
}
function mergeConfigureEvents(configureEvents, rootDirOverride) {
if (!configureEvents.length)
throw new Error("No configure events found");
let config = {
configFile: void 0,
globalTimeout: 0,
maxFailures: 0,
metadata: {},
rootDir: "",
version: "",
workers: 0,
globalSetup: null,
globalTeardown: null
};
for (const event of configureEvents)
config = mergeConfigs(config, event.params.config);
if (rootDirOverride) {
config.rootDir = rootDirOverride;
} else {
const rootDirs = new Set(configureEvents.map((e) => e.params.config.rootDir));
if (rootDirs.size > 1) {
throw new Error([
`Blob reports being merged were recorded with different test directories, and`,
`merging cannot proceed. This may happen if you are merging reports from`,
`machines with different environments, like different operating systems or`,
`if the tests ran with different playwright configs.`,
``,
`You can force merge by specifying a merge config file with "-c" option. If`,
`you'd like all test paths to be correct, make sure 'testDir' in the merge config`,
`file points to the actual tests location.`,
``,
`Found directories:`,
...rootDirs
].join("\n"));
}
}
return {
method: "onConfigure",
params: {
config
}
};
}
function mergeConfigs(to, from) {
return {
...to,
...from,
metadata: {
...to.metadata,
...from.metadata,
actualWorkers: (to.metadata.actualWorkers || 0) + (from.metadata.actualWorkers || 0)
},
workers: to.workers + from.workers
};
}
function mergeEndEvents(endEvents) {
let startTime = endEvents.length ? 1e13 : Date.now();
let status = "passed";
let duration = 0;
for (const event of endEvents) {
const shardResult = event.params.result;
if (shardResult.status === "failed")
status = "failed";
else if (shardResult.status === "timedout" && status !== "failed")
status = "timedout";
else if (shardResult.status === "interrupted" && status !== "failed" && status !== "timedout")
status = "interrupted";
startTime = Math.min(startTime, shardResult.startTime);
duration = Math.max(duration, shardResult.duration);
}
const result = {
status,
startTime,
duration
};
return {
method: "onEnd",
params: {
result
}
};
}
async function sortedShardFiles(dir) {
const files = await import_fs.default.promises.readdir(dir);
return files.filter((file) => file.endsWith(".zip")).sort();
}
function printStatusToStdout(message) {
process.stdout.write(`${message}
`);
}
class UniqueFileNameGenerator {
constructor() {
this._usedNames = /* @__PURE__ */ new Set();
}
makeUnique(name) {
if (!this._usedNames.has(name)) {
this._usedNames.add(name);
return name;
}
const extension = import_path.default.extname(name);
name = name.substring(0, name.length - extension.length);
let index = 0;
while (true) {
const candidate = `${name}-${++index}${extension}`;
if (!this._usedNames.has(candidate)) {
this._usedNames.add(candidate);
return candidate;
}
}
}
}
class IdsPatcher {
constructor(stringPool, botName, salt, globalTestIdSet) {
this._stringPool = stringPool;
this._botName = botName;
this._salt = salt;
this._testIdsMap = /* @__PURE__ */ new Map();
this._globalTestIdSet = globalTestIdSet;
}
patchEvent(event) {
const { method, params } = event;
switch (method) {
case "onProject":
this._onProject(params.project);
return;
case "onAttach":
case "onTestBegin":
case "onStepBegin":
case "onStepEnd":
case "onStdIO":
params.testId = params.testId ? this._mapTestId(params.testId) : void 0;
return;
case "onTestEnd":
params.test.testId = this._mapTestId(params.test.testId);
return;
}
}
_onProject(project) {
project.metadata ??= {};
project.suites.forEach((suite) => this._updateTestIds(suite));
}
_updateTestIds(suite) {
suite.entries.forEach((entry) => {
if ("testId" in entry)
this._updateTestId(entry);
else
this._updateTestIds(entry);
});
}
_updateTestId(test) {
test.testId = this._mapTestId(test.testId);
if (this._botName) {
test.tags = test.tags || [];
test.tags.unshift("@" + this._botName);
}
}
_mapTestId(testId) {
const t1 = this._stringPool.internString(testId);
if (this._testIdsMap.has(t1))
return this._testIdsMap.get(t1);
if (this._globalTestIdSet.has(t1)) {
const t2 = this._stringPool.internString(testId + this._salt);
this._globalTestIdSet.add(t2);
this._testIdsMap.set(t1, t2);
return t2;
}
this._globalTestIdSet.add(t1);
this._testIdsMap.set(t1, t1);
return t1;
}
}
class AttachmentPathPatcher {
constructor(_resourceDir) {
this._resourceDir = _resourceDir;
}
patchEvent(event) {
if (event.method === "onAttach")
this._patchAttachments(event.params.attachments);
else if (event.method === "onTestEnd")
this._patchAttachments(event.params.result.attachments ?? []);
}
_patchAttachments(attachments) {
for (const attachment of attachments) {
if (!attachment.path)
continue;
attachment.path = import_path.default.join(this._resourceDir, attachment.path);
}
}
}
class PathSeparatorPatcher {
constructor(from) {
this._from = from ?? (import_path.default.sep === "/" ? "\\" : "/");
this._to = import_path.default.sep;
}
patchEvent(jsonEvent) {
if (this._from === this._to)
return;
if (jsonEvent.method === "onProject") {
this._updateProject(jsonEvent.params.project);
return;
}
if (jsonEvent.method === "onTestEnd") {
const test = jsonEvent.params.test;
test.annotations?.forEach((annotation) => this._updateAnnotationLocation(annotation));
const testResult = jsonEvent.params.result;
testResult.annotations?.forEach((annotation) => this._updateAnnotationLocation(annotation));
testResult.errors.forEach((error) => this._updateErrorLocations(error));
(testResult.attachments ?? []).forEach((attachment) => {
if (attachment.path)
attachment.path = this._updatePath(attachment.path);
});
return;
}
if (jsonEvent.method === "onStepBegin") {
const step = jsonEvent.params.step;
this._updateLocation(step.location);
return;
}
if (jsonEvent.method === "onStepEnd") {
const step = jsonEvent.params.step;
this._updateErrorLocations(step.error);
step.annotations?.forEach((annotation) => this._updateAnnotationLocation(annotation));
return;
}
if (jsonEvent.method === "onAttach") {
const attach = jsonEvent.params;
attach.attachments.forEach((attachment) => {
if (attachment.path)
attachment.path = this._updatePath(attachment.path);
});
return;
}
}
_updateProject(project) {
project.outputDir = this._updatePath(project.outputDir);
project.testDir = this._updatePath(project.testDir);
project.snapshotDir = this._updatePath(project.snapshotDir);
project.suites.forEach((suite) => this._updateSuite(suite, true));
}
_updateSuite(suite, isFileSuite = false) {
this._updateLocation(suite.location);
if (isFileSuite)
suite.title = this._updatePath(suite.title);
for (const entry of suite.entries) {
if ("testId" in entry) {
this._updateLocation(entry.location);
entry.annotations?.forEach((annotation) => this._updateAnnotationLocation(annotation));
} else {
this._updateSuite(entry);
}
}
}
_updateErrorLocations(error) {
while (error) {
this._updateLocation(error.location);
error = error.cause;
}
}
_updateAnnotationLocation(annotation) {
this._updateLocation(annotation.location);
}
_updateLocation(location) {
if (location)
location.file = this._updatePath(location.file);
}
_updatePath(text) {
return text.split(this._from).join(this._to);
}
}
class GlobalErrorPatcher {
constructor(botName) {
this._prefix = `(${botName}) `;
}
patchEvent(event) {
if (event.method !== "onError")
return;
const error = event.params.error;
if (error.message !== void 0)
error.message = this._prefix + error.message;
if (error.stack !== void 0)
error.stack = this._prefix + error.stack;
}
}
class JsonEventPatchers {
constructor() {
this.patchers = [];
}
patchEvents(events) {
for (const event of events) {
for (const patcher of this.patchers)
patcher.patchEvent(event);
}
}
}
class BlobModernizer {
modernize(fromVersion, events) {
const result = [];
for (const event of events)
result.push(...this._modernize(fromVersion, event));
return result;
}
_modernize(fromVersion, event) {
let events = [event];
for (let version = fromVersion; version < import_blob.currentBlobReportVersion; ++version)
events = this[`_modernize_${version}_to_${version + 1}`].call(this, events);
return events;
}
_modernize_1_to_2(events) {
return events.map((event) => {
if (event.method === "onProject") {
const modernizeSuite = (suite) => {
const newSuites = suite.suites.map(modernizeSuite);
const { suites, tests, ...remainder } = suite;
return { entries: [...newSuites, ...tests], ...remainder };
};
const project = event.params.project;
project.suites = project.suites.map(modernizeSuite);
}
return event;
});
}
}
const modernizer = new BlobModernizer();
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createMergedReport
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var multiplexer_exports = {};
__export(multiplexer_exports, {
Multiplexer: () => Multiplexer
});
module.exports = __toCommonJS(multiplexer_exports);
class Multiplexer {
constructor(reporters) {
this._reporters = reporters;
}
version() {
return "v2";
}
onConfigure(config) {
for (const reporter of this._reporters)
wrap(() => reporter.onConfigure?.(config));
}
onBegin(suite) {
for (const reporter of this._reporters)
wrap(() => reporter.onBegin?.(suite));
}
onTestBegin(test, result) {
for (const reporter of this._reporters)
wrap(() => reporter.onTestBegin?.(test, result));
}
onStdOut(chunk, test, result) {
for (const reporter of this._reporters)
wrap(() => reporter.onStdOut?.(chunk, test, result));
}
onStdErr(chunk, test, result) {
for (const reporter of this._reporters)
wrap(() => reporter.onStdErr?.(chunk, test, result));
}
onTestEnd(test, result) {
for (const reporter of this._reporters)
wrap(() => reporter.onTestEnd?.(test, result));
}
async onEnd(result) {
for (const reporter of this._reporters) {
const outResult = await wrapAsync(() => reporter.onEnd?.(result));
if (outResult?.status)
result.status = outResult.status;
}
return result;
}
async onExit() {
for (const reporter of this._reporters)
await wrapAsync(() => reporter.onExit?.());
}
onError(error) {
for (const reporter of this._reporters)
wrap(() => reporter.onError?.(error));
}
onStepBegin(test, result, step) {
for (const reporter of this._reporters)
wrap(() => reporter.onStepBegin?.(test, result, step));
}
onStepEnd(test, result, step) {
for (const reporter of this._reporters)
wrap(() => reporter.onStepEnd?.(test, result, step));
}
printsToStdio() {
return this._reporters.some((r) => {
let prints = false;
wrap(() => prints = r.printsToStdio ? r.printsToStdio() : true);
return prints;
});
}
}
async function wrapAsync(callback) {
try {
return await callback();
} catch (e) {
console.error("Error in reporter", e);
}
}
function wrap(callback) {
try {
callback();
} catch (e) {
console.error("Error in reporter", e);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Multiplexer
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var reporterV2_exports = {};
__export(reporterV2_exports, {
wrapReporterAsV2: () => wrapReporterAsV2
});
module.exports = __toCommonJS(reporterV2_exports);
function wrapReporterAsV2(reporter) {
try {
if ("version" in reporter && reporter.version() === "v2")
return reporter;
} catch (e) {
}
return new ReporterV2Wrapper(reporter);
}
class ReporterV2Wrapper {
constructor(reporter) {
this._deferred = [];
this._reporter = reporter;
}
version() {
return "v2";
}
onConfigure(config) {
this._config = config;
}
onBegin(suite) {
this._reporter.onBegin?.(this._config, suite);
const deferred = this._deferred;
this._deferred = null;
for (const item of deferred) {
if (item.error)
this.onError(item.error);
if (item.stdout)
this.onStdOut(item.stdout.chunk, item.stdout.test, item.stdout.result);
if (item.stderr)
this.onStdErr(item.stderr.chunk, item.stderr.test, item.stderr.result);
}
}
onTestBegin(test, result) {
this._reporter.onTestBegin?.(test, result);
}
onStdOut(chunk, test, result) {
if (this._deferred) {
this._deferred.push({ stdout: { chunk, test, result } });
return;
}
this._reporter.onStdOut?.(chunk, test, result);
}
onStdErr(chunk, test, result) {
if (this._deferred) {
this._deferred.push({ stderr: { chunk, test, result } });
return;
}
this._reporter.onStdErr?.(chunk, test, result);
}
onTestEnd(test, result) {
this._reporter.onTestEnd?.(test, result);
}
async onEnd(result) {
return await this._reporter.onEnd?.(result);
}
async onExit() {
await this._reporter.onExit?.();
}
onError(error) {
if (this._deferred) {
this._deferred.push({ error });
return;
}
this._reporter.onError?.(error);
}
onStepBegin(test, result, step) {
this._reporter.onStepBegin?.(test, result, step);
}
onStepEnd(test, result, step) {
this._reporter.onStepEnd?.(test, result, step);
}
printsToStdio() {
return this._reporter.printsToStdio ? this._reporter.printsToStdio() : true;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
wrapReporterAsV2
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var teleEmitter_exports = {};
__export(teleEmitter_exports, {
TeleReporterEmitter: () => TeleReporterEmitter
});
module.exports = __toCommonJS(teleEmitter_exports);
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_teleReceiver = require("../isomorphic/teleReceiver");
class TeleReporterEmitter {
constructor(messageSink, options = {}) {
this._resultKnownAttachmentCounts = /* @__PURE__ */ new Map();
// In case there is blob reporter and UI mode, make sure one does override
// the id assigned by the other.
this._idSymbol = Symbol("id");
this._messageSink = messageSink;
this._emitterOptions = options;
}
version() {
return "v2";
}
onConfigure(config) {
this._rootDir = config.rootDir;
this._messageSink({ method: "onConfigure", params: { config: this._serializeConfig(config) } });
}
onBegin(suite) {
const projects = suite.suites.map((projectSuite) => this._serializeProject(projectSuite));
for (const project of projects)
this._messageSink({ method: "onProject", params: { project } });
this._messageSink({ method: "onBegin", params: void 0 });
}
onTestBegin(test, result) {
result[this._idSymbol] = (0, import_utils.createGuid)();
this._messageSink({
method: "onTestBegin",
params: {
testId: test.id,
result: this._serializeResultStart(result)
}
});
}
onTestEnd(test, result) {
const testEnd = {
testId: test.id,
expectedStatus: test.expectedStatus,
timeout: test.timeout,
annotations: []
};
this._sendNewAttachments(result, test.id);
this._messageSink({
method: "onTestEnd",
params: {
test: testEnd,
result: this._serializeResultEnd(result)
}
});
this._resultKnownAttachmentCounts.delete(result[this._idSymbol]);
}
onStepBegin(test, result, step) {
step[this._idSymbol] = (0, import_utils.createGuid)();
this._messageSink({
method: "onStepBegin",
params: {
testId: test.id,
resultId: result[this._idSymbol],
step: this._serializeStepStart(step)
}
});
}
onStepEnd(test, result, step) {
const resultId = result[this._idSymbol];
this._sendNewAttachments(result, test.id);
this._messageSink({
method: "onStepEnd",
params: {
testId: test.id,
resultId,
step: this._serializeStepEnd(step, result)
}
});
}
onError(error) {
this._messageSink({
method: "onError",
params: { error }
});
}
onStdOut(chunk, test, result) {
this._onStdIO("stdout", chunk, test, result);
}
onStdErr(chunk, test, result) {
this._onStdIO("stderr", chunk, test, result);
}
_onStdIO(type, chunk, test, result) {
if (this._emitterOptions.omitOutput)
return;
const isBase64 = typeof chunk !== "string";
const data = isBase64 ? chunk.toString("base64") : chunk;
this._messageSink({
method: "onStdIO",
params: { testId: test?.id, resultId: result ? result[this._idSymbol] : void 0, type, data, isBase64 }
});
}
async onEnd(result) {
const resultPayload = {
status: result.status,
startTime: result.startTime.getTime(),
duration: result.duration
};
this._messageSink({
method: "onEnd",
params: {
result: resultPayload
}
});
}
printsToStdio() {
return false;
}
_serializeConfig(config) {
return {
configFile: this._relativePath(config.configFile),
globalTimeout: config.globalTimeout,
maxFailures: config.maxFailures,
metadata: config.metadata,
rootDir: config.rootDir,
version: config.version,
workers: config.workers,
globalSetup: config.globalSetup,
globalTeardown: config.globalTeardown
};
}
_serializeProject(suite) {
const project = suite.project();
const report = {
metadata: project.metadata,
name: project.name,
outputDir: this._relativePath(project.outputDir),
repeatEach: project.repeatEach,
retries: project.retries,
testDir: this._relativePath(project.testDir),
testIgnore: (0, import_teleReceiver.serializeRegexPatterns)(project.testIgnore),
testMatch: (0, import_teleReceiver.serializeRegexPatterns)(project.testMatch),
timeout: project.timeout,
suites: suite.suites.map((fileSuite) => {
return this._serializeSuite(fileSuite);
}),
grep: (0, import_teleReceiver.serializeRegexPatterns)(project.grep),
grepInvert: (0, import_teleReceiver.serializeRegexPatterns)(project.grepInvert || []),
dependencies: project.dependencies,
snapshotDir: this._relativePath(project.snapshotDir),
teardown: project.teardown,
use: this._serializeProjectUseOptions(project.use)
};
return report;
}
_serializeProjectUseOptions(use) {
return {
testIdAttribute: use.testIdAttribute
};
}
_serializeSuite(suite) {
const result = {
title: suite.title,
location: this._relativeLocation(suite.location),
entries: suite.entries().map((e) => {
if (e.type === "test")
return this._serializeTest(e);
return this._serializeSuite(e);
})
};
return result;
}
_serializeTest(test) {
return {
testId: test.id,
title: test.title,
location: this._relativeLocation(test.location),
retries: test.retries,
tags: test.tags,
repeatEachIndex: test.repeatEachIndex,
annotations: this._relativeAnnotationLocations(test.annotations)
};
}
_serializeResultStart(result) {
return {
id: result[this._idSymbol],
retry: result.retry,
workerIndex: result.workerIndex,
parallelIndex: result.parallelIndex,
startTime: +result.startTime
};
}
_serializeResultEnd(result) {
return {
id: result[this._idSymbol],
duration: result.duration,
status: result.status,
errors: result.errors,
annotations: result.annotations?.length ? this._relativeAnnotationLocations(result.annotations) : void 0
};
}
_sendNewAttachments(result, testId) {
const resultId = result[this._idSymbol];
const knownAttachmentCount = this._resultKnownAttachmentCounts.get(resultId) ?? 0;
if (result.attachments.length > knownAttachmentCount) {
this._messageSink({
method: "onAttach",
params: {
testId,
resultId,
attachments: this._serializeAttachments(result.attachments.slice(knownAttachmentCount))
}
});
}
this._resultKnownAttachmentCounts.set(resultId, result.attachments.length);
}
_serializeAttachments(attachments) {
return attachments.map((a) => {
const { body, ...rest } = a;
return {
...rest,
// There is no Buffer in the browser, so there is no point in sending the data there.
base64: body && !this._emitterOptions.omitBuffers ? body.toString("base64") : void 0
};
});
}
_serializeStepStart(step) {
return {
id: step[this._idSymbol],
parentStepId: step.parent?.[this._idSymbol],
title: step.title,
category: step.category,
startTime: +step.startTime,
location: this._relativeLocation(step.location)
};
}
_serializeStepEnd(step, result) {
return {
id: step[this._idSymbol],
duration: step.duration,
error: step.error,
attachments: step.attachments.length ? step.attachments.map((a) => result.attachments.indexOf(a)) : void 0,
annotations: step.annotations.length ? this._relativeAnnotationLocations(step.annotations) : void 0
};
}
_relativeAnnotationLocations(annotations) {
return annotations.map((annotation) => ({
...annotation,
location: annotation.location ? this._relativeLocation(annotation.location) : void 0
}));
}
_relativeLocation(location) {
if (!location)
return location;
return {
...location,
file: this._relativePath(location.file)
};
}
_relativePath(absolutePath) {
if (!absolutePath)
return absolutePath;
return import_path.default.relative(this._rootDir, absolutePath);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TeleReporterEmitter
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var blobV1_exports = {};
module.exports = __toCommonJS(blobV1_exports);
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var dispatcher_exports = {};
__export(dispatcher_exports, {
Dispatcher: () => Dispatcher
});
module.exports = __toCommonJS(dispatcher_exports);
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_rebase = require("./rebase");
var import_workerHost = require("./workerHost");
var import_ipc = require("../common/ipc");
class Dispatcher {
constructor(config, reporter, failureTracker) {
this._workerSlots = [];
this._queue = [];
this._workerLimitPerProjectId = /* @__PURE__ */ new Map();
this._queuedOrRunningHashCount = /* @__PURE__ */ new Map();
this._finished = new import_utils.ManualPromise();
this._isStopped = true;
this._extraEnvByProjectId = /* @__PURE__ */ new Map();
this._producedEnvByProjectId = /* @__PURE__ */ new Map();
this._config = config;
this._reporter = reporter;
this._failureTracker = failureTracker;
for (const project of config.projects) {
if (project.workers)
this._workerLimitPerProjectId.set(project.id, project.workers);
}
}
_findFirstJobToRun() {
for (let index = 0; index < this._queue.length; index++) {
const job = this._queue[index];
const projectIdWorkerLimit = this._workerLimitPerProjectId.get(job.projectId);
if (!projectIdWorkerLimit)
return index;
const runningWorkersWithSameProjectId = this._workerSlots.filter((w) => w.busy && w.worker && w.worker.projectId() === job.projectId).length;
if (runningWorkersWithSameProjectId < projectIdWorkerLimit)
return index;
}
return -1;
}
_scheduleJob() {
if (this._isStopped)
return;
const jobIndex = this._findFirstJobToRun();
if (jobIndex === -1)
return;
const job = this._queue[jobIndex];
let workerIndex = this._workerSlots.findIndex((w) => !w.busy && w.worker && w.worker.hash() === job.workerHash && !w.worker.didSendStop());
if (workerIndex === -1)
workerIndex = this._workerSlots.findIndex((w) => !w.busy);
if (workerIndex === -1) {
return;
}
this._queue.splice(jobIndex, 1);
const jobDispatcher = new JobDispatcher(job, this._reporter, this._failureTracker, () => this.stop().catch(() => {
}));
this._workerSlots[workerIndex].busy = true;
this._workerSlots[workerIndex].jobDispatcher = jobDispatcher;
void this._runJobInWorker(workerIndex, jobDispatcher).then(() => {
this._workerSlots[workerIndex].jobDispatcher = void 0;
this._workerSlots[workerIndex].busy = false;
this._checkFinished();
this._scheduleJob();
});
}
async _runJobInWorker(index, jobDispatcher) {
const job = jobDispatcher.job;
if (jobDispatcher.skipWholeJob())
return;
let worker = this._workerSlots[index].worker;
if (worker && (worker.hash() !== job.workerHash || worker.didSendStop())) {
await worker.stop();
worker = void 0;
if (this._isStopped)
return;
}
let startError;
if (!worker) {
worker = this._createWorker(job, index, (0, import_ipc.serializeConfig)(this._config, true));
this._workerSlots[index].worker = worker;
worker.on("exit", () => this._workerSlots[index].worker = void 0);
startError = await worker.start();
if (this._isStopped)
return;
}
if (startError)
jobDispatcher.onExit(startError);
else
jobDispatcher.runInWorker(worker);
const result = await jobDispatcher.jobResult;
this._updateCounterForWorkerHash(job.workerHash, -1);
if (result.didFail)
void worker.stop(
true
/* didFail */
);
else if (this._isWorkerRedundant(worker))
void worker.stop();
if (!this._isStopped && result.newJob) {
this._queue.unshift(result.newJob);
this._updateCounterForWorkerHash(result.newJob.workerHash, 1);
}
}
_checkFinished() {
if (this._finished.isDone())
return;
if (this._queue.length && !this._isStopped)
return;
if (this._workerSlots.some((w) => w.busy))
return;
this._finished.resolve();
}
_isWorkerRedundant(worker) {
let workersWithSameHash = 0;
for (const slot of this._workerSlots) {
if (slot.worker && !slot.worker.didSendStop() && slot.worker.hash() === worker.hash())
workersWithSameHash++;
}
return workersWithSameHash > this._queuedOrRunningHashCount.get(worker.hash());
}
_updateCounterForWorkerHash(hash, delta) {
this._queuedOrRunningHashCount.set(hash, delta + (this._queuedOrRunningHashCount.get(hash) || 0));
}
async run(testGroups, extraEnvByProjectId) {
this._extraEnvByProjectId = extraEnvByProjectId;
this._queue = testGroups;
for (const group of testGroups)
this._updateCounterForWorkerHash(group.workerHash, 1);
this._isStopped = false;
this._workerSlots = [];
if (this._failureTracker.hasReachedMaxFailures())
void this.stop();
for (let i = 0; i < this._config.config.workers; i++)
this._workerSlots.push({ busy: false });
for (let i = 0; i < this._workerSlots.length; i++)
this._scheduleJob();
this._checkFinished();
await this._finished;
}
_createWorker(testGroup, parallelIndex, loaderData) {
const projectConfig = this._config.projects.find((p) => p.id === testGroup.projectId);
const outputDir = projectConfig.project.outputDir;
const worker = new import_workerHost.WorkerHost(testGroup, {
parallelIndex,
config: loaderData,
extraEnv: this._extraEnvByProjectId.get(testGroup.projectId) || {},
outputDir,
pauseOnError: this._failureTracker.pauseOnError(),
pauseAtEnd: this._failureTracker.pauseAtEnd(projectConfig)
});
const handleOutput = (params) => {
const chunk = chunkFromParams(params);
if (worker.didFail()) {
return { chunk };
}
const currentlyRunning = this._workerSlots[parallelIndex].jobDispatcher?.currentlyRunning();
if (!currentlyRunning)
return { chunk };
return { chunk, test: currentlyRunning.test, result: currentlyRunning.result };
};
worker.on("stdOut", (params) => {
const { chunk, test, result } = handleOutput(params);
result?.stdout.push(chunk);
this._reporter.onStdOut?.(chunk, test, result);
});
worker.on("stdErr", (params) => {
const { chunk, test, result } = handleOutput(params);
result?.stderr.push(chunk);
this._reporter.onStdErr?.(chunk, test, result);
});
worker.on("teardownErrors", (params) => {
this._failureTracker.onWorkerError();
for (const error of params.fatalErrors)
this._reporter.onError?.(error);
});
worker.on("exit", () => {
const producedEnv = this._producedEnvByProjectId.get(testGroup.projectId) || {};
this._producedEnvByProjectId.set(testGroup.projectId, { ...producedEnv, ...worker.producedEnv() });
});
return worker;
}
producedEnvByProjectId() {
return this._producedEnvByProjectId;
}
async stop() {
if (this._isStopped)
return;
this._isStopped = true;
await Promise.all(this._workerSlots.map(({ worker }) => worker?.stop()));
this._checkFinished();
}
}
class JobDispatcher {
constructor(job, reporter, failureTracker, stopCallback) {
this.jobResult = new import_utils.ManualPromise();
this._listeners = [];
this._failedTests = /* @__PURE__ */ new Set();
this._failedWithNonRetriableError = /* @__PURE__ */ new Set();
this._remainingByTestId = /* @__PURE__ */ new Map();
this._dataByTestId = /* @__PURE__ */ new Map();
this._parallelIndex = 0;
this._workerIndex = 0;
this.job = job;
this._reporter = reporter;
this._failureTracker = failureTracker;
this._stopCallback = stopCallback;
this._remainingByTestId = new Map(this.job.tests.map((e) => [e.id, e]));
}
_onTestBegin(params) {
const test = this._remainingByTestId.get(params.testId);
if (!test) {
return;
}
const result = test._appendTestResult();
this._dataByTestId.set(test.id, { test, result, steps: /* @__PURE__ */ new Map() });
result.parallelIndex = this._parallelIndex;
result.workerIndex = this._workerIndex;
result.startTime = new Date(params.startWallTime);
this._reporter.onTestBegin?.(test, result);
this._currentlyRunning = { test, result };
}
_onTestEnd(params) {
if (this._failureTracker.hasReachedMaxFailures()) {
params.status = "interrupted";
params.errors = [];
}
const data = this._dataByTestId.get(params.testId);
if (!data) {
return;
}
this._dataByTestId.delete(params.testId);
this._remainingByTestId.delete(params.testId);
const { result, test } = data;
result.duration = params.duration;
result.errors = params.errors;
result.error = result.errors[0];
result.status = params.status;
result.annotations = params.annotations;
test.annotations = [...params.annotations];
test.expectedStatus = params.expectedStatus;
test.timeout = params.timeout;
const isFailure = result.status !== "skipped" && result.status !== test.expectedStatus;
if (isFailure)
this._failedTests.add(test);
if (params.hasNonRetriableError)
this._addNonretriableTestAndSerialModeParents(test);
this._reportTestEnd(test, result);
this._currentlyRunning = void 0;
}
_addNonretriableTestAndSerialModeParents(test) {
this._failedWithNonRetriableError.add(test);
for (let parent = test.parent; parent; parent = parent.parent) {
if (parent._parallelMode === "serial")
this._failedWithNonRetriableError.add(parent);
}
}
_onStepBegin(params) {
const data = this._dataByTestId.get(params.testId);
if (!data) {
return;
}
const { result, steps, test } = data;
const parentStep = params.parentStepId ? steps.get(params.parentStepId) : void 0;
const step = {
title: params.title,
titlePath: () => {
const parentPath = parentStep?.titlePath() || [];
return [...parentPath, params.title];
},
parent: parentStep,
category: params.category,
startTime: new Date(params.wallTime),
duration: -1,
steps: [],
attachments: [],
annotations: [],
location: params.location
};
steps.set(params.stepId, step);
(parentStep || result).steps.push(step);
this._reporter.onStepBegin?.(test, result, step);
}
_onStepEnd(params) {
const data = this._dataByTestId.get(params.testId);
if (!data) {
return;
}
const { result, steps, test } = data;
const step = steps.get(params.stepId);
if (!step) {
this._reporter.onStdErr?.("Internal error: step end without step begin: " + params.stepId, test, result);
return;
}
step.duration = params.wallTime - step.startTime.getTime();
if (params.error)
step.error = params.error;
if (params.suggestedRebaseline)
(0, import_rebase.addSuggestedRebaseline)(step.location, params.suggestedRebaseline);
step.annotations = params.annotations;
steps.delete(params.stepId);
this._reporter.onStepEnd?.(test, result, step);
}
_onAttach(params) {
const data = this._dataByTestId.get(params.testId);
if (!data) {
return;
}
const attachment = {
name: params.name,
path: params.path,
contentType: params.contentType,
body: params.body !== void 0 ? Buffer.from(params.body, "base64") : void 0
};
data.result.attachments.push(attachment);
if (params.stepId) {
const step = data.steps.get(params.stepId);
if (step)
step.attachments.push(attachment);
else
this._reporter.onStdErr?.("Internal error: step id not found: " + params.stepId);
}
}
_failTestWithErrors(test, errors) {
const runData = this._dataByTestId.get(test.id);
let result;
if (runData) {
result = runData.result;
} else {
result = test._appendTestResult();
this._reporter.onTestBegin?.(test, result);
}
result.errors = [...errors];
result.error = result.errors[0];
result.status = errors.length ? "failed" : "skipped";
this._reportTestEnd(test, result);
this._failedTests.add(test);
}
_massSkipTestsFromRemaining(testIds, errors) {
for (const test of this._remainingByTestId.values()) {
if (!testIds.has(test.id))
continue;
if (!this._failureTracker.hasReachedMaxFailures()) {
this._failTestWithErrors(test, errors);
errors = [];
}
this._remainingByTestId.delete(test.id);
}
if (errors.length) {
this._failureTracker.onWorkerError();
for (const error of errors)
this._reporter.onError?.(error);
}
}
_onDone(params) {
if (!this._remainingByTestId.size && !this._failedTests.size && !params.fatalErrors.length && !params.skipTestsDueToSetupFailure.length && !params.fatalUnknownTestIds && !params.unexpectedExitError && !params.stoppedDueToUnhandledErrorInTestFail) {
this._finished({ didFail: false });
return;
}
for (const testId of params.fatalUnknownTestIds || []) {
const test = this._remainingByTestId.get(testId);
if (test) {
this._remainingByTestId.delete(testId);
this._failTestWithErrors(test, [{ message: `Test not found in the worker process. Make sure test title does not change.` }]);
}
}
if (params.fatalErrors.length) {
this._massSkipTestsFromRemaining(new Set(this._remainingByTestId.keys()), params.fatalErrors);
}
this._massSkipTestsFromRemaining(new Set(params.skipTestsDueToSetupFailure), []);
if (params.unexpectedExitError) {
if (this._currentlyRunning)
this._massSkipTestsFromRemaining(/* @__PURE__ */ new Set([this._currentlyRunning.test.id]), [params.unexpectedExitError]);
else
this._massSkipTestsFromRemaining(new Set(this._remainingByTestId.keys()), [params.unexpectedExitError]);
}
const retryCandidates = /* @__PURE__ */ new Set();
const serialSuitesWithFailures = /* @__PURE__ */ new Set();
for (const failedTest of this._failedTests) {
if (this._failedWithNonRetriableError.has(failedTest))
continue;
retryCandidates.add(failedTest);
let outermostSerialSuite;
for (let parent = failedTest.parent; parent; parent = parent.parent) {
if (parent._parallelMode === "serial")
outermostSerialSuite = parent;
}
if (outermostSerialSuite && !this._failedWithNonRetriableError.has(outermostSerialSuite))
serialSuitesWithFailures.add(outermostSerialSuite);
}
const testsBelongingToSomeSerialSuiteWithFailures = [...this._remainingByTestId.values()].filter((test) => {
let parent = test.parent;
while (parent && !serialSuitesWithFailures.has(parent))
parent = parent.parent;
return !!parent;
});
this._massSkipTestsFromRemaining(new Set(testsBelongingToSomeSerialSuiteWithFailures.map((test) => test.id)), []);
for (const serialSuite of serialSuitesWithFailures) {
serialSuite.allTests().forEach((test) => retryCandidates.add(test));
}
const remaining = [...this._remainingByTestId.values()];
for (const test of retryCandidates) {
if (test.results.length < test.retries + 1)
remaining.push(test);
}
const newJob = remaining.length ? { ...this.job, tests: remaining } : void 0;
this._finished({ didFail: true, newJob });
}
onExit(data) {
const unexpectedExitError = data.unexpectedly ? {
message: `Error: worker process exited unexpectedly (code=${data.code}, signal=${data.signal})`
} : void 0;
this._onDone({ skipTestsDueToSetupFailure: [], fatalErrors: [], unexpectedExitError });
}
_finished(result) {
import_utils.eventsHelper.removeEventListeners(this._listeners);
this.jobResult.resolve(result);
}
runInWorker(worker) {
this._parallelIndex = worker.parallelIndex;
this._workerIndex = worker.workerIndex;
const runPayload = {
file: this.job.requireFile,
entries: this.job.tests.map((test) => {
return { testId: test.id, retry: test.results.length };
})
};
worker.runTestGroup(runPayload);
this._listeners = [
import_utils.eventsHelper.addEventListener(worker, "testBegin", this._onTestBegin.bind(this)),
import_utils.eventsHelper.addEventListener(worker, "testEnd", this._onTestEnd.bind(this)),
import_utils.eventsHelper.addEventListener(worker, "stepBegin", this._onStepBegin.bind(this)),
import_utils.eventsHelper.addEventListener(worker, "stepEnd", this._onStepEnd.bind(this)),
import_utils.eventsHelper.addEventListener(worker, "attach", this._onAttach.bind(this)),
import_utils.eventsHelper.addEventListener(worker, "done", this._onDone.bind(this)),
import_utils.eventsHelper.addEventListener(worker, "exit", this.onExit.bind(this))
];
}
skipWholeJob() {
const allTestsSkipped = this.job.tests.every((test) => test.expectedStatus === "skipped");
if (allTestsSkipped && !this._failureTracker.hasReachedMaxFailures()) {
for (const test of this.job.tests) {
const result = test._appendTestResult();
this._reporter.onTestBegin?.(test, result);
result.status = "skipped";
this._reportTestEnd(test, result);
}
return true;
}
return false;
}
currentlyRunning() {
return this._currentlyRunning;
}
_reportTestEnd(test, result) {
this._reporter.onTestEnd?.(test, result);
const hadMaxFailures = this._failureTracker.hasReachedMaxFailures();
this._failureTracker.onTestEnd(test, result);
if (this._failureTracker.hasReachedMaxFailures()) {
this._stopCallback();
if (!hadMaxFailures)
this._reporter.onError?.({ message: import_utils2.colors.red(`Testing stopped early after ${this._failureTracker.maxFailures()} maximum allowed failures.`) });
}
}
}
function chunkFromParams(params) {
if (typeof params.text === "string")
return params.text;
return Buffer.from(params.buffer, "base64");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Dispatcher
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var failureTracker_exports = {};
__export(failureTracker_exports, {
FailureTracker: () => FailureTracker
});
module.exports = __toCommonJS(failureTracker_exports);
class FailureTracker {
constructor(_config, options) {
this._config = _config;
this._failureCount = 0;
this._hasWorkerErrors = false;
this._topLevelProjects = [];
this._pauseOnError = options?.pauseOnError ?? false;
this._pauseAtEnd = options?.pauseAtEnd ?? false;
}
onRootSuite(rootSuite, topLevelProjects) {
this._rootSuite = rootSuite;
this._topLevelProjects = topLevelProjects;
}
onTestEnd(test, result) {
if (test.outcome() === "unexpected" && test.results.length > test.retries)
++this._failureCount;
}
onWorkerError() {
this._hasWorkerErrors = true;
}
pauseOnError() {
return this._pauseOnError;
}
pauseAtEnd(inProject) {
return this._pauseAtEnd && this._topLevelProjects.includes(inProject);
}
hasReachedMaxFailures() {
return this.maxFailures() > 0 && this._failureCount >= this.maxFailures();
}
hasWorkerErrors() {
return this._hasWorkerErrors;
}
result() {
return this._hasWorkerErrors || this.hasReachedMaxFailures() || this.hasFailedTests() || this._config.failOnFlakyTests && this.hasFlakyTests() ? "failed" : "passed";
}
hasFailedTests() {
return this._rootSuite?.allTests().some((test) => !test.ok());
}
hasFlakyTests() {
return this._rootSuite?.allTests().some((test) => test.outcome() === "flaky");
}
maxFailures() {
return this._config.config.maxFailures;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
FailureTracker
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var lastRun_exports = {};
__export(lastRun_exports, {
LastRunReporter: () => LastRunReporter
});
module.exports = __toCommonJS(lastRun_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_projectUtils = require("./projectUtils");
class LastRunReporter {
constructor(config) {
this._config = config;
const [project] = (0, import_projectUtils.filterProjects)(config.projects, config.cliProjectFilter);
if (project)
this._lastRunFile = import_path.default.join(project.project.outputDir, ".last-run.json");
}
async filterLastFailed() {
if (!this._lastRunFile)
return;
try {
const lastRunInfo = JSON.parse(await import_fs.default.promises.readFile(this._lastRunFile, "utf8"));
const failedTestIds = new Set(lastRunInfo.failedTests);
this._config.postShardTestFilters.push((test) => failedTestIds.has(test.id));
} catch {
}
}
version() {
return "v2";
}
printsToStdio() {
return false;
}
onBegin(suite) {
this._suite = suite;
}
async onEnd(result) {
if (!this._lastRunFile || this._config.cliListOnly)
return;
const lastRunInfo = {
status: result.status,
failedTests: this._suite?.allTests().filter((t) => !t.ok()).map((t) => t.id) || []
};
await import_fs.default.promises.mkdir(import_path.default.dirname(this._lastRunFile), { recursive: true });
await import_fs.default.promises.writeFile(this._lastRunFile, JSON.stringify(lastRunInfo, void 0, 2));
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
LastRunReporter
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var loaderHost_exports = {};
__export(loaderHost_exports, {
InProcessLoaderHost: () => InProcessLoaderHost,
OutOfProcessLoaderHost: () => OutOfProcessLoaderHost
});
module.exports = __toCommonJS(loaderHost_exports);
var import_processHost = require("./processHost");
var import_esmLoaderHost = require("../common/esmLoaderHost");
var import_ipc = require("../common/ipc");
var import_poolBuilder = require("../common/poolBuilder");
var import_test = require("../common/test");
var import_testLoader = require("../common/testLoader");
var import_compilationCache = require("../transform/compilationCache");
class InProcessLoaderHost {
constructor(config) {
this._config = config;
this._poolBuilder = import_poolBuilder.PoolBuilder.createForLoader();
}
async start(errors) {
return true;
}
async loadTestFile(file, testErrors) {
const result = await (0, import_testLoader.loadTestFile)(file, this._config.config.rootDir, testErrors);
this._poolBuilder.buildPools(result, testErrors);
return result;
}
async stop() {
await (0, import_esmLoaderHost.incorporateCompilationCache)();
}
}
class OutOfProcessLoaderHost {
constructor(config) {
this._config = config;
this._processHost = new import_processHost.ProcessHost(require.resolve("../loader/loaderMain.js"), "loader", {});
}
async start(errors) {
const startError = await this._processHost.startRunner((0, import_ipc.serializeConfig)(this._config, false));
if (startError) {
errors.push({
message: `Test loader process failed to start with code "${startError.code}" and signal "${startError.signal}"`
});
return false;
}
return true;
}
async loadTestFile(file, testErrors) {
const result = await this._processHost.sendMessage({ method: "loadTestFile", params: { file } });
testErrors.push(...result.testErrors);
return import_test.Suite._deepParse(result.fileSuite);
}
async stop() {
const result = await this._processHost.sendMessage({ method: "getCompilationCacheFromLoader" });
(0, import_compilationCache.addToCompilationCache)(result);
await this._processHost.stop();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
InProcessLoaderHost,
OutOfProcessLoaderHost
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var loadUtils_exports = {};
__export(loadUtils_exports, {
collectProjectsAndTestFiles: () => collectProjectsAndTestFiles,
createRootSuite: () => createRootSuite,
loadFileSuites: () => loadFileSuites,
loadGlobalHook: () => loadGlobalHook,
loadReporter: () => loadReporter,
loadTestList: () => loadTestList
});
module.exports = __toCommonJS(loadUtils_exports);
var import_path = __toESM(require("path"));
var import_fs = __toESM(require("fs"));
var import_utils = require("playwright-core/lib/utils");
var import_loaderHost = require("./loaderHost");
var import_util = require("../util");
var import_projectUtils = require("./projectUtils");
var import_testGroups = require("./testGroups");
var import_suiteUtils = require("../common/suiteUtils");
var import_test = require("../common/test");
var import_compilationCache = require("../transform/compilationCache");
var import_transform = require("../transform/transform");
var import_utilsBundle = require("../utilsBundle");
async function collectProjectsAndTestFiles(testRun, doNotRunTestsOutsideProjectFilter) {
const config = testRun.config;
const fsCache = /* @__PURE__ */ new Map();
const sourceMapCache = /* @__PURE__ */ new Map();
const cliFileMatcher = config.cliArgs.length ? (0, import_util.createFileMatcherFromArguments)(config.cliArgs) : null;
const allFilesForProject = /* @__PURE__ */ new Map();
const filteredProjects = (0, import_projectUtils.filterProjects)(config.projects, config.cliProjectFilter);
for (const project of filteredProjects) {
const files = await (0, import_projectUtils.collectFilesForProject)(project, fsCache);
allFilesForProject.set(project, files);
}
const filesToRunByProject = /* @__PURE__ */ new Map();
for (const [project, files] of allFilesForProject) {
const matchedFiles = files.filter((file) => {
const hasMatchingSources = sourceMapSources(file, sourceMapCache).some((source) => {
if (cliFileMatcher && !cliFileMatcher(source))
return false;
return true;
});
return hasMatchingSources;
});
const filteredFiles = matchedFiles.filter(Boolean);
filesToRunByProject.set(project, filteredFiles);
}
const projectClosure = (0, import_projectUtils.buildProjectsClosure)([...filesToRunByProject.keys()]);
for (const [project, type] of projectClosure) {
if (type === "dependency") {
const treatProjectAsEmpty = doNotRunTestsOutsideProjectFilter && !filteredProjects.includes(project);
const files = treatProjectAsEmpty ? [] : allFilesForProject.get(project) || await (0, import_projectUtils.collectFilesForProject)(project, fsCache);
filesToRunByProject.set(project, files);
}
}
testRun.projectFiles = filesToRunByProject;
testRun.projectSuites = /* @__PURE__ */ new Map();
}
async function loadFileSuites(testRun, mode, errors) {
const config = testRun.config;
const allTestFiles = /* @__PURE__ */ new Set();
for (const files of testRun.projectFiles.values())
files.forEach((file) => allTestFiles.add(file));
const fileSuiteByFile = /* @__PURE__ */ new Map();
const loaderHost = mode === "out-of-process" ? new import_loaderHost.OutOfProcessLoaderHost(config) : new import_loaderHost.InProcessLoaderHost(config);
if (await loaderHost.start(errors)) {
for (const file of allTestFiles) {
const fileSuite = await loaderHost.loadTestFile(file, errors);
fileSuiteByFile.set(file, fileSuite);
errors.push(...createDuplicateTitlesErrors(config, fileSuite));
}
await loaderHost.stop();
}
for (const file of allTestFiles) {
for (const dependency of (0, import_compilationCache.dependenciesForTestFile)(file)) {
if (allTestFiles.has(dependency)) {
const importer = import_path.default.relative(config.config.rootDir, file);
const importee = import_path.default.relative(config.config.rootDir, dependency);
errors.push({
message: `Error: test file "${importer}" should not import test file "${importee}"`,
location: { file, line: 1, column: 1 }
});
}
}
}
for (const [project, files] of testRun.projectFiles) {
const suites = files.map((file) => fileSuiteByFile.get(file)).filter(Boolean);
testRun.projectSuites.set(project, suites);
}
}
async function createRootSuite(testRun, errors, shouldFilterOnly) {
const config = testRun.config;
const rootSuite = new import_test.Suite("", "root");
const projectSuites = /* @__PURE__ */ new Map();
const filteredProjectSuites = /* @__PURE__ */ new Map();
{
const cliFileFilters = (0, import_util.createFileFiltersFromArguments)(config.cliArgs);
const grepMatcher = config.cliGrep ? (0, import_util.createTitleMatcher)((0, import_util.forceRegExp)(config.cliGrep)) : () => true;
const grepInvertMatcher = config.cliGrepInvert ? (0, import_util.createTitleMatcher)((0, import_util.forceRegExp)(config.cliGrepInvert)) : () => false;
const cliTitleMatcher = (title) => !grepInvertMatcher(title) && grepMatcher(title);
for (const [project, fileSuites] of testRun.projectSuites) {
const projectSuite = createProjectSuite(project, fileSuites);
projectSuites.set(project, projectSuite);
const filteredProjectSuite = filterProjectSuite(projectSuite, { cliFileFilters, cliTitleMatcher, testFilters: config.preOnlyTestFilters });
filteredProjectSuites.set(project, filteredProjectSuite);
}
}
if (shouldFilterOnly) {
const filteredRoot = new import_test.Suite("", "root");
for (const filteredProjectSuite of filteredProjectSuites.values())
filteredRoot._addSuite(filteredProjectSuite);
(0, import_suiteUtils.filterOnly)(filteredRoot);
for (const [project, filteredProjectSuite] of filteredProjectSuites) {
if (!filteredRoot.suites.includes(filteredProjectSuite))
filteredProjectSuites.delete(project);
}
}
const projectClosure = (0, import_projectUtils.buildProjectsClosure)([...filteredProjectSuites.keys()], (project) => filteredProjectSuites.get(project)._hasTests());
for (const [project, type] of projectClosure) {
if (type === "top-level") {
project.project.repeatEach = project.fullConfig.configCLIOverrides.repeatEach ?? project.project.repeatEach;
rootSuite._addSuite(buildProjectSuite(project, filteredProjectSuites.get(project)));
}
}
if (config.config.forbidOnly) {
const onlyTestsAndSuites = rootSuite._getOnlyItems();
if (onlyTestsAndSuites.length > 0) {
const configFilePath = config.config.configFile ? import_path.default.relative(config.config.rootDir, config.config.configFile) : void 0;
errors.push(...createForbidOnlyErrors(onlyTestsAndSuites, config.configCLIOverrides.forbidOnly, configFilePath));
}
}
if (config.config.shard) {
const testGroups = [];
for (const projectSuite of rootSuite.suites) {
testGroups.push(...(0, import_testGroups.createTestGroups)(projectSuite, config.config.shard.total));
}
const testGroupsInThisShard = (0, import_testGroups.filterForShard)(config.config.shard, testGroups);
const testsInThisShard = /* @__PURE__ */ new Set();
for (const group of testGroupsInThisShard) {
for (const test of group.tests)
testsInThisShard.add(test);
}
(0, import_suiteUtils.filterTestsRemoveEmptySuites)(rootSuite, (test) => testsInThisShard.has(test));
}
if (config.postShardTestFilters.length)
(0, import_suiteUtils.filterTestsRemoveEmptySuites)(rootSuite, (test) => config.postShardTestFilters.every((filter) => filter(test)));
const topLevelProjects = [];
{
const projectClosure2 = new Map((0, import_projectUtils.buildProjectsClosure)(rootSuite.suites.map((suite) => suite._fullProject)));
for (const [project, level] of projectClosure2.entries()) {
if (level === "dependency")
rootSuite._prependSuite(buildProjectSuite(project, projectSuites.get(project)));
else
topLevelProjects.push(project);
}
}
return { rootSuite, topLevelProjects };
}
function createProjectSuite(project, fileSuites) {
const projectSuite = new import_test.Suite(project.project.name, "project");
for (const fileSuite of fileSuites)
projectSuite._addSuite((0, import_suiteUtils.bindFileSuiteToProject)(project, fileSuite));
const grepMatcher = (0, import_util.createTitleMatcher)(project.project.grep);
const grepInvertMatcher = project.project.grepInvert ? (0, import_util.createTitleMatcher)(project.project.grepInvert) : null;
(0, import_suiteUtils.filterTestsRemoveEmptySuites)(projectSuite, (test) => {
const grepTitle = test._grepTitleWithTags();
if (grepInvertMatcher?.(grepTitle))
return false;
return grepMatcher(grepTitle);
});
return projectSuite;
}
function filterProjectSuite(projectSuite, options) {
if (!options.cliFileFilters.length && !options.cliTitleMatcher && !options.testFilters.length)
return projectSuite;
const result = projectSuite._deepClone();
if (options.cliFileFilters.length)
(0, import_suiteUtils.filterByFocusedLine)(result, options.cliFileFilters);
(0, import_suiteUtils.filterTestsRemoveEmptySuites)(result, (test) => {
if (!options.testFilters.every((filter) => filter(test)))
return false;
if (options.cliTitleMatcher && !options.cliTitleMatcher(test._grepTitleWithTags()))
return false;
return true;
});
return result;
}
function buildProjectSuite(project, projectSuite) {
const result = new import_test.Suite(project.project.name, "project");
result._fullProject = project;
if (project.fullyParallel)
result._parallelMode = "parallel";
for (const fileSuite of projectSuite.suites) {
result._addSuite(fileSuite);
for (let repeatEachIndex = 1; repeatEachIndex < project.project.repeatEach; repeatEachIndex++) {
const clone = fileSuite._deepClone();
(0, import_suiteUtils.applyRepeatEachIndex)(project, clone, repeatEachIndex);
result._addSuite(clone);
}
}
return result;
}
function createForbidOnlyErrors(onlyTestsAndSuites, forbidOnlyCLIFlag, configFilePath) {
const errors = [];
for (const testOrSuite of onlyTestsAndSuites) {
const title = testOrSuite.titlePath().slice(2).join(" ");
const configFilePathName = configFilePath ? `'${configFilePath}'` : "the Playwright configuration file";
const forbidOnlySource = forbidOnlyCLIFlag ? `'--forbid-only' CLI flag` : `'forbidOnly' option in ${configFilePathName}`;
const error = {
message: `Error: item focused with '.only' is not allowed due to the ${forbidOnlySource}: "${title}"`,
location: testOrSuite.location
};
errors.push(error);
}
return errors;
}
function createDuplicateTitlesErrors(config, fileSuite) {
const errors = [];
const testsByFullTitle = /* @__PURE__ */ new Map();
for (const test of fileSuite.allTests()) {
const fullTitle = test.titlePath().slice(1).join(" \u203A ");
const existingTest = testsByFullTitle.get(fullTitle);
if (existingTest) {
const error = {
message: `Error: duplicate test title "${fullTitle}", first declared in ${buildItemLocation(config.config.rootDir, existingTest)}`,
location: test.location
};
errors.push(error);
}
testsByFullTitle.set(fullTitle, test);
}
return errors;
}
function buildItemLocation(rootDir, testOrSuite) {
if (!testOrSuite.location)
return "";
return `${import_path.default.relative(rootDir, testOrSuite.location.file)}:${testOrSuite.location.line}`;
}
async function requireOrImportDefaultFunction(file, expectConstructor) {
let func = await (0, import_transform.requireOrImport)(file);
if (func && typeof func === "object" && "default" in func)
func = func["default"];
if (typeof func !== "function")
throw (0, import_util.errorWithFile)(file, `file must export a single ${expectConstructor ? "class" : "function"}.`);
return func;
}
function loadGlobalHook(config, file) {
return requireOrImportDefaultFunction(import_path.default.resolve(config.config.rootDir, file), false);
}
function loadReporter(config, file) {
return requireOrImportDefaultFunction(config ? import_path.default.resolve(config.config.rootDir, file) : file, true);
}
function sourceMapSources(file, cache) {
let sources = [file];
if (!file.endsWith(".js"))
return sources;
if (cache.has(file))
return cache.get(file);
try {
const sourceMap = import_utilsBundle.sourceMapSupport.retrieveSourceMap(file);
const sourceMapData = typeof sourceMap?.map === "string" ? JSON.parse(sourceMap.map) : sourceMap?.map;
if (sourceMapData?.sources)
sources = sourceMapData.sources.map((source) => import_path.default.resolve(import_path.default.dirname(file), source));
} finally {
cache.set(file, sources);
return sources;
}
}
async function loadTestList(config, filePath) {
try {
const content = await import_fs.default.promises.readFile(filePath, "utf-8");
const lines = content.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
const descriptions = lines.map((line) => {
const delimiter = line.includes("\u203A") ? "\u203A" : ">";
const tokens = line.split(delimiter).map((token) => token.trim());
let project;
if (tokens[0].startsWith("[")) {
if (!tokens[0].endsWith("]"))
throw new Error(`Malformed test description: ${line}`);
project = tokens[0].substring(1, tokens[0].length - 1);
tokens.shift();
}
return { project, file: (0, import_utils.toPosixPath)((0, import_util.parseLocationArg)(tokens[0]).file), titlePath: tokens.slice(1) };
});
return (test) => descriptions.some((d) => {
const [projectName, , ...titles] = test.titlePath();
if (d.project !== void 0 && d.project !== projectName)
return false;
const relativeFile = (0, import_utils.toPosixPath)(import_path.default.relative(config.config.rootDir, test.location.file));
if (relativeFile !== d.file)
return false;
return d.titlePath.length === titles.length && d.titlePath.every((_, index) => titles[index] === d.titlePath[index]);
});
} catch (e) {
throw (0, import_util.errorWithFile)(filePath, "Cannot read test list file: " + e.message);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
collectProjectsAndTestFiles,
createRootSuite,
loadFileSuites,
loadGlobalHook,
loadReporter,
loadTestList
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var processHost_exports = {};
__export(processHost_exports, {
ProcessHost: () => ProcessHost
});
module.exports = __toCommonJS(processHost_exports);
var import_child_process = __toESM(require("child_process"));
var import_events = require("events");
var import_utils = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
class ProcessHost extends import_events.EventEmitter {
constructor(runnerScript, processName, env) {
super();
this._didSendStop = false;
this._processDidExit = false;
this._didExitAndRanOnExit = false;
this._lastMessageId = 0;
this._callbacks = /* @__PURE__ */ new Map();
this._producedEnv = {};
this._runnerScript = runnerScript;
this._processName = processName;
this._extraEnv = env;
}
async startRunner(runnerParams, options = {}) {
(0, import_utils.assert)(!this.process, "Internal error: starting the same process twice");
this.process = import_child_process.default.fork(require.resolve("../common/process"), {
detached: false,
env: {
...process.env,
...this._extraEnv
},
stdio: [
"ignore",
options.onStdOut ? "pipe" : "inherit",
options.onStdErr && !process.env.PW_RUNNER_DEBUG ? "pipe" : "inherit",
"ipc"
]
});
this.process.on("exit", async (code, signal) => {
this._processDidExit = true;
await this.onExit();
this._didExitAndRanOnExit = true;
this.emit("exit", { unexpectedly: !this._didSendStop, code, signal });
});
this.process.on("error", (e) => {
});
this.process.on("message", (message) => {
if (import_utilsBundle.debug.enabled("pw:test:protocol"))
(0, import_utilsBundle.debug)("pw:test:protocol")("\u25C0 RECV " + JSON.stringify(message));
if (message.method === "__env_produced__") {
const producedEnv = message.params;
this._producedEnv = Object.fromEntries(producedEnv.map((e) => [e[0], e[1] ?? void 0]));
} else if (message.method === "__dispatch__") {
const { id, error: error2, method, params, result } = message.params;
if (id && this._callbacks.has(id)) {
const { resolve, reject } = this._callbacks.get(id);
this._callbacks.delete(id);
if (error2) {
const errorObject = new Error(error2.message);
errorObject.stack = error2.stack;
reject(errorObject);
} else {
resolve(result);
}
} else {
this.emit(method, params);
}
} else {
this.emit(message.method, message.params);
}
});
if (options.onStdOut)
this.process.stdout?.on("data", options.onStdOut);
if (options.onStdErr)
this.process.stderr?.on("data", options.onStdErr);
const error = await new Promise((resolve) => {
this.process.once("exit", (code, signal) => resolve({ unexpectedly: true, code, signal }));
this.once("ready", () => resolve(void 0));
});
if (error)
return error;
const processParams = {
processName: this._processName,
timeOrigin: (0, import_utils.timeOrigin)()
};
this.send({
method: "__init__",
params: {
processParams,
runnerScript: this._runnerScript,
runnerParams
}
});
}
sendMessage(message) {
const id = ++this._lastMessageId;
this.send({
method: "__dispatch__",
params: { id, ...message }
});
return new Promise((resolve, reject) => {
this._callbacks.set(id, { resolve, reject });
});
}
sendMessageNoReply(message) {
this.sendMessage(message).catch(() => {
});
}
async onExit() {
}
async stop() {
if (!this._processDidExit && !this._didSendStop) {
this.send({ method: "__stop__" });
this._didSendStop = true;
}
if (!this._didExitAndRanOnExit)
await new Promise((f) => this.once("exit", f));
}
didSendStop() {
return this._didSendStop;
}
producedEnv() {
return this._producedEnv;
}
send(message) {
if (import_utilsBundle.debug.enabled("pw:test:protocol"))
(0, import_utilsBundle.debug)("pw:test:protocol")("SEND \u25BA " + JSON.stringify(message));
this.process?.send(message);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ProcessHost
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var projectUtils_exports = {};
__export(projectUtils_exports, {
buildDependentProjects: () => buildDependentProjects,
buildProjectsClosure: () => buildProjectsClosure,
buildTeardownToSetupsMap: () => buildTeardownToSetupsMap,
collectFilesForProject: () => collectFilesForProject,
filterProjects: () => filterProjects,
findTopLevelProjects: () => findTopLevelProjects
});
module.exports = __toCommonJS(projectUtils_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_util = require("util");
var import_utils = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_util2 = require("../util");
const readFileAsync = (0, import_util.promisify)(import_fs.default.readFile);
const readDirAsync = (0, import_util.promisify)(import_fs.default.readdir);
function wildcardPatternToRegExp(pattern) {
return new RegExp("^" + pattern.split("*").map(import_utils.escapeRegExp).join(".*") + "$", "ig");
}
function filterProjects(projects, projectNames) {
if (!projectNames)
return [...projects];
const projectNamesToFind = /* @__PURE__ */ new Set();
const unmatchedProjectNames = /* @__PURE__ */ new Map();
const patterns = /* @__PURE__ */ new Set();
for (const name of projectNames) {
const lowerCaseName = name.toLocaleLowerCase();
if (lowerCaseName.includes("*")) {
patterns.add(wildcardPatternToRegExp(lowerCaseName));
} else {
projectNamesToFind.add(lowerCaseName);
unmatchedProjectNames.set(lowerCaseName, name);
}
}
const result = projects.filter((project) => {
const lowerCaseName = project.project.name.toLocaleLowerCase();
if (projectNamesToFind.has(lowerCaseName)) {
unmatchedProjectNames.delete(lowerCaseName);
return true;
}
for (const regex of patterns) {
regex.lastIndex = 0;
if (regex.test(lowerCaseName))
return true;
}
return false;
});
if (unmatchedProjectNames.size) {
const unknownProjectNames = Array.from(unmatchedProjectNames.values()).map((n) => `"${n}"`).join(", ");
throw new Error(`Project(s) ${unknownProjectNames} not found. Available projects: ${projects.map((p) => `"${p.project.name}"`).join(", ")}`);
}
if (!result.length) {
const allProjects = projects.map((p) => `"${p.project.name}"`).join(", ");
throw new Error(`No projects matched. Available projects: ${allProjects}`);
}
return result;
}
function buildTeardownToSetupsMap(projects) {
const result = /* @__PURE__ */ new Map();
for (const project of projects) {
if (project.teardown) {
const setups = result.get(project.teardown) || [];
setups.push(project);
result.set(project.teardown, setups);
}
}
return result;
}
function buildProjectsClosure(projects, hasTests) {
const result = /* @__PURE__ */ new Map();
const visit = (depth, project) => {
if (depth > 100) {
const error = new Error("Circular dependency detected between projects.");
error.stack = "";
throw error;
}
if (depth === 0 && hasTests && !hasTests(project))
return;
if (result.get(project) !== "dependency")
result.set(project, depth ? "dependency" : "top-level");
for (const dep of project.deps)
visit(depth + 1, dep);
if (project.teardown)
visit(depth + 1, project.teardown);
};
for (const p of projects)
visit(0, p);
return result;
}
function findTopLevelProjects(config) {
const closure = buildProjectsClosure(config.projects);
return [...closure].filter((entry) => entry[1] === "top-level").map((entry) => entry[0]);
}
function buildDependentProjects(forProjects, projects) {
const reverseDeps = new Map(projects.map((p) => [p, []]));
for (const project of projects) {
for (const dep of project.deps)
reverseDeps.get(dep).push(project);
}
const result = /* @__PURE__ */ new Set();
const visit = (depth, project) => {
if (depth > 100) {
const error = new Error("Circular dependency detected between projects.");
error.stack = "";
throw error;
}
result.add(project);
for (const reverseDep of reverseDeps.get(project))
visit(depth + 1, reverseDep);
if (project.teardown)
visit(depth + 1, project.teardown);
};
for (const forProject of forProjects)
visit(0, forProject);
return result;
}
async function collectFilesForProject(project, fsCache = /* @__PURE__ */ new Map()) {
const extensions = /* @__PURE__ */ new Set([".js", ".ts", ".mjs", ".mts", ".cjs", ".cts", ".jsx", ".tsx", ".mjsx", ".mtsx", ".cjsx", ".ctsx"]);
const testFileExtension = (file) => extensions.has(import_path.default.extname(file));
const allFiles = await cachedCollectFiles(project.project.testDir, project.respectGitIgnore, fsCache);
const testMatch = (0, import_util2.createFileMatcher)(project.project.testMatch);
const testIgnore = (0, import_util2.createFileMatcher)(project.project.testIgnore);
const testFiles = allFiles.filter((file) => {
if (!testFileExtension(file))
return false;
const isTest = !testIgnore(file) && testMatch(file);
if (!isTest)
return false;
return true;
});
return testFiles;
}
async function cachedCollectFiles(testDir, respectGitIgnore, fsCache) {
const key = testDir + ":" + respectGitIgnore;
let result = fsCache.get(key);
if (!result) {
result = await collectFiles(testDir, respectGitIgnore);
fsCache.set(key, result);
}
return result;
}
async function collectFiles(testDir, respectGitIgnore) {
if (!import_fs.default.existsSync(testDir))
return [];
if (!import_fs.default.statSync(testDir).isDirectory())
return [];
const checkIgnores = (entryPath, rules, isDirectory, parentStatus) => {
let status = parentStatus;
for (const rule of rules) {
const ruleIncludes = rule.negate;
if (status === "included" === ruleIncludes)
continue;
const relative = import_path.default.relative(rule.dir, entryPath);
if (rule.match("/" + relative) || rule.match(relative)) {
status = ruleIncludes ? "included" : "ignored";
} else if (isDirectory && (rule.match("/" + relative + "/") || rule.match(relative + "/"))) {
status = ruleIncludes ? "included" : "ignored";
} else if (isDirectory && ruleIncludes && (rule.match("/" + relative, true) || rule.match(relative, true))) {
status = "ignored-but-recurse";
}
}
return status;
};
const files = [];
const visit = async (dir, rules, status) => {
const entries = await readDirAsync(dir, { withFileTypes: true });
entries.sort((a, b) => a.name.localeCompare(b.name));
if (respectGitIgnore) {
const gitignore = entries.find((e) => e.isFile() && e.name === ".gitignore");
if (gitignore) {
const content = await readFileAsync(import_path.default.join(dir, gitignore.name), "utf8");
const newRules = content.split(/\r?\n/).map((s) => {
s = s.trim();
if (!s)
return;
const rule = new import_utilsBundle.minimatch.Minimatch(s, { matchBase: true, dot: true, flipNegate: true });
if (rule.comment)
return;
rule.dir = dir;
return rule;
}).filter((rule) => !!rule);
rules = [...rules, ...newRules];
}
}
for (const entry of entries) {
if (entry.name === "." || entry.name === "..")
continue;
if (entry.isFile() && entry.name === ".gitignore")
continue;
if (entry.isDirectory() && entry.name === "node_modules")
continue;
const entryPath = import_path.default.join(dir, entry.name);
const entryStatus = checkIgnores(entryPath, rules, entry.isDirectory(), status);
if (entry.isDirectory() && entryStatus !== "ignored")
await visit(entryPath, rules, entryStatus);
else if (entry.isFile() && entryStatus === "included")
files.push(entryPath);
}
};
await visit(testDir, [], "included");
return files;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
buildDependentProjects,
buildProjectsClosure,
buildTeardownToSetupsMap,
collectFilesForProject,
filterProjects,
findTopLevelProjects
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var rebase_exports = {};
__export(rebase_exports, {
addSuggestedRebaseline: () => addSuggestedRebaseline,
applySuggestedRebaselines: () => applySuggestedRebaselines,
clearSuggestedRebaselines: () => clearSuggestedRebaselines
});
module.exports = __toCommonJS(rebase_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_projectUtils = require("./projectUtils");
var import_babelBundle = require("../transform/babelBundle");
const t = import_babelBundle.types;
const suggestedRebaselines = new import_utils.MultiMap();
function addSuggestedRebaseline(location, suggestedRebaseline) {
suggestedRebaselines.set(location.file, { location, code: suggestedRebaseline });
}
function clearSuggestedRebaselines() {
suggestedRebaselines.clear();
}
async function applySuggestedRebaselines(config, reporter) {
if (config.config.updateSnapshots === "none")
return;
if (!suggestedRebaselines.size)
return;
const [project] = (0, import_projectUtils.filterProjects)(config.projects, config.cliProjectFilter);
if (!project)
return;
const patches = [];
const files = [];
const gitCache = /* @__PURE__ */ new Map();
const patchFile = import_path.default.join(project.project.outputDir, "rebaselines.patch");
for (const fileName of [...suggestedRebaselines.keys()].sort()) {
const source = await import_fs.default.promises.readFile(fileName, "utf8");
const lines = source.split("\n");
const replacements = suggestedRebaselines.get(fileName);
const fileNode = (0, import_babelBundle.babelParse)(source, fileName, true);
const ranges = [];
(0, import_babelBundle.traverse)(fileNode, {
CallExpression: (path2) => {
const node = path2.node;
if (node.arguments.length < 1)
return;
if (!t.isMemberExpression(node.callee))
return;
const argument = node.arguments[0];
if (!t.isStringLiteral(argument) && !t.isTemplateLiteral(argument))
return;
const prop = node.callee.property;
if (!prop.loc || !argument.start || !argument.end)
return;
for (const replacement of replacements) {
if (prop.loc.start.line !== replacement.location.line)
continue;
if (prop.loc.start.column + 1 !== replacement.location.column)
continue;
const indent = lines[prop.loc.start.line - 1].match(/^\s*/)[0];
const newText = replacement.code.replace(/\{indent\}/g, indent);
ranges.push({ start: argument.start, end: argument.end, oldText: source.substring(argument.start, argument.end), newText });
break;
}
}
});
ranges.sort((a, b) => b.start - a.start);
let result = source;
for (const range of ranges)
result = result.substring(0, range.start) + range.newText + result.substring(range.end);
const relativeName = import_path.default.relative(process.cwd(), fileName);
files.push(relativeName);
if (config.config.updateSourceMethod === "overwrite") {
await import_fs.default.promises.writeFile(fileName, result);
} else if (config.config.updateSourceMethod === "3way") {
await import_fs.default.promises.writeFile(fileName, applyPatchWithConflictMarkers(source, result));
} else {
const gitFolder = findGitRoot(import_path.default.dirname(fileName), gitCache);
const relativeToGit = import_path.default.relative(gitFolder || process.cwd(), fileName);
patches.push(createPatch(relativeToGit, source, result));
}
}
const fileList = files.map((file) => " " + import_utils2.colors.dim(file)).join("\n");
reporter.onStdErr(`
New baselines created for:
${fileList}
`);
if (config.config.updateSourceMethod === "patch") {
await import_fs.default.promises.mkdir(import_path.default.dirname(patchFile), { recursive: true });
await import_fs.default.promises.writeFile(patchFile, patches.join("\n"));
reporter.onStdErr(`
` + import_utils2.colors.cyan("git apply " + import_path.default.relative(process.cwd(), patchFile)) + "\n");
}
}
function createPatch(fileName, before, after) {
const file = fileName.replace(/\\/g, "/");
const text = import_utilsBundle.diff.createPatch(file, before, after, void 0, void 0, { context: 3 });
return [
"diff --git a/" + file + " b/" + file,
"--- a/" + file,
"+++ b/" + file,
...text.split("\n").slice(4)
].join("\n");
}
function findGitRoot(dir, cache) {
const result = cache.get(dir);
if (result !== void 0)
return result;
const gitPath = import_path.default.join(dir, ".git");
if (import_fs.default.existsSync(gitPath) && import_fs.default.lstatSync(gitPath).isDirectory()) {
cache.set(dir, dir);
return dir;
}
const parentDir = import_path.default.dirname(dir);
if (dir === parentDir) {
cache.set(dir, null);
return null;
}
const parentResult = findGitRoot(parentDir, cache);
cache.set(dir, parentResult);
return parentResult;
}
function applyPatchWithConflictMarkers(oldText, newText) {
const diffResult = import_utilsBundle.diff.diffLines(oldText, newText);
let result = "";
let conflict = false;
diffResult.forEach((part) => {
if (part.added) {
if (conflict) {
result += part.value;
result += ">>>>>>> SNAPSHOT\n";
conflict = false;
} else {
result += "<<<<<<< HEAD\n";
result += part.value;
result += "=======\n";
conflict = true;
}
} else if (part.removed) {
result += "<<<<<<< HEAD\n";
result += part.value;
result += "=======\n";
conflict = true;
} else {
if (conflict) {
result += ">>>>>>> SNAPSHOT\n";
conflict = false;
}
result += part.value;
}
});
if (conflict)
result += ">>>>>>> SNAPSHOT\n";
return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addSuggestedRebaseline,
applySuggestedRebaselines,
clearSuggestedRebaselines
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var reporters_exports = {};
__export(reporters_exports, {
createErrorCollectingReporter: () => createErrorCollectingReporter,
createReporterForTestServer: () => createReporterForTestServer,
createReporters: () => createReporters
});
module.exports = __toCommonJS(reporters_exports);
var import_utils = require("playwright-core/lib/utils");
var import_loadUtils = require("./loadUtils");
var import_base = require("../reporters/base");
var import_blob = require("../reporters/blob");
var import_dot = __toESM(require("../reporters/dot"));
var import_empty = __toESM(require("../reporters/empty"));
var import_github = __toESM(require("../reporters/github"));
var import_html = __toESM(require("../reporters/html"));
var import_json = __toESM(require("../reporters/json"));
var import_junit = __toESM(require("../reporters/junit"));
var import_line = __toESM(require("../reporters/line"));
var import_list = __toESM(require("../reporters/list"));
var import_listModeReporter = __toESM(require("../reporters/listModeReporter"));
var import_reporterV2 = require("../reporters/reporterV2");
async function createReporters(config, mode, isTestServer, descriptions) {
const defaultReporters = {
blob: import_blob.BlobReporter,
dot: mode === "list" ? import_listModeReporter.default : import_dot.default,
line: mode === "list" ? import_listModeReporter.default : import_line.default,
list: mode === "list" ? import_listModeReporter.default : import_list.default,
github: import_github.default,
json: import_json.default,
junit: import_junit.default,
null: import_empty.default,
html: import_html.default
};
const reporters = [];
descriptions ??= config.config.reporter;
if (config.configCLIOverrides.additionalReporters)
descriptions = [...descriptions, ...config.configCLIOverrides.additionalReporters];
const runOptions = reporterOptions(config, mode, isTestServer);
for (const r of descriptions) {
const [name, arg] = r;
const options = { ...runOptions, ...arg };
if (name in defaultReporters) {
reporters.push(new defaultReporters[name](options));
} else {
const reporterConstructor = await (0, import_loadUtils.loadReporter)(config, name);
reporters.push((0, import_reporterV2.wrapReporterAsV2)(new reporterConstructor(options)));
}
}
if (process.env.PW_TEST_REPORTER) {
const reporterConstructor = await (0, import_loadUtils.loadReporter)(config, process.env.PW_TEST_REPORTER);
reporters.push((0, import_reporterV2.wrapReporterAsV2)(new reporterConstructor(runOptions)));
}
const someReporterPrintsToStdio = reporters.some((r) => r.printsToStdio ? r.printsToStdio() : true);
if (reporters.length && !someReporterPrintsToStdio) {
if (mode === "list")
reporters.unshift(new import_listModeReporter.default());
else if (mode !== "merge")
reporters.unshift(!process.env.CI ? new import_line.default() : new import_dot.default());
}
return reporters;
}
async function createReporterForTestServer(file, messageSink) {
const reporterConstructor = await (0, import_loadUtils.loadReporter)(null, file);
return (0, import_reporterV2.wrapReporterAsV2)(new reporterConstructor({
_send: messageSink
}));
}
function createErrorCollectingReporter(screen) {
const errors = [];
return {
version: () => "v2",
onError(error) {
errors.push(error);
screen.stderr?.write((0, import_base.formatError)(screen, error).message + "\n");
},
errors: () => errors
};
}
function reporterOptions(config, mode, isTestServer) {
return {
configDir: config.configDir,
_mode: mode,
_isTestServer: isTestServer,
_commandHash: computeCommandHash(config)
};
}
function computeCommandHash(config) {
const parts = [];
if (config.cliProjectFilter)
parts.push(...config.cliProjectFilter);
const command = {};
if (config.cliArgs.length)
command.cliArgs = config.cliArgs;
if (config.cliGrep)
command.cliGrep = config.cliGrep;
if (config.cliGrepInvert)
command.cliGrepInvert = config.cliGrepInvert;
if (config.cliOnlyChanged)
command.cliOnlyChanged = config.cliOnlyChanged;
if (Object.keys(command).length)
parts.push((0, import_utils.calculateSha1)(JSON.stringify(command)).substring(0, 7));
return parts.join("-");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createErrorCollectingReporter,
createReporterForTestServer,
createReporters
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var sigIntWatcher_exports = {};
__export(sigIntWatcher_exports, {
SigIntWatcher: () => SigIntWatcher
});
module.exports = __toCommonJS(sigIntWatcher_exports);
class SigIntWatcher {
constructor() {
this._hadSignal = false;
let sigintCallback;
this._sigintPromise = new Promise((f) => sigintCallback = f);
this._sigintHandler = () => {
FixedNodeSIGINTHandler.off(this._sigintHandler);
this._hadSignal = true;
sigintCallback();
};
FixedNodeSIGINTHandler.on(this._sigintHandler);
}
promise() {
return this._sigintPromise;
}
hadSignal() {
return this._hadSignal;
}
disarm() {
FixedNodeSIGINTHandler.off(this._sigintHandler);
}
}
class FixedNodeSIGINTHandler {
static {
this._handlers = [];
}
static {
this._ignoreNextSIGINTs = false;
}
static {
this._handlerInstalled = false;
}
static {
this._dispatch = () => {
if (this._ignoreNextSIGINTs)
return;
this._ignoreNextSIGINTs = true;
setTimeout(() => {
this._ignoreNextSIGINTs = false;
if (!this._handlers.length)
this._uninstall();
}, 1e3);
for (const handler of this._handlers)
handler();
};
}
static _install() {
if (!this._handlerInstalled) {
this._handlerInstalled = true;
process.on("SIGINT", this._dispatch);
}
}
static _uninstall() {
if (this._handlerInstalled) {
this._handlerInstalled = false;
process.off("SIGINT", this._dispatch);
}
}
static on(handler) {
this._handlers.push(handler);
if (this._handlers.length === 1)
this._install();
}
static off(handler) {
this._handlers = this._handlers.filter((h) => h !== handler);
if (!this._ignoreNextSIGINTs && !this._handlers.length)
this._uninstall();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
SigIntWatcher
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var taskRunner_exports = {};
__export(taskRunner_exports, {
TaskRunner: () => TaskRunner
});
module.exports = __toCommonJS(taskRunner_exports);
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_sigIntWatcher = require("./sigIntWatcher");
var import_util = require("../util");
class TaskRunner {
constructor(reporter, globalTimeoutForError) {
this._tasks = [];
this._hasErrors = false;
this._interrupted = false;
this._isTearDown = false;
this._reporter = reporter;
this._globalTimeoutForError = globalTimeoutForError;
}
addTask(task) {
this._tasks.push(task);
}
async run(context, deadline, cancelPromise) {
const { status, cleanup } = await this.runDeferCleanup(context, deadline, cancelPromise);
const teardownStatus = await cleanup();
return status === "passed" ? teardownStatus : status;
}
async runDeferCleanup(context, deadline, cancelPromise = new import_utils.ManualPromise()) {
const sigintWatcher = new import_sigIntWatcher.SigIntWatcher();
const timeoutWatcher = new TimeoutWatcher(deadline);
const teardownRunner = new TaskRunner(this._reporter, this._globalTimeoutForError);
teardownRunner._isTearDown = true;
let currentTaskName;
const taskLoop = async () => {
for (const task of this._tasks) {
currentTaskName = task.title;
if (this._interrupted)
break;
(0, import_utilsBundle.debug)("pw:test:task")(`"${task.title}" started`);
const errors = [];
const softErrors = [];
try {
teardownRunner._tasks.unshift({ title: `teardown for ${task.title}`, setup: task.teardown });
await task.setup?.(context, errors, softErrors);
} catch (e) {
(0, import_utilsBundle.debug)("pw:test:task")(`error in "${task.title}": `, e);
errors.push((0, import_util.serializeError)(e));
} finally {
for (const error of [...softErrors, ...errors])
this._reporter.onError?.(error);
if (errors.length) {
if (!this._isTearDown)
this._interrupted = true;
this._hasErrors = true;
}
}
(0, import_utilsBundle.debug)("pw:test:task")(`"${task.title}" finished`);
}
};
await Promise.race([
taskLoop(),
cancelPromise,
sigintWatcher.promise(),
timeoutWatcher.promise
]);
sigintWatcher.disarm();
timeoutWatcher.disarm();
this._interrupted = true;
let status = "passed";
if (sigintWatcher.hadSignal() || cancelPromise?.isDone()) {
status = "interrupted";
} else if (timeoutWatcher.timedOut()) {
this._reporter.onError?.({ message: import_utils2.colors.red(`Timed out waiting ${this._globalTimeoutForError / 1e3}s for the ${currentTaskName} to run`) });
status = "timedout";
} else if (this._hasErrors) {
status = "failed";
}
cancelPromise?.resolve();
const cleanup = () => teardownRunner.runDeferCleanup(context, deadline).then((r) => r.status);
return { status, cleanup };
}
}
class TimeoutWatcher {
constructor(deadline) {
this._timedOut = false;
this.promise = new import_utils.ManualPromise();
if (!deadline)
return;
if (deadline - (0, import_utils.monotonicTime)() <= 0) {
this._timedOut = true;
this.promise.resolve();
return;
}
this._timer = setTimeout(() => {
this._timedOut = true;
this.promise.resolve();
}, deadline - (0, import_utils.monotonicTime)());
}
timedOut() {
return this._timedOut;
}
disarm() {
clearTimeout(this._timer);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TaskRunner
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tasks_exports = {};
__export(tasks_exports, {
TestRun: () => TestRun,
createApplyRebaselinesTask: () => createApplyRebaselinesTask,
createClearCacheTask: () => createClearCacheTask,
createGlobalSetupTasks: () => createGlobalSetupTasks,
createListFilesTask: () => createListFilesTask,
createLoadTask: () => createLoadTask,
createPluginSetupTasks: () => createPluginSetupTasks,
createReportBeginTask: () => createReportBeginTask,
createRunTestsTasks: () => createRunTestsTasks,
createStartDevServerTask: () => createStartDevServerTask,
runTasks: () => runTasks,
runTasksDeferCleanup: () => runTasksDeferCleanup
});
module.exports = __toCommonJS(tasks_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_util = require("util");
var import_utils = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_dispatcher = require("./dispatcher");
var import_failureTracker = require("./failureTracker");
var import_loadUtils = require("./loadUtils");
var import_projectUtils = require("./projectUtils");
var import_rebase = require("./rebase");
var import_taskRunner = require("./taskRunner");
var import_vcs = require("./vcs");
var import_test = require("../common/test");
var import_testGroups = require("../runner/testGroups");
var import_compilationCache = require("../transform/compilationCache");
var import_util2 = require("../util");
const readDirAsync = (0, import_util.promisify)(import_fs.default.readdir);
class TestRun {
constructor(config, reporter, options) {
this.rootSuite = void 0;
this.phases = [];
this.projectFiles = /* @__PURE__ */ new Map();
this.projectSuites = /* @__PURE__ */ new Map();
this.topLevelProjects = [];
this.config = config;
this.reporter = reporter;
this.failureTracker = new import_failureTracker.FailureTracker(config, options);
}
}
async function runTasks(testRun, tasks, globalTimeout, cancelPromise) {
const deadline = globalTimeout ? (0, import_utils.monotonicTime)() + globalTimeout : 0;
const taskRunner = new import_taskRunner.TaskRunner(testRun.reporter, globalTimeout || 0);
for (const task of tasks)
taskRunner.addTask(task);
testRun.reporter.onConfigure(testRun.config.config);
const status = await taskRunner.run(testRun, deadline, cancelPromise);
return await finishTaskRun(testRun, status);
}
async function runTasksDeferCleanup(testRun, tasks) {
const taskRunner = new import_taskRunner.TaskRunner(testRun.reporter, 0);
for (const task of tasks)
taskRunner.addTask(task);
testRun.reporter.onConfigure(testRun.config.config);
const { status, cleanup } = await taskRunner.runDeferCleanup(testRun, 0);
return { status: await finishTaskRun(testRun, status), cleanup };
}
async function finishTaskRun(testRun, status) {
if (status === "passed")
status = testRun.failureTracker.result();
const modifiedResult = await testRun.reporter.onEnd({ status });
if (modifiedResult && modifiedResult.status)
status = modifiedResult.status;
await testRun.reporter.onExit();
return status;
}
function createGlobalSetupTasks(config) {
const tasks = [];
if (!config.configCLIOverrides.preserveOutputDir)
tasks.push(createRemoveOutputDirsTask());
tasks.push(
...createPluginSetupTasks(config),
...config.globalTeardowns.map((file) => createGlobalTeardownTask(file, config)).reverse(),
...config.globalSetups.map((file) => createGlobalSetupTask(file, config))
);
return tasks;
}
function createRunTestsTasks(config) {
return [
createPhasesTask(),
createReportBeginTask(),
...config.plugins.map((plugin) => createPluginBeginTask(plugin)),
createRunTestsTask()
];
}
function createClearCacheTask(config) {
return {
title: "clear cache",
setup: async () => {
await (0, import_util2.removeDirAndLogToConsole)(import_compilationCache.cacheDir);
for (const plugin of config.plugins)
await plugin.instance?.clearCache?.();
}
};
}
function createReportBeginTask() {
return {
title: "report begin",
setup: async (testRun) => {
testRun.reporter.onBegin?.(testRun.rootSuite);
},
teardown: async ({}) => {
}
};
}
function createPluginSetupTasks(config) {
return config.plugins.map((plugin) => ({
title: "plugin setup",
setup: async ({ reporter }) => {
if (typeof plugin.factory === "function")
plugin.instance = await plugin.factory();
else
plugin.instance = plugin.factory;
await plugin.instance?.setup?.(config.config, config.configDir, reporter);
},
teardown: async () => {
await plugin.instance?.teardown?.();
}
}));
}
function createPluginBeginTask(plugin) {
return {
title: "plugin begin",
setup: async (testRun) => {
await plugin.instance?.begin?.(testRun.rootSuite);
},
teardown: async () => {
await plugin.instance?.end?.();
}
};
}
function createGlobalSetupTask(file, config) {
let title = "global setup";
if (config.globalSetups.length > 1)
title += ` (${file})`;
let globalSetupResult;
return {
title,
setup: async ({ config: config2 }) => {
const setupHook = await (0, import_loadUtils.loadGlobalHook)(config2, file);
globalSetupResult = await setupHook(config2.config);
},
teardown: async () => {
if (typeof globalSetupResult === "function")
await globalSetupResult();
}
};
}
function createGlobalTeardownTask(file, config) {
let title = "global teardown";
if (config.globalTeardowns.length > 1)
title += ` (${file})`;
return {
title,
teardown: async ({ config: config2 }) => {
const teardownHook = await (0, import_loadUtils.loadGlobalHook)(config2, file);
await teardownHook(config2.config);
}
};
}
function createRemoveOutputDirsTask() {
return {
title: "clear output",
setup: async ({ config }) => {
const outputDirs = /* @__PURE__ */ new Set();
const projects = (0, import_projectUtils.filterProjects)(config.projects, config.cliProjectFilter);
projects.forEach((p) => outputDirs.add(p.project.outputDir));
await Promise.all(Array.from(outputDirs).map((outputDir) => (0, import_utils.removeFolders)([outputDir]).then(async ([error]) => {
if (!error)
return;
if (error.code === "EBUSY") {
const entries = await readDirAsync(outputDir).catch((e) => []);
await Promise.all(entries.map((entry) => (0, import_utils.removeFolders)([import_path.default.join(outputDir, entry)])));
} else {
throw error;
}
})));
}
};
}
function createListFilesTask() {
return {
title: "load tests",
setup: async (testRun, errors) => {
const { rootSuite, topLevelProjects } = await (0, import_loadUtils.createRootSuite)(testRun, errors, false);
testRun.rootSuite = rootSuite;
testRun.failureTracker.onRootSuite(rootSuite, topLevelProjects);
await (0, import_loadUtils.collectProjectsAndTestFiles)(testRun, false);
for (const [project, files] of testRun.projectFiles) {
const projectSuite = new import_test.Suite(project.project.name, "project");
projectSuite._fullProject = project;
testRun.rootSuite._addSuite(projectSuite);
const suites = files.map((file) => {
const title = import_path.default.relative(testRun.config.config.rootDir, file);
const suite = new import_test.Suite(title, "file");
suite.location = { file, line: 0, column: 0 };
projectSuite._addSuite(suite);
return suite;
});
testRun.projectSuites.set(project, suites);
}
}
};
}
function createLoadTask(mode, options) {
return {
title: "load tests",
setup: async (testRun, errors, softErrors) => {
await (0, import_loadUtils.collectProjectsAndTestFiles)(testRun, !!options.doNotRunDepsOutsideProjectFilter);
await (0, import_loadUtils.loadFileSuites)(testRun, mode, options.failOnLoadErrors ? errors : softErrors);
if (testRun.config.cliOnlyChanged || options.populateDependencies) {
for (const plugin of testRun.config.plugins)
await plugin.instance?.populateDependencies?.();
}
if (testRun.config.cliOnlyChanged) {
const changedFiles = await (0, import_vcs.detectChangedTestFiles)(testRun.config.cliOnlyChanged, testRun.config.configDir);
testRun.config.preOnlyTestFilters.push((test) => changedFiles.has(test.location.file));
}
if (testRun.config.cliTestList) {
const testListFilter = await (0, import_loadUtils.loadTestList)(testRun.config, testRun.config.cliTestList);
testRun.config.preOnlyTestFilters.push(testListFilter);
}
if (testRun.config.cliTestListInvert) {
const testListInvertFilter = await (0, import_loadUtils.loadTestList)(testRun.config, testRun.config.cliTestListInvert);
testRun.config.preOnlyTestFilters.push((test) => !testListInvertFilter(test));
}
const { rootSuite, topLevelProjects } = await (0, import_loadUtils.createRootSuite)(testRun, options.failOnLoadErrors ? errors : softErrors, !!options.filterOnly);
testRun.rootSuite = rootSuite;
testRun.failureTracker.onRootSuite(rootSuite, topLevelProjects);
if (options.failOnLoadErrors && !testRun.rootSuite.allTests().length && !testRun.config.cliPassWithNoTests && !testRun.config.config.shard && !testRun.config.cliOnlyChanged && !testRun.config.cliTestList && !testRun.config.cliTestListInvert) {
if (testRun.config.cliArgs.length) {
throw new Error([
`No tests found.`,
`Make sure that arguments are regular expressions matching test files.`,
`You may need to escape symbols like "$" or "*" and quote the arguments.`
].join("\n"));
}
throw new Error(`No tests found`);
}
}
};
}
function createApplyRebaselinesTask() {
return {
title: "apply rebaselines",
setup: async () => {
(0, import_rebase.clearSuggestedRebaselines)();
},
teardown: async ({ config, reporter }) => {
await (0, import_rebase.applySuggestedRebaselines)(config, reporter);
}
};
}
function createPhasesTask() {
return {
title: "create phases",
setup: async (testRun) => {
let maxConcurrentTestGroups = 0;
const processed = /* @__PURE__ */ new Set();
const projectToSuite = new Map(testRun.rootSuite.suites.map((suite) => [suite._fullProject, suite]));
const allProjects = [...projectToSuite.keys()];
const teardownToSetups = (0, import_projectUtils.buildTeardownToSetupsMap)(allProjects);
const teardownToSetupsDependents = /* @__PURE__ */ new Map();
for (const [teardown, setups] of teardownToSetups) {
const closure = (0, import_projectUtils.buildDependentProjects)(setups, allProjects);
closure.delete(teardown);
teardownToSetupsDependents.set(teardown, [...closure]);
}
for (let i = 0; i < projectToSuite.size; i++) {
const phaseProjects = [];
for (const project of projectToSuite.keys()) {
if (processed.has(project))
continue;
const projectsThatShouldFinishFirst = [...project.deps, ...teardownToSetupsDependents.get(project) || []];
if (projectsThatShouldFinishFirst.find((p) => !processed.has(p)))
continue;
phaseProjects.push(project);
}
for (const project of phaseProjects)
processed.add(project);
if (phaseProjects.length) {
let testGroupsInPhase = 0;
const phase = { dispatcher: new import_dispatcher.Dispatcher(testRun.config, testRun.reporter, testRun.failureTracker), projects: [] };
testRun.phases.push(phase);
for (const project of phaseProjects) {
const projectSuite = projectToSuite.get(project);
const testGroups = (0, import_testGroups.createTestGroups)(projectSuite, testRun.config.config.workers);
phase.projects.push({ project, projectSuite, testGroups });
testGroupsInPhase += Math.min(project.workers ?? Number.MAX_SAFE_INTEGER, testGroups.length);
}
(0, import_utilsBundle.debug)("pw:test:task")(`created phase #${testRun.phases.length} with ${phase.projects.map((p) => p.project.project.name).sort()} projects, ${testGroupsInPhase} testGroups`);
maxConcurrentTestGroups = Math.max(maxConcurrentTestGroups, testGroupsInPhase);
}
}
testRun.config.config.metadata.actualWorkers = Math.min(testRun.config.config.workers, maxConcurrentTestGroups);
}
};
}
function createRunTestsTask() {
return {
title: "test suite",
setup: async ({ phases, failureTracker }) => {
const successfulProjects = /* @__PURE__ */ new Set();
const extraEnvByProjectId = /* @__PURE__ */ new Map();
const teardownToSetups = (0, import_projectUtils.buildTeardownToSetupsMap)(phases.map((phase) => phase.projects.map((p) => p.project)).flat());
for (const { dispatcher, projects } of phases) {
const phaseTestGroups = [];
for (const { project, testGroups } of projects) {
let extraEnv = {};
for (const dep of project.deps)
extraEnv = { ...extraEnv, ...extraEnvByProjectId.get(dep.id) };
for (const setup of teardownToSetups.get(project) || [])
extraEnv = { ...extraEnv, ...extraEnvByProjectId.get(setup.id) };
extraEnvByProjectId.set(project.id, extraEnv);
const hasFailedDeps = project.deps.some((p) => !successfulProjects.has(p));
if (!hasFailedDeps)
phaseTestGroups.push(...testGroups);
}
if (phaseTestGroups.length) {
await dispatcher.run(phaseTestGroups, extraEnvByProjectId);
await dispatcher.stop();
for (const [projectId, envProduced] of dispatcher.producedEnvByProjectId()) {
const extraEnv = extraEnvByProjectId.get(projectId) || {};
extraEnvByProjectId.set(projectId, { ...extraEnv, ...envProduced });
}
}
if (!failureTracker.hasWorkerErrors()) {
for (const { project, projectSuite } of projects) {
const hasFailedDeps = project.deps.some((p) => !successfulProjects.has(p));
if (!hasFailedDeps && !projectSuite.allTests().some((test) => !test.ok()))
successfulProjects.add(project);
}
}
}
},
teardown: async ({ phases }) => {
for (const { dispatcher } of phases.reverse())
await dispatcher.stop();
}
};
}
function createStartDevServerTask() {
return {
title: "start dev server",
setup: async ({ config }, errors, softErrors) => {
if (config.plugins.some((plugin) => !!plugin.devServerCleanup)) {
errors.push({ message: `DevServer is already running` });
return;
}
for (const plugin of config.plugins)
plugin.devServerCleanup = await plugin.instance?.startDevServer?.();
if (!config.plugins.some((plugin) => !!plugin.devServerCleanup))
errors.push({ message: `DevServer is not available in the package you are using. Did you mean to use component testing?` });
},
teardown: async ({ config }) => {
for (const plugin of config.plugins) {
await plugin.devServerCleanup?.();
plugin.devServerCleanup = void 0;
}
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestRun,
createApplyRebaselinesTask,
createClearCacheTask,
createGlobalSetupTasks,
createListFilesTask,
createLoadTask,
createPluginSetupTasks,
createReportBeginTask,
createRunTestsTasks,
createStartDevServerTask,
runTasks,
runTasksDeferCleanup
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testGroups_exports = {};
__export(testGroups_exports, {
createTestGroups: () => createTestGroups,
filterForShard: () => filterForShard
});
module.exports = __toCommonJS(testGroups_exports);
function createTestGroups(projectSuite, expectedParallelism) {
const groups = /* @__PURE__ */ new Map();
const createGroup = (test) => {
return {
workerHash: test._workerHash,
requireFile: test._requireFile,
repeatEachIndex: test.repeatEachIndex,
projectId: test._projectId,
tests: []
};
};
for (const test of projectSuite.allTests()) {
let withWorkerHash = groups.get(test._workerHash);
if (!withWorkerHash) {
withWorkerHash = /* @__PURE__ */ new Map();
groups.set(test._workerHash, withWorkerHash);
}
let withRequireFile = withWorkerHash.get(test._requireFile);
if (!withRequireFile) {
withRequireFile = {
general: createGroup(test),
parallel: /* @__PURE__ */ new Map(),
parallelWithHooks: createGroup(test)
};
withWorkerHash.set(test._requireFile, withRequireFile);
}
let insideParallel = false;
let outerMostSequentialSuite;
let hasAllHooks = false;
for (let parent = test.parent; parent; parent = parent.parent) {
if (parent._parallelMode === "serial" || parent._parallelMode === "default")
outerMostSequentialSuite = parent;
insideParallel = insideParallel || parent._parallelMode === "parallel";
hasAllHooks = hasAllHooks || parent._hooks.some((hook) => hook.type === "beforeAll" || hook.type === "afterAll");
}
if (insideParallel) {
if (hasAllHooks && !outerMostSequentialSuite) {
withRequireFile.parallelWithHooks.tests.push(test);
} else {
const key = outerMostSequentialSuite || test;
let group = withRequireFile.parallel.get(key);
if (!group) {
group = createGroup(test);
withRequireFile.parallel.set(key, group);
}
group.tests.push(test);
}
} else {
withRequireFile.general.tests.push(test);
}
}
const result = [];
for (const withWorkerHash of groups.values()) {
for (const withRequireFile of withWorkerHash.values()) {
if (withRequireFile.general.tests.length)
result.push(withRequireFile.general);
result.push(...withRequireFile.parallel.values());
const parallelWithHooksGroupSize = Math.ceil(withRequireFile.parallelWithHooks.tests.length / expectedParallelism);
let lastGroup;
for (const test of withRequireFile.parallelWithHooks.tests) {
if (!lastGroup || lastGroup.tests.length >= parallelWithHooksGroupSize) {
lastGroup = createGroup(test);
result.push(lastGroup);
}
lastGroup.tests.push(test);
}
}
}
return result;
}
function filterForShard(shard, testGroups) {
let shardableTotal = 0;
for (const group of testGroups)
shardableTotal += group.tests.length;
const shardSize = Math.floor(shardableTotal / shard.total);
const extraOne = shardableTotal - shardSize * shard.total;
const currentShard = shard.current - 1;
const from = shardSize * currentShard + Math.min(extraOne, currentShard);
const to = from + shardSize + (currentShard < extraOne ? 1 : 0);
let current = 0;
const result = /* @__PURE__ */ new Set();
for (const group of testGroups) {
if (current >= from && current < to)
result.add(group);
current += group.tests.length;
}
return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createTestGroups,
filterForShard
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testRunner_exports = {};
__export(testRunner_exports, {
TestRunner: () => TestRunner,
TestRunnerEvent: () => TestRunnerEvent,
runAllTestsWithConfig: () => runAllTestsWithConfig
});
module.exports = __toCommonJS(testRunner_exports);
var import_events = __toESM(require("events"));
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_server = require("playwright-core/lib/server");
var import_utils = require("playwright-core/lib/utils");
var import_configLoader = require("../common/configLoader");
var import_fsWatcher = require("../fsWatcher");
var import_teleReceiver = require("../isomorphic/teleReceiver");
var import_gitCommitInfoPlugin = require("../plugins/gitCommitInfoPlugin");
var import_webServerPlugin = require("../plugins/webServerPlugin");
var import_base = require("../reporters/base");
var import_internalReporter = require("../reporters/internalReporter");
var import_compilationCache = require("../transform/compilationCache");
var import_util = require("../util");
var import_reporters = require("./reporters");
var import_tasks = require("./tasks");
var import_lastRun = require("./lastRun");
const TestRunnerEvent = {
TestFilesChanged: "testFilesChanged"
};
class TestRunner extends import_events.default {
constructor(configLocation, configCLIOverrides) {
super();
this._watchedProjectDirs = /* @__PURE__ */ new Set();
this._ignoredProjectOutputs = /* @__PURE__ */ new Set();
this._watchedTestDependencies = /* @__PURE__ */ new Set();
this._queue = Promise.resolve();
this._watchTestDirs = false;
this._populateDependenciesOnList = false;
this.configLocation = configLocation;
this._configCLIOverrides = configCLIOverrides;
this._watcher = new import_fsWatcher.Watcher((events) => {
const collector = /* @__PURE__ */ new Set();
events.forEach((f) => (0, import_compilationCache.collectAffectedTestFiles)(f.file, collector));
this.emit(TestRunnerEvent.TestFilesChanged, [...collector]);
});
}
async initialize(params) {
(0, import_utils.setPlaywrightTestProcessEnv)();
this._watchTestDirs = !!params.watchTestDirs;
this._populateDependenciesOnList = !!params.populateDependenciesOnList;
}
resizeTerminal(params) {
process.stdout.columns = params.cols;
process.stdout.rows = params.rows;
process.stderr.columns = params.cols;
process.stderr.rows = params.rows;
}
hasSomeBrowsers() {
for (const browserName of ["chromium", "webkit", "firefox"]) {
try {
import_server.registry.findExecutable(browserName).executablePathOrDie("javascript");
return true;
} catch {
}
}
return false;
}
async installBrowsers() {
const executables = import_server.registry.defaultExecutables();
await import_server.registry.install(executables, false);
}
async loadConfig() {
const { config, error } = await this._loadConfig(this._configCLIOverrides);
if (config)
return config;
throw new Error("Failed to load config: " + (error ? error.message : "Unknown error"));
}
async runGlobalSetup(userReporters) {
await this.runGlobalTeardown();
const reporter = new import_internalReporter.InternalReporter(userReporters);
const config = await this._loadConfigOrReportError(reporter, this._configCLIOverrides);
if (!config)
return { status: "failed" };
const { status, cleanup } = await (0, import_tasks.runTasksDeferCleanup)(new import_tasks.TestRun(config, reporter), [
...(0, import_tasks.createGlobalSetupTasks)(config)
]);
if (status !== "passed")
await cleanup();
else
this._globalSetup = { cleanup };
return { status };
}
async runGlobalTeardown() {
const globalSetup = this._globalSetup;
const status = await globalSetup?.cleanup();
this._globalSetup = void 0;
return { status };
}
async startDevServer(userReporter, mode) {
await this.stopDevServer();
const reporter = new import_internalReporter.InternalReporter([userReporter]);
const config = await this._loadConfigOrReportError(reporter);
if (!config)
return { status: "failed" };
const { status, cleanup } = await (0, import_tasks.runTasksDeferCleanup)(new import_tasks.TestRun(config, reporter), [
...(0, import_tasks.createPluginSetupTasks)(config),
(0, import_tasks.createLoadTask)(mode, { failOnLoadErrors: true, filterOnly: false }),
(0, import_tasks.createStartDevServerTask)()
]);
if (status !== "passed")
await cleanup();
else
this._devServer = { cleanup };
return { status };
}
async stopDevServer() {
const devServer = this._devServer;
const status = await devServer?.cleanup();
this._devServer = void 0;
return { status };
}
async clearCache(userReporter) {
const reporter = new import_internalReporter.InternalReporter(userReporter ? [userReporter] : []);
const config = await this._loadConfigOrReportError(reporter);
if (!config)
return { status: "failed" };
const status = await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), [
...(0, import_tasks.createPluginSetupTasks)(config),
(0, import_tasks.createClearCacheTask)(config)
]);
return { status };
}
async listFiles(userReporter, projects) {
const reporter = new import_internalReporter.InternalReporter([userReporter]);
const config = await this._loadConfigOrReportError(reporter);
if (!config)
return { status: "failed" };
config.cliProjectFilter = projects?.length ? projects : void 0;
const status = await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), [
(0, import_tasks.createListFilesTask)(),
(0, import_tasks.createReportBeginTask)()
]);
return { status };
}
async listTests(userReporter, params) {
let result;
this._queue = this._queue.then(async () => {
const { config, status } = await this._innerListTests(userReporter, params);
if (config)
await this._updateWatchedDirs(config);
result = { status };
}).catch(printInternalError);
await this._queue;
return result;
}
async _innerListTests(userReporter, params) {
const overrides = {
...this._configCLIOverrides,
repeatEach: 1,
retries: 0
};
const reporter = new import_internalReporter.InternalReporter([userReporter]);
const config = await this._loadConfigOrReportError(reporter, overrides);
if (!config)
return { status: "failed" };
config.cliArgs = params.locations || [];
config.cliGrep = params.grep;
config.cliGrepInvert = params.grepInvert;
config.cliProjectFilter = params.projects?.length ? params.projects : void 0;
config.cliListOnly = true;
const status = await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), [
(0, import_tasks.createLoadTask)("out-of-process", { failOnLoadErrors: false, filterOnly: false, populateDependencies: this._populateDependenciesOnList }),
(0, import_tasks.createReportBeginTask)()
]);
return { config, status };
}
async _updateWatchedDirs(config) {
this._watchedProjectDirs = /* @__PURE__ */ new Set();
this._ignoredProjectOutputs = /* @__PURE__ */ new Set();
for (const p of config.projects) {
this._watchedProjectDirs.add(p.project.testDir);
this._ignoredProjectOutputs.add(p.project.outputDir);
}
const result = await resolveCtDirs(config);
if (result) {
this._watchedProjectDirs.add(result.templateDir);
this._ignoredProjectOutputs.add(result.outDir);
}
if (this._watchTestDirs)
await this._updateWatcher(false);
}
async _updateWatcher(reportPending) {
await this._watcher.update([...this._watchedProjectDirs, ...this._watchedTestDependencies], [...this._ignoredProjectOutputs], reportPending);
}
async runTests(userReporter, params) {
let result = { status: "passed" };
this._queue = this._queue.then(async () => {
result = await this._innerRunTests(userReporter, params).catch((e) => {
printInternalError(e);
return { status: "failed" };
});
});
await this._queue;
return result;
}
async _innerRunTests(userReporter, params) {
await this.stopTests();
const overrides = {
...this._configCLIOverrides,
repeatEach: 1,
retries: 0,
timeout: params.timeout,
preserveOutputDir: true,
reporter: params.reporters ? params.reporters.map((r) => [r]) : void 0,
use: {
...this._configCLIOverrides.use,
...params.trace === "on" ? { trace: { mode: "on", sources: false, _live: true } } : {},
...params.trace === "off" ? { trace: "off" } : {},
...params.video === "on" || params.video === "off" ? { video: params.video } : {},
...params.headed !== void 0 ? { headless: !params.headed } : {},
_optionContextReuseMode: params.reuseContext ? "when-possible" : void 0,
_optionConnectOptions: params.connectWsEndpoint ? { wsEndpoint: params.connectWsEndpoint } : void 0
},
...params.updateSnapshots ? { updateSnapshots: params.updateSnapshots } : {},
...params.updateSourceMethod ? { updateSourceMethod: params.updateSourceMethod } : {},
...params.workers ? { workers: params.workers } : {}
};
if (params.trace === "on")
process.env.PW_LIVE_TRACE_STACKS = "1";
else
process.env.PW_LIVE_TRACE_STACKS = void 0;
const config = await this._loadConfigOrReportError(new import_internalReporter.InternalReporter([userReporter]), overrides);
if (!config)
return { status: "failed" };
config.cliListOnly = false;
config.cliPassWithNoTests = true;
config.cliArgs = params.locations || [];
config.cliGrep = params.grep;
config.cliGrepInvert = params.grepInvert;
config.cliProjectFilter = params.projects?.length ? params.projects : void 0;
config.preOnlyTestFilters = [];
if (params.testIds) {
const testIdSet = new Set(params.testIds);
config.preOnlyTestFilters.push((test) => testIdSet.has(test.id));
}
const configReporters = params.disableConfigReporters ? [] : await (0, import_reporters.createReporters)(config, "test", true);
const reporter = new import_internalReporter.InternalReporter([...configReporters, userReporter]);
const stop = new import_utils.ManualPromise();
const tasks = [
(0, import_tasks.createApplyRebaselinesTask)(),
(0, import_tasks.createLoadTask)("out-of-process", { filterOnly: true, failOnLoadErrors: !!params.failOnLoadErrors, doNotRunDepsOutsideProjectFilter: params.doNotRunDepsOutsideProjectFilter }),
...(0, import_tasks.createRunTestsTasks)(config)
];
const testRun = new import_tasks.TestRun(config, reporter, { pauseOnError: params.pauseOnError, pauseAtEnd: params.pauseAtEnd });
const run = (0, import_tasks.runTasks)(testRun, tasks, 0, stop).then(async (status) => {
this._testRun = void 0;
return status;
});
this._testRun = { run, stop };
return { status: await run };
}
async watch(fileNames) {
this._watchedTestDependencies = /* @__PURE__ */ new Set();
for (const fileName of fileNames) {
this._watchedTestDependencies.add(fileName);
(0, import_compilationCache.dependenciesForTestFile)(fileName).forEach((file) => this._watchedTestDependencies.add(file));
}
await this._updateWatcher(true);
}
async findRelatedTestFiles(files, userReporter) {
const errorReporter = (0, import_reporters.createErrorCollectingReporter)(import_base.internalScreen);
const reporter = new import_internalReporter.InternalReporter(userReporter ? [userReporter, errorReporter] : [errorReporter]);
const config = await this._loadConfigOrReportError(reporter);
if (!config)
return { errors: errorReporter.errors(), testFiles: [] };
const status = await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), [
...(0, import_tasks.createPluginSetupTasks)(config),
(0, import_tasks.createLoadTask)("out-of-process", { failOnLoadErrors: true, filterOnly: false, populateDependencies: true })
]);
if (status !== "passed")
return { errors: errorReporter.errors(), testFiles: [] };
return { testFiles: (0, import_compilationCache.affectedTestFiles)(files) };
}
async stopTests() {
this._testRun?.stop?.resolve();
await this._testRun?.run;
}
async closeGracefully() {
(0, import_utils.gracefullyProcessExitDoNotHang)(0);
}
async stop() {
await this.runGlobalTeardown();
}
async _loadConfig(overrides) {
try {
const config = await (0, import_configLoader.loadConfig)(this.configLocation, overrides);
if (!this._plugins) {
(0, import_webServerPlugin.webServerPluginsForConfig)(config).forEach((p) => config.plugins.push({ factory: p }));
(0, import_gitCommitInfoPlugin.addGitCommitInfoPlugin)(config);
this._plugins = config.plugins || [];
} else {
config.plugins.splice(0, config.plugins.length, ...this._plugins);
}
return { config };
} catch (e) {
return { config: null, error: (0, import_util.serializeError)(e) };
}
}
async _loadConfigOrReportError(reporter, overrides) {
const { config, error } = await this._loadConfig(overrides);
if (config)
return config;
reporter.onConfigure(import_teleReceiver.baseFullConfig);
reporter.onError(error);
await reporter.onEnd({ status: "failed" });
await reporter.onExit();
return null;
}
}
function printInternalError(e) {
console.error("Internal error:", e);
}
async function resolveCtDirs(config) {
const use = config.config.projects[0].use;
const relativeTemplateDir = use.ctTemplateDir || "playwright";
const templateDir = await import_fs.default.promises.realpath(import_path.default.normalize(import_path.default.join(config.configDir, relativeTemplateDir))).catch(() => void 0);
if (!templateDir)
return null;
const outDir = use.ctCacheDir ? import_path.default.resolve(config.configDir, use.ctCacheDir) : import_path.default.resolve(templateDir, ".cache");
return {
outDir,
templateDir
};
}
async function runAllTestsWithConfig(config) {
(0, import_utils.setPlaywrightTestProcessEnv)();
const listOnly = config.cliListOnly;
(0, import_gitCommitInfoPlugin.addGitCommitInfoPlugin)(config);
(0, import_webServerPlugin.webServerPluginsForConfig)(config).forEach((p) => config.plugins.push({ factory: p }));
const reporters = await (0, import_reporters.createReporters)(config, listOnly ? "list" : "test", false);
const lastRun = new import_lastRun.LastRunReporter(config);
if (config.cliLastFailed)
await lastRun.filterLastFailed();
const reporter = new import_internalReporter.InternalReporter([...reporters, lastRun]);
const tasks = listOnly ? [
(0, import_tasks.createLoadTask)("in-process", { failOnLoadErrors: true, filterOnly: false }),
(0, import_tasks.createReportBeginTask)()
] : [
(0, import_tasks.createApplyRebaselinesTask)(),
...(0, import_tasks.createGlobalSetupTasks)(config),
(0, import_tasks.createLoadTask)("in-process", { filterOnly: true, failOnLoadErrors: true }),
...(0, import_tasks.createRunTestsTasks)(config)
];
const status = await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), tasks, config.config.globalTimeout);
await new Promise((resolve) => process.stdout.write("", () => resolve()));
await new Promise((resolve) => process.stderr.write("", () => resolve()));
return status;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestRunner,
TestRunnerEvent,
runAllTestsWithConfig
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testServer_exports = {};
__export(testServer_exports, {
TestServerDispatcher: () => TestServerDispatcher,
runTestServer: () => runTestServer,
runUIMode: () => runUIMode
});
module.exports = __toCommonJS(testServer_exports);
var import_util = __toESM(require("util"));
var import_server = require("playwright-core/lib/server");
var import_utils = require("playwright-core/lib/utils");
var import_utilsBundle = require("playwright-core/lib/utilsBundle");
var import_configLoader = require("../common/configLoader");
var import_list = __toESM(require("../reporters/list"));
var import_reporters = require("./reporters");
var import_sigIntWatcher = require("./sigIntWatcher");
var import_testRunner = require("./testRunner");
const originalDebugLog = import_utilsBundle.debug.log;
const originalStdoutWrite = process.stdout.write;
const originalStderrWrite = process.stderr.write;
class TestServer {
constructor(configLocation, configCLIOverrides) {
this._configLocation = configLocation;
this._configCLIOverrides = configCLIOverrides;
}
async start(options) {
this._dispatcher = new TestServerDispatcher(this._configLocation, this._configCLIOverrides);
return await (0, import_server.startTraceViewerServer)({ ...options, transport: this._dispatcher.transport });
}
async stop() {
await this._dispatcher?.stop();
}
}
class TestServerDispatcher {
constructor(configLocation, configCLIOverrides) {
this._serializer = require.resolve("./uiModeReporter");
this._closeOnDisconnect = false;
this._testRunner = new import_testRunner.TestRunner(configLocation, configCLIOverrides);
this.transport = {
onconnect: () => {
},
dispatch: (method, params) => this[method](params),
onclose: () => {
if (this._closeOnDisconnect)
(0, import_utils.gracefullyProcessExitDoNotHang)(0);
}
};
this._dispatchEvent = (method, params) => this.transport.sendEvent?.(method, params);
this._testRunner.on(import_testRunner.TestRunnerEvent.TestFilesChanged, (testFiles) => this._dispatchEvent("testFilesChanged", { testFiles }));
}
async _wireReporter(messageSink) {
return await (0, import_reporters.createReporterForTestServer)(this._serializer, messageSink);
}
async _collectingReporter() {
const report = [];
return {
reporter: await (0, import_reporters.createReporterForTestServer)(this._serializer, (e) => report.push(e)),
report
};
}
async initialize(params) {
this._serializer = params.serializer || require.resolve("./uiModeReporter");
this._closeOnDisconnect = !!params.closeOnDisconnect;
await this._testRunner.initialize({
...params
});
this._setInterceptStdio(!!params.interceptStdio);
}
async ping() {
}
async open(params) {
if ((0, import_utils.isUnderTest)())
return;
(0, import_utilsBundle.open)("vscode://file/" + params.location.file + ":" + params.location.line).catch((e) => console.error(e));
}
async resizeTerminal(params) {
this._testRunner.resizeTerminal(params);
}
async checkBrowsers() {
return { hasBrowsers: this._testRunner.hasSomeBrowsers() };
}
async installBrowsers() {
await this._testRunner.installBrowsers();
}
async runGlobalSetup(params) {
await this.runGlobalTeardown();
const { reporter, report } = await this._collectingReporter();
this._globalSetupReport = report;
const { status } = await this._testRunner.runGlobalSetup([reporter, new import_list.default()]);
return { report, status };
}
async runGlobalTeardown() {
const { status } = await this._testRunner.runGlobalTeardown();
const report = this._globalSetupReport || [];
this._globalSetupReport = void 0;
return { status, report };
}
async startDevServer(params) {
await this.stopDevServer({});
const { reporter, report } = await this._collectingReporter();
const { status } = await this._testRunner.startDevServer(reporter, "out-of-process");
return { report, status };
}
async stopDevServer(params) {
const { status } = await this._testRunner.stopDevServer();
const report = this._devServerReport || [];
this._devServerReport = void 0;
return { status, report };
}
async clearCache(params) {
await this._testRunner.clearCache();
}
async listFiles(params) {
const { reporter, report } = await this._collectingReporter();
const { status } = await this._testRunner.listFiles(reporter, params.projects);
return { report, status };
}
async listTests(params) {
const { reporter, report } = await this._collectingReporter();
const { status } = await this._testRunner.listTests(reporter, params);
return { report, status };
}
async runTests(params) {
const wireReporter = await this._wireReporter((e) => this._dispatchEvent("report", e));
const { status } = await this._testRunner.runTests(wireReporter, {
...params,
doNotRunDepsOutsideProjectFilter: true
});
return { status };
}
async watch(params) {
await this._testRunner.watch(params.fileNames);
}
async findRelatedTestFiles(params) {
return this._testRunner.findRelatedTestFiles(params.files);
}
async stopTests() {
await this._testRunner.stopTests();
}
async stop() {
this._setInterceptStdio(false);
await this._testRunner.stop();
}
async closeGracefully() {
await this._testRunner.closeGracefully();
}
_setInterceptStdio(interceptStdio) {
if (process.env.PWTEST_DEBUG)
return;
if (interceptStdio) {
if (import_utilsBundle.debug.log === originalDebugLog) {
import_utilsBundle.debug.log = (...args) => {
const string = import_util.default.format(...args) + "\n";
return originalStderrWrite.apply(process.stderr, [string]);
};
}
const stdoutWrite = (chunk) => {
this._dispatchEvent("stdio", chunkToPayload("stdout", chunk));
return true;
};
const stderrWrite = (chunk) => {
this._dispatchEvent("stdio", chunkToPayload("stderr", chunk));
return true;
};
process.stdout.write = stdoutWrite;
process.stderr.write = stderrWrite;
} else {
import_utilsBundle.debug.log = originalDebugLog;
process.stdout.write = originalStdoutWrite;
process.stderr.write = originalStderrWrite;
}
}
}
async function runUIMode(configFile, configCLIOverrides, options) {
const configLocation = (0, import_configLoader.resolveConfigLocation)(configFile);
return await innerRunTestServer(configLocation, configCLIOverrides, options, async (server, cancelPromise) => {
await (0, import_server.installRootRedirect)(server, [], { ...options, webApp: "uiMode.html" });
if (options.host !== void 0 || options.port !== void 0) {
await (0, import_server.openTraceInBrowser)(server.urlPrefix("human-readable"));
} else {
const channel = await installedChromiumChannelForUI(configLocation, configCLIOverrides);
const page = await (0, import_server.openTraceViewerApp)(server.urlPrefix("precise"), "chromium", {
headless: (0, import_utils.isUnderTest)() && process.env.PWTEST_HEADED_FOR_TEST !== "1",
persistentContextOptions: {
handleSIGINT: false,
channel
}
});
page.on("close", () => cancelPromise.resolve());
}
});
}
async function installedChromiumChannelForUI(configLocation, configCLIOverrides) {
const config = await (0, import_configLoader.loadConfig)(configLocation, configCLIOverrides).catch((e) => null);
if (!config)
return void 0;
if (config.projects.some((p) => (!p.project.use.browserName || p.project.use.browserName === "chromium") && !p.project.use.channel))
return void 0;
for (const channel of ["chromium", "chrome", "msedge"]) {
if (config.projects.some((p) => p.project.use.channel === channel))
return channel;
}
return void 0;
}
async function runTestServer(configFile, configCLIOverrides, options) {
const configLocation = (0, import_configLoader.resolveConfigLocation)(configFile);
return await innerRunTestServer(configLocation, configCLIOverrides, options, async (server) => {
console.log("Listening on " + server.urlPrefix("precise").replace("http:", "ws:") + "/" + server.wsGuid());
});
}
async function innerRunTestServer(configLocation, configCLIOverrides, options, openUI) {
const testServer = new TestServer(configLocation, configCLIOverrides);
const cancelPromise = new import_utils.ManualPromise();
const sigintWatcher = new import_sigIntWatcher.SigIntWatcher();
process.stdin.on("close", () => (0, import_utils.gracefullyProcessExitDoNotHang)(0));
void sigintWatcher.promise().then(() => cancelPromise.resolve());
try {
const server = await testServer.start(options);
await openUI(server, cancelPromise);
await cancelPromise;
} finally {
await testServer.stop();
sigintWatcher.disarm();
}
return sigintWatcher.hadSignal() ? "interrupted" : "passed";
}
function chunkToPayload(type, chunk) {
if (chunk instanceof Uint8Array)
return { type, buffer: chunk.toString("base64") };
return { type, text: chunk };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestServerDispatcher,
runTestServer,
runUIMode
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var uiModeReporter_exports = {};
__export(uiModeReporter_exports, {
default: () => uiModeReporter_default
});
module.exports = __toCommonJS(uiModeReporter_exports);
var import_teleEmitter = require("../reporters/teleEmitter");
class UIModeReporter extends import_teleEmitter.TeleReporterEmitter {
constructor(options) {
super(options._send, { omitBuffers: true });
}
}
var uiModeReporter_default = UIModeReporter;
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var vcs_exports = {};
__export(vcs_exports, {
detectChangedTestFiles: () => detectChangedTestFiles
});
module.exports = __toCommonJS(vcs_exports);
var import_child_process = __toESM(require("child_process"));
var import_path = __toESM(require("path"));
var import_compilationCache = require("../transform/compilationCache");
async function detectChangedTestFiles(baseCommit, configDir) {
function gitFileList(command) {
try {
return import_child_process.default.execSync(
`git ${command}`,
{ encoding: "utf-8", stdio: "pipe", cwd: configDir }
).split("\n").filter(Boolean);
} catch (_error) {
const error = _error;
const unknownRevision = error.output.some((line) => line?.includes("unknown revision"));
if (unknownRevision) {
const isShallowClone = import_child_process.default.execSync("git rev-parse --is-shallow-repository", { encoding: "utf-8", stdio: "pipe", cwd: configDir }).trim() === "true";
if (isShallowClone) {
throw new Error([
`The repository is a shallow clone and does not have '${baseCommit}' available locally.`,
`Note that GitHub Actions checkout is shallow by default: https://github.com/actions/checkout`
].join("\n"));
}
}
throw new Error([
`Cannot detect changed files for --only-changed mode:`,
`git ${command}`,
"",
...error.output
].join("\n"));
}
}
const untrackedFiles = gitFileList(`ls-files --others --exclude-standard`).map((file) => import_path.default.join(configDir, file));
const [gitRoot] = gitFileList("rev-parse --show-toplevel");
const trackedFilesWithChanges = gitFileList(`diff ${baseCommit} --name-only`).map((file) => import_path.default.join(gitRoot, file));
return new Set((0, import_compilationCache.affectedTestFiles)([...untrackedFiles, ...trackedFilesWithChanges]));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
detectChangedTestFiles
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var watchMode_exports = {};
__export(watchMode_exports, {
runWatchModeLoop: () => runWatchModeLoop
});
module.exports = __toCommonJS(watchMode_exports);
var import_path = __toESM(require("path"));
var import_readline = __toESM(require("readline"));
var import_stream = require("stream");
var import_playwrightServer = require("playwright-core/lib/remote/playwrightServer");
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_base = require("../reporters/base");
var import_utilsBundle = require("../utilsBundle");
var import_testServer = require("./testServer");
var import_teleSuiteUpdater = require("../isomorphic/teleSuiteUpdater");
var import_testServerConnection = require("../isomorphic/testServerConnection");
class InMemoryTransport extends import_stream.EventEmitter {
constructor(send) {
super();
this._send = send;
}
close() {
this.emit("close");
}
onclose(listener) {
this.on("close", listener);
}
onerror(listener) {
}
onmessage(listener) {
this.on("message", listener);
}
onopen(listener) {
this.on("open", listener);
}
send(data) {
this._send(data);
}
}
async function runWatchModeLoop(configLocation, initialOptions) {
const options = { ...initialOptions };
let bufferMode = false;
const testServerDispatcher = new import_testServer.TestServerDispatcher(configLocation, {});
const transport = new InMemoryTransport(
async (data) => {
const { id, method, params } = JSON.parse(data);
try {
const result2 = await testServerDispatcher.transport.dispatch(method, params);
transport.emit("message", JSON.stringify({ id, result: result2 }));
} catch (e) {
transport.emit("message", JSON.stringify({ id, error: String(e) }));
}
}
);
testServerDispatcher.transport.sendEvent = (method, params) => {
transport.emit("message", JSON.stringify({ method, params }));
};
const testServerConnection = new import_testServerConnection.TestServerConnection(transport);
transport.emit("open");
const teleSuiteUpdater = new import_teleSuiteUpdater.TeleSuiteUpdater({ pathSeparator: import_path.default.sep, onUpdate() {
} });
const dirtyTestFiles = /* @__PURE__ */ new Set();
const dirtyTestIds = /* @__PURE__ */ new Set();
let onDirtyTests = new import_utils.ManualPromise();
let queue = Promise.resolve();
const changedFiles = /* @__PURE__ */ new Set();
testServerConnection.onTestFilesChanged(({ testFiles }) => {
testFiles.forEach((file) => changedFiles.add(file));
queue = queue.then(async () => {
if (changedFiles.size === 0)
return;
const { report: report2 } = await testServerConnection.listTests({ locations: options.files, projects: options.projects, grep: options.grep });
teleSuiteUpdater.processListReport(report2);
for (const test of teleSuiteUpdater.rootSuite.allTests()) {
if (changedFiles.has(test.location.file)) {
dirtyTestFiles.add(test.location.file);
dirtyTestIds.add(test.id);
}
}
changedFiles.clear();
if (dirtyTestIds.size > 0) {
onDirtyTests.resolve("changed");
onDirtyTests = new import_utils.ManualPromise();
}
});
});
testServerConnection.onReport((report2) => teleSuiteUpdater.processTestReportEvent(report2));
await testServerConnection.initialize({
interceptStdio: false,
watchTestDirs: true,
populateDependenciesOnList: true
});
await testServerConnection.runGlobalSetup({});
const { report } = await testServerConnection.listTests({});
teleSuiteUpdater.processListReport(report);
const projectNames = teleSuiteUpdater.rootSuite.suites.map((s) => s.title);
let lastRun = { type: "regular" };
let result = "passed";
while (true) {
if (bufferMode)
printBufferPrompt(dirtyTestFiles, teleSuiteUpdater.config.rootDir);
else
printPrompt();
const waitForCommand = readCommand();
const command = await Promise.race([
onDirtyTests,
waitForCommand.result
]);
if (command === "changed")
waitForCommand.dispose();
if (bufferMode && command === "changed")
continue;
const shouldRunChangedFiles = bufferMode ? command === "run" : command === "changed";
if (shouldRunChangedFiles) {
if (dirtyTestIds.size === 0)
continue;
const testIds = [...dirtyTestIds];
dirtyTestIds.clear();
dirtyTestFiles.clear();
await runTests(options, testServerConnection, { testIds, title: "files changed" });
lastRun = { type: "changed", dirtyTestIds: testIds };
continue;
}
if (command === "run") {
await runTests(options, testServerConnection);
lastRun = { type: "regular" };
continue;
}
if (command === "project") {
const { selectedProjects } = await import_utilsBundle.enquirer.prompt({
type: "multiselect",
name: "selectedProjects",
message: "Select projects",
choices: projectNames
}).catch(() => ({ selectedProjects: null }));
if (!selectedProjects)
continue;
options.projects = selectedProjects.length ? selectedProjects : void 0;
await runTests(options, testServerConnection);
lastRun = { type: "regular" };
continue;
}
if (command === "file") {
const { filePattern } = await import_utilsBundle.enquirer.prompt({
type: "text",
name: "filePattern",
message: "Input filename pattern (regex)"
}).catch(() => ({ filePattern: null }));
if (filePattern === null)
continue;
if (filePattern.trim())
options.files = filePattern.split(" ");
else
options.files = void 0;
await runTests(options, testServerConnection);
lastRun = { type: "regular" };
continue;
}
if (command === "grep") {
const { testPattern } = await import_utilsBundle.enquirer.prompt({
type: "text",
name: "testPattern",
message: "Input test name pattern (regex)"
}).catch(() => ({ testPattern: null }));
if (testPattern === null)
continue;
if (testPattern.trim())
options.grep = testPattern;
else
options.grep = void 0;
await runTests(options, testServerConnection);
lastRun = { type: "regular" };
continue;
}
if (command === "failed") {
const failedTestIds = teleSuiteUpdater.rootSuite.allTests().filter((t) => !t.ok()).map((t) => t.id);
await runTests({}, testServerConnection, { title: "running failed tests", testIds: failedTestIds });
lastRun = { type: "failed", failedTestIds };
continue;
}
if (command === "repeat") {
if (lastRun.type === "regular") {
await runTests(options, testServerConnection, { title: "re-running tests" });
continue;
} else if (lastRun.type === "changed") {
await runTests(options, testServerConnection, { title: "re-running tests", testIds: lastRun.dirtyTestIds });
} else if (lastRun.type === "failed") {
await runTests({}, testServerConnection, { title: "re-running tests", testIds: lastRun.failedTestIds });
}
continue;
}
if (command === "toggle-show-browser") {
await toggleShowBrowser();
continue;
}
if (command === "toggle-buffer-mode") {
bufferMode = !bufferMode;
continue;
}
if (command === "exit")
break;
if (command === "interrupted") {
result = "interrupted";
break;
}
}
const teardown = await testServerConnection.runGlobalTeardown({});
return result === "passed" ? teardown.status : result;
}
function readKeyPress(handler) {
const promise = new import_utils.ManualPromise();
const rl = import_readline.default.createInterface({ input: process.stdin, escapeCodeTimeout: 50 });
import_readline.default.emitKeypressEvents(process.stdin, rl);
if (process.stdin.isTTY)
process.stdin.setRawMode(true);
const listener = import_utils.eventsHelper.addEventListener(process.stdin, "keypress", (text, key) => {
const result = handler(text, key);
if (result)
promise.resolve(result);
});
const dispose = () => {
import_utils.eventsHelper.removeEventListeners([listener]);
rl.close();
if (process.stdin.isTTY)
process.stdin.setRawMode(false);
};
void promise.finally(dispose);
return { result: promise, dispose };
}
const isInterrupt = (text, key) => text === "" || text === "\x1B" || key && key.name === "escape" || key && key.ctrl && key.name === "c";
async function runTests(watchOptions, testServerConnection, options) {
printConfiguration(watchOptions, options?.title);
const waitForDone = readKeyPress((text, key) => {
if (isInterrupt(text, key)) {
testServerConnection.stopTestsNoReply({});
return "done";
}
});
await testServerConnection.runTests({
grep: watchOptions.grep,
testIds: options?.testIds,
locations: watchOptions?.files,
projects: watchOptions.projects,
connectWsEndpoint,
reuseContext: connectWsEndpoint ? true : void 0,
workers: connectWsEndpoint ? 1 : void 0,
headed: connectWsEndpoint ? true : void 0
}).finally(() => waitForDone.dispose());
}
function readCommand() {
return readKeyPress((text, key) => {
if (isInterrupt(text, key))
return "interrupted";
if (process.platform !== "win32" && key && key.ctrl && key.name === "z") {
process.kill(process.ppid, "SIGTSTP");
process.kill(process.pid, "SIGTSTP");
}
const name = key?.name;
if (name === "q")
return "exit";
if (name === "h") {
process.stdout.write(`${(0, import_base.separator)(import_base.terminalScreen)}
Run tests
${import_utils2.colors.bold("enter")} ${import_utils2.colors.dim("run tests")}
${import_utils2.colors.bold("f")} ${import_utils2.colors.dim("run failed tests")}
${import_utils2.colors.bold("r")} ${import_utils2.colors.dim("repeat last run")}
${import_utils2.colors.bold("q")} ${import_utils2.colors.dim("quit")}
Change settings
${import_utils2.colors.bold("c")} ${import_utils2.colors.dim("set project")}
${import_utils2.colors.bold("p")} ${import_utils2.colors.dim("set file filter")}
${import_utils2.colors.bold("t")} ${import_utils2.colors.dim("set title filter")}
${import_utils2.colors.bold("s")} ${import_utils2.colors.dim("toggle show & reuse the browser")}
${import_utils2.colors.bold("b")} ${import_utils2.colors.dim("toggle buffer mode")}
`);
return;
}
switch (name) {
case "return":
return "run";
case "r":
return "repeat";
case "c":
return "project";
case "p":
return "file";
case "t":
return "grep";
case "f":
return "failed";
case "s":
return "toggle-show-browser";
case "b":
return "toggle-buffer-mode";
}
});
}
let showBrowserServer;
let connectWsEndpoint = void 0;
let seq = 1;
function printConfiguration(options, title) {
const packageManagerCommand = (0, import_utils.getPackageManagerExecCommand)();
const tokens = [];
tokens.push(`${packageManagerCommand} playwright test`);
if (options.projects)
tokens.push(...options.projects.map((p) => import_utils2.colors.blue(`--project ${p}`)));
if (options.grep)
tokens.push(import_utils2.colors.red(`--grep ${options.grep}`));
if (options.files)
tokens.push(...options.files.map((a) => import_utils2.colors.bold(a)));
if (title)
tokens.push(import_utils2.colors.dim(`(${title})`));
tokens.push(import_utils2.colors.dim(`#${seq++}`));
const lines = [];
const sep = (0, import_base.separator)(import_base.terminalScreen);
lines.push("\x1Bc" + sep);
lines.push(`${tokens.join(" ")}`);
lines.push(`${import_utils2.colors.dim("Show & reuse browser:")} ${import_utils2.colors.bold(showBrowserServer ? "on" : "off")}`);
process.stdout.write(lines.join("\n"));
}
function printBufferPrompt(dirtyTestFiles, rootDir) {
const sep = (0, import_base.separator)(import_base.terminalScreen);
process.stdout.write("\x1Bc");
process.stdout.write(`${sep}
`);
if (dirtyTestFiles.size === 0) {
process.stdout.write(`${import_utils2.colors.dim("Waiting for file changes. Press")} ${import_utils2.colors.bold("q")} ${import_utils2.colors.dim("to quit or")} ${import_utils2.colors.bold("h")} ${import_utils2.colors.dim("for more options.")}
`);
return;
}
process.stdout.write(`${import_utils2.colors.dim(`${dirtyTestFiles.size} test ${dirtyTestFiles.size === 1 ? "file" : "files"} changed:`)}
`);
for (const file of dirtyTestFiles)
process.stdout.write(` \xB7 ${import_path.default.relative(rootDir, file)}
`);
process.stdout.write(`
${import_utils2.colors.dim(`Press`)} ${import_utils2.colors.bold("enter")} ${import_utils2.colors.dim("to run")}, ${import_utils2.colors.bold("q")} ${import_utils2.colors.dim("to quit or")} ${import_utils2.colors.bold("h")} ${import_utils2.colors.dim("for more options.")}
`);
}
function printPrompt() {
const sep = (0, import_base.separator)(import_base.terminalScreen);
process.stdout.write(`
${sep}
${import_utils2.colors.dim("Waiting for file changes. Press")} ${import_utils2.colors.bold("enter")} ${import_utils2.colors.dim("to run tests")}, ${import_utils2.colors.bold("q")} ${import_utils2.colors.dim("to quit or")} ${import_utils2.colors.bold("h")} ${import_utils2.colors.dim("for more options.")}
`);
}
async function toggleShowBrowser() {
if (!showBrowserServer) {
showBrowserServer = new import_playwrightServer.PlaywrightServer({ mode: "extension", path: "/" + (0, import_utils.createGuid)(), maxConnections: 1 });
connectWsEndpoint = await showBrowserServer.listen();
process.stdout.write(`${import_utils2.colors.dim("Show & reuse browser:")} ${import_utils2.colors.bold("on")}
`);
} else {
await showBrowserServer?.close();
showBrowserServer = void 0;
connectWsEndpoint = void 0;
process.stdout.write(`${import_utils2.colors.dim("Show & reuse browser:")} ${import_utils2.colors.bold("off")}
`);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
runWatchModeLoop
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var workerHost_exports = {};
__export(workerHost_exports, {
WorkerHost: () => WorkerHost
});
module.exports = __toCommonJS(workerHost_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_processHost = require("./processHost");
var import_ipc = require("../common/ipc");
var import_folders = require("../isomorphic/folders");
let lastWorkerIndex = 0;
class WorkerHost extends import_processHost.ProcessHost {
constructor(testGroup, options) {
const workerIndex = lastWorkerIndex++;
super(require.resolve("../worker/workerMain.js"), `worker-${workerIndex}`, {
...options.extraEnv,
FORCE_COLOR: "1",
DEBUG_COLORS: process.env.DEBUG_COLORS === void 0 ? "1" : process.env.DEBUG_COLORS
});
this._didFail = false;
this.workerIndex = workerIndex;
this.parallelIndex = options.parallelIndex;
this._hash = testGroup.workerHash;
this._params = {
workerIndex: this.workerIndex,
parallelIndex: options.parallelIndex,
repeatEachIndex: testGroup.repeatEachIndex,
projectId: testGroup.projectId,
config: options.config,
artifactsDir: import_path.default.join(options.outputDir, (0, import_folders.artifactsFolderName)(workerIndex)),
pauseOnError: options.pauseOnError,
pauseAtEnd: options.pauseAtEnd
};
}
async start() {
await import_fs.default.promises.mkdir(this._params.artifactsDir, { recursive: true });
return await this.startRunner(this._params, {
onStdOut: (chunk) => this.emit("stdOut", (0, import_ipc.stdioChunkToParams)(chunk)),
onStdErr: (chunk) => this.emit("stdErr", (0, import_ipc.stdioChunkToParams)(chunk))
});
}
async onExit() {
await (0, import_utils.removeFolders)([this._params.artifactsDir]);
}
async stop(didFail) {
if (didFail)
this._didFail = true;
await super.stop();
}
runTestGroup(runPayload) {
this.sendMessageNoReply({ method: "runTestGroup", params: runPayload });
}
hash() {
return this._hash;
}
projectId() {
return this._params.projectId;
}
didFail() {
return this._didFail;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
WorkerHost
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var pirates_exports = {};
__export(pirates_exports, {
addHook: () => addHook
});
module.exports = __toCommonJS(pirates_exports);
var import_module = __toESM(require("module"));
var import_path = __toESM(require("path"));
function addHook(transformHook, shouldTransform, extensions) {
const extensionsToOverwrite = extensions.filter((e) => e !== ".cjs");
const allSupportedExtensions = new Set(extensions);
const loaders = import_module.default._extensions;
const jsLoader = loaders[".js"];
for (const extension of extensionsToOverwrite) {
let newLoader2 = function(mod, filename, ...loaderArgs) {
if (allSupportedExtensions.has(import_path.default.extname(filename)) && shouldTransform(filename)) {
let newCompile2 = function(code, file, ...ignoredArgs) {
mod._compile = oldCompile;
return oldCompile.call(this, transformHook(code, filename), file);
};
var newCompile = newCompile2;
const oldCompile = mod._compile;
mod._compile = newCompile2;
}
originalLoader.call(this, mod, filename, ...loaderArgs);
};
var newLoader = newLoader2;
const originalLoader = loaders[extension] || jsLoader;
loaders[extension] = newLoader2;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addHook
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var tsconfig_loader_exports = {};
__export(tsconfig_loader_exports, {
loadTsConfig: () => loadTsConfig
});
module.exports = __toCommonJS(tsconfig_loader_exports);
var import_path = __toESM(require("path"));
var import_fs = __toESM(require("fs"));
var import_utilsBundle = require("../utilsBundle");
function loadTsConfig(configPath) {
try {
const references = [];
const config = innerLoadTsConfig(configPath, references);
return [config, ...references];
} catch (e) {
throw new Error(`Failed to load tsconfig file at ${configPath}:
${e.message}`);
}
}
function resolveConfigFile(baseConfigFile, referencedConfigFile) {
if (!referencedConfigFile.endsWith(".json"))
referencedConfigFile += ".json";
const currentDir = import_path.default.dirname(baseConfigFile);
let resolvedConfigFile = import_path.default.resolve(currentDir, referencedConfigFile);
if (referencedConfigFile.includes("/") && referencedConfigFile.includes(".") && !import_fs.default.existsSync(resolvedConfigFile))
resolvedConfigFile = import_path.default.join(currentDir, "node_modules", referencedConfigFile);
return resolvedConfigFile;
}
function innerLoadTsConfig(configFilePath, references, visited = /* @__PURE__ */ new Map()) {
if (visited.has(configFilePath))
return visited.get(configFilePath);
let result = {
tsConfigPath: configFilePath
};
visited.set(configFilePath, result);
if (!import_fs.default.existsSync(configFilePath))
return result;
const configString = import_fs.default.readFileSync(configFilePath, "utf-8");
const cleanedJson = StripBom(configString);
const parsedConfig = import_utilsBundle.json5.parse(cleanedJson);
const extendsArray = Array.isArray(parsedConfig.extends) ? parsedConfig.extends : parsedConfig.extends ? [parsedConfig.extends] : [];
for (const extendedConfig of extendsArray) {
const extendedConfigPath = resolveConfigFile(configFilePath, extendedConfig);
const base = innerLoadTsConfig(extendedConfigPath, references, visited);
Object.assign(result, base, { tsConfigPath: configFilePath });
}
if (parsedConfig.compilerOptions?.allowJs !== void 0)
result.allowJs = parsedConfig.compilerOptions.allowJs;
if (parsedConfig.compilerOptions?.paths !== void 0) {
result.paths = {
mapping: parsedConfig.compilerOptions.paths,
pathsBasePath: import_path.default.dirname(configFilePath)
};
}
if (parsedConfig.compilerOptions?.baseUrl !== void 0) {
result.absoluteBaseUrl = import_path.default.resolve(import_path.default.dirname(configFilePath), parsedConfig.compilerOptions.baseUrl);
}
for (const ref of parsedConfig.references || [])
references.push(innerLoadTsConfig(resolveConfigFile(configFilePath, ref.path), references, visited));
if (import_path.default.basename(configFilePath) === "jsconfig.json" && result.allowJs === void 0)
result.allowJs = true;
return result;
}
function StripBom(string) {
if (typeof string !== "string") {
throw new TypeError(`Expected a string, got ${typeof string}`);
}
if (string.charCodeAt(0) === 65279) {
return string.slice(1);
}
return string;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
loadTsConfig
});

Sorry, the diff of this file is too big to display

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var compilationCache_exports = {};
__export(compilationCache_exports, {
addToCompilationCache: () => addToCompilationCache,
affectedTestFiles: () => affectedTestFiles,
belongsToNodeModules: () => belongsToNodeModules,
cacheDir: () => cacheDir,
collectAffectedTestFiles: () => collectAffectedTestFiles,
currentFileDepsCollector: () => currentFileDepsCollector,
dependenciesForTestFile: () => dependenciesForTestFile,
fileDependenciesForTest: () => fileDependenciesForTest,
getFromCompilationCache: () => getFromCompilationCache,
getUserData: () => getUserData,
installSourceMapSupport: () => installSourceMapSupport,
internalDependenciesForTestFile: () => internalDependenciesForTestFile,
serializeCompilationCache: () => serializeCompilationCache,
setExternalDependencies: () => setExternalDependencies,
startCollectingFileDeps: () => startCollectingFileDeps,
stopCollectingFileDeps: () => stopCollectingFileDeps
});
module.exports = __toCommonJS(compilationCache_exports);
var import_fs = __toESM(require("fs"));
var import_os = __toESM(require("os"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_globals = require("../common/globals");
var import_utilsBundle = require("../utilsBundle");
const cacheDir = process.env.PWTEST_CACHE_DIR || (() => {
if (process.platform === "win32")
return import_path.default.join(import_os.default.tmpdir(), `playwright-transform-cache`);
return import_path.default.join(import_os.default.tmpdir(), `playwright-transform-cache-` + process.geteuid?.());
})();
const sourceMaps = /* @__PURE__ */ new Map();
const memoryCache = /* @__PURE__ */ new Map();
const fileDependencies = /* @__PURE__ */ new Map();
const externalDependencies = /* @__PURE__ */ new Map();
function installSourceMapSupport() {
Error.stackTraceLimit = 200;
import_utilsBundle.sourceMapSupport.install({
environment: "node",
handleUncaughtExceptions: false,
retrieveSourceMap(source) {
if (!sourceMaps.has(source))
return null;
const sourceMapPath = sourceMaps.get(source);
try {
return {
map: JSON.parse(import_fs.default.readFileSync(sourceMapPath, "utf-8")),
url: source
};
} catch {
return null;
}
}
});
}
function _innerAddToCompilationCacheAndSerialize(filename, entry) {
sourceMaps.set(entry.moduleUrl || filename, entry.sourceMapPath);
memoryCache.set(filename, entry);
return {
sourceMaps: [[entry.moduleUrl || filename, entry.sourceMapPath]],
memoryCache: [[filename, entry]],
fileDependencies: [],
externalDependencies: []
};
}
function getFromCompilationCache(filename, contentHash, moduleUrl) {
const cache = memoryCache.get(filename);
if (cache?.codePath) {
try {
return { cachedCode: import_fs.default.readFileSync(cache.codePath, "utf-8") };
} catch {
}
}
const filePathHash = calculateFilePathHash(filename);
const hashPrefix = filePathHash + "_" + contentHash.substring(0, 7);
const cacheFolderName = filePathHash.substring(0, 2);
const cachePath = calculateCachePath(filename, cacheFolderName, hashPrefix);
const codePath = cachePath + ".js";
const sourceMapPath = cachePath + ".map";
const dataPath = cachePath + ".data";
try {
const cachedCode = import_fs.default.readFileSync(codePath, "utf8");
const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });
return { cachedCode, serializedCache };
} catch {
}
return {
addToCache: (code, map, data) => {
if ((0, import_globals.isWorkerProcess)())
return {};
clearOldCacheEntries(cacheFolderName, filePathHash);
import_fs.default.mkdirSync(import_path.default.dirname(cachePath), { recursive: true });
if (map)
import_fs.default.writeFileSync(sourceMapPath, JSON.stringify(map), "utf8");
if (data.size)
import_fs.default.writeFileSync(dataPath, JSON.stringify(Object.fromEntries(data.entries()), void 0, 2), "utf8");
import_fs.default.writeFileSync(codePath, code, "utf8");
const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });
return { serializedCache };
}
};
}
function serializeCompilationCache() {
return {
sourceMaps: [...sourceMaps.entries()],
memoryCache: [...memoryCache.entries()],
fileDependencies: [...fileDependencies.entries()].map(([filename, deps]) => [filename, [...deps]]),
externalDependencies: [...externalDependencies.entries()].map(([filename, deps]) => [filename, [...deps]])
};
}
function addToCompilationCache(payload) {
for (const entry of payload.sourceMaps)
sourceMaps.set(entry[0], entry[1]);
for (const entry of payload.memoryCache)
memoryCache.set(entry[0], entry[1]);
for (const entry of payload.fileDependencies) {
const existing = fileDependencies.get(entry[0]) || [];
fileDependencies.set(entry[0], /* @__PURE__ */ new Set([...entry[1], ...existing]));
}
for (const entry of payload.externalDependencies) {
const existing = externalDependencies.get(entry[0]) || [];
externalDependencies.set(entry[0], /* @__PURE__ */ new Set([...entry[1], ...existing]));
}
}
function calculateFilePathHash(filePath) {
return (0, import_utils.calculateSha1)(filePath).substring(0, 10);
}
function calculateCachePath(filePath, cacheFolderName, hashPrefix) {
const fileName = hashPrefix + "_" + import_path.default.basename(filePath, import_path.default.extname(filePath)).replace(/\W/g, "");
return import_path.default.join(cacheDir, cacheFolderName, fileName);
}
function clearOldCacheEntries(cacheFolderName, filePathHash) {
const cachePath = import_path.default.join(cacheDir, cacheFolderName);
try {
const cachedRelevantFiles = import_fs.default.readdirSync(cachePath).filter((file) => file.startsWith(filePathHash));
for (const file of cachedRelevantFiles)
import_fs.default.rmSync(import_path.default.join(cachePath, file), { force: true });
} catch {
}
}
let depsCollector;
function startCollectingFileDeps() {
depsCollector = /* @__PURE__ */ new Set();
}
function stopCollectingFileDeps(filename) {
if (!depsCollector)
return;
depsCollector.delete(filename);
for (const dep of depsCollector) {
if (belongsToNodeModules(dep))
depsCollector.delete(dep);
}
fileDependencies.set(filename, depsCollector);
depsCollector = void 0;
}
function currentFileDepsCollector() {
return depsCollector;
}
function setExternalDependencies(filename, deps) {
const depsSet = new Set(deps.filter((dep) => !belongsToNodeModules(dep) && dep !== filename));
externalDependencies.set(filename, depsSet);
}
function fileDependenciesForTest() {
return fileDependencies;
}
function collectAffectedTestFiles(changedFile, testFileCollector) {
const isTestFile = (file) => fileDependencies.has(file);
if (isTestFile(changedFile))
testFileCollector.add(changedFile);
for (const [testFile, deps] of fileDependencies) {
if (deps.has(changedFile))
testFileCollector.add(testFile);
}
for (const [importingFile, depsOfImportingFile] of externalDependencies) {
if (depsOfImportingFile.has(changedFile)) {
if (isTestFile(importingFile))
testFileCollector.add(importingFile);
for (const [testFile, depsOfTestFile] of fileDependencies) {
if (depsOfTestFile.has(importingFile))
testFileCollector.add(testFile);
}
}
}
}
function affectedTestFiles(changes) {
const result = /* @__PURE__ */ new Set();
for (const change of changes)
collectAffectedTestFiles(change, result);
return [...result];
}
function internalDependenciesForTestFile(filename) {
return fileDependencies.get(filename);
}
function dependenciesForTestFile(filename) {
const result = /* @__PURE__ */ new Set();
for (const testDependency of fileDependencies.get(filename) || []) {
result.add(testDependency);
for (const externalDependency of externalDependencies.get(testDependency) || [])
result.add(externalDependency);
}
for (const dep of externalDependencies.get(filename) || [])
result.add(dep);
return result;
}
const kPlaywrightInternalPrefix = import_path.default.resolve(__dirname, "../../../playwright");
function belongsToNodeModules(file) {
if (file.includes(`${import_path.default.sep}node_modules${import_path.default.sep}`))
return true;
if (file.startsWith(kPlaywrightInternalPrefix) && (file.endsWith(".js") || file.endsWith(".mjs")))
return true;
return false;
}
async function getUserData(pluginName) {
const result = /* @__PURE__ */ new Map();
for (const [fileName, cache] of memoryCache) {
if (!cache.dataPath)
continue;
if (!import_fs.default.existsSync(cache.dataPath))
continue;
const data = JSON.parse(await import_fs.default.promises.readFile(cache.dataPath, "utf8"));
if (data[pluginName])
result.set(fileName, data[pluginName]);
}
return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addToCompilationCache,
affectedTestFiles,
belongsToNodeModules,
cacheDir,
collectAffectedTestFiles,
currentFileDepsCollector,
dependenciesForTestFile,
fileDependenciesForTest,
getFromCompilationCache,
getUserData,
installSourceMapSupport,
internalDependenciesForTestFile,
serializeCompilationCache,
setExternalDependencies,
startCollectingFileDeps,
stopCollectingFileDeps
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var portTransport_exports = {};
__export(portTransport_exports, {
PortTransport: () => PortTransport
});
module.exports = __toCommonJS(portTransport_exports);
class PortTransport {
constructor(port, handler) {
this._lastId = 0;
this._callbacks = /* @__PURE__ */ new Map();
this._port = port;
port.addEventListener("message", async (event) => {
const message = event.data;
const { id, ackId, method, params, result } = message;
if (ackId) {
const callback = this._callbacks.get(ackId);
this._callbacks.delete(ackId);
this._resetRef();
callback?.(result);
return;
}
const handlerResult = await handler(method, params);
if (id)
this._port.postMessage({ ackId: id, result: handlerResult });
});
this._resetRef();
}
post(method, params) {
this._port.postMessage({ method, params });
}
async send(method, params) {
return await new Promise((f) => {
const id = ++this._lastId;
this._callbacks.set(id, f);
this._resetRef();
this._port.postMessage({ id, method, params });
});
}
_resetRef() {
if (this._callbacks.size) {
this._port.ref();
} else {
this._port.unref();
}
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PortTransport
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var transform_exports = {};
__export(transform_exports, {
requireOrImport: () => requireOrImport,
resolveHook: () => resolveHook,
setSingleTSConfig: () => setSingleTSConfig,
setTransformConfig: () => setTransformConfig,
setTransformData: () => setTransformData,
shouldTransform: () => shouldTransform,
singleTSConfig: () => singleTSConfig,
transformConfig: () => transformConfig,
transformHook: () => transformHook,
wrapFunctionWithLocation: () => wrapFunctionWithLocation
});
module.exports = __toCommonJS(transform_exports);
var import_fs = __toESM(require("fs"));
var import_module = __toESM(require("module"));
var import_path = __toESM(require("path"));
var import_url = __toESM(require("url"));
var import_crypto = __toESM(require("crypto"));
var import_tsconfig_loader = require("../third_party/tsconfig-loader");
var import_util = require("../util");
var import_utilsBundle = require("../utilsBundle");
var import_compilationCache = require("./compilationCache");
var import_pirates = require("../third_party/pirates");
const version = require("../../package.json").version;
const cachedTSConfigs = /* @__PURE__ */ new Map();
let _transformConfig = {
babelPlugins: [],
external: []
};
let _externalMatcher = () => false;
function setTransformConfig(config) {
_transformConfig = config;
_externalMatcher = (0, import_util.createFileMatcher)(_transformConfig.external);
}
function transformConfig() {
return _transformConfig;
}
let _singleTSConfigPath;
let _singleTSConfig;
function setSingleTSConfig(value) {
_singleTSConfigPath = value;
}
function singleTSConfig() {
return _singleTSConfigPath;
}
function validateTsConfig(tsconfig) {
const pathsBase = tsconfig.absoluteBaseUrl ?? tsconfig.paths?.pathsBasePath;
const pathsFallback = tsconfig.absoluteBaseUrl ? [{ key: "*", values: ["*"] }] : [];
return {
allowJs: !!tsconfig.allowJs,
pathsBase,
paths: Object.entries(tsconfig.paths?.mapping || {}).map(([key, values]) => ({ key, values })).concat(pathsFallback)
};
}
function loadAndValidateTsconfigsForFile(file2) {
if (_singleTSConfigPath && !_singleTSConfig)
_singleTSConfig = (0, import_tsconfig_loader.loadTsConfig)(_singleTSConfigPath).map(validateTsConfig);
if (_singleTSConfig)
return _singleTSConfig;
return loadAndValidateTsconfigsForFolder(import_path.default.dirname(file2));
}
function loadAndValidateTsconfigsForFolder(folder) {
const foldersWithConfig = [];
let currentFolder = import_path.default.resolve(folder);
let result2;
while (true) {
const cached = cachedTSConfigs.get(currentFolder);
if (cached) {
result2 = cached;
break;
}
foldersWithConfig.push(currentFolder);
for (const name of ["tsconfig.json", "jsconfig.json"]) {
const configPath = import_path.default.join(currentFolder, name);
if (import_fs.default.existsSync(configPath)) {
const loaded = (0, import_tsconfig_loader.loadTsConfig)(configPath);
result2 = loaded.map(validateTsConfig);
break;
}
}
if (result2)
break;
const parentFolder = import_path.default.resolve(currentFolder, "../");
if (currentFolder === parentFolder)
break;
currentFolder = parentFolder;
}
result2 = result2 || [];
for (const folder2 of foldersWithConfig)
cachedTSConfigs.set(folder2, result2);
return result2;
}
const pathSeparator = process.platform === "win32" ? ";" : ":";
const builtins = new Set(import_module.default.builtinModules);
function resolveHook(filename, specifier) {
if (specifier.startsWith("node:") || builtins.has(specifier))
return;
if (!shouldTransform(filename))
return;
if (isRelativeSpecifier(specifier))
return (0, import_util.resolveImportSpecifierAfterMapping)(import_path.default.resolve(import_path.default.dirname(filename), specifier), false);
const isTypeScript = filename.endsWith(".ts") || filename.endsWith(".tsx");
const tsconfigs = loadAndValidateTsconfigsForFile(filename);
for (const tsconfig of tsconfigs) {
if (!isTypeScript && !tsconfig.allowJs)
continue;
let longestPrefixLength = -1;
let pathMatchedByLongestPrefix;
for (const { key, values } of tsconfig.paths) {
let matchedPartOfSpecifier = specifier;
const [keyPrefix, keySuffix] = key.split("*");
if (key.includes("*")) {
if (keyPrefix) {
if (!specifier.startsWith(keyPrefix))
continue;
matchedPartOfSpecifier = matchedPartOfSpecifier.substring(keyPrefix.length, matchedPartOfSpecifier.length);
}
if (keySuffix) {
if (!specifier.endsWith(keySuffix))
continue;
matchedPartOfSpecifier = matchedPartOfSpecifier.substring(0, matchedPartOfSpecifier.length - keySuffix.length);
}
} else {
if (specifier !== key)
continue;
matchedPartOfSpecifier = specifier;
}
if (keyPrefix.length <= longestPrefixLength)
continue;
for (const value of values) {
let candidate = value;
if (value.includes("*"))
candidate = candidate.replace("*", matchedPartOfSpecifier);
candidate = import_path.default.resolve(tsconfig.pathsBase, candidate);
const existing = (0, import_util.resolveImportSpecifierAfterMapping)(candidate, true);
if (existing) {
longestPrefixLength = keyPrefix.length;
pathMatchedByLongestPrefix = existing;
}
}
}
if (pathMatchedByLongestPrefix)
return pathMatchedByLongestPrefix;
}
if (import_path.default.isAbsolute(specifier)) {
return (0, import_util.resolveImportSpecifierAfterMapping)(specifier, false);
}
}
function shouldTransform(filename) {
if (_externalMatcher(filename))
return false;
return !(0, import_compilationCache.belongsToNodeModules)(filename);
}
let transformData;
function setTransformData(pluginName, value) {
transformData.set(pluginName, value);
}
function transformHook(originalCode, filename, moduleUrl) {
const hasPreprocessor = process.env.PW_TEST_SOURCE_TRANSFORM && process.env.PW_TEST_SOURCE_TRANSFORM_SCOPE && process.env.PW_TEST_SOURCE_TRANSFORM_SCOPE.split(pathSeparator).some((f) => filename.startsWith(f));
const pluginsPrologue = _transformConfig.babelPlugins;
const pluginsEpilogue = hasPreprocessor ? [[process.env.PW_TEST_SOURCE_TRANSFORM]] : [];
const hash = calculateHash(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);
const { cachedCode, addToCache, serializedCache } = (0, import_compilationCache.getFromCompilationCache)(filename, hash, moduleUrl);
if (cachedCode !== void 0)
return { code: cachedCode, serializedCache };
process.env.BROWSERSLIST_IGNORE_OLD_DATA = "true";
const { babelTransform } = require("./babelBundle");
transformData = /* @__PURE__ */ new Map();
const babelResult = babelTransform(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);
if (!babelResult?.code)
return { code: originalCode, serializedCache };
const { code, map } = babelResult;
const added = addToCache(code, map, transformData);
return { code, serializedCache: added.serializedCache };
}
function calculateHash(content, filePath, isModule2, pluginsPrologue, pluginsEpilogue) {
const hash = import_crypto.default.createHash("sha1").update(isModule2 ? "esm" : "no_esm").update(content).update(filePath).update(version).update(pluginsPrologue.map((p) => p[0]).join(",")).update(pluginsEpilogue.map((p) => p[0]).join(",")).digest("hex");
return hash;
}
async function requireOrImport(file) {
installTransformIfNeeded();
const isModule = (0, import_util.fileIsModule)(file);
const esmImport = () => eval(`import(${JSON.stringify(import_url.default.pathToFileURL(file))})`);
if (isModule) {
return await esmImport().finally(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
}
const result = require(file);
const depsCollector = (0, import_compilationCache.currentFileDepsCollector)();
if (depsCollector) {
const module2 = require.cache[file];
if (module2)
collectCJSDependencies(module2, depsCollector);
}
return result;
}
let transformInstalled = false;
function installTransformIfNeeded() {
if (transformInstalled)
return;
transformInstalled = true;
(0, import_compilationCache.installSourceMapSupport)();
const originalResolveFilename = import_module.default._resolveFilename;
function resolveFilename(specifier, parent, ...rest) {
if (parent) {
const resolved = resolveHook(parent.filename, specifier);
if (resolved !== void 0)
specifier = resolved;
}
return originalResolveFilename.call(this, specifier, parent, ...rest);
}
import_module.default._resolveFilename = resolveFilename;
(0, import_pirates.addHook)((code, filename) => {
return transformHook(code, filename).code;
}, shouldTransform, [".ts", ".tsx", ".js", ".jsx", ".mjs", ".mts", ".cjs", ".cts"]);
}
const collectCJSDependencies = (module2, dependencies) => {
module2.children.forEach((child) => {
if (!(0, import_compilationCache.belongsToNodeModules)(child.filename) && !dependencies.has(child.filename)) {
dependencies.add(child.filename);
collectCJSDependencies(child, dependencies);
}
});
};
function wrapFunctionWithLocation(func) {
return (...args) => {
const oldPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = (error, stackFrames) => {
const frame = import_utilsBundle.sourceMapSupport.wrapCallSite(stackFrames[1]);
const fileName = frame.getFileName();
const file2 = fileName && fileName.startsWith("file://") ? import_url.default.fileURLToPath(fileName) : fileName;
return {
file: file2,
line: frame.getLineNumber(),
column: frame.getColumnNumber()
};
};
const oldStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 2;
const obj = {};
Error.captureStackTrace(obj);
const location = obj.stack;
Error.stackTraceLimit = oldStackTraceLimit;
Error.prepareStackTrace = oldPrepareStackTrace;
return func(location, ...args);
};
}
function isRelativeSpecifier(specifier) {
return specifier === "." || specifier === ".." || specifier.startsWith("./") || specifier.startsWith("../");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
requireOrImport,
resolveHook,
setSingleTSConfig,
setTransformConfig,
setTransformData,
shouldTransform,
singleTSConfig,
transformConfig,
transformHook,
wrapFunctionWithLocation
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var utilsBundle_exports = {};
__export(utilsBundle_exports, {
chokidar: () => chokidar,
enquirer: () => enquirer,
getEastAsianWidth: () => getEastAsianWidth,
json5: () => json5,
sourceMapSupport: () => sourceMapSupport,
stoppable: () => stoppable
});
module.exports = __toCommonJS(utilsBundle_exports);
const json5 = require("./utilsBundleImpl").json5;
const sourceMapSupport = require("./utilsBundleImpl").sourceMapSupport;
const stoppable = require("./utilsBundleImpl").stoppable;
const enquirer = require("./utilsBundleImpl").enquirer;
const chokidar = require("./utilsBundleImpl").chokidar;
const getEastAsianWidth = require("./utilsBundleImpl").getEastAsianWidth;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
chokidar,
enquirer,
getEastAsianWidth,
json5,
sourceMapSupport,
stoppable
});

Sorry, the diff of this file is too big to display

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var fixtureRunner_exports = {};
__export(fixtureRunner_exports, {
FixtureRunner: () => FixtureRunner
});
module.exports = __toCommonJS(fixtureRunner_exports);
var import_utils = require("playwright-core/lib/utils");
var import_fixtures = require("../common/fixtures");
var import_util = require("../util");
class Fixture {
constructor(runner, registration) {
this.failed = false;
this._deps = /* @__PURE__ */ new Set();
this._usages = /* @__PURE__ */ new Set();
this.runner = runner;
this.registration = registration;
this.value = null;
const isUserFixture = this.registration.location && (0, import_util.filterStackFile)(this.registration.location.file);
const title = this.registration.customTitle || this.registration.name;
const location = isUserFixture ? this.registration.location : void 0;
this._stepInfo = { title: `Fixture ${(0, import_utils.escapeWithQuotes)(title, '"')}`, category: "fixture", location };
if (this.registration.box === "self")
this._stepInfo = void 0;
else if (this.registration.box)
this._stepInfo.group = isUserFixture ? "configuration" : "internal";
this._setupDescription = {
title,
phase: "setup",
location,
slot: this.registration.timeout === void 0 ? void 0 : {
timeout: this.registration.timeout,
elapsed: 0
}
};
this._teardownDescription = { ...this._setupDescription, phase: "teardown" };
}
async setup(testInfo, runnable) {
this.runner.instanceForId.set(this.registration.id, this);
if (typeof this.registration.fn !== "function") {
this.value = this.registration.fn;
return;
}
const run = () => testInfo._runWithTimeout({ ...runnable, fixture: this._setupDescription }, () => this._setupInternal(testInfo));
if (this._stepInfo)
await testInfo._runAsStep(this._stepInfo, run);
else
await run();
}
async _setupInternal(testInfo) {
const params = {};
for (const name of this.registration.deps) {
const registration = this.runner.pool.resolve(name, this.registration);
const dep = this.runner.instanceForId.get(registration.id);
if (!dep) {
this.failed = true;
return;
}
dep._usages.add(this);
this._deps.add(dep);
params[name] = dep.value;
if (dep.failed) {
this.failed = true;
return;
}
}
let called = false;
const useFuncStarted = new import_utils.ManualPromise();
const useFunc = async (value) => {
if (called)
throw new Error(`Cannot provide fixture value for the second time`);
called = true;
this.value = value;
this._useFuncFinished = new import_utils.ManualPromise();
useFuncStarted.resolve();
await this._useFuncFinished;
};
const workerInfo = { config: testInfo.config, parallelIndex: testInfo.parallelIndex, workerIndex: testInfo.workerIndex, project: testInfo.project };
const info = this.registration.scope === "worker" ? workerInfo : testInfo;
this._selfTeardownComplete = (async () => {
try {
await this.registration.fn(params, useFunc, info);
if (!useFuncStarted.isDone())
throw new Error(`use() was not called in fixture "${this.registration.name}"`);
} catch (error) {
this.failed = true;
if (!useFuncStarted.isDone())
useFuncStarted.reject(error);
else
throw error;
}
})();
await useFuncStarted;
}
async teardown(testInfo, runnable) {
try {
const fixtureRunnable = { ...runnable, fixture: this._teardownDescription };
if (!testInfo._timeoutManager.isTimeExhaustedFor(fixtureRunnable)) {
const run = () => testInfo._runWithTimeout(fixtureRunnable, () => this._teardownInternal());
if (this._stepInfo)
await testInfo._runAsStep(this._stepInfo, run);
else
await run();
}
} finally {
for (const dep of this._deps)
dep._usages.delete(this);
this.runner.instanceForId.delete(this.registration.id);
}
}
async _teardownInternal() {
if (typeof this.registration.fn !== "function")
return;
if (this._usages.size !== 0) {
console.error("Internal error: fixture integrity at", this._teardownDescription.title);
this._usages.clear();
}
if (this._useFuncFinished) {
this._useFuncFinished.resolve();
this._useFuncFinished = void 0;
await this._selfTeardownComplete;
}
}
_collectFixturesInTeardownOrder(scope, collector) {
if (this.registration.scope !== scope)
return;
for (const fixture of this._usages)
fixture._collectFixturesInTeardownOrder(scope, collector);
collector.add(this);
}
}
class FixtureRunner {
constructor() {
this.testScopeClean = true;
this.instanceForId = /* @__PURE__ */ new Map();
}
setPool(pool) {
if (!this.testScopeClean)
throw new Error("Did not teardown test scope");
if (this.pool && pool.digest !== this.pool.digest) {
throw new Error([
`Playwright detected inconsistent test.use() options.`,
`Most common mistakes that lead to this issue:`,
` - Calling test.use() outside of the test file, for example in a common helper.`,
` - One test file imports from another test file.`
].join("\n"));
}
this.pool = pool;
}
_collectFixturesInSetupOrder(registration, collector) {
if (collector.has(registration))
return;
for (const name of registration.deps) {
const dep = this.pool.resolve(name, registration);
this._collectFixturesInSetupOrder(dep, collector);
}
collector.add(registration);
}
async teardownScope(scope, testInfo, runnable) {
const fixtures = Array.from(this.instanceForId.values()).reverse();
const collector = /* @__PURE__ */ new Set();
for (const fixture of fixtures)
fixture._collectFixturesInTeardownOrder(scope, collector);
let firstError;
for (const fixture of collector) {
try {
await fixture.teardown(testInfo, runnable);
} catch (error) {
firstError = firstError ?? error;
}
}
if (scope === "test")
this.testScopeClean = true;
if (firstError)
throw firstError;
}
async resolveParametersForFunction(fn, testInfo, autoFixtures, runnable) {
const collector = /* @__PURE__ */ new Set();
const auto = [];
for (const registration of this.pool.autoFixtures()) {
let shouldRun = true;
if (autoFixtures === "all-hooks-only")
shouldRun = registration.scope === "worker" || registration.auto === "all-hooks-included";
else if (autoFixtures === "worker")
shouldRun = registration.scope === "worker";
if (shouldRun)
auto.push(registration);
}
auto.sort((r1, r2) => (r1.scope === "worker" ? 0 : 1) - (r2.scope === "worker" ? 0 : 1));
for (const registration of auto)
this._collectFixturesInSetupOrder(registration, collector);
const names = getRequiredFixtureNames(fn);
for (const name of names)
this._collectFixturesInSetupOrder(this.pool.resolve(name), collector);
for (const registration of collector)
await this._setupFixtureForRegistration(registration, testInfo, runnable);
const params = {};
for (const name of names) {
const registration = this.pool.resolve(name);
const fixture = this.instanceForId.get(registration.id);
if (!fixture || fixture.failed)
return null;
params[name] = fixture.value;
}
return params;
}
async resolveParametersAndRunFunction(fn, testInfo, autoFixtures, runnable) {
const params = await this.resolveParametersForFunction(fn, testInfo, autoFixtures, runnable);
if (params === null) {
return null;
}
await testInfo._runWithTimeout(runnable, () => fn(params, testInfo));
}
async _setupFixtureForRegistration(registration, testInfo, runnable) {
if (registration.scope === "test")
this.testScopeClean = false;
let fixture = this.instanceForId.get(registration.id);
if (fixture)
return fixture;
fixture = new Fixture(this, registration);
await fixture.setup(testInfo, runnable);
return fixture;
}
dependsOnWorkerFixturesOnly(fn, location) {
const names = getRequiredFixtureNames(fn, location);
for (const name of names) {
const registration = this.pool.resolve(name);
if (registration.scope !== "worker")
return false;
}
return true;
}
}
function getRequiredFixtureNames(fn, location) {
return (0, import_fixtures.fixtureParameterNames)(fn, location ?? { file: "<unknown>", line: 1, column: 1 }, (e) => {
throw new Error(`${(0, import_util.formatLocation)(e.location)}: ${e.message}`);
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
FixtureRunner
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testInfo_exports = {};
__export(testInfo_exports, {
StepSkipError: () => StepSkipError,
TestInfoImpl: () => TestInfoImpl,
TestSkipError: () => TestSkipError,
TestStepInfoImpl: () => TestStepInfoImpl
});
module.exports = __toCommonJS(testInfo_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_timeoutManager = require("./timeoutManager");
var import_util = require("../util");
var import_testTracing = require("./testTracing");
var import_util2 = require("./util");
var import_transform = require("../transform/transform");
class TestInfoImpl {
constructor(configInternal, projectInternal, workerParams, test, retry, onStepBegin, onStepEnd, onAttach) {
this._snapshotNames = { lastAnonymousSnapshotIndex: 0, lastNamedSnapshotIndex: {} };
this._ariaSnapshotNames = { lastAnonymousSnapshotIndex: 0, lastNamedSnapshotIndex: {} };
this._wasInterrupted = false;
this._lastStepId = 0;
this._steps = [];
this._stepMap = /* @__PURE__ */ new Map();
this._onDidFinishTestFunctions = [];
this._hasNonRetriableError = false;
this._hasUnhandledError = false;
this._allowSkips = false;
this.duration = 0;
this.annotations = [];
this.attachments = [];
this.status = "passed";
this.snapshotSuffix = "";
this.errors = [];
this.testId = test?.id ?? "";
this._onStepBegin = onStepBegin;
this._onStepEnd = onStepEnd;
this._onAttach = onAttach;
this._startTime = (0, import_utils.monotonicTime)();
this._startWallTime = Date.now();
this._requireFile = test?._requireFile ?? "";
this._uniqueSymbol = Symbol("testInfoUniqueSymbol");
this._workerParams = workerParams;
this.repeatEachIndex = workerParams.repeatEachIndex;
this.retry = retry;
this.workerIndex = workerParams.workerIndex;
this.parallelIndex = workerParams.parallelIndex;
this._projectInternal = projectInternal;
this.project = projectInternal.project;
this._configInternal = configInternal;
this.config = configInternal.config;
this.title = test?.title ?? "";
this.titlePath = test?.titlePath() ?? [];
this.file = test?.location.file ?? "";
this.line = test?.location.line ?? 0;
this.column = test?.location.column ?? 0;
this.tags = test?.tags ?? [];
this.fn = test?.fn ?? (() => {
});
this.expectedStatus = test?.expectedStatus ?? "skipped";
this._timeoutManager = new import_timeoutManager.TimeoutManager(this.project.timeout);
if (configInternal.configCLIOverrides.debug)
this._setDebugMode();
this.outputDir = (() => {
const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile.replace(/\.(spec|test)\.(js|ts|jsx|tsx|mjs|mts|cjs|cts)$/, ""));
const sanitizedRelativePath = relativeTestFilePath.replace(process.platform === "win32" ? new RegExp("\\\\", "g") : new RegExp("/", "g"), "-");
const fullTitleWithoutSpec = this.titlePath.slice(1).join(" ");
let testOutputDir = (0, import_util.trimLongString)(sanitizedRelativePath + "-" + (0, import_utils.sanitizeForFilePath)(fullTitleWithoutSpec), import_util.windowsFilesystemFriendlyLength);
if (projectInternal.id)
testOutputDir += "-" + (0, import_utils.sanitizeForFilePath)(projectInternal.id);
if (this.retry)
testOutputDir += "-retry" + this.retry;
if (this.repeatEachIndex)
testOutputDir += "-repeat" + this.repeatEachIndex;
return import_path.default.join(this.project.outputDir, testOutputDir);
})();
this.snapshotDir = (() => {
const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile);
return import_path.default.join(this.project.snapshotDir, relativeTestFilePath + "-snapshots");
})();
this._attachmentsPush = this.attachments.push.bind(this.attachments);
this.attachments.push = (...attachments) => {
for (const a of attachments)
this._attach(a, this._parentStep()?.stepId);
return this.attachments.length;
};
this._tracing = new import_testTracing.TestTracing(this, workerParams.artifactsDir);
this.skip = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("skip", location, args));
this.fixme = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("fixme", location, args));
this.fail = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("fail", location, args));
this.slow = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => this._modifier("slow", location, args));
}
get error() {
return this.errors[0];
}
set error(e) {
if (e === void 0)
throw new Error("Cannot assign testInfo.error undefined value!");
this.errors[0] = e;
}
get timeout() {
return this._timeoutManager.defaultSlot().timeout;
}
set timeout(timeout) {
}
_deadlineForMatcher(timeout) {
const startTime = (0, import_utils.monotonicTime)();
const matcherDeadline = timeout ? startTime + timeout : import_timeoutManager.kMaxDeadline;
const testDeadline = this._timeoutManager.currentSlotDeadline() - 250;
const matcherMessage = `Timeout ${timeout}ms exceeded while waiting on the predicate`;
const testMessage = `Test timeout of ${this.timeout}ms exceeded`;
return { deadline: Math.min(testDeadline, matcherDeadline), timeoutMessage: testDeadline < matcherDeadline ? testMessage : matcherMessage };
}
static _defaultDeadlineForMatcher(timeout) {
return { deadline: timeout ? (0, import_utils.monotonicTime)() + timeout : 0, timeoutMessage: `Timeout ${timeout}ms exceeded while waiting on the predicate` };
}
_modifier(type, location, modifierArgs) {
if (typeof modifierArgs[1] === "function") {
throw new Error([
"It looks like you are calling test.skip() inside the test and pass a callback.",
"Pass a condition instead and optional description instead:",
`test('my test', async ({ page, isMobile }) => {`,
` test.skip(isMobile, 'This test is not applicable on mobile');`,
`});`
].join("\n"));
}
if (modifierArgs.length >= 1 && !modifierArgs[0])
return;
const description = modifierArgs[1];
this.annotations.push({ type, description, location });
if (type === "slow") {
this._timeoutManager.slow();
} else if (type === "skip" || type === "fixme") {
this.expectedStatus = "skipped";
throw new TestSkipError("Test is skipped: " + (description || ""));
} else if (type === "fail") {
if (this.expectedStatus !== "skipped")
this.expectedStatus = "failed";
}
}
_findLastPredefinedStep(steps) {
for (let i = steps.length - 1; i >= 0; i--) {
const child = this._findLastPredefinedStep(steps[i].steps);
if (child)
return child;
if ((steps[i].category === "hook" || steps[i].category === "fixture") && !steps[i].endWallTime)
return steps[i];
}
}
_parentStep() {
return (0, import_utils.currentZone)().data("stepZone") ?? this._findLastPredefinedStep(this._steps);
}
_addStep(data, parentStep) {
const stepId = `${data.category}@${++this._lastStepId}`;
if (data.category === "hook" || data.category === "fixture") {
parentStep = this._findLastPredefinedStep(this._steps);
} else {
if (!parentStep)
parentStep = this._parentStep();
}
const filteredStack = (0, import_util.filteredStackTrace)((0, import_utils.captureRawStack)());
let boxedStack = parentStep?.boxedStack;
let location = data.location;
if (!boxedStack && data.box) {
boxedStack = filteredStack.slice(1);
location = location || boxedStack[0];
}
location = location || filteredStack[0];
const step = {
...data,
stepId,
group: parentStep?.group ?? data.group,
boxedStack,
location,
steps: [],
attachmentIndices: [],
info: new TestStepInfoImpl(this, stepId, data.title, parentStep?.info),
complete: (result) => {
if (step.endWallTime)
return;
step.endWallTime = Date.now();
if (result.error) {
if (typeof result.error === "object" && !result.error?.[stepSymbol])
result.error[stepSymbol] = step;
const error = (0, import_util2.testInfoError)(result.error);
if (step.boxedStack)
error.stack = `${error.message}
${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
step.error = error;
}
if (!step.error) {
for (const childStep of step.steps) {
if (childStep.error && childStep.infectParentStepsWithError) {
step.error = childStep.error;
step.infectParentStepsWithError = true;
break;
}
}
}
if (!step.group) {
const payload = {
testId: this.testId,
stepId,
wallTime: step.endWallTime,
error: step.error,
suggestedRebaseline: result.suggestedRebaseline,
annotations: step.info.annotations
};
this._onStepEnd(payload);
}
if (step.group !== "internal") {
const errorForTrace = step.error ? { name: "", message: step.error.message || "", stack: step.error.stack } : void 0;
const attachments = step.attachmentIndices.map((i) => this.attachments[i]);
this._tracing.appendAfterActionForStep(stepId, errorForTrace, attachments, step.info.annotations);
}
}
};
const parentStepList = parentStep ? parentStep.steps : this._steps;
parentStepList.push(step);
this._stepMap.set(stepId, step);
if (!step.group) {
const payload = {
testId: this.testId,
stepId,
parentStepId: parentStep ? parentStep.stepId : void 0,
title: step.title,
category: step.category,
wallTime: Date.now(),
location: step.location
};
this._onStepBegin(payload);
}
if (step.group !== "internal") {
this._tracing.appendBeforeActionForStep({
stepId,
parentId: parentStep?.stepId,
title: step.title,
category: step.category,
params: step.params,
stack: step.location ? [step.location] : [],
group: step.group
});
}
return step;
}
_interrupt() {
this._wasInterrupted = true;
this._timeoutManager.interrupt();
if (this.status === "passed")
this.status = "interrupted";
}
_failWithError(error) {
if (this.status === "passed" || this.status === "skipped")
this.status = error instanceof import_timeoutManager.TimeoutManagerError ? "timedOut" : "failed";
const serialized = (0, import_util2.testInfoError)(error);
const step = typeof error === "object" ? error?.[stepSymbol] : void 0;
if (step && step.boxedStack)
serialized.stack = `${error.name}: ${error.message}
${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
this.errors.push(serialized);
this._tracing.appendForError(serialized);
}
async _runAsStep(stepInfo, cb) {
const step = this._addStep(stepInfo);
try {
await cb();
step.complete({});
} catch (error) {
step.complete({ error });
throw error;
}
}
async _runWithTimeout(runnable, cb) {
try {
await this._timeoutManager.withRunnable(runnable, async () => {
try {
await cb();
} catch (e) {
if (this._allowSkips && e instanceof TestSkipError) {
if (this.status === "passed")
this.status = "skipped";
} else {
this._failWithError(e);
}
throw e;
}
});
} catch (error) {
if (!this._wasInterrupted && error instanceof import_timeoutManager.TimeoutManagerError)
this._failWithError(error);
throw error;
}
}
_isFailure() {
return this.status !== "skipped" && this.status !== this.expectedStatus;
}
_currentHookType() {
const type = this._timeoutManager.currentSlotType();
return ["beforeAll", "afterAll", "beforeEach", "afterEach"].includes(type) ? type : void 0;
}
_setDebugMode() {
this._timeoutManager.setIgnoreTimeouts();
}
// ------------ TestInfo methods ------------
async attach(name, options = {}) {
const step = this._addStep({
title: `Attach ${(0, import_utils.escapeWithQuotes)(name, '"')}`,
category: "test.attach"
});
this._attach(
await (0, import_util.normalizeAndSaveAttachment)(this.outputPath(), name, options),
step.group ? void 0 : step.stepId
);
step.complete({});
}
_attach(attachment, stepId) {
const index = this._attachmentsPush(attachment) - 1;
if (stepId) {
this._stepMap.get(stepId).attachmentIndices.push(index);
} else {
const stepId2 = `attach@${(0, import_utils.createGuid)()}`;
this._tracing.appendBeforeActionForStep({ stepId: stepId2, title: `Attach ${(0, import_utils.escapeWithQuotes)(attachment.name, '"')}`, category: "test.attach", stack: [] });
this._tracing.appendAfterActionForStep(stepId2, void 0, [attachment]);
}
this._onAttach({
testId: this.testId,
name: attachment.name,
contentType: attachment.contentType,
path: attachment.path,
body: attachment.body?.toString("base64"),
stepId
});
}
outputPath(...pathSegments) {
const outputPath = this._getOutputPath(...pathSegments);
import_fs.default.mkdirSync(this.outputDir, { recursive: true });
return outputPath;
}
_getOutputPath(...pathSegments) {
const joinedPath = import_path.default.join(...pathSegments);
const outputPath = (0, import_util.getContainedPath)(this.outputDir, joinedPath);
if (outputPath)
return outputPath;
throw new Error(`The outputPath is not allowed outside of the parent directory. Please fix the defined path.
outputPath: ${joinedPath}`);
}
_fsSanitizedTestName() {
const fullTitleWithoutSpec = this.titlePath.slice(1).join(" ");
return (0, import_utils.sanitizeForFilePath)((0, import_util.trimLongString)(fullTitleWithoutSpec));
}
_resolveSnapshotPaths(kind, name, updateSnapshotIndex, anonymousExtension) {
const snapshotNames = kind === "aria" ? this._ariaSnapshotNames : this._snapshotNames;
const defaultExtensions = { "aria": ".aria.yml", "screenshot": ".png", "snapshot": ".txt" };
const ariaAwareExtname = (filePath) => kind === "aria" && filePath.endsWith(".aria.yml") ? ".aria.yml" : import_path.default.extname(filePath);
let subPath;
let ext;
let relativeOutputPath;
if (!name) {
const index = snapshotNames.lastAnonymousSnapshotIndex + 1;
if (updateSnapshotIndex === "updateSnapshotIndex")
snapshotNames.lastAnonymousSnapshotIndex = index;
const fullTitleWithoutSpec = [...this.titlePath.slice(1), index].join(" ");
ext = anonymousExtension ?? defaultExtensions[kind];
subPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(fullTitleWithoutSpec) + ext, ext);
relativeOutputPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(fullTitleWithoutSpec, import_util.windowsFilesystemFriendlyLength) + ext, ext);
} else {
if (Array.isArray(name)) {
subPath = import_path.default.join(...name);
relativeOutputPath = import_path.default.join(...name);
ext = ariaAwareExtname(subPath);
} else {
ext = ariaAwareExtname(name);
subPath = (0, import_util.sanitizeFilePathBeforeExtension)(name, ext);
relativeOutputPath = (0, import_util.sanitizeFilePathBeforeExtension)((0, import_util.trimLongString)(name, import_util.windowsFilesystemFriendlyLength), ext);
}
const index = (snapshotNames.lastNamedSnapshotIndex[relativeOutputPath] || 0) + 1;
if (updateSnapshotIndex === "updateSnapshotIndex")
snapshotNames.lastNamedSnapshotIndex[relativeOutputPath] = index;
if (index > 1)
relativeOutputPath = (0, import_util.addSuffixToFilePath)(relativeOutputPath, `-${index - 1}`);
}
const absoluteSnapshotPath = this._applyPathTemplate(kind, subPath, ext);
return { absoluteSnapshotPath, relativeOutputPath };
}
_applyPathTemplate(kind, relativePath, ext) {
const legacyTemplate = "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{-snapshotSuffix}{ext}";
let template;
if (kind === "screenshot") {
template = this._projectInternal.expect?.toHaveScreenshot?.pathTemplate || this._projectInternal.snapshotPathTemplate || legacyTemplate;
} else if (kind === "aria") {
const ariaDefaultTemplate = "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{ext}";
template = this._projectInternal.expect?.toMatchAriaSnapshot?.pathTemplate || this._projectInternal.snapshotPathTemplate || ariaDefaultTemplate;
} else {
template = this._projectInternal.snapshotPathTemplate || legacyTemplate;
}
const dir = import_path.default.dirname(relativePath);
const name = import_path.default.basename(relativePath, ext);
const relativeTestFilePath = import_path.default.relative(this.project.testDir, this._requireFile);
const parsedRelativeTestFilePath = import_path.default.parse(relativeTestFilePath);
const projectNamePathSegment = (0, import_utils.sanitizeForFilePath)(this.project.name);
const snapshotPath = template.replace(/\{(.)?testDir\}/g, "$1" + this.project.testDir).replace(/\{(.)?snapshotDir\}/g, "$1" + this.project.snapshotDir).replace(/\{(.)?snapshotSuffix\}/g, this.snapshotSuffix ? "$1" + this.snapshotSuffix : "").replace(/\{(.)?testFileDir\}/g, "$1" + parsedRelativeTestFilePath.dir).replace(/\{(.)?platform\}/g, "$1" + process.platform).replace(/\{(.)?projectName\}/g, projectNamePathSegment ? "$1" + projectNamePathSegment : "").replace(/\{(.)?testName\}/g, "$1" + this._fsSanitizedTestName()).replace(/\{(.)?testFileName\}/g, "$1" + parsedRelativeTestFilePath.base).replace(/\{(.)?testFilePath\}/g, "$1" + relativeTestFilePath).replace(/\{(.)?arg\}/g, "$1" + import_path.default.join(dir, name)).replace(/\{(.)?ext\}/g, ext ? "$1" + ext : "");
return import_path.default.normalize(import_path.default.resolve(this._configInternal.configDir, snapshotPath));
}
snapshotPath(...args) {
let name = args;
let kind = "snapshot";
const options = args[args.length - 1];
if (options && typeof options === "object") {
kind = options.kind ?? kind;
name = args.slice(0, -1);
}
if (!["snapshot", "screenshot", "aria"].includes(kind))
throw new Error(`testInfo.snapshotPath: unknown kind "${kind}", must be one of "snapshot", "screenshot" or "aria"`);
return this._resolveSnapshotPaths(kind, name.length <= 1 ? name[0] : name, "dontUpdateSnapshotIndex").absoluteSnapshotPath;
}
setTimeout(timeout) {
this._timeoutManager.setTimeout(timeout);
}
_pauseOnError() {
return this._workerParams.pauseOnError;
}
_pauseAtEnd() {
return this._workerParams.pauseAtEnd;
}
}
class TestStepInfoImpl {
constructor(testInfo, stepId, title, parentStep) {
this.annotations = [];
this._testInfo = testInfo;
this._stepId = stepId;
this._title = title;
this._parentStep = parentStep;
this.skip = (0, import_transform.wrapFunctionWithLocation)((location, ...args) => {
if (args.length > 0 && !args[0])
return;
const description = args[1];
this.annotations.push({ type: "skip", description, location });
throw new StepSkipError(description);
});
}
async _runStepBody(skip, body, location) {
if (skip) {
this.annotations.push({ type: "skip", location });
return void 0;
}
try {
return await body(this);
} catch (e) {
if (e instanceof StepSkipError)
return void 0;
throw e;
}
}
_attachToStep(attachment) {
this._testInfo._attach(attachment, this._stepId);
}
async attach(name, options) {
this._attachToStep(await (0, import_util.normalizeAndSaveAttachment)(this._testInfo.outputPath(), name, options));
}
get titlePath() {
const parent = this._parentStep ?? this._testInfo;
return [...parent.titlePath, this._title];
}
}
class TestSkipError extends Error {
}
class StepSkipError extends Error {
}
const stepSymbol = Symbol("step");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
StepSkipError,
TestInfoImpl,
TestSkipError,
TestStepInfoImpl
});
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var testTracing_exports = {};
__export(testTracing_exports, {
TestTracing: () => TestTracing,
testTraceEntryName: () => testTraceEntryName
});
module.exports = __toCommonJS(testTracing_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_zipBundle = require("playwright-core/lib/zipBundle");
var import_util = require("../util");
const testTraceEntryName = "test.trace";
const version = 8;
let traceOrdinal = 0;
class TestTracing {
constructor(testInfo, artifactsDir) {
this._traceEvents = [];
this._temporaryTraceFiles = [];
this._didFinishTestFunctionAndAfterEachHooks = false;
this._testInfo = testInfo;
this._artifactsDir = artifactsDir;
this._tracesDir = import_path.default.join(this._artifactsDir, "traces");
this._contextCreatedEvent = {
version,
type: "context-options",
origin: "testRunner",
browserName: "",
options: {},
platform: process.platform,
wallTime: Date.now(),
monotonicTime: (0, import_utils.monotonicTime)(),
sdkLanguage: "javascript"
};
this._appendTraceEvent(this._contextCreatedEvent);
}
_shouldCaptureTrace() {
if (this._options?.mode === "on")
return true;
if (this._options?.mode === "retain-on-failure")
return true;
if (this._options?.mode === "on-first-retry" && this._testInfo.retry === 1)
return true;
if (this._options?.mode === "on-all-retries" && this._testInfo.retry > 0)
return true;
if (this._options?.mode === "retain-on-first-failure" && this._testInfo.retry === 0)
return true;
return false;
}
async startIfNeeded(value) {
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true, attachments: true, _live: false, mode: "off" };
if (!value) {
this._options = defaultTraceOptions;
} else if (typeof value === "string") {
this._options = { ...defaultTraceOptions, mode: value === "retry-with-trace" ? "on-first-retry" : value };
} else {
const mode = value.mode || "off";
this._options = { ...defaultTraceOptions, ...value, mode: mode === "retry-with-trace" ? "on-first-retry" : mode };
}
if (!this._shouldCaptureTrace()) {
this._options = void 0;
return;
}
if (!this._liveTraceFile && this._options._live) {
this._liveTraceFile = { file: import_path.default.join(this._tracesDir, `${this._testInfo.testId}-test.trace`), fs: new import_utils.SerializedFS() };
this._liveTraceFile.fs.mkdir(import_path.default.dirname(this._liveTraceFile.file));
const data = this._traceEvents.map((e) => JSON.stringify(e)).join("\n") + "\n";
this._liveTraceFile.fs.writeFile(this._liveTraceFile.file, data);
}
}
didFinishTestFunctionAndAfterEachHooks() {
this._didFinishTestFunctionAndAfterEachHooks = true;
}
artifactsDir() {
return this._artifactsDir;
}
tracesDir() {
return this._tracesDir;
}
traceTitle() {
return [import_path.default.relative(this._testInfo.project.testDir, this._testInfo.file) + ":" + this._testInfo.line, ...this._testInfo.titlePath.slice(1)].join(" \u203A ");
}
generateNextTraceRecordingName() {
const ordinalSuffix = traceOrdinal ? `-recording${traceOrdinal}` : "";
++traceOrdinal;
const retrySuffix = this._testInfo.retry ? `-retry${this._testInfo.retry}` : "";
return `${this._testInfo.testId}${retrySuffix}${ordinalSuffix}`;
}
_generateNextTraceRecordingPath() {
const file = import_path.default.join(this._artifactsDir, (0, import_utils.createGuid)() + ".zip");
this._temporaryTraceFiles.push(file);
return file;
}
traceOptions() {
return this._options;
}
maybeGenerateNextTraceRecordingPath() {
if (this._didFinishTestFunctionAndAfterEachHooks && this._shouldAbandonTrace())
return;
return this._generateNextTraceRecordingPath();
}
_shouldAbandonTrace() {
if (!this._options)
return true;
const testFailed = this._testInfo.status !== this._testInfo.expectedStatus;
return !testFailed && (this._options.mode === "retain-on-failure" || this._options.mode === "retain-on-first-failure");
}
async stopIfNeeded() {
if (!this._options)
return;
const error = await this._liveTraceFile?.fs.syncAndGetError();
if (error)
throw error;
if (this._shouldAbandonTrace()) {
for (const file of this._temporaryTraceFiles)
await import_fs.default.promises.unlink(file).catch(() => {
});
return;
}
const zipFile = new import_zipBundle.yazl.ZipFile();
if (!this._options?.attachments) {
for (const event of this._traceEvents) {
if (event.type === "after")
delete event.attachments;
}
}
if (this._options?.sources) {
const sourceFiles = /* @__PURE__ */ new Set();
for (const event of this._traceEvents) {
if (event.type === "before") {
for (const frame of event.stack || [])
sourceFiles.add(frame.file);
}
}
for (const sourceFile of sourceFiles) {
await import_fs.default.promises.readFile(sourceFile, "utf8").then((source) => {
zipFile.addBuffer(Buffer.from(source), "resources/src@" + (0, import_utils.calculateSha1)(sourceFile) + ".txt");
}).catch(() => {
});
}
}
const sha1s = /* @__PURE__ */ new Set();
for (const event of this._traceEvents.filter((e) => e.type === "after")) {
for (const attachment of event.attachments || []) {
let contentPromise;
if (attachment.path)
contentPromise = import_fs.default.promises.readFile(attachment.path).catch(() => void 0);
else if (attachment.base64)
contentPromise = Promise.resolve(Buffer.from(attachment.base64, "base64"));
const content = await contentPromise;
if (content === void 0)
continue;
const sha1 = (0, import_utils.calculateSha1)(content);
attachment.sha1 = sha1;
delete attachment.path;
delete attachment.base64;
if (sha1s.has(sha1))
continue;
sha1s.add(sha1);
zipFile.addBuffer(content, "resources/" + sha1);
}
}
const traceContent = Buffer.from(this._traceEvents.map((e) => JSON.stringify(e)).join("\n"));
zipFile.addBuffer(traceContent, testTraceEntryName);
await new Promise((f) => {
zipFile.end(void 0, () => {
zipFile.outputStream.pipe(import_fs.default.createWriteStream(this._generateNextTraceRecordingPath())).on("close", f);
});
});
const tracePath = this._testInfo.outputPath("trace.zip");
await mergeTraceFiles(tracePath, this._temporaryTraceFiles);
this._testInfo.attachments.push({ name: "trace", path: tracePath, contentType: "application/zip" });
}
appendForError(error) {
const rawStack = error.stack?.split("\n") || [];
const stack = rawStack ? (0, import_util.filteredStackTrace)(rawStack) : [];
this._appendTraceEvent({
type: "error",
message: this._formatError(error),
stack
});
}
_formatError(error) {
const parts = [error.message || String(error.value)];
if (error.cause)
parts.push("[cause]: " + this._formatError(error.cause));
return parts.join("\n");
}
appendStdioToTrace(type, chunk) {
this._appendTraceEvent({
type,
timestamp: (0, import_utils.monotonicTime)(),
text: typeof chunk === "string" ? chunk : void 0,
base64: typeof chunk === "string" ? void 0 : chunk.toString("base64")
});
}
appendBeforeActionForStep(options) {
this._appendTraceEvent({
type: "before",
callId: options.stepId,
stepId: options.stepId,
parentId: options.parentId,
startTime: (0, import_utils.monotonicTime)(),
class: "Test",
method: options.category,
title: options.title,
params: Object.fromEntries(Object.entries(options.params || {}).map(([name, value]) => [name, generatePreview(value)])),
stack: options.stack,
group: options.group
});
}
appendAfterActionForStep(callId, error, attachments = [], annotations) {
this._appendTraceEvent({
type: "after",
callId,
endTime: (0, import_utils.monotonicTime)(),
attachments: serializeAttachments(attachments),
annotations,
error
});
}
_appendTraceEvent(event) {
this._traceEvents.push(event);
if (this._liveTraceFile)
this._liveTraceFile.fs.appendFile(this._liveTraceFile.file, JSON.stringify(event) + "\n", true);
}
}
function serializeAttachments(attachments) {
if (attachments.length === 0)
return void 0;
return attachments.filter((a) => a.name !== "trace").map((a) => {
return {
name: a.name,
contentType: a.contentType,
path: a.path,
base64: a.body?.toString("base64")
};
});
}
function generatePreview(value, visited = /* @__PURE__ */ new Set()) {
if (visited.has(value))
return "";
visited.add(value);
if (typeof value === "string")
return value;
if (typeof value === "number")
return value.toString();
if (typeof value === "boolean")
return value.toString();
if (value === null)
return "null";
if (value === void 0)
return "undefined";
if (Array.isArray(value))
return "[" + value.map((v) => generatePreview(v, visited)).join(", ") + "]";
if (typeof value === "object")
return "Object";
return String(value);
}
async function mergeTraceFiles(fileName, temporaryTraceFiles) {
temporaryTraceFiles = temporaryTraceFiles.filter((file) => import_fs.default.existsSync(file));
if (temporaryTraceFiles.length === 1) {
await import_fs.default.promises.rename(temporaryTraceFiles[0], fileName);
return;
}
const mergePromise = new import_utils.ManualPromise();
const zipFile = new import_zipBundle.yazl.ZipFile();
const entryNames = /* @__PURE__ */ new Set();
zipFile.on("error", (error) => mergePromise.reject(error));
for (let i = temporaryTraceFiles.length - 1; i >= 0; --i) {
const tempFile = temporaryTraceFiles[i];
const promise = new import_utils.ManualPromise();
import_zipBundle.yauzl.open(tempFile, (err, inZipFile) => {
if (err) {
promise.reject(err);
return;
}
let pendingEntries = inZipFile.entryCount;
inZipFile.on("entry", (entry) => {
let entryName = entry.fileName;
if (entry.fileName === testTraceEntryName) {
} else if (entry.fileName.match(/trace\.[a-z]*$/)) {
entryName = i + "-" + entry.fileName;
}
if (entryNames.has(entryName)) {
if (--pendingEntries === 0)
promise.resolve();
return;
}
entryNames.add(entryName);
inZipFile.openReadStream(entry, (err2, readStream) => {
if (err2) {
promise.reject(err2);
return;
}
zipFile.addReadStream(readStream, entryName);
if (--pendingEntries === 0)
promise.resolve();
});
});
});
await promise;
}
zipFile.end(void 0, () => {
zipFile.outputStream.pipe(import_fs.default.createWriteStream(fileName)).on("close", () => {
void Promise.all(temporaryTraceFiles.map((tempFile) => import_fs.default.promises.unlink(tempFile))).then(() => {
mergePromise.resolve();
}).catch((error) => mergePromise.reject(error));
}).on("error", (error) => mergePromise.reject(error));
});
await mergePromise;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestTracing,
testTraceEntryName
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var timeoutManager_exports = {};
__export(timeoutManager_exports, {
TimeoutManager: () => TimeoutManager,
TimeoutManagerError: () => TimeoutManagerError,
kMaxDeadline: () => kMaxDeadline
});
module.exports = __toCommonJS(timeoutManager_exports);
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_util = require("../util");
const kMaxDeadline = 2147483647;
class TimeoutManager {
constructor(timeout) {
this._ignoreTimeouts = false;
this._defaultSlot = { timeout, elapsed: 0 };
}
setIgnoreTimeouts() {
this._ignoreTimeouts = true;
if (this._running)
this._updateTimeout(this._running);
}
interrupt() {
if (this._running)
this._running.timeoutPromise.reject(this._createTimeoutError(this._running));
}
isTimeExhaustedFor(runnable) {
const slot = runnable.fixture?.slot || runnable.slot || this._defaultSlot;
return slot.timeout > 0 && slot.elapsed >= slot.timeout - 1;
}
async withRunnable(runnable, cb) {
if (this._running)
throw new Error(`Internal error: duplicate runnable`);
const running = this._running = {
runnable,
slot: runnable.fixture?.slot || runnable.slot || this._defaultSlot,
start: (0, import_utils.monotonicTime)(),
deadline: kMaxDeadline,
timer: void 0,
timeoutPromise: new import_utils.ManualPromise()
};
let debugTitle = "";
try {
if (import_util.debugTest.enabled) {
debugTitle = runnable.fixture ? `${runnable.fixture.phase} "${runnable.fixture.title}"` : runnable.type;
const location = runnable.location ? ` at "${(0, import_util.formatLocation)(runnable.location)}"` : ``;
(0, import_util.debugTest)(`started ${debugTitle}${location}`);
}
this._updateTimeout(running);
return await Promise.race([
cb(),
running.timeoutPromise
]);
} finally {
if (running.timer)
clearTimeout(running.timer);
running.timer = void 0;
running.slot.elapsed += (0, import_utils.monotonicTime)() - running.start;
this._running = void 0;
if (import_util.debugTest.enabled)
(0, import_util.debugTest)(`finished ${debugTitle}`);
}
}
_updateTimeout(running) {
if (running.timer)
clearTimeout(running.timer);
running.timer = void 0;
if (this._ignoreTimeouts || !running.slot.timeout) {
running.deadline = kMaxDeadline;
return;
}
running.deadline = running.start + (running.slot.timeout - running.slot.elapsed);
const timeout = running.deadline - (0, import_utils.monotonicTime)() + 1;
if (timeout <= 0)
running.timeoutPromise.reject(this._createTimeoutError(running));
else
running.timer = setTimeout(() => running.timeoutPromise.reject(this._createTimeoutError(running)), timeout);
}
defaultSlot() {
return this._defaultSlot;
}
slow() {
const slot = this._running ? this._running.slot : this._defaultSlot;
slot.timeout = slot.timeout * 3;
if (this._running)
this._updateTimeout(this._running);
}
setTimeout(timeout) {
const slot = this._running ? this._running.slot : this._defaultSlot;
slot.timeout = timeout;
if (this._running)
this._updateTimeout(this._running);
}
currentSlotDeadline() {
return this._running ? this._running.deadline : kMaxDeadline;
}
currentSlotType() {
return this._running ? this._running.runnable.type : "test";
}
_createTimeoutError(running) {
let message = "";
const timeout = running.slot.timeout;
const runnable = running.runnable;
switch (runnable.type) {
case "test": {
if (runnable.fixture) {
if (runnable.fixture.phase === "setup")
message = `Test timeout of ${timeout}ms exceeded while setting up "${runnable.fixture.title}".`;
else
message = `Tearing down "${runnable.fixture.title}" exceeded the test timeout of ${timeout}ms.`;
} else {
message = `Test timeout of ${timeout}ms exceeded.`;
}
break;
}
case "afterEach":
case "beforeEach":
message = `Test timeout of ${timeout}ms exceeded while running "${runnable.type}" hook.`;
break;
case "beforeAll":
case "afterAll":
message = `"${runnable.type}" hook timeout of ${timeout}ms exceeded.`;
break;
case "teardown": {
if (runnable.fixture)
message = `Worker teardown timeout of ${timeout}ms exceeded while ${runnable.fixture.phase === "setup" ? "setting up" : "tearing down"} "${runnable.fixture.title}".`;
else
message = `Worker teardown timeout of ${timeout}ms exceeded.`;
break;
}
case "skip":
case "slow":
case "fixme":
case "fail":
message = `"${runnable.type}" modifier timeout of ${timeout}ms exceeded.`;
break;
}
const fixtureWithSlot = runnable.fixture?.slot ? runnable.fixture : void 0;
if (fixtureWithSlot)
message = `Fixture "${fixtureWithSlot.title}" timeout of ${timeout}ms exceeded during ${fixtureWithSlot.phase}.`;
message = import_utils2.colors.red(message);
const location = (fixtureWithSlot || runnable).location;
const error = new TimeoutManagerError(message);
error.name = "";
error.stack = message + (location ? `
at ${location.file}:${location.line}:${location.column}` : "");
return error;
}
}
class TimeoutManagerError extends Error {
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TimeoutManager,
TimeoutManagerError,
kMaxDeadline
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var util_exports = {};
__export(util_exports, {
testInfoError: () => testInfoError
});
module.exports = __toCommonJS(util_exports);
var import_util = require("../util");
function testInfoError(error) {
return (0, import_util.serializeError)(error);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
testInfoError
});
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var workerMain_exports = {};
__export(workerMain_exports, {
WorkerMain: () => WorkerMain,
create: () => create
});
module.exports = __toCommonJS(workerMain_exports);
var import_utils = require("playwright-core/lib/utils");
var import_utils2 = require("playwright-core/lib/utils");
var import_configLoader = require("../common/configLoader");
var import_globals = require("../common/globals");
var import_ipc = require("../common/ipc");
var import_util = require("../util");
var import_fixtureRunner = require("./fixtureRunner");
var import_testInfo = require("./testInfo");
var import_util2 = require("./util");
var import_fixtures = require("../common/fixtures");
var import_poolBuilder = require("../common/poolBuilder");
var import_process = require("../common/process");
var import_suiteUtils = require("../common/suiteUtils");
var import_testLoader = require("../common/testLoader");
class WorkerMain extends import_process.ProcessRunner {
constructor(params) {
super();
// Accumulated fatal errors that cannot be attributed to a test.
this._fatalErrors = [];
// The stage of the full cleanup. Once "finished", we can safely stop running anything.
this._didRunFullCleanup = false;
// Whether the worker was stopped due to an unhandled error in a test marked with test.fail().
// This should force dispatcher to use a new worker instead.
this._stoppedDueToUnhandledErrorInTestFail = false;
// Whether the worker was requested to stop.
this._isStopped = false;
// This promise resolves once the single "run test group" call finishes.
this._runFinished = new import_utils.ManualPromise();
this._currentTest = null;
this._lastRunningTests = [];
this._totalRunningTests = 0;
// Suites that had their beforeAll hooks, but not afterAll hooks executed.
// These suites still need afterAll hooks to be executed for the proper cleanup.
// Contains dynamic annotations originated by modifiers with a callback, e.g. `test.skip(() => true)`.
this._activeSuites = /* @__PURE__ */ new Map();
process.env.TEST_WORKER_INDEX = String(params.workerIndex);
process.env.TEST_PARALLEL_INDEX = String(params.parallelIndex);
(0, import_globals.setIsWorkerProcess)();
this._params = params;
this._fixtureRunner = new import_fixtureRunner.FixtureRunner();
this._runFinished.resolve();
process.on("unhandledRejection", (reason) => this.unhandledError(reason));
process.on("uncaughtException", (error) => this.unhandledError(error));
process.stdout.write = (chunk, cb) => {
this.dispatchEvent("stdOut", (0, import_ipc.stdioChunkToParams)(chunk));
this._currentTest?._tracing.appendStdioToTrace("stdout", chunk);
if (typeof cb === "function")
process.nextTick(cb);
return true;
};
if (!process.env.PW_RUNNER_DEBUG) {
process.stderr.write = (chunk, cb) => {
this.dispatchEvent("stdErr", (0, import_ipc.stdioChunkToParams)(chunk));
this._currentTest?._tracing.appendStdioToTrace("stderr", chunk);
if (typeof cb === "function")
process.nextTick(cb);
return true;
};
}
}
_stop() {
if (!this._isStopped) {
this._isStopped = true;
this._currentTest?._interrupt();
}
return this._runFinished;
}
async gracefullyClose() {
try {
await this._stop();
if (!this._config) {
return;
}
const fakeTestInfo = new import_testInfo.TestInfoImpl(this._config, this._project, this._params, void 0, 0, () => {
}, () => {
}, () => {
});
const runnable = { type: "teardown" };
await fakeTestInfo._runWithTimeout(runnable, () => this._loadIfNeeded()).catch(() => {
});
await this._fixtureRunner.teardownScope("test", fakeTestInfo, runnable).catch(() => {
});
await this._fixtureRunner.teardownScope("worker", fakeTestInfo, runnable).catch(() => {
});
await fakeTestInfo._runWithTimeout(runnable, () => (0, import_utils.gracefullyCloseAll)()).catch(() => {
});
this._fatalErrors.push(...fakeTestInfo.errors);
} catch (e) {
this._fatalErrors.push((0, import_util2.testInfoError)(e));
}
if (this._fatalErrors.length) {
this._appendProcessTeardownDiagnostics(this._fatalErrors[this._fatalErrors.length - 1]);
const payload = { fatalErrors: this._fatalErrors };
this.dispatchEvent("teardownErrors", payload);
}
}
_appendProcessTeardownDiagnostics(error) {
if (!this._lastRunningTests.length)
return;
const count = this._totalRunningTests === 1 ? "1 test" : `${this._totalRunningTests} tests`;
let lastMessage = "";
if (this._lastRunningTests.length < this._totalRunningTests)
lastMessage = `, last ${this._lastRunningTests.length} tests were`;
const message = [
"",
"",
import_utils2.colors.red(`Failed worker ran ${count}${lastMessage}:`),
...this._lastRunningTests.map((test) => formatTestTitle(test, this._project.project.name))
].join("\n");
if (error.message) {
if (error.stack) {
let index = error.stack.indexOf(error.message);
if (index !== -1) {
index += error.message.length;
error.stack = error.stack.substring(0, index) + message + error.stack.substring(index);
}
}
error.message += message;
} else if (error.value) {
error.value += message;
}
}
unhandledError(error) {
if (!this._currentTest) {
if (!this._fatalErrors.length)
this._fatalErrors.push((0, import_util2.testInfoError)(error));
void this._stop();
return;
}
if (!this._currentTest._hasUnhandledError) {
this._currentTest._hasUnhandledError = true;
this._currentTest._failWithError(error);
}
const isExpectError = error instanceof Error && !!error.matcherResult;
const shouldContinueInThisWorker = this._currentTest.expectedStatus === "failed" && isExpectError;
if (!shouldContinueInThisWorker) {
this._stoppedDueToUnhandledErrorInTestFail = true;
void this._stop();
}
}
async _loadIfNeeded() {
if (this._config)
return;
const config = await (0, import_configLoader.deserializeConfig)(this._params.config);
const project = config.projects.find((p) => p.id === this._params.projectId);
if (!project)
throw new Error(`Project "${this._params.projectId}" not found in the worker process. Make sure project name does not change.`);
this._config = config;
this._project = project;
this._poolBuilder = import_poolBuilder.PoolBuilder.createForWorker(this._project);
}
async runTestGroup(runPayload) {
this._runFinished = new import_utils.ManualPromise();
const entries = new Map(runPayload.entries.map((e) => [e.testId, e]));
let fatalUnknownTestIds;
try {
await this._loadIfNeeded();
const fileSuite = await (0, import_testLoader.loadTestFile)(runPayload.file, this._config.config.rootDir);
const suite = (0, import_suiteUtils.bindFileSuiteToProject)(this._project, fileSuite);
if (this._params.repeatEachIndex)
(0, import_suiteUtils.applyRepeatEachIndex)(this._project, suite, this._params.repeatEachIndex);
const hasEntries = (0, import_suiteUtils.filterTestsRemoveEmptySuites)(suite, (test) => entries.has(test.id));
if (hasEntries) {
this._poolBuilder.buildPools(suite);
this._activeSuites = /* @__PURE__ */ new Map();
this._didRunFullCleanup = false;
const tests = suite.allTests();
for (let i = 0; i < tests.length; i++) {
if (this._isStopped && this._didRunFullCleanup)
break;
const entry = entries.get(tests[i].id);
entries.delete(tests[i].id);
(0, import_util.debugTest)(`test started "${tests[i].title}"`);
await this._runTest(tests[i], entry.retry, tests[i + 1]);
(0, import_util.debugTest)(`test finished "${tests[i].title}"`);
}
} else {
fatalUnknownTestIds = runPayload.entries.map((e) => e.testId);
void this._stop();
}
} catch (e) {
this._fatalErrors.push((0, import_util2.testInfoError)(e));
void this._stop();
} finally {
const donePayload = {
fatalErrors: this._fatalErrors,
skipTestsDueToSetupFailure: [],
fatalUnknownTestIds,
stoppedDueToUnhandledErrorInTestFail: this._stoppedDueToUnhandledErrorInTestFail
};
for (const test of this._skipRemainingTestsInSuite?.allTests() || []) {
if (entries.has(test.id))
donePayload.skipTestsDueToSetupFailure.push(test.id);
}
this.dispatchEvent("done", donePayload);
this._fatalErrors = [];
this._skipRemainingTestsInSuite = void 0;
this._runFinished.resolve();
}
}
async _runTest(test, retry, nextTest) {
const testInfo = new import_testInfo.TestInfoImpl(
this._config,
this._project,
this._params,
test,
retry,
(stepBeginPayload) => this.dispatchEvent("stepBegin", stepBeginPayload),
(stepEndPayload) => this.dispatchEvent("stepEnd", stepEndPayload),
(attachment) => this.dispatchEvent("attach", attachment)
);
const processAnnotation = (annotation) => {
testInfo.annotations.push(annotation);
switch (annotation.type) {
case "fixme":
case "skip":
testInfo.expectedStatus = "skipped";
break;
case "fail":
if (testInfo.expectedStatus !== "skipped")
testInfo.expectedStatus = "failed";
break;
case "slow":
testInfo._timeoutManager.slow();
break;
}
};
if (!this._isStopped)
this._fixtureRunner.setPool(test._pool);
const suites = getSuites(test);
const reversedSuites = suites.slice().reverse();
const nextSuites = new Set(getSuites(nextTest));
testInfo._timeoutManager.setTimeout(test.timeout);
for (const annotation of test.annotations)
processAnnotation(annotation);
for (const suite of suites) {
const extraAnnotations = this._activeSuites.get(suite) || [];
for (const annotation of extraAnnotations)
processAnnotation(annotation);
}
this._currentTest = testInfo;
(0, import_globals.setCurrentTestInfo)(testInfo);
this.dispatchEvent("testBegin", buildTestBeginPayload(testInfo));
const isSkipped = testInfo.expectedStatus === "skipped";
const hasAfterAllToRunBeforeNextTest = reversedSuites.some((suite) => {
return this._activeSuites.has(suite) && !nextSuites.has(suite) && suite._hooks.some((hook) => hook.type === "afterAll");
});
if (isSkipped && nextTest && !hasAfterAllToRunBeforeNextTest) {
testInfo.status = "skipped";
this.dispatchEvent("testEnd", buildTestEndPayload(testInfo));
return;
}
this._totalRunningTests++;
this._lastRunningTests.push(test);
if (this._lastRunningTests.length > 10)
this._lastRunningTests.shift();
let shouldRunAfterEachHooks = false;
testInfo._allowSkips = true;
await (async () => {
await testInfo._runWithTimeout({ type: "test" }, async () => {
const traceFixtureRegistration = test._pool.resolve("trace");
if (!traceFixtureRegistration)
return;
if (typeof traceFixtureRegistration.fn === "function")
throw new Error(`"trace" option cannot be a function`);
await testInfo._tracing.startIfNeeded(traceFixtureRegistration.fn);
});
if (this._isStopped || isSkipped) {
testInfo.status = "skipped";
return;
}
await (0, import_utils.removeFolders)([testInfo.outputDir]);
let testFunctionParams = null;
await testInfo._runAsStep({ title: "Before Hooks", category: "hook" }, async () => {
for (const suite of suites)
await this._runBeforeAllHooksForSuite(suite, testInfo);
shouldRunAfterEachHooks = true;
await this._runEachHooksForSuites(suites, "beforeEach", testInfo);
testFunctionParams = await this._fixtureRunner.resolveParametersForFunction(test.fn, testInfo, "test", { type: "test" });
});
if (testFunctionParams === null) {
return;
}
await testInfo._runWithTimeout({ type: "test" }, async () => {
const fn = test.fn;
await fn(testFunctionParams, testInfo);
});
})().catch(() => {
});
testInfo.duration = testInfo._timeoutManager.defaultSlot().elapsed | 0;
testInfo._allowSkips = true;
const afterHooksTimeout = calculateMaxTimeout(this._project.project.timeout, testInfo.timeout);
const afterHooksSlot = { timeout: afterHooksTimeout, elapsed: 0 };
await testInfo._runAsStep({ title: "After Hooks", category: "hook" }, async () => {
let firstAfterHooksError;
try {
await testInfo._runWithTimeout({ type: "test", slot: afterHooksSlot }, async () => {
for (const fn of testInfo._onDidFinishTestFunctions)
await fn();
});
} catch (error) {
firstAfterHooksError = firstAfterHooksError ?? error;
}
try {
if (shouldRunAfterEachHooks)
await this._runEachHooksForSuites(reversedSuites, "afterEach", testInfo, afterHooksSlot);
} catch (error) {
firstAfterHooksError = firstAfterHooksError ?? error;
}
testInfo._tracing.didFinishTestFunctionAndAfterEachHooks();
try {
await this._fixtureRunner.teardownScope("test", testInfo, { type: "test", slot: afterHooksSlot });
} catch (error) {
firstAfterHooksError = firstAfterHooksError ?? error;
}
for (const suite of reversedSuites) {
if (!nextSuites.has(suite) || testInfo._isFailure()) {
try {
await this._runAfterAllHooksForSuite(suite, testInfo);
} catch (error) {
firstAfterHooksError = firstAfterHooksError ?? error;
}
}
}
if (firstAfterHooksError)
throw firstAfterHooksError;
}).catch(() => {
});
if (testInfo._isFailure())
this._isStopped = true;
if (this._isStopped) {
this._didRunFullCleanup = true;
await testInfo._runAsStep({ title: "Worker Cleanup", category: "hook" }, async () => {
let firstWorkerCleanupError;
const teardownSlot = { timeout: this._project.project.timeout, elapsed: 0 };
try {
await this._fixtureRunner.teardownScope("test", testInfo, { type: "test", slot: teardownSlot });
} catch (error) {
firstWorkerCleanupError = firstWorkerCleanupError ?? error;
}
for (const suite of reversedSuites) {
try {
await this._runAfterAllHooksForSuite(suite, testInfo);
} catch (error) {
firstWorkerCleanupError = firstWorkerCleanupError ?? error;
}
}
try {
await this._fixtureRunner.teardownScope("worker", testInfo, { type: "teardown", slot: teardownSlot });
} catch (error) {
firstWorkerCleanupError = firstWorkerCleanupError ?? error;
}
if (firstWorkerCleanupError)
throw firstWorkerCleanupError;
}).catch(() => {
});
}
const tracingSlot = { timeout: this._project.project.timeout, elapsed: 0 };
await testInfo._runWithTimeout({ type: "test", slot: tracingSlot }, async () => {
await testInfo._tracing.stopIfNeeded();
}).catch(() => {
});
testInfo.duration = testInfo._timeoutManager.defaultSlot().elapsed + afterHooksSlot.elapsed | 0;
this._currentTest = null;
(0, import_globals.setCurrentTestInfo)(null);
this.dispatchEvent("testEnd", buildTestEndPayload(testInfo));
const preserveOutput = this._config.config.preserveOutput === "always" || this._config.config.preserveOutput === "failures-only" && testInfo._isFailure();
if (!preserveOutput)
await (0, import_utils.removeFolders)([testInfo.outputDir]);
}
_collectHooksAndModifiers(suite, type, testInfo) {
const runnables = [];
for (const modifier of suite._modifiers) {
const modifierType = this._fixtureRunner.dependsOnWorkerFixturesOnly(modifier.fn, modifier.location) ? "beforeAll" : "beforeEach";
if (modifierType !== type)
continue;
const fn = async (fixtures) => {
const result = await modifier.fn(fixtures);
testInfo._modifier(modifier.type, modifier.location, [!!result, modifier.description]);
};
(0, import_fixtures.inheritFixtureNames)(modifier.fn, fn);
runnables.push({
title: `${modifier.type} modifier`,
location: modifier.location,
type: modifier.type,
fn
});
}
runnables.push(...suite._hooks.filter((hook) => hook.type === type));
return runnables;
}
async _runBeforeAllHooksForSuite(suite, testInfo) {
if (this._activeSuites.has(suite))
return;
const extraAnnotations = [];
this._activeSuites.set(suite, extraAnnotations);
await this._runAllHooksForSuite(suite, testInfo, "beforeAll", extraAnnotations);
}
async _runAllHooksForSuite(suite, testInfo, type, extraAnnotations) {
let firstError;
for (const hook of this._collectHooksAndModifiers(suite, type, testInfo)) {
try {
await testInfo._runAsStep({ title: hook.title, category: "hook", location: hook.location }, async () => {
const timeSlot = { timeout: this._project.project.timeout, elapsed: 0 };
const runnable = { type: hook.type, slot: timeSlot, location: hook.location };
const existingAnnotations = new Set(testInfo.annotations);
try {
await this._fixtureRunner.resolveParametersAndRunFunction(hook.fn, testInfo, "all-hooks-only", runnable);
} finally {
if (extraAnnotations) {
const newAnnotations = testInfo.annotations.filter((a) => !existingAnnotations.has(a));
extraAnnotations.push(...newAnnotations);
}
await this._fixtureRunner.teardownScope("test", testInfo, runnable);
}
});
} catch (error) {
firstError = firstError ?? error;
if (type === "beforeAll" && error instanceof import_testInfo.TestSkipError)
break;
if (type === "beforeAll" && !this._skipRemainingTestsInSuite) {
this._skipRemainingTestsInSuite = suite;
}
}
}
if (firstError)
throw firstError;
}
async _runAfterAllHooksForSuite(suite, testInfo) {
if (!this._activeSuites.has(suite))
return;
this._activeSuites.delete(suite);
await this._runAllHooksForSuite(suite, testInfo, "afterAll");
}
async _runEachHooksForSuites(suites, type, testInfo, slot) {
let firstError;
const hooks = suites.map((suite) => this._collectHooksAndModifiers(suite, type, testInfo)).flat();
for (const hook of hooks) {
const runnable = { type: hook.type, location: hook.location, slot };
if (testInfo._timeoutManager.isTimeExhaustedFor(runnable)) {
continue;
}
try {
await testInfo._runAsStep({ title: hook.title, category: "hook", location: hook.location }, async () => {
await this._fixtureRunner.resolveParametersAndRunFunction(hook.fn, testInfo, "test", runnable);
});
} catch (error) {
firstError = firstError ?? error;
if (error instanceof import_testInfo.TestSkipError)
break;
}
}
if (firstError)
throw firstError;
}
}
function buildTestBeginPayload(testInfo) {
return {
testId: testInfo.testId,
startWallTime: testInfo._startWallTime
};
}
function buildTestEndPayload(testInfo) {
return {
testId: testInfo.testId,
duration: testInfo.duration,
status: testInfo.status,
errors: testInfo.errors,
hasNonRetriableError: testInfo._hasNonRetriableError,
expectedStatus: testInfo.expectedStatus,
annotations: testInfo.annotations,
timeout: testInfo.timeout
};
}
function getSuites(test) {
const suites = [];
for (let suite = test?.parent; suite; suite = suite.parent)
suites.push(suite);
suites.reverse();
return suites;
}
function formatTestTitle(test, projectName) {
const [, ...titles] = test.titlePath();
const location = `${(0, import_util.relativeFilePath)(test.location.file)}:${test.location.line}:${test.location.column}`;
const projectTitle = projectName ? `[${projectName}] \u203A ` : "";
return `${projectTitle}${location} \u203A ${titles.join(" \u203A ")}`;
}
function calculateMaxTimeout(t1, t2) {
return !t1 || !t2 ? 0 : Math.max(t1, t2);
}
const create = (params) => new WorkerMain(params);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
WorkerMain,
create
});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display