stevebauman/laravel-husk
Composer 安装命令:
composer require stevebauman/laravel-husk
包简介
A Laravel Dusk environment for your Javascript only applications.
README 文档
README
Laravel Husk is a thin and light scaffolded Laravel Dusk environment.
It allows you to test your JavaScript applications with PHP using Pest, without having to scaffold an entire Laravel application.
Examples
| JS Framework | Tests |
|---|---|
| NuxtJS | |
| NextJS | |
| Svelte | |
| Gatsby | |
| Gridsome | |
| Showcode (NuxtJS) |
Installation
Inside of your JavaScript application folder, run the below command to scaffold the Laravel Husk environment:
Note: This will create the folder named
browserwhich will contain your Laravel Husk test environment.
composer create-project stevebauman/laravel-husk browser
After scaffolding the test environment, you should have the below folder structure;
javascript-app/
├── ...
└── browser/
├── bootstrap/
├── config/
├── storage/
│ ├── log/
│ ├── screenshots/
│ └── source/
└── tests/
├── ...
├── ExampleTest.php
├── DuskTestCase.php
└── Pages/
└── ExamplePage.php
Then, navigate into the browser directory and install the Chrome driver by running the below command:
php application dusk:chrome-driver --detect
Usage
Before running your dusk tests, be sure to set the proper base URL to where your JavaScript application will be served from:
// tests/DuskTestCase.php protected function setUp(): void { parent::setUp(); $this->setupBrowser('http://localhost:3000'); }
After setting the base URL, serve your JavaScript application:
npm run dev
Then, inside of another terminal, navigate into the browser directory:
cd browser
And run the below command:
Important: Make sure you've installed the Chrome driver first, via
php application dusk:chrome-driver --detect
php application pest:dusk
With arguments:
php application pest:dusk --order-by=random --filter="it can load"
Note: You may also insert the below JSON into the
scriptssection of yourpackage.jsonfile to run your browser tests from your root project directory:"scripts": { "test": "cd browser && php application pest:dusk" }npm run test
GitHub Actions
You may use the below GitHub action as a template to run your Laravel Dusk tests:
name: run-tests on: push: pull_request: schedule: - cron: "0 0 * * *" jobs: run-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: cache: "npm" - name: Install Javascript Dependencies run: npm install - name: Start JavaScript Application run: npm run dev & - name: Install Composer Dependencies working-directory: ./browser run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Upgrade Chrome Driver working-directory: ./browser run: php application dusk:chrome-driver `/opt/google/chrome/chrome --version | cut -d " " -f3 | cut -d "." -f1` - name: Run Dusk Tests working-directory: ./browser run: php application pest:dusk - name: Upload Screenshots if: failure() uses: actions/upload-artifact@v2 with: name: screenshots path: browser/storage/screenshots - name: Upload Console Logs if: failure() uses: actions/upload-artifact@v2 with: name: console path: browser/storage/console
stevebauman/laravel-husk 适用场景与选型建议
stevebauman/laravel-husk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64 次下载、GitHub Stars 达 89, 最近一次更新时间为 2022 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 stevebauman/laravel-husk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stevebauman/laravel-husk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 64
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 89
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-18