Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add additional tests to ensure the mocked out flutter pub get call …
…is correct.
  • Loading branch information
IVLIVS-III committed Oct 26, 2022
commit 45ea1cf8433ac2531261516017d4a472d338fd11
4 changes: 3 additions & 1 deletion script/tool/lib/src/create_all_plugins_app_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:io' as io;

import 'package:file/file.dart';
import 'package:path/path.dart' as p;
import 'package:platform/platform.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:pubspec_parse/pubspec_parse.dart';

Expand All @@ -27,7 +28,8 @@ class CreateAllPluginsAppCommand extends PackageCommand {
Directory packagesDir, {
ProcessRunner processRunner = const ProcessRunner(),
Directory? pluginsRoot,
}) : super(packagesDir, processRunner: processRunner) {
Platform platform = const LocalPlatform(),
}) : super(packagesDir, processRunner: processRunner, platform: platform) {
final Directory defaultDir =
pluginsRoot ?? packagesDir.fileSystem.currentDirectory;
argParser.addOption(_outputDirectoryFlag,
Expand Down
63 changes: 62 additions & 1 deletion script/tool/test/create_all_plugins_app_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import 'dart:io' as io;
import 'package:args/command_runner.dart';
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:flutter_plugin_tools/src/common/core.dart';
import 'package:flutter_plugin_tools/src/create_all_plugins_app_command.dart';
import 'package:platform/platform.dart';
import 'package:test/test.dart';

import 'mocks.dart';
import 'util.dart';

void main() {
group('$CreateAllPluginsAppCommand', () {
late CommandRunner<void> runner;
late CreateAllPluginsAppCommand command;
late FileSystem fileSystem;
late MockPlatform mockPlatform;
late Directory testRoot;
late Directory packagesDir;
late RecordingProcessRunner processRunner;
Expand All @@ -27,6 +30,7 @@ void main() {
// has to use the real filesystem. Put everything possible in a unique
// temporary to minimize effect on the host system.
fileSystem = const LocalFileSystem();
mockPlatform = MockPlatform();
testRoot = fileSystem.systemTempDirectory.createTempSync();
packagesDir = testRoot.childDirectory('packages');
processRunner = RecordingProcessRunner();
Expand All @@ -35,6 +39,7 @@ void main() {
packagesDir,
processRunner: processRunner,
pluginsRoot: testRoot,
platform: mockPlatform,
);
runner = CommandRunner<void>(
'create_all_test', 'Test for $CreateAllPluginsAppCommand');
Expand Down Expand Up @@ -107,6 +112,15 @@ void main() {
});

test('macOS deployment target is modified in Podfile', () async {
final RepositoryPackage plugin = createFakePlugin('plugina', packagesDir);
final File podfileFile =
plugin.directory.childDirectory('macos').childFile('Podfile');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is being created in the wrong directory; the podfile should be in the created app, not the plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved creation of the mock Podfile to the app directory.

podfileFile.createSync(recursive: true);
podfileFile.writeAsStringSync("""
platform :osx, '10.11'
# some other line
""");

await runCapturingPrint(runner, <String>['all-plugins-app']);
final List<String> podfile = command.app
.platformDirectory(FlutterPlatform.macos)
Expand All @@ -118,10 +132,21 @@ void main() {
everyElement((String line) =>
!line.contains('platform :osx') || line.contains("'10.15'")));
},
// Podfile is only generated on macOS.
// Podfile is only generated (and thus only edited) on macOS.
skip: !io.Platform.isMacOS);

test('macOS deployment target is modified in pbxproj', () async {
final RepositoryPackage plugin = createFakePlugin('plugina', packagesDir);
final File pbxprojFile = plugin.directory
.childDirectory('Runner.xcodeproj')
.childFile('project.pbxproj');
pbxprojFile.createSync(recursive: true);
pbxprojFile.writeAsStringSync('''
MACOSX_DEPLOYMENT_TARGET = 10.11;
/* some other line */
MACOSX_DEPLOYMENT_TARGET = 10.11;
''');

await runCapturingPrint(runner, <String>['all-plugins-app']);
final List<String> pbxproj = command.app
.platformDirectory(FlutterPlatform.macos)
Expand All @@ -136,6 +161,42 @@ void main() {
line.contains('10.15')));
});

test('calls flutter pub get', () async {
createFakePlugin('plugina', packagesDir);

await runCapturingPrint(runner, <String>['all-plugins-app']);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
getFlutterCommand(mockPlatform),
const <String>['pub', 'get'],
testRoot.childDirectory('all_plugins').path),
]));
});

test('fails if flutter pub get fails', () async {
createFakePlugin('plugina', packagesDir);

processRunner
.mockProcessesForExecutable[getFlutterCommand(mockPlatform)] =
<io.Process>[MockProcess(exitCode: 1)];
Error? commandError;
final List<String> output = await runCapturingPrint(
runner, <String>['all-plugins-app'], errorHandler: (Error e) {
commandError = e;
});

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains(
"Failed to generate native build files via 'flutter pub get'"),
]));
});

test('handles --output-dir', () async {
createFakePlugin('plugina', packagesDir);

Expand Down