Unverified Commit 3bc2378a authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks from devfs web, cache, and xcode migrator test (#81475)

parent 13c346c4
...@@ -8,7 +8,7 @@ import 'package:flutter_tools/src/base/logger.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/precache.dart'; import 'package:flutter_tools/src/commands/precache.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -16,19 +16,11 @@ import '../../src/fakes.dart'; ...@@ -16,19 +16,11 @@ import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart'; import '../../src/test_flutter_command_runner.dart';
void main() { void main() {
MockCache cache; FakeCache cache;
Set<DevelopmentArtifact> artifacts;
setUp(() { setUp(() {
cache = MockCache(); cache = FakeCache();
// Release lock between test cases. cache.isUpToDateValue = false;
cache.releaseLock();
when(cache.isUpToDate()).thenAnswer((Invocation _) => Future<bool>.value(false));
when(cache.updateAll(any)).thenAnswer((Invocation invocation) {
artifacts = invocation.positionalArguments.first as Set<DevelopmentArtifact>;
return Future<void>.value(null);
});
}); });
testUsingContext('precache should acquire lock', () async { testUsingContext('precache should acquire lock', () async {
...@@ -41,8 +33,7 @@ void main() { ...@@ -41,8 +33,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache']); await createTestCommandRunner(command).run(const <String>['precache']);
// Do not throw StateError, lock is acquired. expect(cache.locked, true);
expect(() => cache.checkLockAcquired(), returnsNormally);
}); });
testUsingContext('precache should not re-entrantly acquire lock', () async { testUsingContext('precache should not re-entrantly acquire lock', () async {
...@@ -61,9 +52,7 @@ void main() { ...@@ -61,9 +52,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache']); await createTestCommandRunner(command).run(const <String>['precache']);
expect(Cache.isLocked(), isFalse); expect(cache.locked, false);
// Do not throw StateError, acquired reentrantly with FLUTTER_ALREADY_LOCKED.
expect(() => cache.checkLockAcquired(), returnsNormally);
}); });
testUsingContext('precache downloads web artifacts on dev branch when feature is enabled.', () async { testUsingContext('precache downloads web artifacts on dev branch when feature is enabled.', () async {
...@@ -75,7 +64,7 @@ void main() { ...@@ -75,7 +64,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--web', '--no-android', '--no-ios']); await createTestCommandRunner(command).run(const <String>['precache', '--web', '--no-android', '--no-ios']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.web, DevelopmentArtifact.web,
})); }));
...@@ -90,7 +79,7 @@ void main() { ...@@ -90,7 +79,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--web', '--no-android', '--no-ios']); await createTestCommandRunner(command).run(const <String>['precache', '--web', '--no-android', '--no-ios']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
})); }));
}); });
...@@ -104,7 +93,7 @@ void main() { ...@@ -104,7 +93,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--macos', '--no-android', '--no-ios']); await createTestCommandRunner(command).run(const <String>['precache', '--macos', '--no-android', '--no-ios']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.macOS, DevelopmentArtifact.macOS,
})); }));
...@@ -119,7 +108,7 @@ void main() { ...@@ -119,7 +108,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--macos', '--no-android', '--no-ios']); await createTestCommandRunner(command).run(const <String>['precache', '--macos', '--no-android', '--no-ios']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
})); }));
}); });
...@@ -133,7 +122,7 @@ void main() { ...@@ -133,7 +122,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--windows', '--no-android', '--no-ios']); await createTestCommandRunner(command).run(const <String>['precache', '--windows', '--no-android', '--no-ios']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.windows, DevelopmentArtifact.windows,
})); }));
...@@ -148,7 +137,7 @@ void main() { ...@@ -148,7 +137,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--windows', '--no-android', '--no-ios']); await createTestCommandRunner(command).run(const <String>['precache', '--windows', '--no-android', '--no-ios']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
})); }));
}); });
...@@ -162,7 +151,7 @@ void main() { ...@@ -162,7 +151,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--linux', '--no-android', '--no-ios']); await createTestCommandRunner(command).run(const <String>['precache', '--linux', '--no-android', '--no-ios']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.linux, DevelopmentArtifact.linux,
})); }));
...@@ -177,7 +166,7 @@ void main() { ...@@ -177,7 +166,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--linux', '--no-android', '--no-ios']); await createTestCommandRunner(command).run(const <String>['precache', '--linux', '--no-android', '--no-ios']);
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
})); }));
}); });
...@@ -222,7 +211,7 @@ void main() { ...@@ -222,7 +211,7 @@ void main() {
'--flutter_runner', '--flutter_runner',
], ],
); );
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.iOS, DevelopmentArtifact.iOS,
DevelopmentArtifact.androidGenSnapshot, DevelopmentArtifact.androidGenSnapshot,
...@@ -251,7 +240,7 @@ void main() { ...@@ -251,7 +240,7 @@ void main() {
'--android', '--android',
], ],
); );
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.androidGenSnapshot, DevelopmentArtifact.androidGenSnapshot,
DevelopmentArtifact.androidMaven, DevelopmentArtifact.androidMaven,
...@@ -276,7 +265,7 @@ void main() { ...@@ -276,7 +265,7 @@ void main() {
'--android_internal_build', '--android_internal_build',
], ],
); );
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.androidGenSnapshot, DevelopmentArtifact.androidGenSnapshot,
DevelopmentArtifact.androidMaven, DevelopmentArtifact.androidMaven,
...@@ -298,7 +287,7 @@ void main() { ...@@ -298,7 +287,7 @@ void main() {
], ],
); );
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.iOS, DevelopmentArtifact.iOS,
DevelopmentArtifact.androidGenSnapshot, DevelopmentArtifact.androidGenSnapshot,
...@@ -328,7 +317,7 @@ void main() { ...@@ -328,7 +317,7 @@ void main() {
], ],
); );
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.iOS, DevelopmentArtifact.iOS,
DevelopmentArtifact.androidGenSnapshot, DevelopmentArtifact.androidGenSnapshot,
...@@ -357,7 +346,7 @@ void main() { ...@@ -357,7 +346,7 @@ void main() {
], ],
); );
verify(cache.platformOverrideArtifacts = <String>{}); expect(cache.platformOverrideArtifacts, <String>{});
}); });
testUsingContext('precache with explicit artifact options overrides platform filtering', () async { testUsingContext('precache with explicit artifact options overrides platform filtering', () async {
...@@ -385,15 +374,15 @@ void main() { ...@@ -385,15 +374,15 @@ void main() {
], ],
); );
expect(artifacts, unorderedEquals(<DevelopmentArtifact>{ expect(cache.artifacts, unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.universal, DevelopmentArtifact.universal,
DevelopmentArtifact.macOS, DevelopmentArtifact.macOS,
})); }));
verify(cache.platformOverrideArtifacts = <String>{'macos'}); expect(cache.platformOverrideArtifacts, <String>{'macos'});
}); });
testUsingContext('precache deletes artifact stampfiles when --force is provided', () async { testUsingContext('precache deletes artifact stampfiles when --force is provided', () async {
when(cache.isUpToDate()).thenAnswer((Invocation _) => Future<bool>.value(true)); cache.isUpToDateValue = true;
final PrecacheCommand command = PrecacheCommand( final PrecacheCommand command = PrecacheCommand(
cache: cache, cache: cache,
logger: BufferLogger.test(), logger: BufferLogger.test(),
...@@ -404,7 +393,7 @@ void main() { ...@@ -404,7 +393,7 @@ void main() {
); );
await createTestCommandRunner(command).run(const <String>['precache', '--force']); await createTestCommandRunner(command).run(const <String>['precache', '--force']);
verify(cache.clearStampFiles()).called(1); expect(cache.clearedStampFiles, true);
}); });
testUsingContext('precache downloads all enabled platforms if no flags are provided.', () async { testUsingContext('precache downloads all enabled platforms if no flags are provided.', () async {
...@@ -424,7 +413,7 @@ void main() { ...@@ -424,7 +413,7 @@ void main() {
await createTestCommandRunner(command).run(const <String>['precache']); await createTestCommandRunner(command).run(const <String>['precache']);
expect( expect(
artifacts, cache.artifacts,
unorderedEquals(<DevelopmentArtifact>{ unorderedEquals(<DevelopmentArtifact>{
DevelopmentArtifact.web, DevelopmentArtifact.web,
DevelopmentArtifact.macOS, DevelopmentArtifact.macOS,
...@@ -436,4 +425,38 @@ void main() { ...@@ -436,4 +425,38 @@ void main() {
}); });
} }
class MockCache extends Mock implements Cache {} class FakeCache extends Fake implements Cache {
bool isUpToDateValue = false;
bool clearedStampFiles = false;
bool locked = false;
Set<DevelopmentArtifact> artifacts;
@override
Future<void> lock() async {
locked = true;
}
@override
void releaseLock() {
locked = false;
}
@override
Future<bool> isUpToDate() async => isUpToDateValue;
@override
Future<void> updateAll(Set<DevelopmentArtifact> requiredArtifacts) async {
artifacts = requiredArtifacts;
}
@override
void clearStampFiles() {
clearedStampFiles = true;
}
@override
Set<String> platformOverrideArtifacts;
@override
bool includeAllPlatforms = false;
}
...@@ -15,13 +15,14 @@ import 'package:flutter_tools/src/ios/migrations/xcode_build_system_migration.da ...@@ -15,13 +15,14 @@ import 'package:flutter_tools/src/ios/migrations/xcode_build_system_migration.da
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
void main () { void main () {
group('iOS migration', () { group('iOS migration', () {
TestUsage testUsage; TestUsage testUsage;
setUp(() { setUp(() {
testUsage = TestUsage(); testUsage = TestUsage();
}); });
...@@ -41,20 +42,20 @@ void main () { ...@@ -41,20 +42,20 @@ void main () {
group('remove framework linking and embedding migration', () { group('remove framework linking and embedding migration', () {
MemoryFileSystem memoryFileSystem; MemoryFileSystem memoryFileSystem;
BufferLogger testLogger; BufferLogger testLogger;
MockIosProject mockIosProject; FakeIosProject project;
File xcodeProjectInfoFile; File xcodeProjectInfoFile;
setUp(() { setUp(() {
memoryFileSystem = MemoryFileSystem.test(); memoryFileSystem = MemoryFileSystem.test();
xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj'); xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
testLogger = BufferLogger.test(); testLogger = BufferLogger.test();
mockIosProject = MockIosProject(); project = FakeIosProject();
when(mockIosProject.xcodeProjectInfoFile).thenReturn(xcodeProjectInfoFile); project.xcodeProjectInfoFile = xcodeProjectInfoFile;
}); });
testWithoutContext('skipped if files are missing', () { testWithoutContext('skipped if files are missing', () {
final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration( final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
mockIosProject, project,
testLogger, testLogger,
testUsage testUsage
); );
...@@ -73,7 +74,7 @@ void main () { ...@@ -73,7 +74,7 @@ void main () {
final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync(); final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();
final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration( final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
mockIosProject, project,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -93,7 +94,7 @@ shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend. ...@@ -93,7 +94,7 @@ shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.
xcodeProjectInfoFile.writeAsStringSync(contents); xcodeProjectInfoFile.writeAsStringSync(contents);
final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration( final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
mockIosProject, project,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -120,7 +121,7 @@ keep this 2 ...@@ -120,7 +121,7 @@ keep this 2
'''); ''');
final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration( final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
mockIosProject, project,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -141,7 +142,7 @@ keep this 2 ...@@ -141,7 +142,7 @@ keep this 2
'''); ''');
final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration( final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
mockIosProject, project,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -158,7 +159,7 @@ keep this 2 ...@@ -158,7 +159,7 @@ keep this 2
'''); ''');
final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration( final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
mockIosProject, project,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -174,7 +175,7 @@ keep this 2 ...@@ -174,7 +175,7 @@ keep this 2
'''); ''');
final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration( final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
mockIosProject, project,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -188,20 +189,20 @@ keep this 2 ...@@ -188,20 +189,20 @@ keep this 2
group('new Xcode build system', () { group('new Xcode build system', () {
MemoryFileSystem memoryFileSystem; MemoryFileSystem memoryFileSystem;
BufferLogger testLogger; BufferLogger testLogger;
MockIosProject mockIosProject; FakeIosProject project;
File xcodeWorkspaceSharedSettings; File xcodeWorkspaceSharedSettings;
setUp(() { setUp(() {
memoryFileSystem = MemoryFileSystem.test(); memoryFileSystem = MemoryFileSystem.test();
xcodeWorkspaceSharedSettings = memoryFileSystem.file('WorkspaceSettings.xcsettings'); xcodeWorkspaceSharedSettings = memoryFileSystem.file('WorkspaceSettings.xcsettings');
testLogger = BufferLogger.test(); testLogger = BufferLogger.test();
mockIosProject = MockIosProject(); project = FakeIosProject();
when(mockIosProject.xcodeWorkspaceSharedSettings).thenReturn(xcodeWorkspaceSharedSettings); project.xcodeWorkspaceSharedSettings = xcodeWorkspaceSharedSettings;
}); });
testWithoutContext('skipped if files are missing', () { testWithoutContext('skipped if files are missing', () {
final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration( final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -224,7 +225,7 @@ keep this 2 ...@@ -224,7 +225,7 @@ keep this 2
xcodeWorkspaceSharedSettings.writeAsStringSync(contents); xcodeWorkspaceSharedSettings.writeAsStringSync(contents);
final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration( final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -247,7 +248,7 @@ keep this 2 ...@@ -247,7 +248,7 @@ keep this 2
xcodeWorkspaceSharedSettings.writeAsStringSync(contents); xcodeWorkspaceSharedSettings.writeAsStringSync(contents);
final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration( final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -260,20 +261,20 @@ keep this 2 ...@@ -260,20 +261,20 @@ keep this 2
group('Xcode default build location', () { group('Xcode default build location', () {
MemoryFileSystem memoryFileSystem; MemoryFileSystem memoryFileSystem;
BufferLogger testLogger; BufferLogger testLogger;
MockIosProject mockIosProject; FakeIosProject project;
File xcodeProjectWorkspaceData; File xcodeProjectWorkspaceData;
setUp(() { setUp(() {
memoryFileSystem = MemoryFileSystem(); memoryFileSystem = MemoryFileSystem();
xcodeProjectWorkspaceData = memoryFileSystem.file('contents.xcworkspacedata'); xcodeProjectWorkspaceData = memoryFileSystem.file('contents.xcworkspacedata');
testLogger = BufferLogger.test(); testLogger = BufferLogger.test();
mockIosProject = MockIosProject(); project = FakeIosProject();
when(mockIosProject.xcodeProjectWorkspaceData).thenReturn(xcodeProjectWorkspaceData); project.xcodeProjectWorkspaceData = xcodeProjectWorkspaceData;
}); });
testWithoutContext('skipped if files are missing', () { testWithoutContext('skipped if files are missing', () {
final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration( final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -295,7 +296,7 @@ keep this 2 ...@@ -295,7 +296,7 @@ keep this 2
xcodeProjectWorkspaceData.writeAsStringSync(contents); xcodeProjectWorkspaceData.writeAsStringSync(contents);
final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration( final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -319,7 +320,7 @@ keep this 2 ...@@ -319,7 +320,7 @@ keep this 2
xcodeProjectWorkspaceData.writeAsStringSync(contents); xcodeProjectWorkspaceData.writeAsStringSync(contents);
final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration( final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -339,20 +340,20 @@ keep this 2 ...@@ -339,20 +340,20 @@ keep this 2
group('remove Runner project base configuration', () { group('remove Runner project base configuration', () {
MemoryFileSystem memoryFileSystem; MemoryFileSystem memoryFileSystem;
BufferLogger testLogger; BufferLogger testLogger;
MockIosProject mockIosProject; FakeIosProject project;
File xcodeProjectInfoFile; File xcodeProjectInfoFile;
setUp(() { setUp(() {
memoryFileSystem = MemoryFileSystem(); memoryFileSystem = MemoryFileSystem();
xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj'); xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
testLogger = BufferLogger.test(); testLogger = BufferLogger.test();
mockIosProject = MockIosProject(); project = FakeIosProject();
when(mockIosProject.xcodeProjectInfoFile).thenReturn(xcodeProjectInfoFile); project.xcodeProjectInfoFile = xcodeProjectInfoFile;
}); });
testWithoutContext('skipped if files are missing', () { testWithoutContext('skipped if files are missing', () {
final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration( final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -368,7 +369,7 @@ keep this 2 ...@@ -368,7 +369,7 @@ keep this 2
final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync(); final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();
final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration( final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -396,7 +397,7 @@ keep this 3 ...@@ -396,7 +397,7 @@ keep this 3
'''); ''');
final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration( final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -451,7 +452,7 @@ keep this 3 ...@@ -451,7 +452,7 @@ keep this 3
'''); ''');
final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration( final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration(
mockIosProject, project,
testLogger, testLogger,
); );
expect(iosProjectMigration.migrate(), isTrue); expect(iosProjectMigration.migrate(), isTrue);
...@@ -492,7 +493,16 @@ keep this 3 ...@@ -492,7 +493,16 @@ keep this 3
}); });
} }
class MockIosProject extends Mock implements IosProject {} class FakeIosProject extends Fake implements IosProject {
@override
File xcodeProjectWorkspaceData;
@override
File xcodeWorkspaceSharedSettings;
@override
File xcodeProjectInfoFile;
}
class FakeIOSMigrator extends ProjectMigrator { class FakeIOSMigrator extends ProjectMigrator {
FakeIOSMigrator({@required this.succeeds}) FakeIOSMigrator({@required this.succeeds})
......
...@@ -15,9 +15,9 @@ import 'package:flutter_tools/src/convert.dart'; ...@@ -15,9 +15,9 @@ import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/isolated/devfs_web.dart'; import 'package:flutter_tools/src/isolated/devfs_web.dart';
import 'package:flutter_tools/src/web/compile.dart'; import 'package:flutter_tools/src/web/compile.dart';
import 'package:mockito/mockito.dart';
import 'package:package_config/package_config.dart'; import 'package:package_config/package_config.dart';
import 'package:shelf/shelf.dart'; import 'package:shelf/shelf.dart';
import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/testbed.dart'; import '../../src/testbed.dart';
...@@ -37,7 +37,7 @@ void main() { ...@@ -37,7 +37,7 @@ void main() {
Platform linux; Platform linux;
PackageConfig packages; PackageConfig packages;
Platform windows; Platform windows;
MockHttpServer mockHttpServer; FakeHttpServer httpServer;
setUpAll(() async { setUpAll(() async {
packages = PackageConfig(<Package>[ packages = PackageConfig(<Package>[
...@@ -46,12 +46,12 @@ void main() { ...@@ -46,12 +46,12 @@ void main() {
}); });
setUp(() { setUp(() {
mockHttpServer = MockHttpServer(); httpServer = FakeHttpServer();
linux = FakePlatform(operatingSystem: 'linux', environment: <String, String>{}); linux = FakePlatform(operatingSystem: 'linux', environment: <String, String>{});
windows = FakePlatform(operatingSystem: 'windows', environment: <String, String>{}); windows = FakePlatform(operatingSystem: 'windows', environment: <String, String>{});
testbed = Testbed(setup: () { testbed = Testbed(setup: () {
webAssetServer = WebAssetServer( webAssetServer = WebAssetServer(
mockHttpServer, httpServer,
packages, packages,
InternetAddress.loopbackIPv4, InternetAddress.loopbackIPv4,
null, null,
...@@ -232,7 +232,7 @@ void main() { ...@@ -232,7 +232,7 @@ void main() {
webDir.childFile('index.html').writeAsStringSync(htmlContent); webDir.childFile('index.html').writeAsStringSync(htmlContent);
final WebAssetServer webAssetServer = WebAssetServer( final WebAssetServer webAssetServer = WebAssetServer(
mockHttpServer, httpServer,
packages, packages,
InternetAddress.loopbackIPv4, InternetAddress.loopbackIPv4,
null, null,
...@@ -251,7 +251,7 @@ void main() { ...@@ -251,7 +251,7 @@ void main() {
webDir.childFile('index.html').writeAsStringSync(htmlContent); webDir.childFile('index.html').writeAsStringSync(htmlContent);
final WebAssetServer webAssetServer = WebAssetServer( final WebAssetServer webAssetServer = WebAssetServer(
mockHttpServer, httpServer,
packages, packages,
InternetAddress.loopbackIPv4, InternetAddress.loopbackIPv4,
null, null,
...@@ -272,7 +272,7 @@ void main() { ...@@ -272,7 +272,7 @@ void main() {
expect( expect(
() => WebAssetServer( () => WebAssetServer(
mockHttpServer, httpServer,
packages, packages,
InternetAddress.loopbackIPv4, InternetAddress.loopbackIPv4,
null, null,
...@@ -292,7 +292,7 @@ void main() { ...@@ -292,7 +292,7 @@ void main() {
expect( expect(
() => WebAssetServer( () => WebAssetServer(
mockHttpServer, httpServer,
packages, packages,
InternetAddress.loopbackIPv4, InternetAddress.loopbackIPv4,
null, null,
...@@ -588,7 +588,7 @@ void main() { ...@@ -588,7 +588,7 @@ void main() {
test('calling dispose closes the http server', () => testbed.run(() async { test('calling dispose closes the http server', () => testbed.run(() async {
await webAssetServer.dispose(); await webAssetServer.dispose();
verify(mockHttpServer.close()).called(1); expect(httpServer.closed, true);
})); }));
test('Can start web server with specified assets', () => testbed.run(() async { test('Can start web server with specified assets', () => testbed.run(() async {
...@@ -599,17 +599,8 @@ void main() { ...@@ -599,17 +599,8 @@ void main() {
outputFile.parent.childFile('a.map').writeAsStringSync('{}'); outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('a.metadata').writeAsStringSync('{}'); outputFile.parent.childFile('a.metadata').writeAsStringSync('{}');
final ResidentCompiler residentCompiler = MockResidentCompiler(); final ResidentCompiler residentCompiler = FakeResidentCompiler()
when(residentCompiler.recompile( ..output = const CompilerOutput('a', 0, <Uri>[]);
any,
any,
outputPath: anyNamed('outputPath'),
packageConfig: anyNamed('packageConfig'),
projectRootPath: anyNamed('projectRootPath'),
fs: anyNamed('fs'),
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('a', 0, <Uri>[]);
});
final WebDevFS webDevFS = WebDevFS( final WebDevFS webDevFS = WebDevFS(
hostname: 'localhost', hostname: 'localhost',
...@@ -719,17 +710,8 @@ void main() { ...@@ -719,17 +710,8 @@ void main() {
outputFile.parent.childFile('a.map').writeAsStringSync('{}'); outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('a.metadata').writeAsStringSync('{}'); outputFile.parent.childFile('a.metadata').writeAsStringSync('{}');
final ResidentCompiler residentCompiler = MockResidentCompiler(); final ResidentCompiler residentCompiler = FakeResidentCompiler()
when(residentCompiler.recompile( ..output = const CompilerOutput('a', 0, <Uri>[]);
any,
any,
outputPath: anyNamed('outputPath'),
packageConfig: anyNamed('packageConfig'),
projectRootPath: anyNamed('projectRootPath'),
fs: anyNamed('fs'),
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('a', 0, <Uri>[]);
});
final WebDevFS webDevFS = WebDevFS( final WebDevFS webDevFS = WebDevFS(
hostname: 'localhost', hostname: 'localhost',
...@@ -836,18 +818,6 @@ void main() { ...@@ -836,18 +818,6 @@ void main() {
outputFile.parent.childFile('a.json').writeAsStringSync('{}'); outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}'); outputFile.parent.childFile('a.map').writeAsStringSync('{}');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
any,
any,
outputPath: anyNamed('outputPath'),
packageConfig: anyNamed('packageConfig'),
projectRootPath: anyNamed('projectRootPath'),
fs: anyNamed('fs'),
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('a', 0, <Uri>[]);
});
final WebDevFS webDevFS = WebDevFS( final WebDevFS webDevFS = WebDevFS(
hostname: 'any', hostname: 'any',
port: 0, port: 0,
...@@ -883,18 +853,6 @@ void main() { ...@@ -883,18 +853,6 @@ void main() {
outputFile.parent.childFile('a.json').writeAsStringSync('{}'); outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}'); outputFile.parent.childFile('a.map').writeAsStringSync('{}');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
any,
any,
outputPath: anyNamed('outputPath'),
packageConfig: anyNamed('packageConfig'),
projectRootPath: anyNamed('projectRootPath'),
fs: anyNamed('fs'),
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('a', 0, <Uri>[]);
});
final WebDevFS webDevFS = WebDevFS( final WebDevFS webDevFS = WebDevFS(
hostname: 'localhost', hostname: 'localhost',
port: 0, port: 0,
...@@ -938,18 +896,6 @@ void main() { ...@@ -938,18 +896,6 @@ void main() {
outputFile.parent.childFile('a.json').writeAsStringSync('{}'); outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}'); outputFile.parent.childFile('a.map').writeAsStringSync('{}');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
any,
any,
outputPath: anyNamed('outputPath'),
packageConfig: anyNamed('packageConfig'),
projectRootPath: anyNamed('projectRootPath'),
fs: anyNamed('fs'),
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('a', 0, <Uri>[]);
});
final WebDevFS webDevFS = WebDevFS( final WebDevFS webDevFS = WebDevFS(
hostname: 'localhost', hostname: 'localhost',
port: 0, port: 0,
...@@ -1033,7 +979,7 @@ void main() { ...@@ -1033,7 +979,7 @@ void main() {
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(htmlContent); ..writeAsStringSync(htmlContent);
final WebAssetServer webAssetServer = WebAssetServer( final WebAssetServer webAssetServer = WebAssetServer(
MockHttpServer(), FakeHttpServer(),
PackageConfig.empty, PackageConfig.empty,
InternetAddress.anyIPv4, InternetAddress.anyIPv4,
<String, String>{}, <String, String>{},
...@@ -1060,18 +1006,6 @@ void main() { ...@@ -1060,18 +1006,6 @@ void main() {
outputFile.parent.childFile('a.map').writeAsStringSync('{}'); outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('a.metadata').writeAsStringSync('{}'); outputFile.parent.childFile('a.metadata').writeAsStringSync('{}');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
any,
any,
outputPath: anyNamed('outputPath'),
packageConfig: anyNamed('packageConfig'),
projectRootPath: anyNamed('projectRootPath'),
fs: anyNamed('fs'),
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('a', 0, <Uri>[]);
});
final WebDevFS webDevFS = WebDevFS( final WebDevFS webDevFS = WebDevFS(
hostname: 'localhost', hostname: 'localhost',
port: 0, port: 0,
...@@ -1107,5 +1041,29 @@ void main() { ...@@ -1107,5 +1041,29 @@ void main() {
})); }));
} }
class MockHttpServer extends Mock implements HttpServer {} class FakeHttpServer extends Fake implements HttpServer {
class MockResidentCompiler extends Mock implements ResidentCompiler {} bool closed = false;
@override
Future<void> close({bool force = false}) async {
closed = true;
}
}
class FakeResidentCompiler extends Fake implements ResidentCompiler {
CompilerOutput output;
@override
void addFileSystemRoot(String root) { }
@override
Future<CompilerOutput> recompile(Uri mainUri, List<Uri> invalidatedFiles, {
String outputPath,
PackageConfig packageConfig,
String projectRootPath,
FileSystem fs,
bool suppressErrors = false,
}) async {
return output;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment