Skip to content
Merged
Changes from all commits
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
30 changes: 30 additions & 0 deletions packages/google_fonts/test/google_fonts_text_style_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<http.Response> gets(dynamic uri, {dynamic headers}) {
Expand All @@ -27,6 +34,19 @@ class MockAssetManifest extends Mock implements AssetManifest {
List<String> listAssets() => <String>[];
}

class FakePathProviderPlatform extends Fake
with MockPlatformInterfaceMixin
implements PathProviderPlatform {
FakePathProviderPlatform(this._applicationSupportPath);

final String _applicationSupportPath;

@override
Future<String?> getApplicationSupportPath() async {
return _applicationSupportPath;
}
}

const String _fakeResponse = 'fake response body - success';
// The number of bytes in _fakeResponse.
const int _fakeResponseLengthInBytes = 28;
Expand Down Expand Up @@ -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);
Comment thread
Piinks marked this conversation as resolved.
Resolved
});

tearDown(() {
Expand Down
Loading