A thin and light scaffolded Laravel Dusk environment.

Related tags

Laravel laravel-husk
Overview

Laravel Husk

Larvel 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 Nuxt Tests
NextJS Next Tests
Svelte Svelte Tests
Gatsby Gatsby Tests
Gridsome Gridsome Tests
Showcode (NuxtJS) Gridsome Tests

Installation

Inside of your JavaScript application folder, run the below command to scaffold the Laravel Husk environment:

Note: This will create the folder named browser which 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

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

php application pest:dusk

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
You might also like...
A Laravel 8 and Livewire 2 demo showing how to search and filter by tags, showing article and video counts for each tag (Polymorphic relationship)
A Laravel 8 and Livewire 2 demo showing how to search and filter by tags, showing article and video counts for each tag (Polymorphic relationship)

Advanced search and filter with Laravel and Livewire A demo app using Laravel 8 and Livewire 2 showing how to implement a list of articles and tags, v

Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and User Authentication.
Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and User Authentication.

Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and

Nebula is a minimalistic and easy to use administration tool for Laravel applications, made with Laravel, Alpine.js, and Tailwind CSS.

Nebula Nebula is a minimalistic and easy to use administration tool for Laravel applications, made with Laravel, Alpine.js, and Tailwind CSS. Nebula m

Laravel package to generate and to validate a UUID according to the RFC 4122 standard. Only support for version 1, 3, 4 and 5 UUID are built-in.

Laravel Uuid Laravel package to generate and to validate a universally unique identifier (UUID) according to the RFC 4122 standard. Support for versio

An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality.

Support An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality. Ins

Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css. Requires Livewire and AlpineJS.

Laravel Livewire Window Size and Breakpoints Laravel blade directives and php helpers for server side rendered content, based on browser window size W

Sweetalert and Toaster notifications for Laravel livewire with support for tailwind and bootstrap.

Larabell Integrate livewire with sweetalert. Installation How to use Sweetalert Toast Available configuration Installation composer require simtabi/la

Invoices, Expenses and Tasks built with Laravel and Flutter

Invoice Ninja Hosted | Self-Hosted We're on Slack, join us at slack.invoiceninja.com or if you like StackOverflow Just make sure to add the invoice-ni

Fast and simple implementation of a REST API based on the Laravel Framework, Repository Pattern, Eloquent Resources, Translatability, and Swagger.

Laravel Headless What about? This allows a fast and simple implementation of a REST API based on the Laravel Framework, Repository Pattern, Eloquent R

Releases(v1.0.1)
Owner
Steve Bauman
I like to build things on the web 💻
Steve Bauman
Inertia.js Events for Laravel Dusk

Inertia.js Events for Laravel Dusk Requirements PHP 7.4+ Vue Laravel 8.0 and higher Support We proudly support the community by developing Laravel pac

Protone Media 23 Sep 29, 2022
Persistent Fakes for Laravel Dusk

Laravel Dusk Fakes Support this package! ❤️ We proudly support the community by developing Laravel packages and giving them away for free. If this pac

Protone Media 3 Sep 5, 2022
A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Adnane Kadri 49 Jun 22, 2022
A suit of basic files samples to build a light-weight , short-handed & a strong Laravel REST API Applications.

Concerning Laravel. I found myself repeating a very basic form of code each time i begin a new REST API. in which the whole Interface's pieces are dev

Adnane Kadri 1 Nov 22, 2021
Package for Laravel that gives artisan commands to setup and edit environment files.

Setup and work with .env files in Laravel from the command line NOTE: This doesn't work with Laravel 5 since .env files were changed. This is for Lara

Matt Brunt 6 Dec 17, 2022
A Laravel package that allows you to validate your config values and environment.

Table of Contents Overview Installation Requirements Install the Package Publishing the Default Rulesets Usage Creating a Validation Ruleset Using the

Ash Allen 152 Dec 15, 2022
A kernel designed to run one and only one application in a virtualized environment

nanos Nanos is a new kernel designed to run one and only one application in a virtualized environment. It has several constraints on it compared to a

NanoVMs 2k Dec 20, 2022
An artisan command for using multiple environment configurations in Laravel 5

Laravel 5 env An artisan command for managing multiple .env of your Laravel 5 app. Installation Copy EnvCommand.php to app/Console/Commands/ of your L

Tommy Ku 18 Nov 29, 2022
Load Laravel service providers based on your application's environment.

Laravel EnvProviders A more finetuned way of managing your service providers in Laravel. This package allows you to configure the environment certain

Sven Luijten 79 Dec 29, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023