testflowlabs/pest-plugin-bridge 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

testflowlabs/pest-plugin-bridge

Composer 安装命令:

composer require --dev testflowlabs/pest-plugin-bridge

包简介

Pest plugin for browser testing external frontend applications

README 文档

README

Pest Bridge Plugin

Pest Bridge Plugin

Tests License

Test external frontends from Laravel — write browser tests in PHP for Vue, React, Nuxt, Next.js.

Documentation · Getting Started


The Problem

You have a headless Laravel API and a separate frontend (Vue, Nuxt, React, Next.js). Two apps, two ports, two problems:

  • Your tests can't reach the frontend
  • Your frontend can't find the API during tests

The Solution

Pest Bridge Plugin solves both directions:

// test → frontend: bridge() visits the external frontend
$this->bridge('/login')->assertSee('Welcome');

// frontend → API: automatic environment variable injection
// VITE_API_URL, NUXT_PUBLIC_API_BASE, NEXT_PUBLIC_API_URL, etc.

Installation

composer require testflowlabs/pest-plugin-bridge --dev

Requires pestphp/pest-plugin-browser

Quick Start

// tests/Pest.php
use TestFlowLabs\PestPluginBridge\Bridge;

Bridge::add('http://localhost:3000')
    ->serve('npm run dev', cwd: '../frontend');
// tests/Browser/LoginTest.php
test('user can login', function () {
    $user = User::factory()->create(['email' => 'test@example.com']);

    $this->bridge('/login')
        ->typeSlowly('[data-testid="email"]', 'test@example.com')
        ->typeSlowly('[data-testid="password"]', 'password')
        ->click('[data-testid="submit"]')
        ->waitForEvent('networkidle')
        ->assertPathContains('/dashboard');
});

Features

Automatic Server Management

Frontend starts on first bridge() call, stops when tests complete. No manual server management.

Bridge::add('http://localhost:3000')
    ->serve('npm run dev', cwd: '../frontend')
    ->readyWhen('VITE.*ready');

Multiple Bridged Frontends

Test multiple frontends in one suite. Child frontends share the parent's server process.

Bridge::add('http://localhost:3000');                  // Default
Bridge::add('http://localhost:3001', 'admin')
    ->child('/analytics', 'analytics')                 // Same server, /analytics path
    ->serve('npm run dev', cwd: '../admin');
$this->bridge('/products');                            // Default frontend
$this->bridge('/users', 'admin');                      // Admin frontend
$this->bridge('/', 'analytics');                       // Child of admin

Multi-Repository CI/CD

GitHub Actions checks out both repos side-by-side. Works with private repos.

- uses: actions/checkout@v4
  with: { path: backend }
- uses: actions/checkout@v4
  with: { repository: your-org/frontend, path: frontend }

Vue/React Compatible

typeSlowly() triggers real keyboard events that Vue v-model and React hooks respond to.

// fill() sets DOM directly — Vue won't see it
// typeSlowly() fires keydown/input/keyup events
->typeSlowly('[data-testid="email"]', 'test@example.com')

Documentation

For complete guides, examples, and CI/CD workflows:

bridge.testflowlabs.dev

Development

composer install
composer test

License

MIT License. See LICENSE for details.

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-28