diff --git a/CHANGELOG.md b/CHANGELOG.md index 2834dbd..3a558cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.0.4 (2024-11-06) + +- Remove `dart:io` dependency to support web. +- Update more test. + ## 1.0.3 (2024-11-06) - Return `null` when provided `T` is incorrect. diff --git a/lib/src/simple_remote_config.dart b/lib/src/simple_remote_config.dart index c99b49e..bf56800 100644 --- a/lib/src/simple_remote_config.dart +++ b/lib/src/simple_remote_config.dart @@ -1,8 +1,7 @@ import 'dart:convert'; -import 'dart:io'; import 'package:http/http.dart'; -import 'package:simple_remote_config/src/simple_remote_config_exception.dart'; +import 'package:simple_remote_config/simple_remote_config.dart'; /// A [SimpleRemoteConfig] class that fetches a JSON config from a URL and /// provides a way to access the config values. @@ -43,8 +42,7 @@ class SimpleRemoteConfig { } catch (e) { throw SimpleRemoteConfigException( message: switch (e) { - SocketException() => 'No internet connection', - FormatException() => 'Invalid remote config format', + FormatException() => 'Invalid remote config', _ => 'Error when handling: $e', }); } diff --git a/pubspec.lock b/pubspec.lock index 540acaa..9301dd2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -394,4 +394,4 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.4.0 <4.0.0" + dart: ">=3.5.0 <4.0.0" diff --git a/test/simple_remote_config_test.dart b/test/simple_remote_config_test.dart index 367165d..4346b6c 100644 --- a/test/simple_remote_config_test.dart +++ b/test/simple_remote_config_test.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:http/http.dart' as http; import 'package:http/testing.dart'; import 'package:simple_remote_config/src/simple_remote_config.dart'; @@ -90,10 +88,11 @@ void main() { ); }); - test('initialize throws SimpleRemoteConfigException on SocketException', + test( + 'initialize with invalid network JSON throws SimpleRemoteConfigException on FormatException', () async { final mockClient = MockClient((request) async { - throw SocketException('No internet connection'); + return http.Response('Invalid JSON', 200); }); final config = SimpleRemoteConfig(client: mockClient); @@ -101,11 +100,12 @@ void main() { () async => await config.initilize(configUrl: 'http://example.com/config'), throwsA(isA() - .having((e) => e.message, 'message', 'No internet connection')), + .having((e) => e.message, 'message', 'Invalid remote config')), ); }); - test('initialize throws SimpleRemoteConfigException on FormatException', + test( + 'initialize with invalid config url throws SimpleRemoteConfigException on FormatException', () async { final mockClient = MockClient((request) async { return http.Response('Invalid JSON', 200); @@ -113,10 +113,9 @@ void main() { final config = SimpleRemoteConfig(client: mockClient); expect( - () async => - await config.initilize(configUrl: 'http://example.com/config'), - throwsA(isA().having( - (e) => e.message, 'message', 'Invalid remote config format')), + () async => await config.initilize(configUrl: 'example.com/config'), + throwsA(isA() + .having((e) => e.message, 'message', 'Invalid remote config')), ); }); });