Commit df9bbd43 authored by Thibaud-Vdb's avatar Thibaud-Vdb
Browse files

Merge branch 'cypress_run' into 'latest'

feat: [New job] cypress_run

See merge request r2devops/hub!300
parents 8d0e9bc5 46488fa1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ DevOps's
Devops's
devops's
dictionnaries
dir
DLL
dll
DocBlocks
@@ -137,6 +138,7 @@ Gzip
HADOLINT
hadolint
hardcoded
headlessly
Hotjar
Hotjar's
html
@@ -216,6 +218,7 @@ md
minify
Mkdocs
mkdocs
Mocka
Monorepo
monorepo
MONTPELLIER
@@ -248,6 +251,7 @@ openssl
opensslv
os
OSS
output
OWASP
PDF
pdf
@@ -299,12 +303,14 @@ RetireJS
RuboCop
rubocop
runtime
rustdoc
salesforce
SAS
sast
scala
SCALAFIX
scalafix
Scaleway
schemas
serverless
Severities
+37 −0
Original line number Diff line number Diff line
## Objective

This job test your front end web application by running tests headlessly in a CI context.


## How to use it

1. Ensure that your project is set to use Cypress. You can refer to the [Cypress Getting Started](https://docs.cypress.io/guides/getting-started/installing-cypress). You can see your job record on the Cypress Dashboard by connecting your GitLab account and set the `CYPRESS_RECORD_KEY` variable. See how to [Set up your project to record](https://docs.cypress.io/guides/dashboard/projects#Set-up-a-project-to-record) and [Connect GitLab with Cypress Dashboard](https://docs.cypress.io/guides/dashboard/gitlab-integration#Installing-the-GitLab-integration).
!!! warning You must override `CYPRESS_BASE_URL` variable.
    To ensure that the job work you have to specify the URL of your server (Example: `http://localhost:4200` for Angular web Application, `http://localhost:3000` for React, etc.).
    It's used to     prevent Cypress runs before your web sever is up and available. You can see more [here](https://docs.cypress.io/guides/continuous-integration/introduction#Boot-your-server)
1. 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/cypress_run.yml'
    ```
1. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
1. Well done, your job is ready to work ! 😀

## Job details

* Job name: `cypress_run`
* Docker image:
[`cypress/browsers:node16.5.0-chrome94-ff93`](https://hub.docker.com/r/cypress/browsers)
* Default stage: `dynamic_tests`
* When: `always`

### Variables

| Name | Description | Default | 
| ---- | ----------- | ------- |
| `CYPRESS_CONFIG_FILE` | Specify a config file to use | `cypress.json` |
| `CYPRESS_PROJECT_PATH` | Path to project directory | `.` |
| `CYPRESS_RECORD_KEY` | Specify a record key in order to get a video of tests | ` ` |
| `CYPRESS_REPORTER` | Name of the [Mocka reporter](https://docs.cypress.io/guides/tooling/reporters) used| `spec` |
| `CYPRESS_BASE_URL`  | **(MANDATORY)** The base URL of your server | ` `|
| `ADDITIONAL_OPTIONS` | Additional options to the run | ` ` |
+45 −0
Original line number Diff line number Diff line
stages:
  - dynamic_tests

cypress_run:
    image: cypress/browsers:node16.5.0-chrome94-ff93
    stage: dynamic_tests

    cache:
      key: ${CI_COMMIT_REF_SLUG}
      paths:
        - .npm/
        - ~/.cache

    variables:
      CYPRESS_CONFIG_FILE : "cypress.json"
      CYPRESS_PROJECT_PATH : "."
      CYPRESS_RECORD_KEY : ""
      CYPRESS_REPORTER : "spec"
      CYPRESS_BASE_URL : ""
      ADDITIONAL_OPTIONS : ""

    script:
      # install dependencies
      - npm ci
      # install module wait-on to ensure that cypress will run after the serve start
      - npm i -g wait-on
      # start the server in the background and pause Cypress until the server is running
      - if [ ! -z ${CYPRESS_BASE_URL} ]; then
      -   npm start --no-clipboard & wait-on ${CYPRESS_BASE_URL}
      - else
      -   echo "Variable CYPRESS_BASE_URL is MANDATORY. You must fill it !"
      -   exit 1
      - fi
      # run Cypress tests
      - if [ ! -z ${CYPRESS_RECORD_KEY} ]; then
      -   npx cypress run -P ${CYPRESS_PROJECT_PATH} -C ${CYPRESS_CONFIG_FILE} -r ${CYPRESS_REPORTER} ${ADDITIONAL_OPTIONS} --record
      - else
      -   npx cypress run -P ${CYPRESS_PROJECT_PATH} -C ${CYPRESS_CONFIG_FILE} -r ${CYPRESS_REPORTER} ${ADDITIONAL_OPTIONS}
      - fi
      
    artifacts:
        when: always
        paths:
          - cypress/videos/**/*.mp4
          - cypress/screenshots/**/*.png
+9 −0
Original line number Diff line number Diff line
name: cypress_run
description: A job to run end-to-end test
default_stage: dynamic_tests
icon: 🧠
maintainer: DjNaGuRo
license: MIT
images:
  cypress/browsers:node16.5.0-chrome94-ff93
tools:
+0 −0

Empty file added.

Loading