From 965da2c022a59093704d59adbde359b1973de923 Mon Sep 17 00:00:00 2001 From: Anatoly Pulyaevskiy Date: Wed, 14 Mar 2018 14:56:26 -0700 Subject: [PATCH 1/4] Fixed tests for Dart2 --- .gitignore | 2 +- lib/sentry.dart | 13 ++++++------- test/sentry_test.dart | 32 +++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 19 deletions(-) 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/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/test/sentry_test.dart b/test/sentry_test.dart index 5313a98909..618de8b210 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,8 +31,8 @@ void main() { String postUri; Map headers; List body; - when(httpMock.post(any, headers: any, body: any)) - .thenAnswer((Invocation invocation) { + httpMock.answerWith((Invocation invocation) { + if (invocation.memberName == #close) return null; postUri = invocation.positionalArguments.single; headers = invocation.namedArguments[#headers]; body = invocation.namedArguments[#body]; @@ -79,13 +78,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 +97,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,8 +127,7 @@ 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) { + httpMock.answerWith((Invocation invocation) { return new Response('', 401, headers: { 'x-sentry-error': 'Invalid api key', }); @@ -199,4 +197,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); + } +} From 1208ab4f597632621b2932f48968b2cd2c34ce77 Mon Sep 17 00:00:00 2001 From: Anatoly Pulyaevskiy Date: Wed, 14 Mar 2018 15:09:24 -0700 Subject: [PATCH 2/4] Run tests with --preview-dart-2 flag --- tool/dart2_test.sh | 6 ++++++ tool/presubmit.sh | 1 + 2 files changed, 7 insertions(+) create mode 100755 tool/dart2_test.sh diff --git a/tool/dart2_test.sh b/tool/dart2_test.sh new file mode 100755 index 0000000000..27f4dd17f3 --- /dev/null +++ b/tool/dart2_test.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# Temporary workaround until Pub supports --preview-dart-2 flag +set -e +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 ./ From 40b9980ea989c7806b5666766fa262ec5e01b6fb Mon Sep 17 00:00:00 2001 From: Anatoly Pulyaevskiy Date: Tue, 20 Mar 2018 14:02:38 -0700 Subject: [PATCH 3/4] Addressed PR comments --- test/sentry_test.dart | 27 +++++++++++++++++++-------- tool/dart2_test.sh | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/test/sentry_test.dart b/test/sentry_test.dart index 618de8b210..4710b4f555 100644 --- a/test/sentry_test.dart +++ b/test/sentry_test.dart @@ -32,11 +32,16 @@ void main() { Map headers; List body; httpMock.answerWith((Invocation invocation) { - if (invocation.memberName == #close) return null; - postUri = invocation.positionalArguments.single; - headers = invocation.namedArguments[#headers]; - body = invocation.namedArguments[#body]; - return new Response('{"id": "test-event-id"}', 200); + 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( @@ -128,9 +133,15 @@ void main() { final Clock fakeClock = new Clock.fixed(new DateTime(2017, 1, 2)); httpMock.answerWith((Invocation invocation) { - return new Response('', 401, headers: { - 'x-sentry-error': 'Invalid api key', - }); + 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( diff --git a/tool/dart2_test.sh b/tool/dart2_test.sh index 27f4dd17f3..d9f38d362c 100755 --- a/tool/dart2_test.sh +++ b/tool/dart2_test.sh @@ -1,6 +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 From c1e6a0bc6ea63156a78ea64cb59703a344141a45 Mon Sep 17 00:00:00 2001 From: Anatoly Pulyaevskiy Date: Tue, 20 Mar 2018 15:29:05 -0700 Subject: [PATCH 4/4] Updated changelog and bumped version to 2.0.0 --- CHANGELOG.md | 5 +++++ lib/src/version.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) 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/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