Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(developer): unify test action #12736

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, and presumably we can crank the number up as tests improve..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you get a nice little warning that coverage is low. As tests are added, I have been bumping up the coverage number already. This is a little easier to read 😁


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
20 changes: 20 additions & 0 deletions resources/build/builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,26 @@ fi

--------------------------------------------------------------------------------

## `builder_do_typescript_tests` function

Runs eslint, builds tests, and then runs tests with mocha + c8 (coverage)

**Note:** this is currently hosted in shellHelperFunctions.sh, but will
be moved to builder.typescript.inc.sh in the future.

### Usage

```bash
builder_run_action test builder_do_typescript_tests [coverage_threshold]
```

### Parameters

* **coverage_threshold** optional, minimum coverage for c8 to pass tests,
defaults to 90 (percent)

--------------------------------------------------------------------------------

## Formatting variables

These helper variables define ANSI color escapes when running in color mode, and
Expand Down
Loading