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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-sloths-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

chore: move Vitest unit tests to packages/core/tests
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"typecheck": "tsc --noEmit",
"build": "pnpm run gen-version && pnpm run build-dom-scripts && pnpm run build-js && pnpm run typecheck",
"example": "node --import tsx -e \"const args=process.argv.slice(1).filter(a=>a!=='--'); const [p]=args; const n=(p||'example').replace(/^\\.\\//,'').replace(/\\.ts$/i,''); import(new URL(require('node:path').resolve('examples', n + '.ts'), 'file:'));\" --",
"test": "playwright test --config=lib/v3/tests/v3.playwright.config.ts",
"e2e": "playwright test --config=lib/v3/tests/v3.local.playwright.config.ts",
"e2e:local": "playwright test --config=lib/v3/tests/v3.local.playwright.config.ts",
"e2e:bb": "playwright test --config=lib/v3/tests/v3.bb.playwright.config.ts",
"test": "playwright test --config=tests/integration/v3.playwright.config.ts",
"e2e": "playwright test --config=tests/integration/v3.local.playwright.config.ts",
"e2e:local": "playwright test --config=tests/integration/v3.local.playwright.config.ts",
"e2e:bb": "playwright test --config=tests/integration/v3.bb.playwright.config.ts",
"lint": "cd ../.. && prettier --check packages/core && cd packages/core && eslint .",
"format": "prettier --write .",
"test:vitest": "turbo run build && vitest run --config vitest.config.ts"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import { AgentAbortError } from "../types/public/sdkErrors";
import { AgentAbortError } from "../../lib/v3/types/public/sdkErrors";

