<commit_before>#!/bin/bash
#
# Run project tests
#
# NOTE: This script expects to be run from the project root with
# ./scripts/run_tests.sh

# Use default environment vars for localhost if not already set
export DM_API_URL=${DM_API_URL:=http://localhost:5000}
export DM_BUYER_FRONTEND_API_AUTH_TOKEN=${DM_BUYER_FRONTEND_API_AUTH_TOKEN:=myToken}
export DM_SEARCH_API_URL=${DM_SEARCH_API_URL:=http://localhost:5001}
export DM_BUYER_FRONTEND_SEARCH_API_AUTH_TOKEN=${DM_BUYER_FRONTEND_SEARCH_API_AUTH_TOKEN:=myToken}

echo "Environment variables in use:"
env | grep DM_

set -o pipefail

function display_result {
  RESULT=$1
  EXIT_STATUS=$2
  TEST=$3

  if [ $RESULT -ne 0 ]; then
    echo -e "\033[31m$TEST failed\033[0m"
    exit $EXIT_STATUS
  else
    echo -e "\033[32m$TEST passed\033[0m"
  fi
}

pep8 .
display_result $? 2 "Code style check"

npm run --silent frontend-build:production
display_result $? 1 "Build of front end static assets"

nosetests -v -s --with-doctest
display_result $? 3 "Unit tests"<commit_msg>Add JS tests to the run_tests.sh script<commit_after>#!/bin/bash
#
# Run project tests
#
# NOTE: This script expects to be run from the project root with
# ./scripts/run_tests.sh

# Use default environment vars for localhost if not already set
export DM_API_URL=${DM_API_URL:=http://localhost:5000}
export DM_BUYER_FRONTEND_API_AUTH_TOKEN=${DM_BUYER_FRONTEND_API_AUTH_TOKEN:=myToken}
export DM_SEARCH_API_URL=${DM_SEARCH_API_URL:=http://localhost:5001}
export DM_BUYER_FRONTEND_SEARCH_API_AUTH_TOKEN=${DM_BUYER_FRONTEND_SEARCH_API_AUTH_TOKEN:=myToken}

echo "Environment variables in use:"
env | grep DM_

set -o pipefail

function display_result {
  RESULT=$1
  EXIT_STATUS=$2
  TEST=$3

  if [ $RESULT -ne 0 ]; then
    echo -e "\033[31m$TEST failed\033[0m"
    exit $EXIT_STATUS
  else
    echo -e "\033[32m$TEST passed\033[0m"
  fi
}

pep8 .
display_result $? 2 "Code style check"

npm run --silent frontend-build:production
display_result $? 1 "Build of front end static assets"

nosetests -v -s --with-doctest
display_result $? 3 "Python unit tests"

npm test
display_result $? 3 "JavaScript unit tests"
{'fraction_non_alphanumeric': 0.1027686532144533, 'fraction_numerical': 0.0323791647114031, 'mean_word_length': 5.056818181818182, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5483696', 'n_tokens_mistral': 832, 'n_tokens_neox': 777, 'n_words': 201}