[flutter_tools] reland: cache pub invocations (#70180)
Disabled caching of pub invocations on flutter drive.
This commit is contained in:
@@ -30,6 +30,269 @@ void main() {
|
||||
MockDirectory.findCache = false;
|
||||
});
|
||||
|
||||
testWithoutContext('checkUpToDate skips pub get if the package config is newer than the pubspec '
|
||||
'and the current framework version is the same as the last version', () async {
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('pubspec.lock').createSync();
|
||||
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('.dart_tool/version').writeAsStringSync('a');
|
||||
fileSystem.file('version').writeAsStringSync('a');
|
||||
|
||||
final Pub pub = Pub(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
processManager: processManager,
|
||||
usage: MockUsage(),
|
||||
platform: FakePlatform(
|
||||
environment: const <String, String>{},
|
||||
),
|
||||
botDetector: const BotDetectorAlwaysNo(),
|
||||
);
|
||||
|
||||
await pub.get(
|
||||
context: PubContext.pubGet,
|
||||
checkUpToDate: true,
|
||||
);
|
||||
|
||||
expect(logger.traceText, contains('Skipping pub get: version match.'));
|
||||
});
|
||||
|
||||
testWithoutContext('checkUpToDate does not skip pub get if the package config is newer than the pubspec '
|
||||
'but the current framework version is not the same as the last version', () async {
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'bin/cache/dart-sdk/bin/pub',
|
||||
'--verbosity=warning',
|
||||
'get',
|
||||
'--no-precompile',
|
||||
])
|
||||
]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('pubspec.lock').createSync();
|
||||
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('.dart_tool/version').writeAsStringSync('a');
|
||||
fileSystem.file('version').writeAsStringSync('b');
|
||||
|
||||
final Pub pub = Pub(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
processManager: processManager,
|
||||
usage: MockUsage(),
|
||||
platform: FakePlatform(
|
||||
environment: const <String, String>{},
|
||||
),
|
||||
botDetector: const BotDetectorAlwaysNo(),
|
||||
);
|
||||
|
||||
await pub.get(
|
||||
context: PubContext.pubGet,
|
||||
checkUpToDate: true,
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, false);
|
||||
expect(fileSystem.file('.dart_tool/version').readAsStringSync(), 'b');
|
||||
});
|
||||
|
||||
testWithoutContext('checkUpToDate does not skip pub get if the package config is newer than the pubspec '
|
||||
'but the current framework version does not exist yet', () async {
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'bin/cache/dart-sdk/bin/pub',
|
||||
'--verbosity=warning',
|
||||
'get',
|
||||
'--no-precompile',
|
||||
])
|
||||
]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('pubspec.lock').createSync();
|
||||
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('version').writeAsStringSync('b');
|
||||
|
||||
final Pub pub = Pub(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
processManager: processManager,
|
||||
usage: MockUsage(),
|
||||
platform: FakePlatform(
|
||||
environment: const <String, String>{},
|
||||
),
|
||||
botDetector: const BotDetectorAlwaysNo(),
|
||||
);
|
||||
|
||||
await pub.get(
|
||||
context: PubContext.pubGet,
|
||||
checkUpToDate: true,
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, false);
|
||||
expect(fileSystem.file('.dart_tool/version').readAsStringSync(), 'b');
|
||||
});
|
||||
|
||||
testWithoutContext('checkUpToDate does not skip pub get if the package config does not exist', () async {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
FakeCommand(command: const <String>[
|
||||
'bin/cache/dart-sdk/bin/pub',
|
||||
'--verbosity=warning',
|
||||
'get',
|
||||
'--no-precompile',
|
||||
], onRun: () {
|
||||
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
|
||||
})
|
||||
]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('pubspec.lock').createSync();
|
||||
fileSystem.file('version').writeAsStringSync('b');
|
||||
|
||||
final Pub pub = Pub(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
processManager: processManager,
|
||||
usage: MockUsage(),
|
||||
platform: FakePlatform(
|
||||
environment: const <String, String>{},
|
||||
),
|
||||
botDetector: const BotDetectorAlwaysNo(),
|
||||
);
|
||||
|
||||
await pub.get(
|
||||
context: PubContext.pubGet,
|
||||
checkUpToDate: true,
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, false);
|
||||
expect(fileSystem.file('.dart_tool/version').readAsStringSync(), 'b');
|
||||
});
|
||||
|
||||
testWithoutContext('checkUpToDate does not skip pub get if the pubspec.lock does not exist', () async {
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'bin/cache/dart-sdk/bin/pub',
|
||||
'--verbosity=warning',
|
||||
'get',
|
||||
'--no-precompile',
|
||||
]),
|
||||
]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('version').writeAsStringSync('b');
|
||||
fileSystem.file('.dart_tool/package_config.json').createSync(recursive: true);
|
||||
fileSystem.file('.dart_tool/version').writeAsStringSync('b');
|
||||
|
||||
final Pub pub = Pub(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
processManager: processManager,
|
||||
usage: MockUsage(),
|
||||
platform: FakePlatform(
|
||||
environment: const <String, String>{},
|
||||
),
|
||||
botDetector: const BotDetectorAlwaysNo(),
|
||||
);
|
||||
|
||||
await pub.get(
|
||||
context: PubContext.pubGet,
|
||||
checkUpToDate: true,
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, false);
|
||||
expect(fileSystem.file('.dart_tool/version').readAsStringSync(), 'b');
|
||||
});
|
||||
|
||||
testWithoutContext('checkUpToDate does not skip pub get if the package config is older that the pubspec', () async {
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'bin/cache/dart-sdk/bin/pub',
|
||||
'--verbosity=warning',
|
||||
'get',
|
||||
'--no-precompile',
|
||||
])
|
||||
]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('pubspec.lock').createSync();
|
||||
fileSystem.file('.dart_tool/package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..setLastModifiedSync(DateTime(1991));
|
||||
fileSystem.file('version').writeAsStringSync('b');
|
||||
|
||||
final Pub pub = Pub(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
processManager: processManager,
|
||||
usage: MockUsage(),
|
||||
platform: FakePlatform(
|
||||
environment: const <String, String>{},
|
||||
),
|
||||
botDetector: const BotDetectorAlwaysNo(),
|
||||
);
|
||||
|
||||
await pub.get(
|
||||
context: PubContext.pubGet,
|
||||
checkUpToDate: true,
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, false);
|
||||
expect(fileSystem.file('.dart_tool/version').readAsStringSync(), 'b');
|
||||
});
|
||||
|
||||
testWithoutContext('checkUpToDate does not skip pub get if the pubspec.lock is older that the pubspec', () async {
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'bin/cache/dart-sdk/bin/pub',
|
||||
'--verbosity=warning',
|
||||
'get',
|
||||
'--no-precompile',
|
||||
])
|
||||
]);
|
||||
final BufferLogger logger = BufferLogger.test();
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('pubspec.lock')
|
||||
..createSync()
|
||||
..setLastModifiedSync(DateTime(1991));
|
||||
fileSystem.file('.dart_tool/package_config.json')
|
||||
.createSync(recursive: true);
|
||||
fileSystem.file('version').writeAsStringSync('b');
|
||||
fileSystem.file('.dart_tool/version').writeAsStringSync('b');
|
||||
|
||||
final Pub pub = Pub(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
processManager: processManager,
|
||||
usage: MockUsage(),
|
||||
platform: FakePlatform(
|
||||
environment: const <String, String>{},
|
||||
),
|
||||
botDetector: const BotDetectorAlwaysNo(),
|
||||
);
|
||||
|
||||
await pub.get(
|
||||
context: PubContext.pubGet,
|
||||
checkUpToDate: true,
|
||||
);
|
||||
|
||||
expect(processManager.hasRemainingExpectations, false);
|
||||
expect(fileSystem.file('.dart_tool/version').readAsStringSync(), 'b');
|
||||
});
|
||||
|
||||
testWithoutContext('pub get 69', () async {
|
||||
String error;
|
||||
|
||||
@@ -209,6 +472,7 @@ void main() {
|
||||
}
|
||||
),
|
||||
);
|
||||
fileSystem.file('version').createSync();
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('.dart_tool/package_config.json')
|
||||
..createSync(recursive: true)
|
||||
@@ -237,6 +501,7 @@ void main() {
|
||||
}
|
||||
),
|
||||
);
|
||||
fileSystem.file('version').createSync();
|
||||
fileSystem.file('pubspec.yaml').createSync();
|
||||
fileSystem.file('.dart_tool/package_config.json')
|
||||
..createSync(recursive: true)
|
||||
@@ -377,6 +642,7 @@ void main() {
|
||||
botDetector: const BotDetectorAlwaysNo()
|
||||
);
|
||||
|
||||
fileSystem.file('version').createSync();
|
||||
// the good scenario: .packages is old, pub updates the file.
|
||||
fileSystem.file('.dart_tool/package_config.json')
|
||||
..createSync(recursive: true)
|
||||
|
||||
@@ -30,6 +30,7 @@ class ThrowingPub implements Pub {
|
||||
bool skipPubspecYamlCheck = false,
|
||||
bool generateSyntheticPackage = false,
|
||||
String flutterRootOverride,
|
||||
bool checkUpToDate = false,
|
||||
}) {
|
||||
throw UnsupportedError('Attempted to invoke pub during test.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user