mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 00:15:32 +00:00
* Centralize the api-extractor.json files, update usage * Support @since * Tidy up a few warnings relating to API documentation content Fixes: #14838 Test-bot: skip
109 lines
No EOL
3.8 KiB
Bash
109 lines
No EOL
3.8 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=()
|
|
local TEST_DIR
|
|
|
|
if builder_is_running_on_teamcity; then
|
|
# we're running in TeamCity
|
|
MOCHA_FLAGS+=(--reporter "${KEYMAN_ROOT}/common/test/resources/mocha-teamcity-reporter/teamcity.cjs" --reporter-options parentFlowId="unit_tests")
|
|
echo "##teamcity[flowStarted flowId='unit_tests']"
|
|
fi
|
|
|
|
eslint .
|
|
|
|
# TODO: Unify test directory names (#14878)
|
|
if [[ -d test/ ]]; then
|
|
TEST_DIR="test/"
|
|
elif [[ -d tests/ ]]; then
|
|
TEST_DIR="tests/"
|
|
else
|
|
builder_die "No test/ or tests/ directory found."
|
|
fi
|
|
|
|
tsc --build "${TEST_DIR}"
|
|
|
|
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
|
|
|
|
if builder_is_running_on_teamcity; then
|
|
# we're running in TeamCity
|
|
echo "##teamcity[flowFinished flowId='unit_tests']"
|
|
fi
|
|
}
|
|
|
|
#
|
|
# Run api-extractor, preparing config files for each folder. As the config files
|
|
# are largely identical for each project, we copy them in rather than
|
|
# duplicating them across the repo (as that is hard to maintain over time)
|
|
#
|
|
# NOTE: this is setup only for Developer projects at this time as outputs go
|
|
# into developer/docs and developer/build; future generalization requires
|
|
# changing only report_temp and report_folder parameters.
|
|
#
|
|
# See also: /common/tools/api-extractor/README.md
|
|
#
|
|
typescript_run_api_extractor() {
|
|
project_path="$1"
|
|
index_d_ts="$2"
|
|
|
|
# tsdoc config file must be in same folder as tsconfig.json
|
|
cp "${KEYMAN_ROOT}/common/tools/api-extractor/tsdoc.template.json" "${THIS_SCRIPT_PATH}/tsdoc.json"
|
|
|
|
# api-extractor configuration must be stored in a file, so patch the
|
|
# file with the relevant parameters
|
|
|
|
if builder_is_windows; then
|
|
# replace \ with / on Windows in KEYMAN_ROOT path, so we don't end up with
|
|
# silly unescaped strings in JSON
|
|
keyman_root="$(echo "$KEYMAN_ROOT" | sed "s=\\\=/=g")"
|
|
else
|
|
keyman_root="${KEYMAN_ROOT}"
|
|
fi
|
|
|
|
# For now, these two variables are Developer-specific
|
|
report_temp="$keyman_root/developer/build/api"
|
|
report_folder="$keyman_root/developer/docs/api/etc"
|
|
export project_path index_d_ts keyman_root report_temp report_folder
|
|
|
|
envsubst "\$keyman_root,\$project_path,\$index_d_ts,\$report_temp,\$report_folder" \
|
|
< "${KEYMAN_ROOT}/common/tools/api-extractor/api-extractor.template.json" \
|
|
> "${THIS_SCRIPT_PATH}/api-extractor.json"
|
|
|
|
export -n project_path index_d_ts keyman_root report_temp report_folder
|
|
|
|
api-extractor run \
|
|
--local \
|
|
--verbose \
|
|
--config "${THIS_SCRIPT_PATH}/api-extractor.json"
|
|
|
|
rm "${THIS_SCRIPT_PATH}/tsdoc.json"
|
|
rm "${THIS_SCRIPT_PATH}/api-extractor.json"
|
|
} |