Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[connectivity] Web version #2545

Closed
wants to merge 27 commits into from
Closed

Conversation

ditman
Copy link
Member

@ditman ditman commented Feb 21, 2020

Description

This is a version of the connectivity plugin for the web platform, using the experimental NetworkInformation API with a (mostly) auto-generated JS Interop facade.

Related Issues

Fixes flutter/flutter#46735

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

@ditman ditman added the WIP label Feb 21, 2020
@ditman ditman self-assigned this Feb 21, 2020
@ditman
Copy link
Member Author

ditman commented Feb 21, 2020

There's a bunch of formatting BS going on, but worst of all is that I don't have tests. I want to experiment with e2e to start moving away from flutter test --platform chrome.

@ditman
Copy link
Member Author

ditman commented Feb 25, 2020

Some tests now run:

00:00 +0: checkConnectivity in Chrome 0 downlink and rtt -> none
00:00 +1: checkConnectivity in Chrome slow-2g -> mobile
00:00 +2: checkConnectivity in Chrome 2g -> mobile
00:00 +3: checkConnectivity in Chrome 3g -> mobile
00:00 +4: checkConnectivity in Chrome 4g -> wifi
00:00 +5: checkConnectivity unsupported browsers null connection -> none
00:00 +6: get onConnectivityChanged in Chrome puts change events in a Stream
00:00 +7: get onConnectivityChanged unsupported browsers null connection -> none
00:00 +8: (tearDownAll)

@ditman ditman removed the WIP label Feb 25, 2020
@ditman
Copy link
Member Author

ditman commented Feb 25, 2020

After the whole mocking I did, I just realized that these are proper unit tests (that probably don't need to run in a browser at all).

I'm going to refactor my tests for them to be just normal unit tests, and remove unneeded dependencies.

@ditman
Copy link
Member Author

ditman commented Feb 25, 2020

Nope:

Compiler message:
src/connectivity_mocks.dart:1:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^

@woutervanwijk
Copy link

Just curious: does the use of NetworkInformation API mean it doesn't do anything in Firefox and Safari, since these browsers do not support the NetworkInformation API by default?

@ditman
Copy link
Member Author

ditman commented Mar 2, 2020

@woutervanwijk correct, in other browsers it reports "offline" by default, but it could be changed to any other result. I'm thinking of returning 'null' for the cases where the connectivity cannot be determined.

flutter run -d chrome
```

Contributions to this package are welcome. Read the [Contributing to Flutter Plugins](https://github.com/flutter/plugins/blob/master/CONTRIBUTING.md) guide to get started.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already wrote the test using the e2e package. I wonder if we can also run them by using the driver?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I want to do this. The easier it is to run the tests in the package, the better!

expect(plugin.checkConnectivity(), completion(equals(expected)));
}

group('in Chrome', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: we can add a browser based skip, if we want to show if something runs on chrome but does not run in any other browser. In CI we can run it against two different drivers? (we can also do it later when we are adding this to CI)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this done with the @TestOn('chrome') annotation, or do I need to split this test in different files per-browser?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Right now I'm mocking the behavior of other browsers, but that can get obsolete. It'd be great to be able to run these tests in multiple browsers and get the actual API doing its thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can run it on multiple browsers when you are adding them to CI.

We can change the argument for browser-name, and choose another browsers when we are starting a drive test.

https://github.com/flutter/flutter/blob/master/.cirrus.yml#L288

@ditman ditman force-pushed the connectivity-web branch from b0cd9c8 to 1dc4491 Compare March 4, 2020 19:43
@ditman
Copy link
Member Author

ditman commented Mar 4, 2020

Bringing this back to life. Rebased with the latest master, and returned null on unsupported browsers.

ditman added 13 commits April 7, 2020 15:15
```
Checking that connectivity_web can be published.
Suggestions:
* line 1, column 1 of test/lib/main.dart: This package does not have connectivity_web_example in the `dependencies` section of `pubspec.yaml`.
    ╷
  1 │ import 'package:connectivity_web_example/src/connectivity_mocks.dart';
    │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵
* line 2, column 1 of test/lib/main.dart: This package does not have e2e in the `dependencies` section of `pubspec.yaml`.
    ╷
  2 │ import 'package:e2e/e2e.dart';
    │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵
* line 3, column 1 of test/lib/main.dart: This package does not have flutter_test in the `dependencies` section of `pubspec.yaml`.
    ╷
  3 │ import 'package:flutter_test/flutter_test.dart';
    │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵

Package has 3 warnings.
```
Surprisingly, the script doesn't detect that "test" is a package of its
own, and it requires the connectivity_web package to dev-depend on
things that are only used by "test"...
@ditman ditman force-pushed the connectivity-web branch from 1dc4491 to 442852f Compare April 7, 2020 22:16
@ditman
Copy link
Member Author

ditman commented Apr 9, 2020

I'm going to land this into an experimental branch in my fork of flutter/plugins. If more contributions come (for more browsers, etc...) let's push it to the official repo. But for now, IMO, this is not fully flutter-worthy.

@ditman
Copy link
Member Author

ditman commented Apr 9, 2020

I'm publishing this package from this branch, instead of merging into flutter/plugins:master, until it is mature enough.

@ditman ditman closed this Apr 9, 2020
@ditman
Copy link
Member Author

ditman commented Apr 9, 2020

Tagged and published experimental_connectivity_web.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[connectivity] Add web support
6 participants