Skip to content

Commit 5105369

Browse files
authored
Migrate inspector_test to null-safety (#1712)
1 parent e34f5b7 commit 5105369

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

dwds/test/inspector_test.dart

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@TestOn('vm')
86
import 'package:dwds/dwds.dart';
97
import 'package:dwds/src/connections/debug_connection.dart';
@@ -23,8 +21,8 @@ final context = TestContext(
2321
WipConnection get tabConnection => context.tabConnection;
2422

2523
void main() {
26-
AppInspector inspector;
27-
Debugger debugger;
24+
late AppInspector inspector;
25+
late Debugger debugger;
2826

2927
setUpAll(() async {
3028
await context.setUp();
@@ -60,7 +58,7 @@ void main() {
6058
() => inspector.jsEvaluate('<'),
6159
throwsA(isA<ChromeDebugException>()
6260
.having((e) => e.text, 'text', 'Uncaught')
63-
.having((e) => e.exception.description, 'description',
61+
.having((e) => e.exception?.description, 'description',
6462
contains('SyntaxError'))
6563
.having((e) => e.stackTrace, 'stackTrace', isNull)
6664
.having((e) => e.evalContents, 'evalContents', '<')));
@@ -78,9 +76,9 @@ void main() {
7876
'''),
7977
throwsA(isA<ChromeDebugException>()
8078
.having((e) => e.text, 'text', 'Uncaught')
81-
.having((e) => e.exception.description, 'description',
79+
.having((e) => e.exception?.description, 'description',
8280
contains('ReferenceError'))
83-
.having((e) => e.stackTrace.printFrames()[0], 'stackTrace',
81+
.having((e) => e.stackTrace?.printFrames()[0], 'stackTrace',
8482
contains('foo()'))
8583
.having((e) => e.evalContents, 'evalContents', contains('foo'))));
8684
});
@@ -89,17 +87,17 @@ void main() {
8987
test('send toString', () async {
9088
final remoteObject = await libraryPublicFinal();
9189
final toString =
92-
await inspector.invoke(remoteObject.objectId, 'toString', []);
90+
await inspector.invoke(remoteObject.objectId!, 'toString', []);
9391
expect(toString.value, 'A test class with message world');
9492
});
9593

9694
group('getObject', () {
9795
test('for class with generic', () async {
9896
final remoteObject = await libraryPublicFinal();
9997
final instance =
100-
await inspector.getObject(remoteObject.objectId) as Instance;
101-
final classRef = instance.classRef;
102-
final clazz = await inspector.getObject(classRef.id) as Class;
98+
await inspector.getObject(remoteObject.objectId!) as Instance;
99+
final classRef = instance.classRef!;
100+
final clazz = await inspector.getObject(classRef.id!) as Class;
103101
expect(clazz.name, 'MyTestClass<dynamic>');
104102
});
105103
});
@@ -120,7 +118,7 @@ void main() {
120118

121119
test('properties', () async {
122120
final remoteObject = await libraryPublicFinal();
123-
final properties = await debugger.getProperties(remoteObject.objectId);
121+
final properties = await debugger.getProperties(remoteObject.objectId!);
124122
final names =
125123
properties.map((p) => p.name).where((x) => x != '__proto__').toList();
126124
final expected = [
@@ -141,16 +139,18 @@ void main() {
141139
// We test these here because the test fixture has more complicated members
142140
// to exercise.
143141

144-
LibraryRef bootstrapLibrary;
145-
RemoteObject instance;
142+
LibraryRef? bootstrapLibrary;
143+
late RemoteObject instance;
144+
late String objectId;
146145

147146
setUp(() async {
148147
bootstrapLibrary = inspector.isolate.rootLib;
149148
instance = await libraryPublicFinal();
149+
objectId = instance.objectId!;
150150
});
151151

152152
test('invoke top-level private', () async {
153-
final remote = await inspector.invoke(bootstrapLibrary.id,
153+
final remote = await inspector.invoke(bootstrapLibrary!.id!,
154154
'_libraryPrivateFunction', [dartIdFor(2), dartIdFor(3)]);
155155
expect(
156156
remote,
@@ -159,17 +159,16 @@ void main() {
159159
});
160160

161161
test('invoke instance private', () async {
162-
final remote = await inspector.invoke(
163-
instance.objectId, 'privateMethod', [dartIdFor('some string')]);
162+
final remote = await inspector
163+
.invoke(objectId, 'privateMethod', [dartIdFor('some string')]);
164164
expect(
165165
remote,
166166
const TypeMatcher<RemoteObject>().having((instance) => instance.value,
167167
'result', 'some string : a private field'));
168168
});
169169

170170
test('invoke instance method with object parameter', () async {
171-
final remote = await inspector
172-
.invoke(instance.objectId, 'equals', [instance.objectId]);
171+
final remote = await inspector.invoke(objectId, 'equals', [objectId]);
173172
expect(
174173
remote,
175174
const TypeMatcher<RemoteObject>()
@@ -179,15 +178,15 @@ void main() {
179178
test('invoke instance method with object parameter 2', () async {
180179
final libraryPrivateList = await libraryPrivate();
181180
final remote = await inspector
182-
.invoke(instance.objectId, 'equals', [libraryPrivateList.objectId]);
181+
.invoke(objectId, 'equals', [libraryPrivateList.objectId]);
183182
expect(
184183
remote,
185184
const TypeMatcher<RemoteObject>()
186185
.having((instance) => instance.value, 'result', false));
187186
});
188187

189188
test('invoke closure stored in an instance field', () async {
190-
final remote = await inspector.invoke(instance.objectId, 'closure', []);
189+
final remote = await inspector.invoke(objectId, 'closure', []);
191190
expect(
192191
remote,
193192
const TypeMatcher<RemoteObject>()
@@ -196,7 +195,7 @@ void main() {
196195

197196
test('invoke a torn-off method', () async {
198197
final toString = await inspector.loadField(instance, 'tornOff');
199-
final result = await inspector.invoke(toString.objectId, 'call', []);
198+
final result = await inspector.invoke(toString.objectId!, 'call', []);
200199
expect(
201200
result,
202201
const TypeMatcher<RemoteObject>().having((instance) => instance.value,

0 commit comments

Comments
 (0)