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

Commit de50d56

Browse files
committed
Port tests from --platform=chrome to integration_test
1 parent 5e7abfd commit de50d56

File tree

11 files changed

+127
-9
lines changed

11 files changed

+127
-9
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ task:
168168
env:
169169
# Currently missing; see https://github.com/flutter/flutter/issues/81982
170170
# and https://github.com/flutter/flutter/issues/82211
171-
PLUGINS_TO_EXCLUDE_INTEGRATION_TESTS: "file_selector,image_picker_for_web,shared_preferences_web"
171+
PLUGINS_TO_EXCLUDE_INTEGRATION_TESTS: "file_selector,shared_preferences_web"
172172
matrix:
173173
CHANNEL: "master"
174174
CHANNEL: "stable"

packages/image_picker/image_picker_for_web/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 2.1.0
22

3-
* Added getImage, getVideo and getFile methods that return XFile instances rather than PickedFile instances.
3+
* Implemented `getImage`, `getVideo` and `getFile` methods that return `XFile` instances.
4+
* Move tests to `example` directory, so they run as integration_tests with `flutter drive`.
45

56
# 2.0.0
67

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Testing
2+
3+
This package uses `package:integration_test` to run its tests in a web browser.
4+
5+
See [Plugin Tests > Web Tests](https://github.com/flutter/flutter/wiki/Plugin-Tests#web-tests)
6+
in the Flutter wiki for instructions to setup and run the tests in this package.
7+
8+
Check [flutter.dev > Integration testing](https://flutter.dev/docs/testing/integration-tests)
9+
for more info.

packages/image_picker/image_picker_for_web/test/image_picker_for_web_test.dart renamed to packages/image_picker/image_picker_for_web/example/integration_test/image_picker_for_web_test.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
@TestOn('chrome') // Uses dart:html
6-
75
import 'dart:convert';
86
import 'dart:html' as html;
97
import 'dart:typed_data';
108

119
import 'package:flutter_test/flutter_test.dart';
1210
import 'package:image_picker_for_web/image_picker_for_web.dart';
1311
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
12+
import 'package:integration_test/integration_test.dart';
1413

1514
final String expectedStringContents = "Hello, world!";
1615
final Uint8List bytes = utf8.encode(expectedStringContents) as Uint8List;
1716
final html.File textFile = html.File([bytes], "hello.txt");
1817

1918
void main() {
19+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
20+
2021
// Under test...
2122
late ImagePickerPlugin plugin;
2223

2324
setUp(() {
2425
plugin = ImagePickerPlugin();
2526
});
2627

27-
test('Can select a file (Deprecated)', () async {
28+
testWidgets('Can select a file (Deprecated)', (WidgetTester tester) async {
2829
final mockInput = html.FileUploadInputElement();
2930

3031
final overrides = ImagePickerPluginTestOverrides()
@@ -45,7 +46,7 @@ void main() {
4546
expect((await file).readAsBytes(), completion(isNotEmpty));
4647
});
4748

48-
test('Can select a file', () async {
49+
testWidgets('Can select a file', (WidgetTester tester) async {
4950
final mockInput = html.FileUploadInputElement();
5051

5152
final overrides = ImagePickerPluginTestOverrides()
@@ -68,7 +69,7 @@ void main() {
6869

6970
// There's no good way of detecting when the user has "aborted" the selection.
7071

71-
test('computeCaptureAttribute', () {
72+
testWidgets('computeCaptureAttribute', (WidgetTester tester) async {
7273
expect(
7374
plugin.computeCaptureAttribute(ImageSource.gallery, CameraDevice.front),
7475
isNull,
@@ -88,14 +89,14 @@ void main() {
8889
});
8990

9091
group('createInputElement', () {
91-
test('accept: any, capture: null', () {
92+
testWidgets('accept: any, capture: null', (WidgetTester tester) async {
9293
html.Element input = plugin.createInputElement('any', null);
9394

9495
expect(input.attributes, containsPair('accept', 'any'));
9596
expect(input.attributes, isNot(contains('capture')));
9697
});
9798

98-
test('accept: any, capture: something', () {
99+
testWidgets('accept: any, capture: something', (WidgetTester tester) async {
99100
html.Element input = plugin.createInputElement('any', 'something');
100101

101102
expect(input.attributes, containsPair('accept', 'any'));
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
void main() {
8+
runApp(MyApp());
9+
}
10+
11+
/// App for testing
12+
class MyApp extends StatefulWidget {
13+
@override
14+
_MyAppState createState() => _MyAppState();
15+
}
16+
17+
class _MyAppState extends State<MyApp> {
18+
@override
19+
Widget build(BuildContext context) {
20+
return Directionality(
21+
textDirection: TextDirection.ltr,
22+
child: Text('Testing... Look at the console output for results!'),
23+
);
24+
}
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: connectivity_for_web_integration_tests
2+
publish_to: none
3+
4+
environment:
5+
sdk: ">=2.12.0 <3.0.0"
6+
flutter: ">=2.2.0"
7+
8+
dependencies:
9+
image_picker_for_web:
10+
path: ../
11+
flutter:
12+
sdk: flutter
13+
14+
dev_dependencies:
15+
js: ^0.6.3
16+
flutter_test:
17+
sdk: flutter
18+
flutter_driver:
19+
sdk: flutter
20+
integration_test:
21+
sdk: flutter
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/bash
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
if pgrep -lf chromedriver > /dev/null; then
7+
echo "chromedriver is running."
8+
9+
if [ $# -eq 0 ]; then
10+
echo "No target specified, running all tests..."
11+
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.dart --target='{}'
12+
else
13+
echo "Running test target: $1..."
14+
set -x
15+
flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target=$1
16+
fi
17+
18+
else
19+
echo "chromedriver is not running."
20+
echo "Please, check the README.md for instructions on how to use run_test.sh"
21+
fi
22+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:integration_test/integration_test_driver.dart';
6+
7+
Future<void> main() => integrationDriver();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<!-- Copyright 2013 The Flutter Authors. All rights reserved.
3+
Use of this source code is governed by a BSD-style license that can be
4+
found in the LICENSE file. -->
5+
<html>
6+
<head>
7+
<meta charset="UTF-8">
8+
<title>example</title>
9+
</head>
10+
<body>
11+
<script src="main.dart.js" type="application/javascript"></script>
12+
</body>
13+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## test
2+
3+
This package uses integration tests for testing.
4+
5+
See `example/README.md` for more info.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
7+
void main() {
8+
test('Tell the user where to find the real tests', () {
9+
print('---');
10+
print('This package uses integration_test for its tests.');
11+
print('See `example/README.md` for more info.');
12+
print('---');
13+
});
14+
}

0 commit comments

Comments
 (0)