mbland/custom-links

View on GitHub
scripts/test.d/end-to-end

Summary

Maintainability
Test Coverage
#! /usr/bin/env bash
#
# Runs end-to-end tests using Selenium-WebDriver and Mocha
#
# Usage:
#   [SELENIUM_BROWSER=<browser>] {{go}} {{cmd}}
#
# Where:
#   <browser>  Browser to use, e.g. chrome (default), firefox, phantomjs, safari
#
# Note the the end-to-end tests DO NOT collect coverage.

_test_end_to_end() {
  local node_version
  local major_version

  node_version="$(node --version)"

  if [[ "$?" -eq '0' && "$node_version" =~ v([0-9]+)\. ]]; then
    major_version="${BASH_REMATCH[1]}"
  else
    @go.printf '%s' "Can't determine Node.js version from " \
      '`node --version`. Aborting...'$'\n' >&2
    return 1
  fi

  if [[ "$major_version" -lt '6' ]]; then
    @go.printf '%s' 'The selenium-webdriver package uses JavaScript syntax ' \
      "that isn't available until Node.js v6.0.0 and later, but the " \
      "available Node.js version is $node_version. Skipping..."$'\n' >&2
    return
  fi
  mocha tests/end-to-end/end-to-end.js
}

_test_end_to_end "$@"