-
Notifications
You must be signed in to change notification settings - Fork 83
Migrate asset_handler_test
to null-safety
#1710
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,14 @@ int _clientsConnected = 0; | |
|
||
Logger _logger = Logger('DebugService'); | ||
|
||
void Function(WebSocketChannel, String) _createNewConnectionHandler( | ||
void Function(WebSocketChannel) _createNewConnectionHandler( | ||
ChromeProxyService chromeProxyService, | ||
ServiceExtensionRegistry serviceExtensionRegistry, { | ||
void Function(Map<String, dynamic>)? onRequest, | ||
void Function(Map<String, dynamic>)? onResponse, | ||
void Function(Map<String, Object>)? onRequest, | ||
void Function(Map<String, Object?>)? onResponse, | ||
}) { | ||
return (webSocket, protocol) { | ||
final responseController = StreamController<Map<String, Object>>(); | ||
return (webSocket) { | ||
final responseController = StreamController<Map<String, Object?>>(); | ||
webSocket.sink.addStream(responseController.stream.map((response) { | ||
if (onResponse != null) onResponse(response); | ||
return jsonEncode(response); | ||
|
@@ -53,7 +53,7 @@ void Function(WebSocketChannel, String) _createNewConnectionHandler( | |
'Got value with unexpected type ${value.runtimeType} from web ' | ||
'socket, expected a List<int> or String.'); | ||
} | ||
final request = jsonDecode(value as String) as Map<String, Object>; | ||
final request = Map<String, Object>.from(jsonDecode(value)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the new object necessary here as well? |
||
if (onRequest != null) onRequest(request); | ||
return request; | ||
}); | ||
|
@@ -76,12 +76,12 @@ Future<void> _handleSseConnections( | |
SseHandler handler, | ||
ChromeProxyService chromeProxyService, | ||
ServiceExtensionRegistry serviceExtensionRegistry, { | ||
void Function(Map<String, dynamic>)? onRequest, | ||
void Function(Map<String, dynamic>)? onResponse, | ||
void Function(Map<String, Object>)? onRequest, | ||
void Function(Map<String, Object?>)? onResponse, | ||
}) async { | ||
while (await handler.connections.hasNext) { | ||
final connection = await handler.connections.next; | ||
final responseController = StreamController<Map<String, Object>>(); | ||
final responseController = StreamController<Map<String, Object?>>(); | ||
final sub = responseController.stream.map((response) { | ||
if (onResponse != null) onResponse(response); | ||
return jsonEncode(response); | ||
|
@@ -214,8 +214,8 @@ class DebugService { | |
LoadStrategy loadStrategy, | ||
AppConnection appConnection, | ||
UrlEncoder? urlEncoder, { | ||
void Function(Map<String, dynamic>)? onRequest, | ||
void Function(Map<String, dynamic>)? onResponse, | ||
void Function(Map<String, Object>)? onRequest, | ||
void Function(Map<String, Object?>)? onResponse, | ||
bool spawnDds = true, | ||
bool useSse = false, | ||
ExpressionCompiler? expressionCompiler, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,9 @@ class TestContext { | |
WebkitDebugger get webkitDebugger => _webkitDebugger!; | ||
late WebkitDebugger? _webkitDebugger; | ||
|
||
Handler get assetHandler => _assetHandler!; | ||
late Handler? _assetHandler; | ||
|
||
Client get client => _client!; | ||
late Client? _client; | ||
|
||
|
@@ -203,7 +206,6 @@ class TestContext { | |
|
||
ExpressionCompiler? expressionCompiler; | ||
AssetReader assetReader; | ||
Handler assetHandler; | ||
Stream<BuildResults> buildResults; | ||
RequireStrategy requireStrategy; | ||
String basePath = ''; | ||
|
@@ -237,7 +239,7 @@ class TestContext { | |
.timeout(const Duration(seconds: 60)); | ||
|
||
final assetServerPort = daemonPort(workingDirectory); | ||
assetHandler = proxyHandler( | ||
_assetHandler = proxyHandler( | ||
'http://localhost:$assetServerPort/$pathToServe/', | ||
client: client); | ||
assetReader = | ||
|
@@ -291,7 +293,7 @@ class TestContext { | |
|
||
basePath = webRunner.devFS.assetServer.basePath; | ||
assetReader = webRunner.devFS.assetServer; | ||
assetHandler = webRunner.devFS.assetServer.handleRequest; | ||
_assetHandler = webRunner.devFS.assetServer.handleRequest; | ||
|
||
requireStrategy = FrontendServerRequireStrategyProvider( | ||
reloadConfiguration, assetReader, () async => {}, basePath) | ||
|
@@ -353,11 +355,14 @@ class TestContext { | |
: 'http://localhost:$port/$basePath/$path'; | ||
|
||
await _webDriver?.get(appUrl); | ||
final tab = await (connection.getTab((t) => t.url == appUrl) | ||
as FutureOr<ChromeTab>); | ||
_tabConnection = await tab.connect(); | ||
await tabConnection.runtime.enable(); | ||
await tabConnection.debugger.enable(); | ||
final tab = await connection.getTab((t) => t.url == appUrl); | ||
if (tab != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should throw if tab is not found, the tests won't run properly in that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, done! |
||
_tabConnection = await tab.connect(); | ||
await tabConnection.runtime.enable(); | ||
await tabConnection.debugger.enable(); | ||
} else { | ||
throw StateError('Unable to connect to tab.'); | ||
} | ||
|
||
if (enableDebugExtension) { | ||
final extensionTab = await _fetchDartDebugExtensionTab(connection); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it is necessary to create a new object here (possible performance hit?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure of another way -
jsonDecode
returnsdynamic
, so usingas
to cast is throwing a type error (as
should only be used "if and only if you are sure that the object is of that type": https://dart.dev/guides/language/language-tour#type-test-operators)