mirror of
https://github.com/flutter/packages.git
synced 2025-08-23 18:44:31 +08:00
[tool] Add initial file-based command skipping (#8928)
Adds initial file-based filtering. This does not attempt to be comprehensive, just to get some low-hanging fruit, and to create a blueprint for anyone to follow in the future when adding more filtering. I expect that once this is in place, what will happen is that as we notice cases where PRs are hitting slow or flaky tests that they clearly don't need to, we can incrementally improve the filtering on demand. Fixes https://github.com/flutter/flutter/issues/136394
This commit is contained in:
@ -28,11 +28,12 @@ void main() {
|
||||
late Directory packagesDir;
|
||||
late CommandRunner<void> runner;
|
||||
late RecordingProcessRunner processRunner;
|
||||
late RecordingProcessRunner gitProcessRunner;
|
||||
|
||||
setUp(() {
|
||||
mockPlatform = MockPlatform();
|
||||
final GitDir gitDir;
|
||||
(:packagesDir, :processRunner, gitProcessRunner: _, :gitDir) =
|
||||
(:packagesDir, :processRunner, :gitProcessRunner, :gitDir) =
|
||||
configureBaseCommandMocks(platform: mockPlatform);
|
||||
final DriveExamplesCommand command = DriveExamplesCommand(
|
||||
packagesDir,
|
||||
@ -1714,6 +1715,73 @@ void main() {
|
||||
expect(processRunner.recordedCalls.isEmpty, true);
|
||||
});
|
||||
});
|
||||
|
||||
group('file filtering', () {
|
||||
const List<String> files = <String>[
|
||||
'pubspec.yaml',
|
||||
'foo.dart',
|
||||
'foo.java',
|
||||
'foo.kt',
|
||||
'foo.m',
|
||||
'foo.swift',
|
||||
'foo.cc',
|
||||
'foo.cpp',
|
||||
'foo.h',
|
||||
];
|
||||
for (final String file in files) {
|
||||
test('runs command for changes to $file', () async {
|
||||
createFakePackage('package_a', packagesDir);
|
||||
|
||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] =
|
||||
<FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(stdout: '''
|
||||
packages/package_a/$file
|
||||
''')),
|
||||
];
|
||||
|
||||
// The target platform is irrelevant here; because this repo's
|
||||
// packages are fully federated, there's no need to distinguish
|
||||
// the ignore list by target (e.g., skipping iOS tests if only Java or
|
||||
// Kotlin files change), because package-level filering will already
|
||||
// accomplish the same goal.
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['drive-examples', '--web']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Running for package_a'),
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
test('skips commands if all files should be ignored', () async {
|
||||
createFakePackage('package_a', packagesDir);
|
||||
|
||||
gitProcessRunner.mockProcessesForExecutable['git-diff'] =
|
||||
<FakeProcessInfo>[
|
||||
FakeProcessInfo(MockProcess(stdout: '''
|
||||
README.md
|
||||
CODEOWNERS
|
||||
packages/package_a/CHANGELOG.md
|
||||
''')),
|
||||
];
|
||||
|
||||
final List<String> output =
|
||||
await runCapturingPrint(runner, <String>['drive-examples']);
|
||||
|
||||
expect(
|
||||
output,
|
||||
isNot(containsAllInOrder(<Matcher>[
|
||||
contains('Running for package_a'),
|
||||
])));
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('SKIPPING ALL PACKAGES'),
|
||||
]));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user