Skip to content

Commit f8ed85b

Browse files
Added runner tests and configured PR validation
1 parent cdbbee6 commit f8ed85b

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Analyze & Test
2+
on: [pull_request, workflow_dispatch]
3+
4+
jobs:
5+
analyze:
6+
runs-on: ubuntu-latest
7+
steps:
8+
# Checkout the PR branch
9+
- uses: actions/checkout@v3
10+
11+
# Setup Flutter environment
12+
- uses: subosito/flutter-action@v2
13+
with:
14+
channel: "stable"
15+
16+
# Download all the packages that the app uses
17+
- run: flutter pub get
18+
19+
# Enforce lint rules
20+
- run: flutter analyze
21+
22+
test:
23+
runs-on: ubuntu-latest
24+
steps:
25+
# Checkout the PR branch
26+
- uses: actions/checkout@v3
27+
28+
# Setup Flutter environment
29+
- uses: subosito/flutter-action@v2
30+
with:
31+
channel: "stable"
32+
33+
# Download all the packages that the app uses
34+
- run: flutter pub get
35+
36+
# Run all tests
37+
- run: flutter test

lib/src/platform_runners.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ void testWidgetsOnMac(
9696
await test(tester);
9797
} finally {
9898
debugDefaultTargetPlatformOverride = null;
99+
tester.view.reset();
99100
}
100101
}, skip: skip, variant: variant);
101102
}
@@ -144,6 +145,7 @@ void testWidgetsOnWindows(
144145
await test(tester);
145146
} finally {
146147
debugDefaultTargetPlatformOverride = null;
148+
tester.view.reset();
147149
}
148150
}, skip: skip, variant: variant);
149151
}
@@ -192,6 +194,7 @@ void testWidgetsOnLinux(
192194
await test(tester);
193195
} finally {
194196
debugDefaultTargetPlatformOverride = null;
197+
tester.view.reset();
195198
}
196199
}, skip: skip, variant: variant);
197200
}

test/test_runners_test.dart

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:flutter_test_runners/flutter_test_runners.dart';
4+
5+
void main() {
6+
group("Runners simulate platforms >", () {
7+
group("all platforms >", () {
8+
final expectedPlatforms = [
9+
TargetPlatform.iOS,
10+
TargetPlatform.android,
11+
TargetPlatform.macOS,
12+
TargetPlatform.windows,
13+
TargetPlatform.linux,
14+
];
15+
16+
testWidgetsOnAllPlatforms("all platforms runner", (tester) async {
17+
expect(expectedPlatforms, contains(defaultTargetPlatform));
18+
expectedPlatforms.remove(defaultTargetPlatform);
19+
});
20+
});
21+
22+
group("mobile >", () {
23+
final expectedPlatforms = [TargetPlatform.iOS, TargetPlatform.android];
24+
25+
testWidgetsOnMobile("mobile runner", (tester) async {
26+
expect(expectedPlatforms, contains(defaultTargetPlatform));
27+
expectedPlatforms.remove(defaultTargetPlatform);
28+
});
29+
});
30+
31+
testWidgetsOnIos("iOS runner", (tester) async {
32+
expect(defaultTargetPlatform, TargetPlatform.iOS);
33+
34+
// We leave mobile pixel ratios alone because the default Flutter value
35+
// approximates real mobile pixel ratios.
36+
expect(tester.view.devicePixelRatio, 3.0);
37+
});
38+
39+
testWidgetsOnAndroid("Android runner", (tester) async {
40+
expect(defaultTargetPlatform, TargetPlatform.android);
41+
42+
// We leave mobile pixel ratios alone because the default Flutter value
43+
// approximates real mobile pixel ratios.
44+
expect(tester.view.devicePixelRatio, 3.0);
45+
});
46+
47+
group("desktop >", () {
48+
final expectedPlatforms = [TargetPlatform.macOS, TargetPlatform.windows, TargetPlatform.linux];
49+
50+
testWidgetsOnDesktop("desktop runner", (tester) async {
51+
expect(expectedPlatforms, contains(defaultTargetPlatform));
52+
expectedPlatforms.remove(defaultTargetPlatform);
53+
54+
// We configure desktop for a 1:1 pixel density to match real desktops.
55+
expect(tester.view.devicePixelRatio, 1.0);
56+
});
57+
});
58+
59+
testWidgetsOnMac("Mac runner", (tester) async {
60+
expect(defaultTargetPlatform, TargetPlatform.macOS);
61+
62+
// We configure desktop for a 1:1 pixel density to match real desktops.
63+
expect(tester.view.devicePixelRatio, 1.0);
64+
});
65+
66+
testWidgetsOnWindows("Windows runner", (tester) async {
67+
expect(defaultTargetPlatform, TargetPlatform.windows);
68+
69+
// We configure desktop for a 1:1 pixel density to match real desktops.
70+
expect(tester.view.devicePixelRatio, 1.0);
71+
});
72+
73+
testWidgetsOnLinux("Linux runner", (tester) async {
74+
expect(defaultTargetPlatform, TargetPlatform.linux);
75+
76+
// We configure desktop for a 1:1 pixel density to match real desktops.
77+
expect(tester.view.devicePixelRatio, 1.0);
78+
});
79+
});
80+
}

0 commit comments

Comments
 (0)