Add a more complete app template for Flutter (skeleton) (#83530)

This commit is contained in:
Filip Hracek
2021-06-28 15:26:04 -07:00
committed by GitHub
parent b001671ffb
commit 76d5e62f42
253 changed files with 1141 additions and 399 deletions

View File

@@ -29,7 +29,7 @@ void main() {
setUp(() {
testbed = Testbed(setup: () {
Cache.flutterRoot = 'flutter';
final List<String> paths = <String>[
final List<String> filePaths = <String>[
globals.fs.path.join('flutter', 'packages', 'flutter', 'pubspec.yaml'),
globals.fs.path.join('flutter', 'packages', 'flutter_driver', 'pubspec.yaml'),
globals.fs.path.join('flutter', 'packages', 'flutter_test', 'pubspec.yaml'),
@@ -37,8 +37,20 @@ void main() {
globals.fs.path.join('usr', 'local', 'bin', 'adb'),
globals.fs.path.join('Android', 'platform-tools', 'adb.exe'),
];
for (final String path in paths) {
globals.fs.file(path).createSync(recursive: true);
for (final String filePath in filePaths) {
globals.fs.file(filePath).createSync(recursive: true);
}
final List<String> templatePaths = <String>[
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'app'),
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'app_shared'),
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'cocoapods'),
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'skeleton'),
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'module', 'common'),
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'package'),
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'plugin'),
];
for (final String templatePath in templatePaths) {
globals.fs.directory(templatePath).createSync(recursive: true);
}
// Set up enough of the packages to satisfy the templating code.
final File packagesFile = globals.fs.file(
@@ -76,6 +88,9 @@ void main() {
await runner.run(<String>['create', '--no-pub', '--template=app', 'testy']);
expect((await command.usageValues).commandCreateProjectType, 'app');
await runner.run(<String>['create', '--no-pub', '--template=skeleton', 'testy']);
expect((await command.usageValues).commandCreateProjectType, 'skeleton');
await runner.run(<String>['create', '--no-pub', '--template=package', 'testy']);
expect((await command.usageValues).commandCreateProjectType, 'package');

View File

@@ -137,6 +137,51 @@ void main() {
),
});
testUsingContext('can create a skeleton (list/detail) app', () async {
await _createAndAnalyzeProject(
projectDir,
<String>['-t', 'skeleton', '-i', 'objc', '-a', 'java', '--implementation-tests'],
<String>[
'analysis_options.yaml',
'android/app/src/main/java/com/example/flutter_project/MainActivity.java',
'android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
'flutter_project.iml',
'ios/Flutter/AppFrameworkInfo.plist',
'ios/Runner/AppDelegate.m',
'ios/Runner/GeneratedPluginRegistrant.h',
'lib/main.dart',
'l10n.yaml',
'assets/images/2.0x/flutter_logo.png',
'assets/images/flutter_logo.png',
'assets/images/3.0x/flutter_logo.png',
'test/unit_test.dart',
'test/widget_test.dart',
'test/implementation_test.dart',
'lib/src/localization/app_en.arb',
'lib/src/app.dart',
'lib/src/sample_feature/sample_item_details_view.dart',
'lib/src/sample_feature/sample_item_list_view.dart',
'lib/src/sample_feature/sample_item.dart',
'lib/src/settings/settings_controller.dart',
'lib/src/settings/settings_view.dart',
'lib/src/settings/settings_service.dart',
'lib/main.dart',
'pubspec.yaml',
'README.md',
],
);
return _runFlutterTest(projectDir);
}, overrides: <Type, Generator>{
Pub: () => Pub(
fileSystem: globals.fs,
logger: globals.logger,
processManager: globals.processManager,
usage: globals.flutterUsage,
botDetector: globals.botDetector,
platform: globals.platform,
),
});
testUsingContext('can create a default project if empty directory exists', () async {
await projectDir.create(recursive: true);
await _createAndAnalyzeProject(

View File

@@ -58,12 +58,12 @@ void main() {
});
testUsingContext('androidComponentSetup build.gradle does not exist', () async {
final Directory templatesDir = flutterRootDir.childDirectory('templates').childDirectory('deferred_component');
final File buildGradleTemplate = templatesDir.childFile('build.gradle.tmpl');
final File androidManifestTemplate = templatesDir.childDirectory('src').childDirectory('main').childFile('AndroidManifest.xml.tmpl');
if (templatesDir.existsSync()) {
templatesDir.deleteSync(recursive: true);
}
final Directory templatesDir = flutterRootDir.childDirectory('templates');
final Directory deferredComponentDir = templatesDir.childDirectory('module').childDirectory('android').childDirectory('deferred_component');
final File buildGradleTemplate = deferredComponentDir.childFile('build.gradle.tmpl');
final File androidManifestTemplate = deferredComponentDir.childDirectory('src').childDirectory('main').childFile('AndroidManifest.xml.tmpl');
deferredComponentDir.createSync(recursive: true);
buildGradleTemplate.createSync(recursive: true);
androidManifestTemplate.createSync(recursive: true);
buildGradleTemplate.writeAsStringSync('fake build.gradle template {{componentName}}', flush: true, mode: FileMode.append);
@@ -94,15 +94,18 @@ void main() {
file.deleteSync();
expect(logger.statusText.contains('Newly generated android files:\n'), true);
expect(logger.statusText.contains('build/${DeferredComponentsValidator.kDeferredComponentsTempDirectory}/component1/build.gradle\n'), true);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('androidComponentSetup AndroidManifest.xml does not exist', () async {
final Directory templatesDir = flutterRootDir.childDirectory('templates').childDirectory('deferred_component');
final File buildGradleTemplate = templatesDir.childFile('build.gradle.tmpl');
final File androidManifestTemplate = templatesDir.childDirectory('src').childDirectory('main').childFile('AndroidManifest.xml.tmpl');
if (templatesDir.existsSync()) {
templatesDir.deleteSync(recursive: true);
}
final Directory templatesDir = flutterRootDir.childDirectory('templates');
final Directory deferredComponentDir = templatesDir.childDirectory('module').childDirectory('android').childDirectory('deferred_component');
final File buildGradleTemplate = deferredComponentDir.childFile('build.gradle.tmpl');
final File androidManifestTemplate = deferredComponentDir.childDirectory('src').childDirectory('main').childFile('AndroidManifest.xml.tmpl');
deferredComponentDir.createSync(recursive: true);
buildGradleTemplate.createSync(recursive: true);
androidManifestTemplate.createSync(recursive: true);
buildGradleTemplate.writeAsStringSync('fake build.gradle template {{componentName}}', flush: true, mode: FileMode.append);
@@ -133,6 +136,9 @@ void main() {
file.deleteSync();
expect(logger.statusText.contains('Newly generated android files:\n'), true);
expect(logger.statusText.contains('build/${DeferredComponentsValidator.kDeferredComponentsTempDirectory}/component1/src/main/AndroidManifest.xml\n'), true);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testWithoutContext('androidComponentSetup all files exist passes', () async {

View File

@@ -11,12 +11,25 @@ import 'package:flutter_tools/src/template.dart';
import '../src/common.dart';
void main() {
testWithoutContext('Template constructor throws ToolExit when source directory is missing', () {
final FileExceptionHandler handler = FileExceptionHandler();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);
expect(() => Template(
fileSystem.directory('doesNotExist'),
fileSystem.currentDirectory,
fileSystem: fileSystem,
logger: BufferLogger.test(),
templateRenderer: FakeTemplateRenderer(),
templateManifest: null,
), throwsToolExit());
});
testWithoutContext('Template.render throws ToolExit when FileSystem exception is raised', () {
final FileExceptionHandler handler = FileExceptionHandler();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);
final Template template = Template(
fileSystem.directory('examples'),
fileSystem.currentDirectory,
fileSystem.directory('examples')..createSync(recursive: true),
fileSystem.currentDirectory,
fileSystem: fileSystem,
logger: BufferLogger.test(),
@@ -42,7 +55,6 @@ void main() {
sourceImage.writeAsStringSync("Ceci n'est pas une pipe");
final Template template = Template(
templateDir,
templateDir,
imageSourceDir,
fileSystem: fileSystem,

View File

@@ -22,6 +22,7 @@ void main() {
.listSync(recursive: true)
.whereType<File>()
.where((File file) => fileSystem.path.basename(file.path) != 'template_manifest.json' &&
fileSystem.path.basename(file.path) != 'README.md' &&
fileSystem.path.basename(file.path) != '.DS_Store')
.map((File file) => file.uri)
.toSet();