Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Codegen mocks
Move tests to the right directory structure

Update run_test script to work with all of the above
  • Loading branch information
ditman committed Feb 10, 2021
commit 3a9e3d8127b93bc7c49efabcb9af7eae6dd4a0f0
1 change: 1 addition & 0 deletions packages/url_launcher/url_launcher_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dev_dependencies:
mockito: ^5.0.0-nullsafety.5
integration_test:
sdk: flutter
build_runner: ^1.10.0

environment:
sdk: ">=2.12.0-0 <3.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/url_launcher/url_launcher_web/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
integration_test/*.mocks.dart
6 changes: 6 additions & 0 deletions packages/url_launcher/url_launcher_web/test/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
targets:
$default:
sources:
- integration_test/*.dart
- lib/$lib$
- $package$
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,37 @@

import 'dart:html' as html;
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:mockito/mockito.dart';
import 'package:integration_test/integration_test.dart';

class _MockWindow extends Mock implements html.Window {}

class _MockNavigator extends Mock implements html.Navigator {}
import 'url_launcher_web_test.mocks.dart';

@GenerateMocks([], customMocks: [
MockSpec<html.Window>(returnNullOnMissingStub: true),
MockSpec<html.Navigator>(returnNullOnMissingStub: true)
])
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('UrlLauncherPlugin', () {
late _MockWindow mockWindow;
late _MockNavigator mockNavigator;
late MockWindow mockWindow;
late MockNavigator mockNavigator;

late UrlLauncherPlugin plugin;

setUp(() {
mockWindow = _MockWindow();
mockNavigator = _MockNavigator();
mockWindow = MockWindow();
mockNavigator = MockNavigator();
when(mockWindow.navigator).thenReturn(mockNavigator);

// Simulate that window.open does something.
when(mockWindow.open(any, any)).thenReturn(MockWindow());

when(mockNavigator.vendor).thenReturn('Google LLC');
when(mockNavigator.appVersion).thenReturn('Mock version!');

plugin = UrlLauncherPlugin(debugWindow: mockWindow);
});

Expand Down Expand Up @@ -55,17 +64,6 @@ void main() {
});

group('launch', () {
setUp(() {
// Simulate that window.open does something.
when(mockWindow.open('https://www.google.com', ''))
.thenReturn(_MockWindow());
when(mockWindow.open('mailto:[email protected]', ''))
.thenReturn(_MockWindow());
when(mockWindow.open('tel:5551234567', '')).thenReturn(_MockWindow());
when(mockWindow.open('sms:+19725551212?body=hello%20there', ''))
.thenReturn(_MockWindow());
});

testWidgets('launching a URL returns true', (WidgetTester _) async {
expect(
plugin.launch(
Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher_web/test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ dev_dependencies:
path: ../
integration_test:
sdk: flutter

build_runner: ^1.10.0
9 changes: 7 additions & 2 deletions packages/url_launcher/url_launcher_web/test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
if pgrep -lf chromedriver > /dev/null; then
echo "chromedriver is running."

flutter pub get

echo "(Re)generating mocks."
flutter pub run build_runner build

if [ $# -eq 0 ]; then
echo "No target specified, running all tests..."
find test_driver/ -iname *_integration.dart | xargs -n1 -i -t flutter drive -d web-server --web-port=7357 --browser-name=chrome --target='{}'
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_test_driver.dart --target='{}'
else
echo "Running test target: $1..."
set -x
flutter drive -d web-server --web-port=7357 --browser-name=chrome --target=$1
flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test_driver.dart --target=$1
fi

else
Expand Down

This file was deleted.