spiegel-keyman/resources/build/typescript.inc.sh
2025-08-03 07:01:57 +10:00

43 lines
1.5 KiB
Bash

# shellcheck shell=bash
# Keyman is copyright (C) SIL Global. MIT License.
#
# Runs eslint, builds tests, and then runs tests with mocha + c8 (coverage)
#
# Usage:
# builder_run_action test typescript_run_eslint_mocha_tests [coverage_threshold]
# Parameters:
# 1: coverage_threshold optional, minimum coverage for c8 to pass tests,
# defaults to 90 (percent)
typescript_run_eslint_mocha_tests() {
local MOCHA_FLAGS=
if builder_is_running_on_teamcity; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi
eslint .
tsc --build test/
local THRESHOLD_PARAMS=
local C8_THRESHOLD=
if [[ $# -gt 0 ]]; then
C8_THRESHOLD=$1
THRESHOLD_PARAMS="--lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD"
else
# Seems like a bug in TeamCity reporter if we don't list default thresholds,
# see #13418.
#
# Making branch and function thresholds slightly lower, because the default
# for c8 is 0 for these anyway.
THRESHOLD_PARAMS="--lines 90 --statements 90 --branches 80 --functions 80"
fi
c8 --reporter=lcov --reporter=text --exclude-after-remap --check-coverage $THRESHOLD_PARAMS mocha ${MOCHA_FLAGS} "${builder_extra_params[@]}"
if [[ ! -z "$C8_THRESHOLD" ]]; then
builder_echo warning "Coverage thresholds are currently $C8_THRESHOLD%, which is lower than ideal."
builder_echo warning "Please increase threshold in build.sh as test coverage improves."
fi
}