This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[connectivity_for_web] Migration to null-safety. #3652
Merged
fluttergithubbot
merged 7 commits into
flutter:master
from
ditman:nnbd-connectivity_for_web
Mar 2, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
86890ad
First pass at the migration
ditman ad9672f
Move integration_tests to the right place
ditman 5677a3f
Simplify _connectivityResultStream so it uses Stream transformations,…
ditman cbfec80
Add root tests to tell the user where the integration tests are
ditman 29aa268
pubspec cleanup
ditman bddbfda
Restore writing to onchange directly, instead of using a transform st…
ditman 6da5bcd
Fix null-check in late variable!
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/connectivity/connectivity_for_web/example/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Testing | ||
|
||
This package utilizes the `integration_test` package to run its tests in a web browser. | ||
|
||
See [flutter.dev > Integration testing](https://flutter.dev/docs/testing/integration-tests) for more info. | ||
|
||
## Running the tests | ||
|
||
Make sure you have updated to the latest Flutter master. | ||
|
||
1. Check what version of Chrome is running on the machine you're running tests on. | ||
|
||
2. Download and install driver for that version from here: | ||
* <https://chromedriver.chromium.org/downloads> | ||
|
||
3. Start the driver using `chromedriver --port=4444` | ||
|
||
4. Run tests: `flutter drive -d web-server --browser-name=chrome --driver=test_driver/integration_driver.dart --target=integration_test/TEST_NAME.dart`, or (in Linux): | ||
|
||
* Single: `./run_test.sh integration_test/TEST_NAME.dart` | ||
* All: `./run_test.sh` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...es/connectivity/connectivity_for_web/example/integration_test/src/connectivity_mocks.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'dart:async'; | ||
import 'dart:html'; | ||
import 'dart:js_util' show getProperty; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
/// A Fake implementation of the NetworkInformation API that allows | ||
/// for external modification of its values. | ||
/// | ||
/// Note that the DOM API works by internally mutating and broadcasting | ||
/// 'change' events. | ||
class FakeNetworkInformation extends Fake implements NetworkInformation { | ||
String? _type; | ||
String? _effectiveType; | ||
num? _downlink; | ||
int? _rtt; | ||
|
||
@override | ||
String? get type => _type; | ||
|
||
@override | ||
String? get effectiveType => _effectiveType; | ||
|
||
@override | ||
num? get downlink => _downlink; | ||
|
||
@override | ||
int? get rtt => _rtt; | ||
|
||
FakeNetworkInformation({ | ||
String? type, | ||
String? effectiveType, | ||
num? downlink, | ||
int? rtt, | ||
}) : this._type = type, | ||
this._effectiveType = effectiveType, | ||
this._downlink = downlink, | ||
this._rtt = rtt; | ||
|
||
/// Changes the desired values, and triggers the change event listener. | ||
Future<void> mockChangeValue({ | ||
String? type, | ||
String? effectiveType, | ||
num? downlink, | ||
int? rtt, | ||
}) async { | ||
this._type = type; | ||
this._effectiveType = effectiveType; | ||
this._downlink = downlink; | ||
this._rtt = rtt; | ||
|
||
// This is set by the onConnectivityChanged getter... | ||
final Function onchange = getProperty(this, 'onchange') as Function; | ||
onchange(Event('change')); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/connectivity/connectivity_for_web/example/lib/main.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
runApp(MyApp()); | ||
} | ||
|
||
/// App for testing | ||
class MyApp extends StatefulWidget { | ||
@override | ||
_MyAppState createState() => _MyAppState(); | ||
} | ||
|
||
class _MyAppState extends State<MyApp> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: Text('Testing... Look at the console output for results!'), | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/connectivity/connectivity_for_web/example/pubspec.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: connectivity_for_web_integration_tests | ||
publish_to: none | ||
|
||
dependencies: | ||
connectivity_for_web: | ||
path: ../ | ||
flutter: | ||
sdk: flutter | ||
|
||
dev_dependencies: | ||
js: ^0.6.3 | ||
flutter_test: | ||
sdk: flutter | ||
flutter_driver: | ||
sdk: flutter | ||
integration_test: | ||
sdk: flutter | ||
|
||
environment: | ||
sdk: ">=2.12.0-259.9.beta <3.0.0" | ||
flutter: ">=1.27.0-0" # For integration_test from sdk |
18 changes: 18 additions & 0 deletions
18
packages/connectivity/connectivity_for_web/example/run_test.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/bash | ||
if pgrep -lf chromedriver > /dev/null; then | ||
echo "chromedriver is running." | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "No target specified, running all tests..." | ||
find integration_test/ -iname *_test.dart | xargs -n1 -i -t flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_driver.dart --target='{}' | ||
else | ||
echo "Running test target: $1..." | ||
set -x | ||
flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_driver.dart --target=$1 | ||
fi | ||
|
||
else | ||
echo "chromedriver is not running." | ||
echo "Please, check the README.md for instructions on how to use run_test.sh" | ||
fi | ||
|
7 changes: 7 additions & 0 deletions
7
packages/connectivity/connectivity_for_web/example/test_driver/integration_driver.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:integration_test/integration_test_driver.dart'; | ||
|
||
Future<void> main() async => integrationDriver(); |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ensured by the
isSupported
method that is used before instantiating this plugin class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems worth documenting that requirement in the constructor comment.