Skip to content
Merged
Changes from 2 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
38 changes: 18 additions & 20 deletions dwds/test/inspector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

@TestOn('vm')
import 'package:dwds/dwds.dart';
import 'package:dwds/src/connections/debug_connection.dart';
Expand All @@ -23,8 +21,8 @@ final context = TestContext(
WipConnection get tabConnection => context.tabConnection;

void main() {
AppInspector inspector;
Debugger debugger;
late AppInspector inspector;
late Debugger debugger;

setUpAll(() async {
await context.setUp();
Expand Down Expand Up @@ -60,7 +58,7 @@ void main() {
() => inspector.jsEvaluate('<'),
throwsA(isA<ChromeDebugException>()
.having((e) => e.text, 'text', 'Uncaught')
.having((e) => e.exception.description, 'description',
.having((e) => e.exception?.description, 'description',
contains('SyntaxError'))
.having((e) => e.stackTrace, 'stackTrace', isNull)
.having((e) => e.evalContents, 'evalContents', '<')));
Expand All @@ -78,9 +76,9 @@ void main() {
'''),
throwsA(isA<ChromeDebugException>()
.having((e) => e.text, 'text', 'Uncaught')
.having((e) => e.exception.description, 'description',
.having((e) => e.exception?.description, 'description',
contains('ReferenceError'))
.having((e) => e.stackTrace.printFrames()[0], 'stackTrace',
.having((e) => e.stackTrace?.printFrames()[0], 'stackTrace',
contains('foo()'))
.having((e) => e.evalContents, 'evalContents', contains('foo'))));
});
Expand All @@ -89,17 +87,17 @@ void main() {
test('send toString', () async {
final remoteObject = await libraryPublicFinal();
final toString =
await inspector.invoke(remoteObject.objectId, 'toString', []);
await inspector.invoke(remoteObject.objectId!, 'toString', []);
expect(toString.value, 'A test class with message world');
});

group('getObject', () {
test('for class with generic', () async {
final remoteObject = await libraryPublicFinal();
final instance =
await inspector.getObject(remoteObject.objectId) as Instance;
final classRef = instance.classRef;
final clazz = await inspector.getObject(classRef.id) as Class;
await inspector.getObject(remoteObject.objectId!) as Instance;
final classRef = instance.classRef!;
final clazz = await inspector.getObject(classRef.id!) as Class;
expect(clazz.name, 'MyTestClass<dynamic>');
});
});
Expand All @@ -120,7 +118,7 @@ void main() {

test('properties', () async {
final remoteObject = await libraryPublicFinal();
final properties = await debugger.getProperties(remoteObject.objectId);
final properties = await debugger.getProperties(remoteObject.objectId!);
final names =
properties.map((p) => p.name).where((x) => x != '__proto__').toList();
final expected = [
Expand All @@ -141,16 +139,16 @@ void main() {
// We test these here because the test fixture has more complicated members
// to exercise.

LibraryRef bootstrapLibrary;
RemoteObject instance;
LibraryRef? bootstrapLibrary;
late RemoteObject instance;

setUp(() async {
bootstrapLibrary = inspector.isolate.rootLib;
instance = await libraryPublicFinal();
});

test('invoke top-level private', () async {
final remote = await inspector.invoke(bootstrapLibrary.id,
final remote = await inspector.invoke(bootstrapLibrary!.id!,
'_libraryPrivateFunction', [dartIdFor(2), dartIdFor(3)]);
expect(
remote,
Expand All @@ -160,7 +158,7 @@ void main() {

test('invoke instance private', () async {
final remote = await inspector.invoke(
instance.objectId, 'privateMethod', [dartIdFor('some string')]);
instance.objectId!, 'privateMethod', [dartIdFor('some string')]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like instance.objectId! is used in many places, would be great to have a non-nullable objectId variable instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

expect(
remote,
const TypeMatcher<RemoteObject>().having((instance) => instance.value,
Expand All @@ -169,7 +167,7 @@ void main() {

test('invoke instance method with object parameter', () async {
final remote = await inspector
.invoke(instance.objectId, 'equals', [instance.objectId]);
.invoke(instance.objectId!, 'equals', [instance.objectId]);
expect(
remote,
const TypeMatcher<RemoteObject>()
Expand All @@ -179,15 +177,15 @@ void main() {
test('invoke instance method with object parameter 2', () async {
final libraryPrivateList = await libraryPrivate();
final remote = await inspector
.invoke(instance.objectId, 'equals', [libraryPrivateList.objectId]);
.invoke(instance.objectId!, 'equals', [libraryPrivateList.objectId]);
expect(
remote,
const TypeMatcher<RemoteObject>()
.having((instance) => instance.value, 'result', false));
});

test('invoke closure stored in an instance field', () async {
final remote = await inspector.invoke(instance.objectId, 'closure', []);
final remote = await inspector.invoke(instance.objectId!, 'closure', []);
expect(
remote,
const TypeMatcher<RemoteObject>()
Expand All @@ -196,7 +194,7 @@ void main() {

test('invoke a torn-off method', () async {
final toString = await inspector.loadField(instance, 'tornOff');
final result = await inspector.invoke(toString.objectId, 'call', []);
final result = await inspector.invoke(toString.objectId!, 'call', []);
expect(
result,
const TypeMatcher<RemoteObject>().having((instance) => instance.value,
Expand Down