Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Dart 2.10. #217

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
19 changes: 7 additions & 12 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,30 @@ homepage: https://github.com/mmcc007/screenshots
author: Maurice McCabe <[email protected]>

environment:
sdk: '>=2.2.2 <3.0.0'
sdk: '>=2.10.0 <3.0.0'

dependencies:
args: ^1.5.1
yaml: ^2.1.15
resource: ^2.1.5
path: ^1.6.2
file: ^5.0.7
file: ^6.0.0-nullsafety.2
archive: ^2.0.9
platform: ^2.2.0
process: ^3.0.9
platform: ^3.0.0-nullsafety.2
process: ^4.0.0-nullsafety.2
meta: ^1.1.6
intl: ">=0.15.0 <1.0.0"
tool_mobile: ^1.9.5
# tool_mobile:
# path: ../tool_mobile
tool_mobile: ^2.0.0

dev_dependencies:
test: ^1.5.1+1
test_api: ^0.2.5
mockito: ^4.1.0
pedantic: ^1.8.0+1
quiver: '>=2.0.0 <3.0.0'
fake_process_manager: ^0.1.0
fake_process_manager: ^0.2.0
# path: ../fake_process_manager
tool_base_test:
git: https://github.com/mmcc007/tool_base_test.git
# path: ../tool_base_test
collection: any

