diff --git a/compass_app/README.md b/compass_app/README.md index 05ed7670aa4..4401179a37f 100644 --- a/compass_app/README.md +++ b/compass_app/README.md @@ -32,7 +32,7 @@ $ cd server $ dart run # => Server listening on port 8080 -$ cd ../compass_app/app +$ cd ../app $ flutter run --target lib/main_staging.dart ``` @@ -48,10 +48,10 @@ $ flutter test integration_test/app_local_data_test.dart ``` **Integration tests with background server and remote data** - +> Simulators have their own `localhost`, separate from the desktop's. Therefore, tests on a simulator that try to connect to a local background server using `localhost` will fail to reach. To resolve this, find a non-loopback IPv4 address (e.g., using `ifconfig | grep inet` and choosing an address other than `127.0.0.1`, such as `192.168.0.106`). ```bash cd app -$ flutter test integration_test/app_server_data_test.dart +$ LOCALHOST='your_non-loopback_ipv4_address' dart run integration_test/test_app_server_data.dart ``` Running the tests together with `flutter test integration_test` will fail. diff --git a/compass_app/app/integration_test/app_server_data_test.dart b/compass_app/app/integration_test/app_server_data_test.dart index cb4bb28b7ef..f6285aaa27b 100644 --- a/compass_app/app/integration_test/app_server_data_test.dart +++ b/compass_app/app/integration_test/app_server_data_test.dart @@ -25,28 +25,13 @@ void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); group('end-to-end test with remote data', () { - const port = '8080'; - late Process p; setUpAll(() async { // Clear any stored shared preferences final sharedPreferences = await SharedPreferences.getInstance(); await sharedPreferences.clear(); - - // Start the dart server - p = await Process.start( - 'dart', - ['run', 'bin/compass_server.dart'], - environment: {'PORT': port}, - // Relative to the app/ folder - workingDirectory: '../server', - ); - // Wait for server to start and print to stdout. - await p.stdout.first; }); - tearDownAll(() => p.kill()); - testWidgets('should load app', (tester) async { // Load app widget. await tester.pumpWidget( @@ -147,7 +132,7 @@ void main() { // Select guests await tester.tap( - find.byKey(const ValueKey('add_guests')), + find.byKey(const ValueKey('add-guests')), warnIfMissed: false, ); @@ -155,7 +140,7 @@ void main() { await tester.pumpAndSettle(); // Perform search and navigate to next screen - await tester.tap(find.byKey(const ValueKey('submit_button'))); + await tester.tap(find.byKey(const ValueKey('submit-button'))); await tester.pumpAndSettle(); // Results Screen diff --git a/compass_app/app/integration_test/test_app_server_data.dart b/compass_app/app/integration_test/test_app_server_data.dart new file mode 100644 index 00000000000..b4694a783ca --- /dev/null +++ b/compass_app/app/integration_test/test_app_server_data.dart @@ -0,0 +1,30 @@ +import 'dart:io'; + +void main() async { + const port = '8080'; + late Process p; + + // Start the dart server + p = await Process.start( + 'dart', + ['run', 'bin/compass_server.dart'], + environment: {'PORT': port}, + // Relative to the app/ folder + workingDirectory: '../server', + ); + // Wait for server to start and print to stdout. + await p.stdout.first; + + final testProcess = await Process.start('flutter', [ + 'test', + 'integration_test/app_server_data_test.dart', + ], workingDirectory: '../app'); + + await testProcess.stdout.pipe(stdout); + await testProcess.stderr.pipe(stderr); + + await testProcess.exitCode; + + // tearDownAll(() => p.kill()); + p.kill(); +} diff --git a/compass_app/app/lib/config/dependencies.dart b/compass_app/app/lib/config/dependencies.dart index 3b2bd541af7..aa17951f83c 100644 --- a/compass_app/app/lib/config/dependencies.dart +++ b/compass_app/app/lib/config/dependencies.dart @@ -1,7 +1,7 @@ // Copyright 2024 The Flutter team. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - +import 'dart:io'; import 'package:provider/provider.dart'; import 'package:provider/single_child_widget.dart'; @@ -53,8 +53,8 @@ List _sharedProviders = [ /// This dependency list uses repositories that connect to a remote server. List get providersRemote { return [ - Provider(create: (context) => AuthApiClient()), - Provider(create: (context) => ApiClient()), + Provider(create: (context) => AuthApiClient(host: Platform.environment['LOCALHOST'])), + Provider(create: (context) => ApiClient(host: Platform.environment['LOCALHOST'])), Provider(create: (context) => SharedPreferencesService()), ChangeNotifierProvider( create: