Created
March 31, 2017 15:13
-
-
Save mhazy/8b6e2f6238adfc557738844bcc02f86c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Environment | |
export ALDO_ENV="test" | |
export NODE_ENV="test" | |
# Containers, etc. | |
CONTAINERS_TOTAL=${CIRCLE_NODE_TOTAL:-"1"} | |
CONTAINERS_INDEX=${CIRCLE_NODE_INDEX:-"1"} | |
# Test command to pass test file paths to | |
MOCHA_CMD="./node_modules/.bin/nyc --check-coverage --statements 0 --lines 0 --functions 0 --branches 0 ./node_modules/.bin/_mocha --opts ./test/mocha.opts" | |
# Other tasks | |
TODO_CHECK_CMD="./test/todos-check.sh" | |
LINT_JS_CMD="npm run test:lint-js" | |
LINT_CSS_CMD="npm run test:lint-css" | |
# Test File Listing | |
LIST_FILES_CMD="find ./src -name *.test.js" | |
doTodoCheck() { | |
echo "--- TODO Check" | |
eval $TODO_CHECK_CMD | |
} | |
doLintJS() { | |
echo "--- Linting (JS)" | |
eval $LINT_JS_CMD | |
} | |
doLintCSS() { | |
echo "--- Linting (CSS)" | |
eval $LINT_CSS_CMD | |
} | |
doTests() { | |
echo "--- Test Batch" | |
eval $MOCHA_CMD $@ | |
} | |
# One container, do everything | |
if [ "$CONTAINERS_TOTAL" -eq "1" ]; then | |
echo "Running Single Container" | |
doTodoCheck | |
doLintJS | |
doLintCSS | |
doTests $(eval $LIST_FILES_CMD) | |
else | |
echo "Running Multi Container" | |
if [ "$CONTAINERS_INDEX" -eq "0" ]; then | |
# First container for linting, etc. | |
doTodoCheck | |
doLintJS | |
doLintCSS | |
else | |
# All other containers run tests | |
TOTAL_TEST_CONTAINERS=$((CONTAINERS_TOTAL - 1)) | |
CURRENT_TEST_CONTAINER=$((CONTAINERS_INDEX - 1)) | |
echo "Total containers for testing: ${TOTAL_TEST_CONTAINERS}" | |
echo "Running tests for container: $((CURRENT_TEST_CONTAINER + 1)) of ${TOTAL_TEST_CONTAINERS}" | |
SPLIT_TESTS=$(eval $LIST_FILES_CMD | awk "NR%${TOTAL_TEST_CONTAINERS}==${CURRENT_TEST_CONTAINER}" | tr "\n" " ") | |
doTests $SPLIT_TESTS | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment