Commit d1ac3c3d authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: add hook scripts support

parent 70bf84ba
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -96,3 +96,10 @@ environments) will automatically be propagated to your Puppeteer tests.

If you're not using a smart deployment job, you may still explicitly declare the `PUPPETEER_BASE_URL` variable (but that
will be unfortunately hardcoded to a single server).

### Hook scripts

The Puppeteer template supports _optional_ **hook scripts** from your project, located in the `$PUPPETEER_PROJECT_DIR` directory to perform additional project-specific logic:

* `pre-puppeteer.sh` is executed **before** running Puppeteer,
* `post-puppeteer.sh` is executed **after** running Puppeteer (whichever the tests status).
+23 −1
Original line number Diff line number Diff line
@@ -243,6 +243,21 @@ stages:
    fi
  }

  function maybe_exec_hook() {
    if [[ -f "$1" ]]
    then
      log_info "\\e[33;1m$1\\e[0m hook found: execute"
      if [[ ! -x "$1" ]] && ! chmod +x "$1"
      then
        log_warn "... could not make \\e[33;1m${1}\\e[0m executable: please do it (chmod +x)"
        # fallback technique
        sh "$1"
      else
        "$1"
      fi
    fi
  }

  function eval_base_url() {
    # shellcheck disable=SC2154
    if [[ -n "$environment_url" ]]
@@ -290,10 +305,17 @@ puppeteer:
    - export JEST_JUNIT_OUTPUT_DIR="reports"
    - export JEST_JUNIT_OUTPUT_NAME="puppeteer.xunit.xml"
  script:
    # maybe execute pre hook
    - maybe_exec_hook "./pre-puppeteer.sh"
    # run tests
    # maybe activate DEBUG traces
    - 'if [[ "$TRACE" ]]; then export DEBUG=puppeteer:*; fi'
    # run puppeteer tests
    - npm run puppeteer -- --config '{"globals":{"URL":"$PUPPETEER_BASE_URL"}}' --reporters=default --reporters=jest-junit $PUPPETEER_TEST_EXTRA_ARGS
    - npm run puppeteer -- --config '{"globals":{"URL":"$PUPPETEER_BASE_URL"}}' --reporters=default --reporters=jest-junit $PUPPETEER_TEST_EXTRA_ARGS || rc=$?
    # maybe execute post hook
    - maybe_exec_hook "./post-puppeteer.sh"
    # exit with return code
    - exit $rc
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always