Skip to content

Commit

Permalink
refactor(developer): unify test action
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdurdin committed Nov 28, 2024
1 parent 21736d8 commit 70a32f0
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 201 deletions.
18 changes: 1 addition & 17 deletions developer/src/common/web/utils/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,8 @@ function do_build() {
tsc --build
}

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi

eslint .
tsc --build test
readonly C8_THRESHOLD=50
c8 --reporter=lcov --reporter=text --exclude-after-remap --check-coverage=false --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS}
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."
}

builder_run_action clean rm -rf ./build/
builder_run_action configure verify_npm_setup
builder_run_action build do_build
builder_run_action test do_test
builder_run_action test builder_do_typescript_tests 50
builder_run_action publish builder_publish_npm
18 changes: 1 addition & 17 deletions developer/src/kmc-analyze/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,9 @@ builder_parse "$@"

#-------------------------------------------------------------------------------------------------------------------

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi

eslint .
cd test
tsc --build
cd ..
readonly C8_THRESHOLD=70
c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS}
}

builder_run_action clean rm -rf ./build/
builder_run_action configure verify_npm_setup
builder_run_action build tsc --build
builder_run_action api api-extractor run --local --verbose
builder_run_action test do_test
builder_run_action test builder_do_typescript_tests 70
builder_run_action publish builder_publish_npm
27 changes: 7 additions & 20 deletions developer/src/kmc-copy/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,16 @@ builder_parse "$@"

#-------------------------------------------------------------------------------------------------------------------

do_test() {
# note: `export TEST_SAVE_ARTIFACTS=1` to save a copy of artifacts to temp path
# note: `export TEST_SAVE_FIXTURES=1` to get a copy of cloud-based fixtures saved to online/
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi

eslint .
cd test
tsc --build
cd ..
readonly C8_THRESHOLD=70
c8 -skip-full --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS} "${builder_extra_params[@]}"
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."
}


builder_run_action clean rm -rf ./build/
builder_run_action configure verify_npm_setup
builder_run_action build tsc --build
builder_run_action api api-extractor run --local --verbose
builder_run_action test do_test

# note: `export TEST_SAVE_ARTIFACTS=1` to save a copy of artifacts to temp path
# note: `export TEST_SAVE_FIXTURES=1` to get a copy of cloud-based fixtures saved to online/
# TODO: -skip-full
builder_run_action test builder_do_typescript_tests 70

builder_run_action publish builder_publish_npm
17 changes: 1 addition & 16 deletions developer/src/kmc-generate/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,9 @@ do_build() {
cp -R ./src/template/ ./build/src/
}

do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi

eslint .
cd test
tsc --build
cd ..
c8 --reporter=lcov --reporter=text mocha ${MOCHA_FLAGS} "${builder_extra_params[@]}"
}

builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_run_action configure verify_npm_setup
builder_run_action build do_build
builder_run_action api api-extractor run --local --verbose
builder_run_action test do_test
builder_run_action test builder_do_typescript_tests
builder_run_action publish builder_publish_npm
15 changes: 1 addition & 14 deletions developer/src/kmc-keyboard-info/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,13 @@ function do_configure() {
cat "$KEYMAN_ROOT/resources/standards-data/langtags/langtags.json" >> src/imports/langtags.js
}

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi

eslint .
tsc --build test
c8 --reporter=lcov --reporter=text --exclude-after-remap --check-coverage=false mocha ${MOCHA_FLAGS}
}

#-------------------------------------------------------------------------------------------------------------------

builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_run_action configure do_configure
builder_run_action build tsc --build
builder_run_action api api-extractor run --local --verbose
builder_run_action test do_test
builder_run_action test builder_do_typescript_tests

#-------------------------------------------------------------------------------------------------------------------

Expand Down
14 changes: 1 addition & 13 deletions developer/src/kmc-kmn/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,8 @@ function do_build() {
}

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi

copy_deps
tsc --build test/
npm run lint
readonly C8_THRESHOLD=80
c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS}
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."
builder_do_typescript_tests 80
}

builder_run_action build do_build
Expand Down
17 changes: 1 addition & 16 deletions developer/src/kmc-ldml/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,12 @@ function do_build_fixtures() {
node ../../../common/tools/hextobin/build/hextobin.js ./test/fixtures/basic.txt ./build/test/fixtures/basic-txt.kmx
}

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi

eslint .
cd test
tsc -b
cd ..
c8 --reporter=lcov --reporter=text mocha ${MOCHA_FLAGS} "${builder_extra_params[@]}"
}

builder_run_action clean do_clean
builder_run_action configure do_configure
builder_run_action build do_build
builder_run_action build-fixtures do_build_fixtures
builder_run_action api api-extractor run --local --verbose
builder_run_action test do_test
builder_run_action test builder_do_typescript_tests

