Unverified Commit 03a59bff authored by Jacob MacDonald's avatar Jacob MacDonald Committed by GitHub

Serve packages uris in flutter_tools dev web server (#48743)

* support mapping /packages/<package>/<path> requests to package:<package>/<path> uris in the web device file server
parent 03496606
...@@ -11,6 +11,8 @@ import 'package:flutter_tools/src/base/io.dart'; ...@@ -11,6 +11,8 @@ import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/web/devfs_web.dart'; import 'package:flutter_tools/src/web/devfs_web.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:package_config/discovery.dart';
import 'package:package_config/packages.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals.dart' as globals;
...@@ -36,6 +38,11 @@ void main() { ...@@ -36,6 +38,11 @@ void main() {
WebAssetServer webAssetServer; WebAssetServer webAssetServer;
MockPlatform windows; MockPlatform windows;
MockPlatform linux; MockPlatform linux;
Packages packages;
setUpAll(() async {
packages = await loadPackagesFile(Uri.base.resolve('.packages'));
});
setUp(() { setUp(() {
windows = MockPlatform(); windows = MockPlatform();
...@@ -60,7 +67,8 @@ void main() { ...@@ -60,7 +67,8 @@ void main() {
when(response.close()).thenAnswer((Invocation invocation) async { when(response.close()).thenAnswer((Invocation invocation) async {
closeCompleter.complete(); closeCompleter.complete();
}); });
webAssetServer = WebAssetServer(mockHttpServer, onError: (dynamic error, StackTrace stackTrace) { webAssetServer = WebAssetServer(
mockHttpServer, packages, onError: (dynamic error, StackTrace stackTrace) {
closeCompleter.completeError(error, stackTrace); closeCompleter.completeError(error, stackTrace);
}); });
}); });
...@@ -291,6 +299,23 @@ void main() { ...@@ -291,6 +299,23 @@ void main() {
verify(response.statusCode = HttpStatus.notFound).called(1); verify(response.statusCode = HttpStatus.notFound).called(1);
})); }));
test('serves /packages/<package>/<path> files as if they were '
'package:<package>/<path> uris', () => testbed.run(() async {
final Uri expectedUri = packages.resolve(
Uri.parse('package:flutter_tools/foo.dart'));
final File source = globals.fs.file(globals.fs.path.fromUri(expectedUri))
..createSync(recursive: true)
..writeAsBytesSync(<int>[1, 2, 3]);
when(request.uri).thenReturn(
Uri.parse('http:///packages/flutter_tools/foo.dart'));
requestController.add(request);
await closeCompleter.future;
verify(headers.add('Content-Length', source.lengthSync())).called(1);
verify(headers.add('Content-Type', 'application/octet-stream')).called(1);
verify(response.addStream(any)).called(1);
}));
test('calling dispose closes the http server', () => testbed.run(() async { test('calling dispose closes the http server', () => testbed.run(() async {
await webAssetServer.dispose(); await webAssetServer.dispose();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment