diff --git a/.gitignore b/.gitignore index aeb3c1d58c..826669578d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .DS_Store .atom/ .packages -.pub/ +.dart_tool/ build/ packages pubspec.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f257958c..45f48e624c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # package:sentry changelog +## 2.0.0 + +- Fixed deprecation warnings for Dart 2 +- Refactored tests to work with Dart 2 + ## 1.0.0 - first and last Dart 1-compatible release (we may fix bugs on a separate branch if there's demand) diff --git a/lib/sentry.dart b/lib/sentry.dart index 19e873e531..3dbbb93518 100644 --- a/lib/sentry.dart +++ b/lib/sentry.dart @@ -106,8 +106,7 @@ class SentryClient { @required this.secretKey, @required this.compressPayload, @required this.projectId, - }) - : _httpClient = httpClient, + }) : _httpClient = httpClient, _clock = clock, _uuidGenerator = uuidGenerator; @@ -161,7 +160,7 @@ class SentryClient { 'sentry_secret=$secretKey', }; - final Map json = { + final Map data = { 'project': projectId, 'event_id': _uuidGenerator(), 'timestamp': formatDateAsIso8601WithSecondPrecision(_clock.now()), @@ -169,11 +168,11 @@ class SentryClient { }; if (environmentAttributes != null) - mergeAttributes(environmentAttributes.toJson(), into: json); + mergeAttributes(environmentAttributes.toJson(), into: data); - mergeAttributes(event.toJson(), into: json); + mergeAttributes(event.toJson(), into: data); - List body = UTF8.encode(JSON.encode(json)); + List body = utf8.encode(json.encode(data)); if (compressPayload) { headers['Content-Encoding'] = 'gzip'; body = GZIP.encode(body); @@ -190,7 +189,7 @@ class SentryClient { return new SentryResponse.failure(errorMessage); } - final String eventId = JSON.decode(response.body)['id']; + final String eventId = json.decode(response.body)['id']; return new SentryResponse.success(eventId: eventId); } diff --git a/lib/src/version.dart b/lib/src/version.dart index f470521fc3..1cd67219db 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -9,7 +9,7 @@ library version; /// The SDK version reported to Sentry.io in the submitted events. -const String sdkVersion = '1.0.0'; +const String sdkVersion = '2.0.0'; /// The SDK name reported to Sentry.io in the submitted events. const String sdkName = 'dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 5ed4510594..ddca895183 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sentry -version: 1.0.0 +version: 2.0.0 description: A pure Dart Sentry.io client. author: Flutter Authors homepage: https://github.com/flutter/sentry diff --git a/test/sentry_test.dart b/test/sentry_test.dart index 5313a98909..4710b4f555 100644 --- a/test/sentry_test.dart +++ b/test/sentry_test.dart @@ -6,7 +6,6 @@ import 'dart:convert'; import 'dart:io'; import 'package:http/http.dart'; -import 'package:mockito/mockito.dart'; import 'package:quiver/time.dart'; import 'package:sentry/sentry.dart'; import 'package:test/test.dart'; @@ -32,12 +31,17 @@ void main() { String postUri; Map headers; List body; - when(httpMock.post(any, headers: any, body: any)) - .thenAnswer((Invocation invocation) { - postUri = invocation.positionalArguments.single; - headers = invocation.namedArguments[#headers]; - body = invocation.namedArguments[#body]; - return new Response('{"id": "test-event-id"}', 200); + httpMock.answerWith((Invocation invocation) { + if (invocation.memberName == #close) { + return null; + } + if (invocation.memberName == #post) { + postUri = invocation.positionalArguments.single; + headers = invocation.namedArguments[#headers]; + body = invocation.namedArguments[#body]; + return new Response('{"id": "test-event-id"}', 200); + } + fail('Unexpected invocation of ${invocation.memberName} in HttpMock'); }); final SentryClient client = new SentryClient( @@ -79,13 +83,13 @@ void main() { expect(headers, expectedHeaders); - Map json; + Map data; if (compressPayload) { - json = JSON.decode(UTF8.decode(GZIP.decode(body))); + data = json.decode(utf8.decode(GZIP.decode(body))); } else { - json = JSON.decode(UTF8.decode(body)); + data = json.decode(utf8.decode(body)); } - final Map stacktrace = json.remove('stacktrace'); + final Map stacktrace = data.remove('stacktrace'); expect(stacktrace['frames'], const isInstanceOf()); expect(stacktrace['frames'], isNotEmpty); @@ -98,7 +102,7 @@ void main() { expect(topFrame['in_app'], true); expect(topFrame['filename'], 'sentry_test.dart'); - expect(json, { + expect(data, { 'project': '1', 'event_id': 'X' * 32, 'timestamp': '2017-01-02T00:00:00', @@ -128,11 +132,16 @@ void main() { final MockClient httpMock = new MockClient(); final Clock fakeClock = new Clock.fixed(new DateTime(2017, 1, 2)); - when(httpMock.post(any, headers: any, body: any)) - .thenAnswer((Invocation invocation) { - return new Response('', 401, headers: { - 'x-sentry-error': 'Invalid api key', - }); + httpMock.answerWith((Invocation invocation) { + if (invocation.memberName == #close) { + return null; + } + if (invocation.memberName == #post) { + return new Response('', 401, headers: { + 'x-sentry-error': 'Invalid api key', + }); + } + fail('Unexpected invocation of ${invocation.memberName} in HttpMock'); }); final SentryClient client = new SentryClient( @@ -199,4 +208,16 @@ void main() { }); } -class MockClient extends Mock implements Client {} +typedef Answer = dynamic Function(Invocation invocation); + +class MockClient implements Client { + Answer _answer; + + void answerWith(Answer answer) { + _answer = answer; + } + + noSuchMethod(Invocation invocation) { + return _answer(invocation); + } +} diff --git a/tool/dart2_test.sh b/tool/dart2_test.sh new file mode 100755 index 0000000000..d9f38d362c --- /dev/null +++ b/tool/dart2_test.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# Temporary workaround until Pub supports --preview-dart-2 flag +set -e +set -x +for filename in test/*_test.dart; do + dart --preview-dart-2 --enable_asserts "$filename" +done diff --git a/tool/presubmit.sh b/tool/presubmit.sh index a50a5f167d..a464495fd0 100755 --- a/tool/presubmit.sh +++ b/tool/presubmit.sh @@ -6,4 +6,5 @@ set -x pub get dartanalyzer --strong --fatal-warnings ./ pub run test --platform vm +./tool/dart2_test.sh dartfmt -n --set-exit-if-changed ./