Skip to content

Migrate inspector_test to null-safety #1712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Changes from all 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
43 changes: 21 additions & 22 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,18 @@ 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;
late String objectId;

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

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 @@ -159,17 +159,16 @@ void main() {
});

test('invoke instance private', () async {
final remote = await inspector.invoke(
instance.objectId, 'privateMethod', [dartIdFor('some string')]);
final remote = await inspector
.invoke(objectId, 'privateMethod', [dartIdFor('some string')]);
expect(
remote,
const TypeMatcher<RemoteObject>().having((instance) => instance.value,
'result', 'some string : a private field'));
});

test('invoke instance method with object parameter', () async {
final remote = await inspector
.invoke(instance.objectId, 'equals', [instance.objectId]);
final remote = await inspector.invoke(objectId, 'equals', [objectId]);
expect(
remote,
const TypeMatcher<RemoteObject>()
Expand All @@ -179,15 +178,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(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(objectId, 'closure', []);
expect(
remote,
const TypeMatcher<RemoteObject>()
Expand All @@ -196,7 +195,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