test.describe("Stagehand agent abort signal", () => {
let v3: V3;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { test, expect } from "@playwright/test";
import fs from "fs/promises";
import path from "path";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import type {
AgentReplayActStep,
AgentReplayFillFormStep,
CachedAgentEntry,
} from "../types/private/cache";
} from "../../lib/v3/types/private/cache";

test.describe("Agent cache self-heal (e2e)", () => {
let v3: V3;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import type { StepResult, ToolSet } from "ai";
import { StreamingCallbacksInNonStreamingModeError } from "../types/public/sdkErrors";
import { StreamingCallbacksInNonStreamingModeError } from "../../lib/v3/types/public/sdkErrors";

test.describe("Stagehand agent callbacks behavior", () => {
let v3: V3;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { test, expect } from "@playwright/test";
import { z } from "zod";
import { tool } from "ai";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import {
ExperimentalNotConfiguredError,
StagehandInvalidArgumentError,
} from "../types/public/sdkErrors";
} from "../../lib/v3/types/public/sdkErrors";

// Define a mock custom tool for testing
const mockCustomTool = tool({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import { createAgentTools } from "../agent/tools";
import { buildAgentSystemPrompt } from "../agent/prompts/agentSystemPrompt";
import { createAgentTools } from "../../lib/v3/agent/tools";
import { buildAgentSystemPrompt } from "../../lib/v3/agent/prompts/agentSystemPrompt";
import type { StepResult, ToolSet } from "ai";

test.describe("Stagehand agent hybrid mode", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import type { ModelMessage } from "ai";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import type { AgentResult } from "../types/public/agent";
import type { AgentResult } from "../../lib/v3/types/public/agent";

test.describe("Stagehand agent streaming behavior", () => {
let v3: V3;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Locator and Page click methods", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3BBTestConfig } from "./v3.bb.config";

const PAGE_TARGET_COUNT = 5;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import { V3Context } from "../understudy/context";
import { V3Context } from "../../lib/v3/understudy/context";

const toDataUrl = (html: string): string =>
`data:text/html,${encodeURIComponent(html)}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3DynamicTestConfig } from "./v3.dynamic.config";

test.describe.configure({ mode: "parallel" });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import Browserbase from "@browserbasehq/sdk";
import AdmZip from "adm-zip";
import { v3DynamicTestConfig } from "./v3.dynamic.config";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Coordinate-based clicking", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3DynamicTestConfig } from "./v3.dynamic.config";

function dataUrl(html: string): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Locator.backendNodeId() - CDP DOM node ID", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Locator content methods (textContent, innerHtml, innerText, inputValue)", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3DynamicTestConfig } from "./v3.dynamic.config";

test.describe("Locator count() method with iframes", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3DynamicTestConfig } from "./v3.dynamic.config";

test.describe("Locator count() method tests", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Locator input methods (fill, type, hover, isVisible, isChecked)", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3DynamicTestConfig } from "./v3.dynamic.config";

test.describe("Locator nth() method tests", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Locator.selectOption() method", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
unbindInstanceLogger,
withInstanceLogContext,
v3Logger,
} from "../logger";
import type { LogLine } from "../types/public/logs";
} from "../../lib/v3/logger";
import type { LogLine } from "../../lib/v3/types/public/logs";

test.describe("V3 Logger Instance Routing", () => {
test.afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { getV3DynamicTestConfig } from "./v3.dynamic.config";
import type { LogLine } from "../types/public/logs";
import type { LogLine } from "../../lib/v3/types/public/logs";

test.describe("V3 Multi-Instance Logger Isolation", () => {
// Run tests serially to avoid resource exhaustion from creating many Chrome instances
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { captureHybridSnapshot } from "../understudy/a11y/snapshot";
import { V3 } from "../../lib/v3";
import { captureHybridSnapshot } from "../../lib/v3/understudy/a11y/snapshot";
import { v3TestConfig } from "./v3.config";

test.describe("tests captureHybridSnapshot() does not break due to -32000 Failed to convert response to JSON: CBOR: stack limit exceeded", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import { V3Context } from "../understudy/context";
import { V3Context } from "../../lib/v3/understudy/context";

const EXAMPLE_URL = "https://example.com";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Page console events", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Page.dragAndDrop() - dragging elements", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Page.goto() response surface", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Page.hover() - mouse hover at coordinates", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { test, expect } from "@playwright/test";
import { promises as fs } from "fs";
import * as os from "os";
import * as path from "path";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import { Frame } from "../understudy/frame";
import { Frame } from "../../lib/v3/understudy/frame";

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Page.scroll() - mouse wheel scrolling", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

test.describe("Page sendCDP method", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3DynamicTestConfig } from "./v3.dynamic.config";
import { performUnderstudyMethod } from "../handlers/handlerUtils/actHandlerUtils";
import { performUnderstudyMethod } from "../../lib/v3/handlers/handlerUtils/actHandlerUtils";

test.describe("tests performUnderstudyMethod", () => {
let v3: V3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Buffer } from "buffer";
import { promises as fs } from "fs";
import path from "path";
import crypto from "crypto";
import type { Page as V3Page } from "../understudy/page";
import { V3 } from "../v3";
import type { Page as V3Page } from "../../lib/v3/understudy/page";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";

const FILE_UPLOAD_IFRAME_URL =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import puppeteer from "puppeteer-core";
import { chromium as playwrightChromium } from "playwright";
import { chromium as patchrightChromium } from "patchright-core";
import { Action } from "../types/public/methods";
import { AnyPage } from "../types/public/page";
import { Action } from "../../lib/v3/types/public/methods";
import { AnyPage } from "../../lib/v3/types/public/page";
import { v3DynamicTestConfig } from "./v3.dynamic.config";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "@playwright/test";
import { Protocol } from "devtools-protocol";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3DynamicTestConfig } from "./v3.dynamic.config";

test.describe("Text selector innermost element matching", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3DynamicTestConfig } from "./v3.dynamic.config";
import { z } from "zod";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { V3 } from "../v3";
import { V3 } from "../../lib/v3";
import { v3TestConfig } from "./v3.config";
import * as fs from "fs";
import * as path from "path";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { V3Options } from "../types/public/options";
import type { LogLine } from "../types/public/logs";
import type { V3Options } from "../../lib/v3/types/public/options";
import type { LogLine } from "../../lib/v3/types/public/logs";
import dotenv from "dotenv";
import path from "path";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import path from "path";
// Load environment variables before setting TEST_ENV
dotenv.config();

// Try loading from repo root (packages/core/lib/v3/tests -> repo root = 5 levels up)
const repoRootEnvPath = path.resolve(__dirname, "../../../../../.env");
// Try loading from repo root (packages/core/tests/integration -> repo root = 4 levels up)
const repoRootEnvPath = path.resolve(__dirname, "../../../../.env");
dotenv.config({ path: repoRootEnvPath, override: false });

// Set TEST_ENV before tests run
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { V3Options } from "../types/public/options";
import type { LogLine } from "../types/public/logs";
import type { V3Options } from "../../lib/v3/types/public/options";
import type { LogLine } from "../../lib/v3/types/public/logs";

export const v3TestConfig: V3Options = {
env: "LOCAL",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { V3Options } from "../types/public/options";
import type { LogLine } from "../types/public/logs";
import type { V3Options } from "../../lib/v3/types/public/options";
import type { LogLine } from "../../lib/v3/types/public/logs";
import dotenv from "dotenv";
import path from "path";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import path from "path";
// Load environment variables before setting TEST_ENV
dotenv.config();

// Try loading from repo root (packages/core/lib/v3/tests -> repo root = 5 levels up)
const repoRootEnvPath = path.resolve(__dirname, "../../../../../.env");
// Try loading from repo root (packages/core/tests/integration -> repo root = 4 levels up)
const repoRootEnvPath = path.resolve(__dirname, "../../../../.env");
dotenv.config({ path: repoRootEnvPath, override: false });

// Set TEST_ENV before tests run
Expand Down
Loading