executables:
screenshots: main
screenshots: main
27 changes: 8 additions & 19 deletions test/daemon_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ main() {

group('daemon client', () {
const streamPeriod = 150;
FakePlatform fakePlatform;

setUp(() {
fakePlatform = FakePlatform.fromPlatform(const LocalPlatform());
final linux = FakePlatform(operatingSystem: 'linux', environment: {});
final linuxCi = FakePlatform(operatingSystem: 'linux', environment: {
'CI': 'true',
});
final macos = FakePlatform(operatingSystem: 'macos', environment: {});

group('mocked process', () {
MockProcessManager mockProcessManager;
Expand Down Expand Up @@ -92,7 +92,6 @@ main() {
testUsingContext('start/stop', () async {
DaemonClient daemonClient = DaemonClient();

fakePlatform.operatingSystem = 'linux';
List<int> getLine(int i) {
final lines = <List<int>>[
utf8.encode('Starting device daemon...\n'),
Expand All @@ -119,16 +118,14 @@ main() {
verify(mockProcess.exitCode).called(1);
}, skip: false, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Platform: () => fakePlatform,
Platform: () => linux,
// Logger: () => VerboseLogger(StdoutLogger()),
});

testUsingContext('get emulators and devices, and launch emulator',
() async {
final daemonClient = DaemonClient();

fakePlatform.operatingSystem = 'linux';

// responses from daemon (called sequentially)
List<int> getLine(int i) {
final lines = <List<int>>[
Expand Down Expand Up @@ -179,7 +176,7 @@ main() {
verify(mockProcess.exitCode).called(1);
}, skip: false, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Platform: () => fakePlatform,
Platform: () => linux,
// Logger: () => VerboseLogger(StdoutLogger()),
});
});
Expand All @@ -200,8 +197,6 @@ main() {
testUsingContext('real devices (iPhone and Android)', () async {
final daemonClient = DaemonClient();

fakePlatform.operatingSystem = 'macos';

// responses from daemon (called sequentially)
List<int> getLine(int i) {
final lines = <List<int>>[
Expand Down Expand Up @@ -254,14 +249,13 @@ main() {
fakeProcessManager.verifyCalls();
}, skip: false, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
Platform: () => fakePlatform,
Platform: () => macos,
// Logger: () => VerboseLogger(StdoutLogger()),
});
});

group('in CI', () {
FakeProcessManager fakeProcessManager;
FakePlatform fakePlatform;
final List<String> stdinCaptured = <String>[];

void _captureStdin(String item) {
Expand All @@ -271,14 +265,9 @@ main() {
setUp(() async {
fakeProcessManager =
FakeProcessManager(stdinResults: _captureStdin, isPeriodic: true);
fakePlatform = FakePlatform.fromPlatform(const LocalPlatform());
});

testUsingContext('bad android emulator hack', () async {
fakePlatform.environment = {
'CI': 'true',
};
fakePlatform.operatingSystem = 'linux';
final id = 'device id';
final name = 'device name';
final emulator = false;
Expand Down Expand Up @@ -345,7 +334,7 @@ main() {
fakeProcessManager.verifyCalls();
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
Platform: () => fakePlatform,
Platform: () => linuxCi,
// Logger: () => VerboseLogger(StdoutLogger()),
});
});
Expand Down
9 changes: 3 additions & 6 deletions test/image_magick_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ main() {
fakeProcessManager.verifyCalls();
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
..operatingSystem = 'macos',
Platform: () => FakePlatform(operatingSystem: 'macos'),
});

testUsingContext('is installed on windows', () async {
Expand All @@ -97,8 +96,7 @@ main() {
fakeProcessManager.verifyCalls();
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
..operatingSystem = 'windows',
Platform: () => FakePlatform(operatingSystem: 'windows'),
});

testUsingContext('is not installed on windows', () async {
Expand All @@ -110,8 +108,7 @@ main() {
fakeProcessManager.verifyCalls();
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
..operatingSystem = 'windows',
Platform: () => FakePlatform(operatingSystem: 'windows'),
});
});

Expand Down
25 changes: 15 additions & 10 deletions test/run_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import 'package:screenshots/src/run.dart';
import 'package:screenshots/src/screens.dart';
import 'package:test/test.dart';
import 'package:tool_base/tool_base.dart';
import 'package:tool_base_test/tool_base_test.dart';

import 'src/common_tools.dart';
import 'src/context.dart';
import 'src/mocks.dart';

main() {
Expand Down Expand Up @@ -50,9 +51,11 @@ main() {
});

FakeProcessManager fakeProcessManager;
LocalPlatform localPlatform;
MockDaemonClient mockDaemonClient;

setUp(() async {
localPlatform = LocalPlatform();
fakeProcessManager = FakeProcessManager(stdinResults: _captureStdin);
mockDaemonClient = MockDaemonClient();
when(mockDaemonClient.emulators)
Expand Down Expand Up @@ -449,13 +452,14 @@ main() {
}, skip: false, overrides: <Type, Generator>{
DaemonClient: () => mockDaemonClient,
ProcessManager: () => fakeProcessManager,
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
..environment = {
// 'CI': 'false',
// 'HOME': LocalPlatform().environment['HOME']
'HOME': memoryFileSystem.currentDirectory.path
}
..operatingSystem = 'macos',
Platform: () => FakePlatform(
operatingSystem: 'macos',
environment: {
// 'CI': 'false',
// 'HOME': LocalPlatform().environment['HOME']
'HOME': memoryFileSystem.currentDirectory.path
},
),
Logger: () => BufferLogger(),
FileSystem: () => memoryFileSystem,
});
Expand Down Expand Up @@ -534,8 +538,9 @@ main() {
}, skip: false, overrides: <Type, Generator>{
DaemonClient: () => mockDaemonClient,
ProcessManager: () => fakeProcessManager,
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
..environment = {'CI': 'true'},
Platform: () => FakePlatform(
operatingSystem: localPlatform.operatingSystem,
environment: {'CI': 'true'}),
Logger: () => BufferLogger(),
});
});
Expand Down
9 changes: 3 additions & 6 deletions test/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import 'package:screenshots/src/daemon_client.dart';
import 'package:screenshots/src/utils.dart';
import 'package:test/test.dart';
import 'package:tool_base/tool_base.dart';
import 'package:tool_base_test/tool_base_test.dart';
import 'package:tool_mobile/tool_mobile.dart';

import 'src/common.dart';
import 'src/context.dart';

class FakeAndroidSDK extends Fake implements AndroidSdk {
@override
Expand Down Expand Up @@ -63,10 +62,8 @@ main() {
}, overrides: <Type, Generator>{
FileSystem: () => mockFileSystem,
ProcessManager: () => fakeProcessManager,
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
..environment = {
'HOME': ''
}, });
Platform: () => FakePlatform(environment: {'HOME': ''})
});
});

group('not in context', () {
Expand Down
22 changes: 10 additions & 12 deletions test/validate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import 'src/context.dart';
main() {
group('validate', () {
FakeProcessManager fakeProcessManager;
FakePlatform fakePlatform;
FakePlatform macos;

setUp(() {
fakeProcessManager = FakeProcessManager();
fakePlatform = FakePlatform.fromPlatform(const LocalPlatform())
..operatingSystem = 'linux'
..environment['CI'] = 'false';
macos = FakePlatform(
stdoutSupportsAnsi: false,
operatingSystem: 'macos',
environment: {'CI': 'false'},
);
});

final callListIosDevices = Call(
Expand Down Expand Up @@ -51,7 +53,6 @@ main() {
''));

testUsingContext('pass on iOS with \'availability\'', () async {
fakePlatform.operatingSystem = 'macos';
final configStr = '''
tests:
- example/test_driver/main.dart
Expand All @@ -78,7 +79,7 @@ main() {
}, skip: false, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
// Logger: () => VerboseLogger(StdoutLogger()),
Platform: () => fakePlatform
Platform: () => macos
});

testUsingContext('pass on iOS with \'isAvailable\'', () async {
Expand Down Expand Up @@ -135,8 +136,7 @@ main() {
}, skip: false, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
// Logger: () => VerboseLogger(StdoutLogger()),
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
..operatingSystem = 'macos',
Platform: () => macos,
});

testUsingContext('getIosSimulators', () async {
Expand All @@ -151,7 +151,6 @@ main() {
});

testUsingContext('fail', () async {
fakePlatform.operatingSystem = 'macos';
final BufferLogger logger = context.get<Logger>();
final configStr = '''
tests:
Expand Down Expand Up @@ -231,12 +230,11 @@ main() {
// expect(logger.errorText, isNot(contains('No device attached or simulator installed for device \'Bad ios phone\' in screenshots.yaml.')));
}, skip: false, overrides: <Type, Generator>{
Logger: () => BufferLogger(),
Platform: () => fakePlatform,
Platform: () => macos,
ProcessManager: () => fakeProcessManager,
});

testUsingContext('show device guide', () async {
fakePlatform.operatingSystem = 'macos';
final BufferLogger logger = context.get<Logger>();
final screens = Screens();
await screens.init();
Expand Down Expand Up @@ -298,7 +296,7 @@ main() {
fakeProcessManager.verifyCalls();
}, skip: false, overrides: <Type, Generator>{
Logger: () => BufferLogger(),
Platform: () => fakePlatform,
Platform: () => macos,
ProcessManager: () => fakeProcessManager,
});
});
Expand Down