Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Oct 18, 2022
1 parent 801f6fe commit 5b8d4ed
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 30 deletions.
128 changes: 107 additions & 21 deletions packages/patrol_cli/test/common/artifacts_repository_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@ class MockHttpClient extends Mock implements http.Client {}

class MockZipDecoder extends Mock implements ZipDecoder {}

extension _FileSystemX on FileSystem {
void _createAndroidArtifacts() {
file(
join(_artifactPath, 'server-$globalVersion.apk'),
).createSync(recursive: true);

file(
join(_artifactPath, 'instrumentation-$globalVersion.apk'),
).createSync();
}

void _createIOSArtifacts() {
directory(join(_artifactPath, 'ios-$globalVersion')).createSync();

directory(
join(
_artifactPath,
'AutomatorServer-iphonesimulator-arm64-$globalVersion.app',
),
).createSync();

directory(
join(
_artifactPath,
'AutomatorServer-iphonesimulator-x86_64-$globalVersion.app',
),
).createSync();

directory(
join(
_artifactPath,
'AutomatorServer-iphoneos-arm64-$globalVersion.app',
),
).createSync();
}
}

void main() {
setUpFakes();

Expand All @@ -48,11 +85,30 @@ void main() {
);

zipDecoder = MockZipDecoder();
when(() => zipDecoder.decodeBytes(any())).thenAnswer((invocation) {
final archiveFile = ArchiveFile.string('ios-$globalVersion', '')
when(() => zipDecoder.decodeBytes(any())).thenAnswer((_) {
final iosArchive = ArchiveFile.string('ios-$globalVersion', '')
..isFile = false;

return Archive()..addFile(archiveFile);
final iosDeviceArchive = ArchiveFile.string(
'AutomatorServer-iphoneos-arm64-$globalVersion.app',
'',
)..isFile = false;

final iosSimulatorArmArchive = ArchiveFile.string(
'AutomatorServer-iphonesimulator-arm64-$globalVersion.app',
'',
)..isFile = false;

final iosSimulatorAmdArchive = ArchiveFile.string(
'AutomatorServer-iphonesimulator-x86_64-$globalVersion.app',
'',
)..isFile = false;

return Archive()
..addFile(iosArchive)
..addFile(iosDeviceArchive)
..addFile(iosSimulatorArmArchive)
..addFile(iosSimulatorAmdArchive);
});

fs = MemoryFileSystem.test();
Expand All @@ -78,13 +134,14 @@ void main() {
expect(
artifactsRepository.instrumentationArtifactPath,
equals(
'/home/johndoe/.cache/patrol/instrumentation-$globalVersion.apk'),
'/home/johndoe/.cache/patrol/instrumentation-$globalVersion.apk',
),
);

// expect(
// artifactsRepository.iosArtifactDirPath,
// equals('/home/johndoe/.cache/patrol/ios-$version'),
// );
expect(
artifactsRepository.iosPath,
equals('/home/johndoe/.cache/patrol/ios-$globalVersion'),
);
});

test('are correct for debug artifacts', () {
Expand Down Expand Up @@ -142,25 +199,17 @@ void main() {
test('returns false when only Android artifacts exist on macOS', () {
artifactsRepository.platform = _macos;

fs
.file(join(_artifactPath, 'server-$globalVersion.apk'))
.createSync(recursive: true);
fs
.file(join(_artifactPath, 'instrumentation-$globalVersion.apk'))
.createSync();
fs._createAndroidArtifacts();

expect(artifactsRepository.areArtifactsPresent(), equals(false));
});

test('returns true when Android and iOS artifacts exist on macOS', () {
artifactsRepository.platform = _macos;

fs
.file(join(_artifactPath, 'server-$globalVersion.apk'))
.createSync(recursive: true);
fs
.file(join(_artifactPath, 'instrumentation-$globalVersion.apk'))
.createSync();
fs.directory(join(_artifactPath, 'ios-$globalVersion')).createSync();
.._createAndroidArtifacts()
.._createIOSArtifacts();

expect(artifactsRepository.areArtifactsPresent(), equals(true));
});
Expand Down Expand Up @@ -238,7 +287,44 @@ void main() {
isTrue,
);

verify(() => httpClient.get(any())).called(3);
expect(
fs
.directory(
join(
_artifactPath,
'AutomatorServer-iphonesimulator-arm64-$globalVersion.app',
),
)
.existsSync(),
isTrue,
reason: "iOS Simulator arm64 artifact doesn't exist",
);

expect(
fs
.directory(
join(
_artifactPath,
'AutomatorServer-iphonesimulator-x86_64-$globalVersion.app',
),
)
.existsSync(),
isTrue,
);

expect(
fs
.directory(
join(
_artifactPath,
'AutomatorServer-iphoneos-arm64-$globalVersion.app',
),
)
.existsSync(),
isTrue,
);

verify(() => httpClient.get(any())).called(6);
});
});
});
Expand Down
26 changes: 17 additions & 9 deletions packages/patrol_cli/test/features/drive/test_finder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,31 @@ void main() {
fs.file('integration_test/app_test.dart').createSync(recursive: true);
fs.file('integration_test/permission_test.dart').createSync();

expect(testFinder.findAllTests(), [
'${wd.path}/integration_test/app_test.dart',
'${wd.path}/integration_test/permission_test.dart'
]);
expect(
testFinder.findAllTests(),
equals([
'${wd.path}/integration_test/app_test.dart',
'${wd.path}/integration_test/permission_test.dart'
]),
);
});

test('finds tests recursively', () {
fs.file('integration_test/app_test.dart').createSync(recursive: true);
fs.file('integration_test/permission_test.dart').createSync();
fs.file('integration_test/webview_test.dart').createSync();
fs
.file('integration_test/auth/sign_in_test.dart')
.createSync(recursive: true);

expect(testFinder.findAllTests(), [
'${wd.path}/integration_test/app_test.dart',
'${wd.path}/integration_test/permission_test.dart',
'${wd.path}/integration_test/auth/sign_in_test.dart',
]);
expect(
testFinder.findAllTests(),
equals([
'${wd.path}/integration_test/app_test.dart',
'${wd.path}/integration_test/permission_test.dart',
'${wd.path}/integration_test/webview_test.dart',
'${wd.path}/integration_test/auth/sign_in_test.dart',
]),
);
});
}

0 comments on commit 5b8d4ed

Please sign in to comment.