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(() {