From a37922690f555dda490412c583a58c997637287b Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 26 Jan 2021 11:51:31 -0800 Subject: [PATCH 1/3] fix test --- packages/cross_file/test/x_file_io_test.dart | 2 +- .../image_picker/image_picker_platform_interface/CHANGELOG.md | 4 ++++ .../image_picker/image_picker_platform_interface/pubspec.yaml | 2 +- .../test/picked_file_io_test.dart | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/cross_file/test/x_file_io_test.dart b/packages/cross_file/test/x_file_io_test.dart index 25f46a4edad9..ce7f260fa875 100644 --- a/packages/cross_file/test/x_file_io_test.dart +++ b/packages/cross_file/test/x_file_io_test.dart @@ -21,7 +21,7 @@ import 'package:cross_file/cross_file.dart'; // // https://github.com/flutter/flutter/issues/20907 -final pathPrefix = './assets/'; +final pathPrefix = './test/assets/'; final path = pathPrefix + 'hello.txt'; final String expectedStringContents = 'Hello, world!'; final Uint8List bytes = Uint8List.fromList(utf8.encode(expectedStringContents)); diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index efcef0146cdc..581cf1830610 100644 --- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md +++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.6 + +* Fix test asset file location. + ## 1.1.5 * Update Flutter SDK constraint. diff --git a/packages/image_picker/image_picker_platform_interface/pubspec.yaml b/packages/image_picker/image_picker_platform_interface/pubspec.yaml index 7943a2a3eccd..b9ad12a50eb6 100644 --- a/packages/image_picker/image_picker_platform_interface/pubspec.yaml +++ b/packages/image_picker/image_picker_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the image_picker plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 1.1.5 +version: 1.1.6 dependencies: flutter: diff --git a/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart b/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart index 94ff759a2fb2..0b7267c8beea 100644 --- a/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart @@ -13,7 +13,7 @@ import 'package:image_picker_platform_interface/image_picker_platform_interface. final String expectedStringContents = 'Hello, world!'; final Uint8List bytes = utf8.encode(expectedStringContents); -final File textFile = File('./assets/hello.txt'); +final File textFile = File('./test/assets/hello.txt'); final String textFilePath = textFile.path; void main() { From 90727ff821fbd08633ab03032a1ffba0be1ab391 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 26 Jan 2021 12:45:23 -0800 Subject: [PATCH 2/3] test for stable --- packages/cross_file/test/x_file_io_test.dart | 19 ++++++++----------- .../test/picked_file_io_test.dart | 11 +++++++++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/cross_file/test/x_file_io_test.dart b/packages/cross_file/test/x_file_io_test.dart index ce7f260fa875..df1995c45a09 100644 --- a/packages/cross_file/test/x_file_io_test.dart +++ b/packages/cross_file/test/x_file_io_test.dart @@ -11,16 +11,6 @@ import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; import 'package:cross_file/cross_file.dart'; -// Please note that executing this test with command -// `flutter test test/x_file_io_test.dart` will set the directory -// to ./file_selector_platform_interface. -// -// This will cause our hello.txt file to be not be found. Please -// execute this test with `flutter test` or change the path prefix -// to ./test/assets/ -// -// https://github.com/flutter/flutter/issues/20907 - final pathPrefix = './test/assets/'; final path = pathPrefix + 'hello.txt'; final String expectedStringContents = 'Hello, world!'; @@ -30,7 +20,14 @@ final String textFilePath = textFile.path; void main() { group('Create with a path', () { - final file = XFile(textFilePath); + XFile file; + if (Directory(textFilePath).existsSync()) { + file = XFile(textFilePath); + } else { + // TODO(cyanglaz): remove this alternative file location when https://github.com/flutter/flutter/commit/22f170042746ff253997236f6350ecb7403cf3b1 + // lands on stable. + file = XFile(File('./assets/hello.txt').path); + } test('Can be read as a string', () async { expect(await file.readAsString(), equals(expectedStringContents)); diff --git a/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart b/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart index 0b7267c8beea..ba04b1dde01b 100644 --- a/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart @@ -14,11 +14,18 @@ import 'package:image_picker_platform_interface/image_picker_platform_interface. final String expectedStringContents = 'Hello, world!'; final Uint8List bytes = utf8.encode(expectedStringContents); final File textFile = File('./test/assets/hello.txt'); -final String textFilePath = textFile.path; +String textFilePath = textFile.path; void main() { group('Create with an objectUrl', () { - final pickedFile = PickedFile(textFilePath); + PickedFile pickedFile; + if (Directory(textFilePath).existsSync()) { + pickedFile = PickedFile(textFilePath); + } else { + // TODO(cyanglaz): remove this alternative file location when https://github.com/flutter/flutter/commit/22f170042746ff253997236f6350ecb7403cf3b1 + // lands on stable. + pickedFile = PickedFile(File('./assets/hello.txt').path); + } test('Can be read as a string', () async { expect(await pickedFile.readAsString(), equals(expectedStringContents)); From 612af75435f006ca45f52aa30714c9e8eb03d0b0 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 26 Jan 2021 13:39:25 -0800 Subject: [PATCH 3/3] fix --- packages/cross_file/test/x_file_io_test.dart | 12 +++--------- .../test/picked_file_io_test.dart | 18 +++++++----------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/packages/cross_file/test/x_file_io_test.dart b/packages/cross_file/test/x_file_io_test.dart index df1995c45a09..94ac81c4cac4 100644 --- a/packages/cross_file/test/x_file_io_test.dart +++ b/packages/cross_file/test/x_file_io_test.dart @@ -11,7 +11,8 @@ import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; import 'package:cross_file/cross_file.dart'; -final pathPrefix = './test/assets/'; +final pathPrefix = + Directory.current.path.endsWith('test') ? './assets/' : './test/assets/'; final path = pathPrefix + 'hello.txt'; final String expectedStringContents = 'Hello, world!'; final Uint8List bytes = Uint8List.fromList(utf8.encode(expectedStringContents)); @@ -20,14 +21,7 @@ final String textFilePath = textFile.path; void main() { group('Create with a path', () { - XFile file; - if (Directory(textFilePath).existsSync()) { - file = XFile(textFilePath); - } else { - // TODO(cyanglaz): remove this alternative file location when https://github.com/flutter/flutter/commit/22f170042746ff253997236f6350ecb7403cf3b1 - // lands on stable. - file = XFile(File('./assets/hello.txt').path); - } + final XFile file = XFile(textFilePath); test('Can be read as a string', () async { expect(await file.readAsString(), equals(expectedStringContents)); diff --git a/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart b/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart index ba04b1dde01b..28c0886b864e 100644 --- a/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/picked_file_io_test.dart @@ -11,21 +11,17 @@ import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; +final pathPrefix = + Directory.current.path.endsWith('test') ? './assets/' : './test/assets/'; +final path = pathPrefix + 'hello.txt'; final String expectedStringContents = 'Hello, world!'; -final Uint8List bytes = utf8.encode(expectedStringContents); -final File textFile = File('./test/assets/hello.txt'); -String textFilePath = textFile.path; +final Uint8List bytes = Uint8List.fromList(utf8.encode(expectedStringContents)); +final File textFile = File(path); +final String textFilePath = textFile.path; void main() { group('Create with an objectUrl', () { - PickedFile pickedFile; - if (Directory(textFilePath).existsSync()) { - pickedFile = PickedFile(textFilePath); - } else { - // TODO(cyanglaz): remove this alternative file location when https://github.com/flutter/flutter/commit/22f170042746ff253997236f6350ecb7403cf3b1 - // lands on stable. - pickedFile = PickedFile(File('./assets/hello.txt').path); - } + final PickedFile pickedFile = PickedFile(textFilePath); test('Can be read as a string', () async { expect(await pickedFile.readAsString(), equals(expectedStringContents));