Skip to content

Commit 6976fae

Browse files
authored
chore: Generate coverage reports and upload them. (#1110)
* chore: Update CI to generate coverage report. * chore: Upload coverage results * removed unneccessary code * update command name * test command * verify melos path * Update workflow to format and upload the report * fix functions ci * update path of functionc ci * fix path for all ci * fix: Update type for customAccessToken * set concurrency to 1 for realtime tests * fix: failing realtime tests * add stub to realtime * more stubs * update analyzer check in ci * Run tests on every PR for every packages and upload combined coverage report * Let the coverage workflow take care of everything about test coverage * update coverage workflow to setup test infra * add sleep after docker compose up * move the sleep * take down docker after testing * go back to the infra directory for taking down docker * revert changes on the individual CI files * Properly upload code coverage to coverall
1 parent d04d9e6 commit 6976fae

12 files changed

+141
-5
lines changed

.github/workflows/coverage.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Combined Coverage Report
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
coverage:
11+
name: Generate Combined Coverage
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- uses: subosito/flutter-action@v2
18+
with:
19+
flutter-version: '3.x'
20+
channel: 'stable'
21+
22+
- name: Install dependencies
23+
run: |
24+
dart pub global activate melos
25+
dart pub global activate coverage
26+
dart pub global activate combine_coverage
27+
melos bootstrap
28+
29+
- name: Run tests with coverage for all packages
30+
run: |
31+
# Create directory for combined coverage
32+
mkdir coverage
33+
34+
# Run tests for each package and generate coverage
35+
cd packages
36+
for d in */ ; do
37+
cd "$d"
38+
if [ -f "pubspec.yaml" ]; then
39+
echo "Running tests for $d"
40+
if [[ "$d" == "supabase_flutter/"* ]]; then
41+
flutter test --coverage --concurrency=1
42+
else
43+
# Set up Docker containers based on package
44+
if [[ "$d" == "postgrest/"* ]]; then
45+
cd ../../infra/postgrest
46+
docker compose down
47+
docker compose up -d
48+
cd ../../packages/postgrest
49+
dart test --coverage=coverage --concurrency=1
50+
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
51+
cd ../../infra/postgrest
52+
docker compose down
53+
sleep 5s
54+
cd ../../packages/postgrest
55+
elif [[ "$d" == "gotrue/"* ]]; then
56+
cd ../../infra/gotrue
57+
docker compose down
58+
docker compose up -d
59+
cd ../../packages/gotrue
60+
dart test --coverage=coverage --concurrency=1
61+
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
62+
cd ../../infra/gotrue
63+
docker compose down
64+
sleep 5s
65+
cd ../../packages/gotrue
66+
elif [[ "$d" == "storage_client/"* ]]; then
67+
cd ../../infra/storage_client
68+
docker compose down
69+
docker compose up -d
70+
cd ../../packages/storage_client
71+
dart test --coverage=coverage --concurrency=1
72+
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
73+
cd ../../infra/storage_client
74+
docker compose down
75+
sleep 5s
76+
cd ../../packages/storage_client
77+
else
78+
cd ../../packages/$d
79+
dart test --coverage=coverage --concurrency=1
80+
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
81+
fi
82+
fi
83+
fi
84+
cd ..
85+
done
86+
cd ..
87+
88+
- name: Combine coverage reports
89+
run: |
90+
dart pub global run combine_coverage:combine_coverage --repo-path="./" --output-directory="coverage"
91+
92+
- name: Upload combined coverage report
93+
uses: coverallsapp/github-action@v2
94+
with:
95+
github-token: ${{ secrets.GITHUB_TOKEN }}
96+
path-to-lcov: ./coverage/lcov.info

.github/workflows/functions_client.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ jobs:
5151
run: dart format lib test -l 80 --set-exit-if-changed
5252

5353
- name: analyzer
54+
if: ${{ matrix.sdk == 'stable'}}
5455
run: dart analyze --fatal-warnings --fatal-infos .
5556

57+
- name: analyzer
58+
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
59+
run: dart analyze
60+
5661
- name: Run tests
5762
run: dart test

.github/workflows/gotrue.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ jobs:
4848
run: dart format lib test -l 80 --set-exit-if-changed
4949

5050
- name: analyzer
51+
if: ${{ matrix.sdk == 'stable'}}
5152
run: dart analyze --fatal-warnings --fatal-infos .
5253

54+
- name: analyzer
55+
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
56+
run: dart analyze
57+
5358
- name: Build Docker image
5459
run: |
5560
cd ../../infra/gotrue

.github/workflows/postgrest.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ jobs:
5050
run: dart format lib test -l 80 --set-exit-if-changed
5151

5252
- name: analyzer
53+
if: ${{ matrix.sdk == 'stable'}}
5354
run: dart analyze --fatal-warnings --fatal-infos .
5455

56+
- name: analyzer
57+
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
58+
run: dart analyze
59+
5560
- name: Build Docker image
5661
run: |
5762
cd ../../infra/postgrest

.github/workflows/realtime_client.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ jobs:
4848
run: dart format lib test -l 80 --set-exit-if-changed
4949

5050
- name: analyzer
51+
if: ${{ matrix.sdk == 'stable'}}
5152
run: dart analyze --fatal-warnings --fatal-infos .
5253

54+
- name: analyzer
55+
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
56+
run: dart analyze
57+
5358
- name: Run tests
54-
run: dart test
59+
run: dart test --concurrency=1

.github/workflows/storage_client.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ jobs:
4747
run: dart format lib test -l 80 --set-exit-if-changed
4848

4949
- name: analyzer
50+
if: ${{ matrix.sdk == 'stable'}}
5051
run: dart analyze --fatal-warnings --fatal-infos .
5152

53+
- name: analyzer
54+
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
55+
run: dart analyze
56+
5257
- name: Build Docker image
5358
run: |
5459
cd ../../infra/storage_client

.github/workflows/supabase.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ jobs:
5858
run: dart format lib test -l 80 --set-exit-if-changed
5959

6060
- name: analyzer
61+
if: ${{ matrix.sdk == 'stable'}}
6162
run: dart analyze --fatal-warnings --fatal-infos .
6263

64+
- name: analyzer
65+
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
66+
run: dart analyze
67+
6368
- name: Run tests
6469
run: dart test --concurrency=1

.github/workflows/supabase_flutter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ jobs:
7878
- name: Verify if Flutter web build is successful
7979
run: |
8080
cd example
81-
flutter build web
81+
flutter build web

.github/workflows/yet_another_json_isolate.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ jobs:
4848
run: dart format lib test -l 80 --set-exit-if-changed
4949

5050
- name: analyzer
51+
if: ${{ matrix.sdk == 'stable'}}
5152
run: dart analyze --fatal-warnings --fatal-infos .
5253

54+
- name: analyzer
55+
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
56+
run: dart analyze
57+
5358
- name: Run tests
5459
run: dart test

melos.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ scripts:
3939
exec: dart pub outdated
4040

4141
update-version:
42+
description: Updates the version.dart file for each packages except yet_another_json_isolate
4243
run: |
4344
# Loop through the packages directory
4445
for d in packages/*/ ; do
@@ -53,4 +54,4 @@ scripts:
5354
rm packages/yet_another_json_isolate/lib/src/version.dart
5455
# Stage the version.dart file change
5556
git add packages/*/lib/src/version.dart
56-
description: Updates the version.dart file for each packages except yet_another_json_isolate
57+

packages/realtime_client/lib/src/realtime_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class RealtimeClient {
9191
int longpollerTimeout = 20000;
9292
SocketStates? connState;
9393
// This is called `accessToken` in realtime-js
94-
Future<String> Function()? customAccessToken;
94+
Future<String?> Function()? customAccessToken;
9595

9696
/// Initializes the Socket
9797
///

packages/realtime_client/test/socket_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ void main() {
393393
mockedSink = MockWebSocketSink();
394394

395395
when(() => mockedSocketChannel.sink).thenReturn(mockedSink);
396+
when(() => mockedSocketChannel.ready).thenAnswer((_) => Future.value());
397+
when(() => mockedSink.close()).thenAnswer((_) => Future.value());
396398
});
397399

398400
test('sends data to connection when connected', () {
@@ -407,7 +409,7 @@ void main() {
407409
.called(1);
408410
});
409411

410-
test('buffers data when not connected', () {
412+
test('buffers data when not connected', () async {
411413
mockedSocket.connect();
412414
mockedSocket.connState = SocketStates.connecting;
413415

@@ -575,6 +577,8 @@ void main() {
575577
mockedSink = MockWebSocketSink();
576578

577579
when(() => mockedSocketChannel.sink).thenReturn(mockedSink);
580+
when(() => mockedSink.close()).thenAnswer((_) => Future.value());
581+
when(() => mockedSocketChannel.ready).thenAnswer((_) => Future.value());
578582

579583
mockedSocket.connect();
580584
});

0 commit comments

Comments
 (0)