mirror of
https://github.com/flutter/packages.git
synced 2025-08-23 10:25:45 +08:00

Consolidates the code to find all changed file paths into the `PackageLoopingCommand` class that is the base of almost all of the repo tooling commands. This in a preparatory PR for a future change to allow each command to define a list of files or file patterns that definitively *don't* affect that test, so that CI can be smarter about what tests to run (e.g., not running expensive integration tests for README changes). A side effect of this change is that tests of almost all commands now need a mock `GitDir` instance. This would add a lot of copy/pasted boilerplate to the test setup, and there is already too much of that, so instead this refactors common test setup: - Creating a memory file system - Populating it with a packages directory - Creating a RecordingProcessRunner to mock out process calls - Creating a mock GitDir that forwards to a RecordingProcessRunner into a helper method (using records and destructuring to easily return multiple values). While some tests don't need all of these steps, those that don't can easily ignore parts of it, and it will make it much easier to update tests in the future if they need them, and it makes the setup much more consistent which makes it easier to reason about test setup in general. Prep for https://github.com/flutter/flutter/issues/136394
104 lines
2.9 KiB
Dart
104 lines
2.9 KiB
Dart
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:args/command_runner.dart';
|
|
import 'package:file/file.dart';
|
|
import 'package:flutter_plugin_tools/src/remove_dev_dependencies_command.dart';
|
|
import 'package:git/git.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'util.dart';
|
|
|
|
void main() {
|
|
late Directory packagesDir;
|
|
late CommandRunner<void> runner;
|
|
|
|
setUp(() {
|
|
final GitDir gitDir;
|
|
(:packagesDir, processRunner: _, gitProcessRunner: _, :gitDir) =
|
|
configureBaseCommandMocks();
|
|
|
|
final RemoveDevDependenciesCommand command = RemoveDevDependenciesCommand(
|
|
packagesDir,
|
|
gitDir: gitDir,
|
|
);
|
|
runner = CommandRunner<void>('trim_dev_dependencies_command',
|
|
'Test for trim_dev_dependencies_command');
|
|
runner.addCommand(command);
|
|
});
|
|
|
|
void addToPubspec(RepositoryPackage package, String addition) {
|
|
final String originalContent = package.pubspecFile.readAsStringSync();
|
|
package.pubspecFile.writeAsStringSync('''
|
|
$originalContent
|
|
$addition
|
|
''');
|
|
}
|
|
|
|
test('skips if nothing is removed', () async {
|
|
createFakePackage('a_package', packagesDir, version: '1.0.0');
|
|
|
|
final List<String> output =
|
|
await runCapturingPrint(runner, <String>['remove-dev-dependencies']);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('SKIPPING: Nothing to remove.'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
test('removes dev_dependencies', () async {
|
|
final RepositoryPackage package =
|
|
createFakePackage('a_package', packagesDir, version: '1.0.0');
|
|
|
|
addToPubspec(package, '''
|
|
dev_dependencies:
|
|
some_dependency: ^2.1.8
|
|
another_dependency: ^1.0.0
|
|
''');
|
|
|
|
final List<String> output =
|
|
await runCapturingPrint(runner, <String>['remove-dev-dependencies']);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('Removed dev_dependencies'),
|
|
]),
|
|
);
|
|
expect(package.pubspecFile.readAsStringSync(),
|
|
isNot(contains('some_dependency:')));
|
|
expect(package.pubspecFile.readAsStringSync(),
|
|
isNot(contains('another_dependency:')));
|
|
});
|
|
|
|
test('removes from examples', () async {
|
|
final RepositoryPackage package =
|
|
createFakePackage('a_package', packagesDir, version: '1.0.0');
|
|
|
|
final RepositoryPackage example = package.getExamples().first;
|
|
addToPubspec(example, '''
|
|
dev_dependencies:
|
|
some_dependency: ^2.1.8
|
|
another_dependency: ^1.0.0
|
|
''');
|
|
|
|
final List<String> output =
|
|
await runCapturingPrint(runner, <String>['remove-dev-dependencies']);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('Removed dev_dependencies'),
|
|
]),
|
|
);
|
|
expect(package.pubspecFile.readAsStringSync(),
|
|
isNot(contains('some_dependency:')));
|
|
expect(package.pubspecFile.readAsStringSync(),
|
|
isNot(contains('another_dependency:')));
|
|
});
|
|
}
|