Skip to content

Commit 66f7aec

Browse files
author
Anna Gringauze
authored
Run frontend server tests and fix failures (#1658)
* Run frontend server tests and fix failures * Fix typo * Fix analyzer warnings * Pass uri instead of strings where required * Fixed some failing tests on windows and disabled others
1 parent 58ca230 commit 66f7aec

22 files changed

+315
-211
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 14.0.4-dev
22
- Port some `dwds` files to null safety.
3+
- Fix failing `frontend_server_evaluate` tests.
34

45
## 14.0.3
56
- Make data types null safe.

dwds/lib/src/debugging/location.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// @dart = 2.9
66

77
import 'package:async/async.dart';
8+
import 'package:dwds/src/loaders/require.dart';
89
import 'package:path/path.dart' as p;
910
import 'package:source_maps/parser.dart';
1011
import 'package:source_maps/source_maps.dart';
@@ -272,7 +273,7 @@ class Locations {
272273
await globalLoadStrategy.sourceMapPathForModule(_entrypoint, module);
273274
final sourceMapContents =
274275
await _assetReader.sourceMapContents(sourceMapPath);
275-
final scriptLocation = p.url.dirname('/$modulePath');
276+
final scriptLocation = p.url.dirname('/${relativizePath(modulePath)}');
276277
if (sourceMapContents == null) return result;
277278
// This happens to be a [SingleMapping] today in DDC.
278279
final mapping = parse(sourceMapContents);

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:async';
88
import 'dart:convert';
99
import 'dart:io';
1010

11+
import 'package:dwds/src/loaders/require.dart';
1112
import 'package:logging/logging.dart';
1213
import 'package:shelf/shelf.dart';
1314
import 'package:sse/server/sse_handler.dart';
@@ -201,7 +202,7 @@ class DevHandler {
201202
'localhost',
202203
webkitDebugger,
203204
executionContext,
204-
appTab.url,
205+
basePathForServerUri(appTab.url),
205206
_assetReader,
206207
_loadStrategy,
207208
appConnection,

dwds/lib/src/loaders/frontend_server_require.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class FrontendServerRequireStrategyProvider {
2222
RequireStrategy _requireStrategy;
2323

2424
FrontendServerRequireStrategyProvider(this._configuration, this._assetReader,
25-
this._digestsProvider, String basePath)
26-
: _basePath = basePathForServerUri(basePath);
25+
this._digestsProvider, this._basePath);
2726

2827
RequireStrategy get strategy => _requireStrategy ??= RequireStrategy(
2928
_configuration,
@@ -37,8 +36,12 @@ class FrontendServerRequireStrategyProvider {
3736
_assetReader,
3837
);
3938

40-
String _removeBasePath(String path) =>
41-
path.startsWith(_basePath) ? path.substring(_basePath.length) : null;
39+
String _removeBasePath(String path) {
40+
if (_basePath.isEmpty) return path;
41+
// If path is a server path it might start with a '/'.
42+
final base = path.startsWith('/') ? '/$_basePath' : _basePath;
43+
return path.startsWith(base) ? path.substring(base.length) : path;
44+
}
4245

4346
String _addBasePath(String serverPath) =>
4447
_basePath == null || _basePath.isEmpty

dwds/lib/src/loaders/require.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ import '../services/expression_compiler.dart';
1717
/// Find the path we are serving from the url.
1818
///
1919
/// Example:
20-
/// https://localhost/base/index.html => /base
21-
/// https://localhost/base => /base
20+
/// https://localhost/base/index.html => base
21+
/// https://localhost/base => base
2222
String basePathForServerUri(String url) {
2323
if (url == null) return null;
2424
final uri = Uri.parse(url);
2525
var base = uri.path.endsWith('.html') ? p.dirname(uri.path) : uri.path;
26-
if (base.isNotEmpty) {
27-
base = base.startsWith('/') ? base : '/$base';
28-
}
29-
return base;
26+
return base = base.startsWith('/') ? base.substring(1) : base;
3027
}
3128

3229
String relativizePath(String path) =>

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class ChromeProxyService implements VmServiceInterface {
6262
Completer<void> _compilerCompleter = Completer<void>();
6363
Future<void> get isCompilerInitialized => _compilerCompleter.future;
6464

65-
/// The root URI at which we're serving.
66-
final String uri;
65+
/// The root at which we're serving.
66+
final String root;
6767

6868
final RemoteDebugger remoteDebugger;
6969
final ExecutionContext executionContext;
@@ -104,7 +104,7 @@ class ChromeProxyService implements VmServiceInterface {
104104

105105
ChromeProxyService._(
106106
this._vm,
107-
this.uri,
107+
this.root,
108108
this._assetReader,
109109
this.remoteDebugger,
110110
this._modules,
@@ -120,14 +120,14 @@ class ChromeProxyService implements VmServiceInterface {
120120
appInspectorProvider,
121121
_locations,
122122
_skipLists,
123-
uri,
123+
root,
124124
);
125125
_debuggerCompleter.complete(debugger);
126126
}
127127

128128
static Future<ChromeProxyService> create(
129129
RemoteDebugger remoteDebugger,
130-
String tabUrl,
130+
String root,
131131
AssetReader assetReader,
132132
LoadStrategy loadStrategy,
133133
AppConnection appConnection,
@@ -150,12 +150,12 @@ class ChromeProxyService implements VmServiceInterface {
150150
pid: -1,
151151
);
152152

153-
final modules = Modules(tabUrl);
154-
final locations = Locations(assetReader, modules, tabUrl);
153+
final modules = Modules(root);
154+
final locations = Locations(assetReader, modules, root);
155155
final skipLists = SkipLists();
156156
final service = ChromeProxyService._(
157157
vm,
158-
tabUrl,
158+
root,
159159
assetReader,
160160
remoteDebugger,
161161
modules,
@@ -229,7 +229,7 @@ class ChromeProxyService implements VmServiceInterface {
229229
remoteDebugger,
230230
_assetReader,
231231
_locations,
232-
uri,
232+
root,
233233
debugger,
234234
executionContext,
235235
sdkConfiguration,
@@ -352,7 +352,7 @@ class ChromeProxyService implements VmServiceInterface {
352352
'The VM is unable to add a breakpoint '
353353
'at the specified line or function');
354354
}
355-
final dartUri = DartUri(scriptUri, uri);
355+
final dartUri = DartUri(scriptUri, root);
356356
final ref = await _inspector.scriptRefFor(dartUri.serverPath);
357357
return (await _debugger)
358358
.addBreakpoint(isolateId, ref.id, line, column: column);

dwds/lib/src/services/debug_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class DebugService {
210210
String hostname,
211211
RemoteDebugger remoteDebugger,
212212
ExecutionContext executionContext,
213-
String tabUrl,
213+
String root,
214214
AssetReader assetReader,
215215
LoadStrategy loadStrategy,
216216
AppConnection appConnection,
@@ -225,7 +225,7 @@ class DebugService {
225225
useSse ??= false;
226226
final chromeProxyService = await ChromeProxyService.create(
227227
remoteDebugger,
228-
tabUrl,
228+
root,
229229
assetReader,
230230
loadStrategy,
231231
appConnection,

dwds/lib/src/utilities/dart_uri.dart

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:logging/logging.dart';
88
import 'package:package_config/package_config.dart';
99
import 'package:path/path.dart' as p;
1010

11-
import '../loaders/require.dart';
1211
import '../loaders/strategy.dart';
1312
import 'sdk_configuration.dart';
1413

@@ -30,26 +29,22 @@ class DartUri {
3029
/// path is a web server path and so relative to the directory being
3130
/// served, not to the package.
3231
///
33-
/// The optional [serverUri] is a temporary workaround for a bug with construction.
34-
/// Older SDKs (before D24) gave us a path that didn't include the full path,
35-
/// e.g. main.dart rather than hello_world/main.dart and src/path.dart rather than
36-
/// packages/path/src/path.dart. The optional [serverUri] is the full URI of the
37-
/// JS script. The dirname of that path should give us the missing prefix.
38-
factory DartUri(String uri, [String serverUri]) {
32+
/// The optional [root] is the directory the app is served from.
33+
factory DartUri(String uri, [String root]) {
3934
final serverPath = globalLoadStrategy.serverPathForAppUri(uri);
4035
if (serverPath != null) {
4136
return DartUri._(serverPath);
4237
}
4338
// TODO(annagrin): Support creating DartUris from `dart:` uris.
4439
// Issue: https://github.com/dart-lang/webdev/issues/1584
4540
if (uri.startsWith('package:')) {
46-
return DartUri._fromPackageUri(uri, serverUri: serverUri);
41+
return DartUri._fromPackageUri(uri, root: root);
4742
}
4843
if (uri.startsWith('file:')) {
49-
return DartUri._fromFileUri(uri, serverUri: serverUri);
44+
return DartUri._fromFileUri(uri, root: root);
5045
}
5146
if (uri.startsWith('/packages/')) {
52-
return DartUri._fromRelativePath(uri, serverUri: serverUri);
47+
return DartUri._fromRelativePath(uri, root: root);
5348
}
5449
if (uri.startsWith('/')) {
5550
return DartUri._fromRelativePath(uri);
@@ -65,32 +60,30 @@ class DartUri {
6560
String toString() => 'DartUri: $serverPath';
6661

6762
/// Construct from a package: URI
68-
factory DartUri._fromPackageUri(String uri, {String serverUri}) {
69-
final basePath = basePathForServerUri(serverUri);
63+
factory DartUri._fromPackageUri(String uri, {String root}) {
7064
final packagePath = 'packages/${uri.substring("package:".length)}';
71-
if (serverUri != null) {
72-
final relativePath = p.url.join(basePath, packagePath);
65+
if (root != null) {
66+
final relativePath = p.url.join(root, packagePath);
7367
return DartUri._fromRelativePath(relativePath);
7468
}
7569
return DartUri._(packagePath);
7670
}
7771

7872
/// Construct from a file: URI
79-
factory DartUri._fromFileUri(String uri, {String serverUri}) {
73+
factory DartUri._fromFileUri(String uri, {String root}) {
8074
final libraryName = _resolvedUriToUri[uri];
81-
if (libraryName != null) return DartUri(libraryName, serverUri);
75+
if (libraryName != null) return DartUri(libraryName, root);
8276
// This is not one of our recorded libraries.
8377
throw ArgumentError.value(uri, 'uri', 'Unknown library');
8478
}
8579

8680
/// Construct from a path, relative to the directory being served.
87-
factory DartUri._fromRelativePath(String uri, {String serverUri}) {
81+
factory DartUri._fromRelativePath(String uri, {String root}) {
8882
uri = uri[0] == '.' ? uri.substring(1) : uri;
8983
uri = uri[0] == '/' ? uri.substring(1) : uri;
9084

91-
if (serverUri != null) {
92-
final basePath = basePathForServerUri(serverUri);
93-
return DartUri._fromRelativePath(p.url.join(basePath, uri));
85+
if (root != null) {
86+
return DartUri._fromRelativePath(p.url.join(root, uri));
9487
}
9588
return DartUri._(uri);
9689
}

dwds/test/build_daemon_callstack_test.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,20 @@ void main() {
4646
// Enable verbose logging for debugging.
4747
final debug = false;
4848

49-
for (var soundNullSafety in [false, true]) {
49+
for (var nullSafety in NullSafety.values) {
50+
final soundNullSafety = nullSafety == NullSafety.sound;
5051
final setup = soundNullSafety ? TestSetup.sound() : TestSetup.unsound();
5152
final context = setup.context;
5253

53-
group('${soundNullSafety ? "sound" : "weak"} null safety |', () {
54+
group('${nullSafety.name} null safety |', () {
5455
setUpAll(() async {
5556
setCurrentLogWriter(debug: debug);
5657
await context.setUp(
57-
enableExpressionEvaluation: true, verboseCompiler: debug);
58+
compilationMode: CompilationMode.buildDaemon,
59+
nullSafety: nullSafety,
60+
enableExpressionEvaluation: true,
61+
verboseCompiler: debug,
62+
);
5863
});
5964

6065
tearDownAll(() async {

dwds/test/build_daemon_evaluate_test.dart

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@ void main() async {
1515
// Enable verbose logging for debugging.
1616
final debug = false;
1717

18-
for (var soundNullSafety in [false, true]) {
19-
group('${soundNullSafety ? "sound" : "weak"} null safety |', () {
20-
for (var basePath in ['', 'abc']) {
21-
group('with base "$basePath" |', () {
22-
testAll(
23-
compilationMode: CompilationMode.buildDaemon,
24-
soundNullSafety: soundNullSafety,
25-
basePath: basePath,
26-
debug: debug,
27-
);
28-
});
29-
}
18+
for (var nullSafety in NullSafety.values) {
19+
group('${nullSafety.name} null safety |', () {
20+
testAll(
21+
compilationMode: CompilationMode.buildDaemon,
22+
nullSafety: nullSafety,
23+
debug: debug,
24+
);
3025
});
3126
}
3227
}

0 commit comments

Comments
 (0)