continuous-integration-run-tests.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. # For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. packages=$(ls packages -1 | sed -e 's#^ckeditor5\?-\(.\+\)$#\1#')
  5. errorOccured=0
  6. rm -r -f .nyc_output
  7. mkdir .nyc_output
  8. failedTestsPackages=""
  9. failedCoveragePackages=""
  10. RED='\033[0;31m'
  11. NC='\033[0m'
  12. # Travis functions inspired by https://github.com/travis-ci/travis-rubies/blob/a10ba31e3f508650204017332a608ef9bce2c733/build.sh.
  13. function travis_nanoseconds() {
  14. local cmd="date"
  15. local format="+%s%N"
  16. local os=$(uname)
  17. if hash gdate > /dev/null 2>&1; then
  18. cmd="gdate" # use gdate if available
  19. elif [[ "$os" = Darwin ]]; then
  20. format="+%s000000000" # fallback to second precision on darwin (does not support %N)
  21. fi
  22. $cmd -u $format
  23. }
  24. travis_time_start() {
  25. travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
  26. travis_start_time=$(travis_nanoseconds)
  27. echo -en "travis_time:start:$travis_timer_id\r${ANSI_CLEAR}"
  28. }
  29. travis_time_finish() {
  30. local result=$?
  31. travis_end_time=$(travis_nanoseconds)
  32. local duration=$(($travis_end_time-$travis_start_time))
  33. echo -en "\ntravis_time:end:$travis_timer_id:start=$travis_start_time,finish=$travis_end_time,duration=$duration\r${ANSI_CLEAR}"
  34. return $result
  35. }
  36. fold_start() {
  37. echo -e "travis_fold:start:$1\033[33;1m$2\033[0m"
  38. travis_time_start
  39. }
  40. fold_end() {
  41. travis_time_finish
  42. echo -e "\ntravis_fold:end:$1\n"
  43. }
  44. for package in $packages; do
  45. fold_start "package:$package" "Testing $package${NC}"
  46. yarn run test -f $package --reporter=dots --production --coverage
  47. if [ "$?" -ne "0" ]; then
  48. echo
  49. echo -e "💥 ${RED}$package${NC} failed to pass unit tests 💥"
  50. failedTestsPackages="$failedTestsPackages $package"
  51. errorOccured=1
  52. fi
  53. cp coverage/*/coverage-final.json .nyc_output
  54. npx nyc check-coverage --branches 100 --functions 100 --lines 100 --statements 100
  55. if [ "$?" -ne "0" ]; then
  56. echo -e "💥 ${RED}$package${NC} doesn't have required code coverage 💥"
  57. failedCoveragePackages="$failedCoveragePackages $package"
  58. errorOccured=1
  59. fi
  60. fold_end "package:$package"
  61. done;
  62. if [ "$errorOccured" -eq "1" ]; then
  63. echo
  64. echo "---"
  65. echo
  66. if ! [[ -z $failedTestsPackages ]]; then
  67. echo -e "Following packages did not pass unit tests:${RED}$failedTestsPackages${NC}"
  68. fi
  69. if ! [[ -z $failedCoveragePackages ]]; then
  70. echo -e "Following packages did not provide required code coverage:${RED}$failedCoveragePackages${NC}"
  71. fi
  72. echo
  73. exit 1 # Will break the CI build
  74. fi