Skip to content
Snippets Groups Projects
Verified Commit 3662badf authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: test runners are now empowered to run selected files #166

parent 25e7ff7d
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,104 @@
if pkgs.stdenv.system != null
then pkgs.stdenv.system
else builtins.currentSystem;
commonFunctionsScript = pkgs.writeScript "common-functions" ''
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RESET='\033[0m'
BOLD='\033[1m'
else
RED=""
GREEN=""
BLUE=""
RESET=""
fi
is_true() {
val="$1"
if [ "$val" = 'true' ] || [ "$val" = '1' ]; then
return 0
else
return 1
fi
}
CURRENT_LEVEL=0
get_padding() {
local padding=""
for ((i=0; i < CURRENT_LEVEL; i++)); do
padding+=" "
done
echo "$padding"
}
increase_level() {
CURRENT_LEVEL=$((CURRENT_LEVEL + 1))
}
decrease_level() {
CURRENT_LEVEL=$((CURRENT_LEVEL - 1))
}
echo_ok() {
padding=$(get_padding)
echo -e "$padding$GREEN✔$RESET $1"
}
echo_delimiter() {
echo " "
}
echo_section() {
decrease_level
padding=$(get_padding)
echo -e "\n\n$padding$BOLD$1$RESET"
increase_level
}
echo_text() {
padding=$(get_padding)
echo -e "$padding$1"
}
echo_fail() {
padding=$(get_padding)
echo -e "$padding$RED✖ $1$RESET"
}
echo_hint() {
padding=$(get_padding)
echo -e "$padding$BLUE→ $1$RESET"
}
echo_step() {
padding=$(get_padding)
echo -e "$padding$BLUE•$RESET $1"
}
convert_multiline_for_nix() {
printf "%s" "$1" | ${pkgs.gnused}/bin/sed 's/\\/\\\\/g; s/"/\\"/g; s/$/\\n/g' | tr -d '\n'
}
if [ -z "$DEBUG_MODE" ]; then
DEBUG_MODE='false'
fi
if [ -n "$CI_JOB_TOKEN" ]; then
CI_MODE='true'
fi
if is_true "$DEBUG_MODE" || is_true "$CI_MODE"; then
set -x
fi
'';
in {
env.APP_NAME = "monster";
env.dddd = "@schukai/monster";
......@@ -92,6 +190,7 @@ in {
${pkgs.git-chglog}/bin/git-chglog --config ${config.devenv.root}/.chglog/config.yml -o ${config.devenv.root}/CHANGELOG.md
'';
scripts.build-and-publish.exec = ''
if [ -t 1 ]; then
......@@ -256,13 +355,57 @@ in {
'';
scripts.run-tests.exec = ''
#!${pkgs.bash}/bin/bash
TEST_PATH="${config.devenv.root}/test"
TEST_CASES_PATH="''${TEST_PATH}/cases/"
source ${commonFunctionsScript}
update-versions
if ! ${pkgs.nodePackages.pnpm}/bin/pnpm mocha --colors --jobs 1 --bail --recursive test/cases/
echo_section "run tests"
selection=$(gum choose "run specific test" "run all tests" "Cancel")
if [[ "$selection" == "Cancel" ]]; then
echo_text "Exiting."
exit 0
fi
if [[ "$selection" == "run all tests" ]]; then
echo_step "run specific tests"
if ! ${pkgs.nodePackages.pnpm}/bin/pnpm mocha --colors --jobs 1 --bail --recursive $TEST_CASES_PATH
then
echo "ERROR: Tests failed, check your JS!"
exit 1
fi
exit 0
fi
escaped_test_cases_path=$(printf '%s\n' "$TEST_CASES_PATH" | sed 's:[\\/&]:\\&:g;$!s/$/\\/')
echo_step "run all tests"
files=$(find $TEST_CASES_PATH -type f -name "*.mjs")
relative_files=$(echo "$files" | sed "s|''${escaped_test_cases_path}||g")
selected=$(echo "$relative_files" | gum filter --no-limit --header="Select the test case to run" --placeholder="Select test case to run, use tab to select multiple files")
if [[ -z "$selected" ]]; then
echo_text "No files selected. Exiting."
exit 0
fi
full_paths=$(echo "$selected" | sed "s|^|''${escaped_test_cases_path}|")
if ! ${pkgs.nodePackages.pnpm}/bin/pnpm mocha --colors --jobs 1 --bail --recursive $full_paths
then
echo "ERROR: Tests failed, check your JS!"
exit 1
fi
'';
scripts.build-monster-mjs.exec = ''
......@@ -313,6 +456,7 @@ in {
'';
scripts.publish-doc.exec = ''
#!${pkgs.bash}/bin/bash
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment