machine:
  environment:
    PORT: 8080

dependencies:
  post:
    - npm install saucelabs # allow sending Watai results to SauceLabs
    - wget https://saucelabs.com/downloads/sc-latest-linux.tar.gz
    - tar -xzf sc-latest-linux.tar.gz

test:
  pre:
    - mkdir $HOME/.watai && cp test/config-ci.js $HOME/.watai/config.js # prepare CI-specific config holder and add CI-specific config to Watai
  override:
    - cd sc-*-linux && ./bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY --tunnel-identifier "circle-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX" --readyfile ~/sauce_is_ready:
        background: true
    - /usr/bin/python3 -m http.server $PORT:
        background: true
    # wait for Sauce Connect
    - while [ ! -e ~/sauce_is_ready ]; do sleep 1; done
    # wait for server
    - curl --retry 20 --retry-delay 1 -v http://localhost:$PORT
    - npm test

machine:
  environment:
    PORT: 8080
    # SAUCE_USERNAME is defined in the CircleCI web UI
    # SAUCE_ACCESS_KEY is defined in the CircleCI web UI

dependencies:
  post:
    - npm install saucelabs # allow sending Watai results to SauceLabs
    - wget https://saucelabs.com/downloads/sc-latest-linux.tar.gz
    - tar -xzf sc-latest-linux.tar.gz

test:
  pre:
    - mkdir $HOME/.watai && cp test/config-ci.js $HOME/.watai/config.js # prepare CI-specific config holder and add CI-specific config to Watai
  override:
    - cd sc-*-linux && ./bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY --tunnel-identifier "circle-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX" --readyfile ~/sauce_is_ready:
        background: true
    - /usr/bin/python3 -m http.server $PORT:
        background: true
    # wait for Sauce Connect
    - while [ ! -e ~/sauce_is_ready ]; do sleep 1; done
    # wait for server
    - curl --retry 20 --retry-delay 1 -v http://localhost:$PORT
    - npm test

Document origin of SAUCE_USERNAME and SAUCE_ACCESS_KEY env variables
Document origin of SAUCE_USERNAME and SAUCE_ACCESS_KEY env variables
