[flutter_tools] Generate Localizations on flutter run
for web (#110526)
This commit is contained in:
parent
34a628483c
commit
0508a1defd
@ -280,6 +280,7 @@ class ResidentWebRunner extends ResidentRunner {
|
|||||||
);
|
);
|
||||||
final Uri url = await device!.devFS!.create();
|
final Uri url = await device!.devFS!.create();
|
||||||
if (debuggingOptions.buildInfo.isDebug) {
|
if (debuggingOptions.buildInfo.isDebug) {
|
||||||
|
await runSourceGenerators();
|
||||||
final UpdateFSReport report = await _updateDevFS(fullRestart: true);
|
final UpdateFSReport report = await _updateDevFS(fullRestart: true);
|
||||||
if (!report.success) {
|
if (!report.success) {
|
||||||
_logger!.printError('Failed to compile application.');
|
_logger!.printError('Failed to compile application.');
|
||||||
|
@ -1388,6 +1388,47 @@ flutter:
|
|||||||
expect(testLogger.statusText, isEmpty);
|
expect(testLogger.statusText, isEmpty);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
testUsingContext('ResidentRunner generates files when l10n.yaml exists', () => testbed.run(() async {
|
||||||
|
globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
|
||||||
|
.createSync(recursive: true);
|
||||||
|
final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'app_en.arb'))
|
||||||
|
..createSync(recursive: true);
|
||||||
|
arbFile.writeAsStringSync('''
|
||||||
|
{
|
||||||
|
"helloWorld": "Hello, World!",
|
||||||
|
"@helloWorld": {
|
||||||
|
"description": "Sample description"
|
||||||
|
}
|
||||||
|
}''');
|
||||||
|
globals.fs.file('l10n.yaml').createSync();
|
||||||
|
globals.fs.file('pubspec.yaml').writeAsStringSync('flutter:\n generate: true\n');
|
||||||
|
|
||||||
|
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
|
||||||
|
final FakeResidentCompiler residentCompiler = FakeResidentCompiler()
|
||||||
|
..nextOutput = const CompilerOutput('foo', 1 ,<Uri>[]);
|
||||||
|
residentRunner = HotRunner(
|
||||||
|
<FlutterDevice>[
|
||||||
|
flutterDevice,
|
||||||
|
],
|
||||||
|
stayResident: false,
|
||||||
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||||
|
target: 'main.dart',
|
||||||
|
devtoolsHandler: createNoOpHandler,
|
||||||
|
);
|
||||||
|
flutterDevice.generator = residentCompiler;
|
||||||
|
|
||||||
|
await residentRunner.run();
|
||||||
|
|
||||||
|
final File generatedLocalizationsFile = globals.fs.directory('.dart_tool')
|
||||||
|
.childDirectory('flutter_gen')
|
||||||
|
.childDirectory('gen_l10n')
|
||||||
|
.childFile('app_localizations.dart');
|
||||||
|
expect(generatedLocalizationsFile.existsSync(), isTrue);
|
||||||
|
|
||||||
|
// Completing this future ensures that the daemon can exit correctly.
|
||||||
|
expect(await residentRunner.waitForAppToFinish(), 1);
|
||||||
|
}));
|
||||||
|
|
||||||
testUsingContext('ResidentRunner printHelpDetails hot runner', () => testbed.run(() {
|
testUsingContext('ResidentRunner printHelpDetails hot runner', () => testbed.run(() {
|
||||||
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
|
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
|
||||||
|
|
||||||
|
@ -1049,6 +1049,69 @@ void main() {
|
|||||||
ProcessManager: () => processManager,
|
ProcessManager: () => processManager,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('ResidentWebRunner generates files when l10n.yaml exists', () async {
|
||||||
|
fakeVmServiceHost =
|
||||||
|
FakeVmServiceHost(requests: kAttachExpectations.toList());
|
||||||
|
setupMocks();
|
||||||
|
final ResidentRunner residentWebRunner = ResidentWebRunner(
|
||||||
|
flutterDevice,
|
||||||
|
flutterProject:
|
||||||
|
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
|
||||||
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
||||||
|
ipv6: true,
|
||||||
|
stayResident: false,
|
||||||
|
fileSystem: fileSystem,
|
||||||
|
logger: BufferLogger.test(),
|
||||||
|
usage: globals.flutterUsage,
|
||||||
|
systemClock: globals.systemClock,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create necessary files.
|
||||||
|
globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
|
||||||
|
.createSync(recursive: true);
|
||||||
|
globals.fs.file(globals.fs.path.join('lib', 'l10n', 'app_en.arb'))
|
||||||
|
..createSync(recursive: true)
|
||||||
|
..writeAsStringSync('''
|
||||||
|
{
|
||||||
|
"helloWorld": "Hello, World!",
|
||||||
|
"@helloWorld": {
|
||||||
|
"description": "Sample description"
|
||||||
|
}
|
||||||
|
}''');
|
||||||
|
globals.fs.file('l10n.yaml').createSync();
|
||||||
|
globals.fs.file('pubspec.yaml').writeAsStringSync('''
|
||||||
|
flutter:
|
||||||
|
generate: true
|
||||||
|
''');
|
||||||
|
globals.fs.directory('.dart_tool')
|
||||||
|
.childFile('package_config.json')
|
||||||
|
..createSync(recursive: true)
|
||||||
|
..writeAsStringSync('''
|
||||||
|
{
|
||||||
|
"configVersion": 2,
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "path_provider_linux",
|
||||||
|
"rootUri": "../../../path_provider_linux",
|
||||||
|
"packageUri": "lib/",
|
||||||
|
"languageVersion": "2.12"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
expect(await residentWebRunner.run(), 0);
|
||||||
|
final File generatedLocalizationsFile = globals.fs.directory('.dart_tool')
|
||||||
|
.childDirectory('flutter_gen')
|
||||||
|
.childDirectory('gen_l10n')
|
||||||
|
.childFile('app_localizations.dart');
|
||||||
|
expect(generatedLocalizationsFile.existsSync(), isTrue);
|
||||||
|
// Completing this future ensures that the daemon can exit correctly.
|
||||||
|
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
FileSystem: () => fileSystem,
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
});
|
||||||
|
|
||||||
// While this file should be ignored on web, generating it here will cause a
|
// While this file should be ignored on web, generating it here will cause a
|
||||||
// perf regression in hot restart.
|
// perf regression in hot restart.
|
||||||
testUsingContext('Does not generate dart_plugin_registrant.dart', () async {
|
testUsingContext('Does not generate dart_plugin_registrant.dart', () async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user