[flutter_plugin_tools] Include examples in test (#5453)

This commit is contained in:
stuartmorgan
2022-05-03 00:44:10 -04:00
committed by GitHub
parent fbf53f284b
commit 1186d6831f
4 changed files with 53 additions and 6 deletions

View File

@ -1,5 +1,6 @@
## NEXT
## 0.8.5
- Updates `test` to inculde the Dart unit tests of examples, if any.
- `drive-examples` now supports non-plugin packages.
- Commands that iterate over examples now include non-Flutter example packages.

View File

@ -36,6 +36,9 @@ class TestCommand extends PackageLoopingCommand {
final String description = 'Runs the Dart tests for all packages.\n\n'
'This command requires "flutter" to be in your path.';
@override
bool get includeSubpackages => true;
@override
Future<PackageResult> runForPackage(RepositoryPackage package) async {
if (!package.directory.childDirectory('test').existsSync()) {
@ -88,7 +91,6 @@ class TestCommand extends PackageLoopingCommand {
exitCode = await processRunner.runAndStream(
'dart',
<String>[
'pub',
'run',
if (experiment.isNotEmpty) '--enable-experiment=$experiment',
'test',

View File

@ -1,7 +1,7 @@
name: flutter_plugin_tools
description: Productivity utils for flutter/plugins and flutter/packages
repository: https://github.com/flutter/plugins/tree/main/script/tool
version: 0.8.4
version: 0.8.5
dependencies:
args: ^2.1.0

View File

@ -58,6 +58,28 @@ void main() {
);
});
test('runs flutter test on Flutter package example tests', () async {
final Directory pluginDir = createFakePlugin('a_plugin', packagesDir,
extraFiles: <String>[
'test/empty_test.dart',
'example/test/an_example_test.dart'
]);
await runCapturingPrint(runner, <String>['test']);
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(getFlutterCommand(mockPlatform),
const <String>['test', '--color'], pluginDir.path),
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>['test', '--color'],
pluginDir.childDirectory('example').path),
]),
);
});
test('fails when Flutter tests fail', () async {
createFakePlugin('plugin1', packagesDir,
extraFiles: <String>['test/empty_test.dart']);
@ -102,7 +124,7 @@ void main() {
);
});
test('runs pub run test on non-Flutter packages', () async {
test('runs dart run test on non-Flutter packages', () async {
final Directory pluginDir = createFakePlugin('a', packagesDir,
extraFiles: <String>['test/empty_test.dart']);
final Directory packageDir = createFakePackage('b', packagesDir,
@ -121,12 +143,34 @@ void main() {
ProcessCall('dart', const <String>['pub', 'get'], packageDir.path),
ProcessCall(
'dart',
const <String>['pub', 'run', '--enable-experiment=exp1', 'test'],
const <String>['run', '--enable-experiment=exp1', 'test'],
packageDir.path),
]),
);
});
test('runs dart run test on non-Flutter package examples', () async {
final Directory packageDir = createFakePackage('a_package', packagesDir,
extraFiles: <String>[
'test/empty_test.dart',
'example/test/an_example_test.dart'
]);
await runCapturingPrint(runner, <String>['test']);
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall('dart', const <String>['pub', 'get'], packageDir.path),
ProcessCall('dart', const <String>['run', 'test'], packageDir.path),
ProcessCall('dart', const <String>['pub', 'get'],
packageDir.childDirectory('example').path),
ProcessCall('dart', const <String>['run', 'test'],
packageDir.childDirectory('example').path),
]),
);
});
test('fails when getting non-Flutter package dependencies fails', () async {
createFakePackage('a_package', packagesDir,
extraFiles: <String>['test/empty_test.dart']);
@ -217,7 +261,7 @@ void main() {
ProcessCall('dart', const <String>['pub', 'get'], packageDir.path),
ProcessCall(
'dart',
const <String>['pub', 'run', '--enable-experiment=exp1', 'test'],
const <String>['run', '--enable-experiment=exp1', 'test'],
packageDir.path),
]),
);