Skip to content

Commit

Permalink
test(package_info_plus): run integration tests (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold authored Apr 24, 2023
1 parent 19918c8 commit 7ba127f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/package_info_plus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,16 @@ jobs:
run: ./.github/workflows/scripts/install-tools.sh
- name: "Build Example"
run: ./.github/workflows/scripts/build-examples.sh web ./lib/main.dart

web_integration_test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
- name: "Install Flutter"
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: "Install Tools"
run: ./.github/workflows/scripts/install-tools.sh
- name: "Run Integration Test"
run: ./.github/workflows/scripts/integration-test.sh web package_info_plus_example
14 changes: 14 additions & 0 deletions .github/workflows/scripts/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,17 @@ then
melos exec -c 1 --scope="$SCOPE" --dir-exists="./integration_test" -- \
"flutter test ./integration_test/MELOS_PARENT_PACKAGE_NAME_test.dart --dart-define=CI=true"
fi

if [ "$ACTION" == "web" ]
then
# Start x virtual framebuffer for chrome to run.
export DISPLAY=:99
Xvfb $DISPLAY -screen 0 1024x768x16 &
sleep 5 # Give xvfb some time to start.

# Start chrome driver.
chromedriver --port=4444 &

melos exec -c 1 --scope="$SCOPE" --dir-exists="./integration_test" -- \
"flutter drive -d chrome --driver ./integration_test/driver.dart --target ./integration_test/MELOS_PARENT_PACKAGE_NAME_web_test.dart --dart-define=CI=true"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ void main() {
final info = await PackageInfo.fromPlatform();
// These tests are based on the example app. The tests should be updated if any related info changes.
if (kIsWeb) {
expect(info.appName, 'package_info_example');
expect(info.appName, 'package_info_plus_example');
expect(info.buildNumber, '4');
expect(info.buildSignature, isEmpty);
expect(info.packageName, 'package_info_example');
expect(info.packageName, 'package_info_plus_example');
expect(info.version, '1.2.3');
expect(info.installerStore, null);
} else {
Expand Down Expand Up @@ -68,7 +68,7 @@ void main() {
await tester.pumpWidget(const MyApp());
await tester.pumpAndSettle();
if (kIsWeb) {
expect(find.text('package_info_example'), findsNWidgets(2));
expect(find.text('package_info_plus_example'), findsNWidgets(2));
expect(find.text('1.2.3'), findsOneWidget);
expect(find.text('4'), findsOneWidget);
expect(find.text('Not set'), findsOneWidget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:integration_test/integration_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:package_info_plus/src/package_info_plus_web.dart';

import 'package_info_plus_test.dart' as common_tests;
import 'package_info_plus_web_test.mocks.dart';

@GenerateMocks([http.Client])
void main() {
common_tests.main();

IntegrationTestWidgetsFlutterBinding.ensureInitialized();

// ignore: constant_identifier_names
const VERSION_JSON = {
'app_name': 'package_info_example',
Expand All @@ -31,9 +37,9 @@ void main() {
group(
'Package Info Web',
() {
test(
testWidgets(
'Get correct values when response status is 200',
() async {
(tester) async {
when(client.get(any)).thenAnswer(
(_) => Future.value(
http.Response(jsonEncode(VERSION_JSON), 200),
Expand All @@ -50,9 +56,9 @@ void main() {
},
);

test(
testWidgets(
'Get empty values when response status is not 200',
() async {
(tester) async {
when(client.get(any)).thenAnswer(
(_) => Future.value(
http.Response('', 404),
Expand All @@ -69,9 +75,9 @@ void main() {
},
);

test(
testWidgets(
'Get correct versionJsonUrl for http and https',
() {
(tester) async {
expect(
plugin.versionJsonUrl('https://example.com/#/my-page', 1),
Uri.parse('https://example.com/version.json?cachebuster=1'),
Expand Down Expand Up @@ -102,7 +108,8 @@ void main() {
},
);

test('Get correct versionJsonUrl for chrome-extension', () {
testWidgets('Get correct versionJsonUrl for chrome-extension',
(tester) async {
expect(
plugin.versionJsonUrl('chrome-extension://abcdefgh', 1),
Uri.parse('chrome-extension://abcdefgh/version.json?cachebuster=1'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ environment:
dependencies:
flutter:
sdk: flutter
http: ^0.13.5
package_info_plus: ^3.1.0

dev_dependencies:
build_runner: ^2.0.3
integration_test:
sdk: flutter
flutter_driver:
sdk: flutter
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
mockito: ^5.0.7

flutter:
uses-material-design: true
2 changes: 0 additions & 2 deletions packages/package_info_plus/package_info_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ dependencies:
win32: ">=2.7.0 <5.0.0"

dev_dependencies:
build_runner: ^2.0.3
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
mockito: ^5.0.7
test: ^1.21.1

environment:
Expand Down

0 comments on commit 7ba127f

Please sign in to comment.