Skip to content

Commit 3827bc0

Browse files
alsiratappalsiratapp
alsiratapp
authored and
alsiratapp
committed
Add readme resources
Add test_with_coverage.sh Fix Integration test
1 parent 8f01768 commit 3827bc0

8 files changed

+107
-127
lines changed

coverage/lcov.info

-125
This file was deleted.

lib/articles_list/presentation/widget/article_list_item.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import '../../../common/constant.dart';
66
import '../../data/model/article.dart';
77

88
class ArticleListItem extends StatelessWidget {
9-
109
const ArticleListItem({
1110
Key? key,
1211
required this.article,
@@ -17,7 +16,9 @@ class ArticleListItem extends StatelessWidget {
1716
@override
1817
Widget build(BuildContext context) {
1918
String imageUrl = defaultImage;
20-
if (article.media.isNotEmpty && article.media.first.metaData.isNotEmpty) {
19+
if (article.media.isNotEmpty &&
20+
article.media.first.metaData.isNotEmpty &&
21+
article.media.first.metaData.first.url.contains('http')) {
2122
imageUrl = article.media.first.metaData.first.url;
2223
}
2324

readme_res/code_coverage.png

52.5 KB
Loading
Loading
Loading

readme_res/lint.png

15.3 KB
Loading

readme_res/nyt-flutter-emulator.gif

15.7 MB
Loading

test_with_coverage.sh

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
red=$(tput setaf 1)
3+
none=$(tput sgr0)
4+
filename=
5+
open_browser=
6+
7+
show_help() {
8+
printf "
9+
Script for running all unit and widget tests with code coverage.
10+
(run it from your root Flutter's project)
11+
*Important: requires lcov
12+
13+
Usage:
14+
$0 [--help] [--open] [--filename <path>]
15+
where:
16+
-o, --open
17+
Open the coverage in your browser,
18+
Default is google-chrome you can change this in the function open_cov().
19+
-h, --help
20+
print this message
21+
-f <path>, --filename <path>
22+
Run a particular test file. For example:
23+
24+
-f test/a_particular_test.dart
25+
26+
Or you can run all tests in a directory
27+
-f test/some_directory/
28+
"
29+
}
30+
31+
run_tests() {
32+
if [[ -f "pubspec.yaml" ]]; then
33+
rm -f coverage/lcov.info
34+
rm -f coverage/lcov-final.info
35+
flutter test --coverage "$filename"
36+
ch_dir
37+
else
38+
printf "\n${red}Error: this is not a Flutter project${none}\n"
39+
exit 1
40+
fi
41+
}
42+
43+
run_report() {
44+
if [[ -f "coverage/lcov.info" ]]; then
45+
lcov -r coverage/lcov.info lib/resources/l10n/\* lib/\*/fake_\*.dart \
46+
-o coverage/lcov-final.info
47+
genhtml -o coverage coverage/lcov-final.info
48+
else
49+
printf "\n${red}Error: no coverage info was generated${none}\n"
50+
exit 1
51+
fi
52+
}
53+
54+
ch_dir(){
55+
dir=$(pwd)
56+
input="$dir/coverage/lcov.info"
57+
output="$dir/coverage/lcov_new.info"
58+
echo "$input"
59+
while read line
60+
do
61+
secondString="SF:$dir/"
62+
echo "${line/SF:/$secondString}" >> $output
63+
done < "$input"
64+
65+
mv $output $input
66+
}
67+
68+
open_cov(){
69+
# This depends on your system
70+
# Google Chrome:
71+
# google-chrome coverage/index-sort-l.html
72+
# Mozilla:
73+
firefox coverage/index-sort-l.html
74+
}
75+
76+
while [ "$1" != "" ]; do
77+
case $1 in
78+
-h|--help)
79+
show_help
80+
exit
81+
;;
82+
-o|--open)
83+
open_browser=1
84+
;;
85+
-f|--filename)
86+
shift
87+
filename=$1
88+
;;
89+
*)
90+
show_help
91+
exit
92+
;;
93+
esac
94+
shift
95+
done
96+
97+
run_tests
98+
remove_from_coverage -f coverage/lcov.info -r '.g.dart$'
99+
remove_from_coverage -f coverage/lcov.info -r '.freezed.dart$'
100+
remove_from_coverage -f coverage/lcov.info -r '.config.dart$'
101+
run_report
102+
if [ "$open_browser" = "1" ]; then
103+
open_cov
104+
fi

0 commit comments

Comments
 (0)