Skip to content

[compass_app] fix local & remote integration test #2599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compass_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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.
Expand Down
19 changes: 2 additions & 17 deletions compass_app/app/integration_test/app_server_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -147,15 +132,15 @@ void main() {

// Select guests
await tester.tap(
find.byKey(const ValueKey('add_guests')),
find.byKey(const ValueKey('add-guests')),
warnIfMissed: false,
);

// Refresh screen state
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
Expand Down
30 changes: 30 additions & 0 deletions compass_app/app/integration_test/test_app_server_data.dart
Original file line number Diff line number Diff line change
@@ -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();
}
6 changes: 3 additions & 3 deletions compass_app/app/lib/config/dependencies.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -53,8 +53,8 @@ List<SingleChildWidget> _sharedProviders = [
/// This dependency list uses repositories that connect to a remote server.
List<SingleChildWidget> 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:
Expand Down