#-------------------------------------------------------------------------------------------------------------------

Expand Down
42 changes: 5 additions & 37 deletions developer/src/kmc-model-info/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,11 @@ builder_parse "$@"

#-------------------------------------------------------------------------------------------------------------------

if builder_start_action clean; then
rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_finish_action success clean
fi

#-------------------------------------------------------------------------------------------------------------------

if builder_start_action configure; then
verify_npm_setup
builder_finish_action success configure
fi

#-------------------------------------------------------------------------------------------------------------------

if builder_start_action build; then
npm run build
builder_finish_action success build
fi

builder_run_action api api-extractor run --local --verbose

#-------------------------------------------------------------------------------------------------------------------

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi
eslint .
tsc --build test
c8 --reporter=lcov --reporter=text --exclude-after-remap --check-coverage=false --lines 80 mocha ${MOCHA_FLAGS}
# TODO: remove --lines 80 and improve coverage
}

builder_run_action test do_test
builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_run_action configure verify_npm_setup
builder_run_action build tsc --build
builder_run_action api api-extractor run --local --verbose
builder_run_action test builder_do_typescript_tests 80

#-------------------------------------------------------------------------------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion developer/src/kmc-model-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"url": "https://github.com/keymanapp/keyman/issues"
},
"dependencies": {
"@keymanapp/common-types": "*",
"@keymanapp/common-types": "*",
"@keymanapp/developer-utils": "*"
},
Expand Down
16 changes: 1 addition & 15 deletions developer/src/kmc-model/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,13 @@ builder_parse "$@"

function do_build() {
tsc -b ./tools/tsconfig.json
npm run build
}

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi
npm run lint
cd test
tsc -b
cd ..
c8 --reporter=lcov --reporter=text mocha ${MOCHA_FLAGS}
}

builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_run_action configure verify_npm_setup
builder_run_action build do_build
builder_run_action api api-extractor run --local --verbose
builder_run_action test do_test
builder_run_action test builder_do_typescript_tests
builder_run_action publish builder_publish_npm

1 change: 0 additions & 1 deletion developer/src/kmc-model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"dependencies": {
"@keymanapp/common-types": "*",
"@keymanapp/keyman-version": "*",
"@keymanapp/common-types": "*",
"typescript": "^5.4.5"
},
"devDependencies": {
Expand Down
16 changes: 1 addition & 15 deletions developer/src/kmc-package/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,11 @@ builder_describe_outputs \

builder_parse "$@"

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi
eslint .
cd test
tsc --build
cd ..
c8 --reporter=lcov --reporter=text mocha ${MOCHA_FLAGS}
}

#-------------------------------------------------------------------------------------------------------------------

builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_run_action configure verify_npm_setup
builder_run_action build tsc --build
builder_run_action api api-extractor run --local --verbose
builder_run_action test do_test
builder_run_action test builder_do_typescript_tests
builder_run_action publish builder_publish_npm
20 changes: 1 addition & 19 deletions developer/src/kmc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,6 @@ function do_api() {

#-------------------------------------------------------------------------------------------------------------------

function do_test() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; then
# we're running in TeamCity
MOCHA_FLAGS="-reporter mocha-teamcity-reporter"
fi

eslint .
tsc --build test/
readonly C8_THRESHOLD=50
c8 --reporter=lcov --reporter=text --lines $C8_THRESHOLD --statements $C8_THRESHOLD --branches $C8_THRESHOLD --functions $C8_THRESHOLD mocha ${MOCHA_FLAGS}
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."
}

#-------------------------------------------------------------------------------------------------------------------

function do_bundle() {
SOURCEMAP_PATHS=( "${PACKAGES[@]}" )
SOURCEMAP_PATHS=( "${SOURCEMAP_PATHS[@]/%//build}" )
Expand Down Expand Up @@ -117,7 +99,7 @@ function do_bundle() {
builder_run_action clean rm -rf ./build/ ./tsconfig.tsbuildinfo
builder_run_action configure verify_npm_setup
builder_run_action build do_build
builder_run_action test do_test
builder_run_action test builder_do_typescript_tests 50
builder_run_action api do_api
builder_run_action bundle do_bundle
builder_run_action publish builder_publish_npm
26 changes: 26 additions & 0 deletions resources/shellHelperFunctions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,30 @@ _select_node_version_with_nvm() {

check-markdown() {
node "$KEYMAN_ROOT/resources/tools/check-markdown" --root "$1"
}

builder_do_typescript_tests() {
local MOCHA_FLAGS=

if [[ "${TEAMCITY_GIT_PATH:-}" != "" ]]; 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"
fi

c8 --reporter=lcov --reporter=text --exclude-after-remap --check-coverage=false $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
}

0 comments on commit 70a32f0

Please sign in to comment.