Commit 65bdc60f authored by Mohamed S's avatar Mohamed S Committed by Protocole
Browse files

Feat: new job PHP dusk 0.1

parent 4165543e
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -315,3 +315,21 @@ Jdk
JaCoCo
Jacoco
jacoco
Laravel
laravel
DuskTestCase
dev
Dev
ChromeDriver
Chromedriver
chromedriver
JUnit's
Junit's
CSV
csv
golang
Golang
Customise
customise
monorepo
Monorepo
+67 −0
Original line number Diff line number Diff line
## Objective

This job tests your final project by using Laravel Dusk, this will run tests that you already created beforehand and stored on the folder `tests/Browser`, all the logs, console output and screenshots, if generated, will be available as an artifact when the job succeeds.


## How to use it

1. Ensure that your project has Laravel Dusk installed (see how to do that [here](https://laravel.com/docs/8.x/dusk#installation){:target="_blank"})
2. Make sure your `DuskTestCase` class in `/tests/DuskTestCase.php` matches all attributes, like drive options, host url, and port, like in this example [DuskTestCase.php](https://github.com/chilio/laravel-dusk-ci/blob/master/examples/DuskTestCase.php){:target="_blank"}

    !!! warning
        There are some modifications which **you need to apply** (especially adding `--no-sandbox` in $options for driver), these changes should not affect your local dev environment, otherwise there might be something else wrong with your project. 

3. Add this job URL inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
    ```yaml
      - remote: 'https://jobs.r2devops.io/latest/dusk_test.yml'
    ```
4. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
5. Well done, your job is ready to work ! 😀


## Job details

* Job name: `dusk_test`
* Default stage: `dynamic_tests`
* Docker image: [`chilio/laravel-dusk-ci:php-8.0`](https://hub.docker.com/r/chilio/laravel-dusk-ci){:target="_blank"}
* When: `always`


### Variables

!!! note
    All paths defined in variables are relative and starts from the root of your
    repository.

| Name | Description | Default |
| ---- | ----------- | ------- |
| `PROJECT_ROOT` | Path to the project's root directory   | `.` |
| `ENV_NAME` | Name of the environment variables file to use | `.env.testing` |
| `COMPOSER_INSTALL_OPTIONS` | Additional options for `composer install` | ` ` |
| `CHROME_DRIVER_VERSION` | Specific ChromeDriver version to use | `88` |
| `DUSK_OPTIONS` | Additional options for `php artisan dusk` | `--log-junit dusk_junit.xml` |


### Cache

This job creates a global cache configuration. Regarding the configuration
applied, cache behavior is the following:

* Shared between all jobs and pipelines on the same branch
* Contains folder `$PROJECT_ROOT/vendor`
* If `composer install` produces different result than the cached content

More information on Gitlab caching mechanism in [Gitlab CI/CD caching
documentation](https://docs.gitlab.com/ee/ci/caching/index.html).


### Artifact

When the job is done, it will provide an artifact containing the output from Dusk tests under these folders:

* `tests/Browser/console`
* `tests/Browser/screenshots`
* `storage/logs`

We also use Junit's XML report to display error report directly in pipeline `Tests` tab and in merge request widget. The report defined as `dusk_junit.xml` is also available directly in the artifact.
 No newline at end of file
+52 −0
Original line number Diff line number Diff line
# Job from R2Devops hub --> r2devops.io

stages:
  - dynamic_tests

cache:
  key:
    files:
      - "${CI_PROJECT_DIR}/${PROJECT_ROOT}/composer.lock"
      - "${CI_PROJECT_DIR}/${PROJECT_ROOT}/composer.json"
    prefix: "composer-${CI_COMMIT_REF_SLUG}"
  paths:
    - "${CI_PROJECT_DIR}/${PROJECT_ROOT}/vendor"

dusk_test:
  stage: dynamic_tests
  image: chilio/laravel-dusk-ci:php-8.0
  variables:
    PROJECT_ROOT: .
    ENV_NAME: ".env.testing"
    COMPOSER_INSTALL_OPTIONS: ""
    CHROME_DRIVER_VERSION: "88"
    DUSK_OPTIONS: "--log-junit dusk_junit.xml"

  script:
    # Navigate to working directory
    - cd ${CI_PROJECT_DIR}/${PROJECT_ROOT}
    # Setup .env
    - cp -f ${ENV_NAME} .env
    # Install dependencies
    - composer install $COMPOSER_INSTALL_OPTIONS
    # Basic Laravel config
    - configure-laravel
    # Choose chrome-driver version
    - php artisan dusk:chrome-driver $CHROME_DRIVER_VERSION
    # Run chrome driver
    - chromedriver &
    # Setup and start webserver
    - start-nginx-ci-project

    - php artisan dusk $DUSK_OPTIONS

  artifacts:
    paths:
      - tests/Browser/screenshots
      - tests/Browser/console
      - storage/logs
      - dusk_junit.xml
    reports:
      junit:
        - dusk_junit.xml

jobs/dusk_test/job.yml

0 → 100644
+14 −0
Original line number Diff line number Diff line
name: dusk_test
description: A ready to use Laravel Dusk job to test your project
default_stage: dynamic_tests
icon: 🌙
maintainer: moha-s
license: MIT
images:
    "chilio/laravel-dusk-ci": "php-8.0"
tools:
labels:
    - GitLab
    - Utilities
    - Laravel
    - Test
+0 −0

Empty file added.

Loading