From 375702ed6074ac1d5d88b78438845bb0ea3c97c2 Mon Sep 17 00:00:00 2001 From: Elijah Okoroh Date: Wed, 14 Oct 2026 19:24:51 +0000 Subject: [PATCH] [google_fonts] Make the pendingFonts test deterministic The test exercised the HTTP fetch path without faking PathProviderPlatform, so the package's background write to the application support directory failed with MissingPluginException after the test body had finished. Whether that late error was still attributed to the test was a matter of timing; on Windows CI it was, roughly 3 runs out of 10. Point the package at a temp directory the same way load_font_if_necessary_test.dart already does. Fixes flutter/flutter#194407 --- .../test/google_fonts_text_style_test.dart | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/google_fonts/test/google_fonts_text_style_test.dart b/packages/google_fonts/test/google_fonts_text_style_test.dart index 96ecd4894eec..2143f1e2c411 100644 --- a/packages/google_fonts/test/google_fonts_text_style_test.dart +++ b/packages/google_fonts/test/google_fonts_text_style_test.dart @@ -2,6 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +@TestOn('vm') // Uses dart:io +library; + +import 'dart:io'; + import 'package:cupertino_ui/cupertino_ui.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -12,6 +17,8 @@ import 'package:google_fonts/src/google_fonts_variant.dart'; import 'package:http/http.dart' as http; import 'package:material_ui/material_ui.dart'; import 'package:mockito/mockito.dart'; +import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; class MockHttpClient extends Mock implements http.Client { Future gets(dynamic uri, {dynamic headers}) { @@ -27,6 +34,19 @@ class MockAssetManifest extends Mock implements AssetManifest { List listAssets() => []; } +class FakePathProviderPlatform extends Fake + with MockPlatformInterfaceMixin + implements PathProviderPlatform { + FakePathProviderPlatform(this._applicationSupportPath); + + final String _applicationSupportPath; + + @override + Future getApplicationSupportPath() async { + return _applicationSupportPath; + } +} + const String _fakeResponse = 'fake response body - success'; // The number of bytes in _fakeResponse. const int _fakeResponseLengthInBytes = 28; @@ -56,6 +76,16 @@ void main() { when(mockHttpClient.gets(any)).thenAnswer((_) async { return http.Response(_fakeResponse, 200); }); + + // After a font is fetched over HTTP, the package writes it to the + // application support directory without awaiting the result. In a + // `flutter test` environment there is no path_provider implementation, so + // that write fails with a MissingPluginException after the test body has + // already finished. Whether that late error is still attributed to this + // test depends on timing (it regularly is on Windows CI), so point the + // package at a real temporary directory instead. + final Directory directory = await Directory.systemTemp.createTemp(); + PathProviderPlatform.instance = FakePathProviderPlatform(directory.path); }); tearDown(() {