Skip to content

Commit 840c7f3

Browse files
committed
Migrate webdev tests to null safety
Towards #1640 Migrate all test files that don't import an unmigrated `lib/` library.
1 parent a02f073 commit 840c7f3

11 files changed

+68
-90
lines changed

webdev/test/build/min_sdk_test.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@TestOn('vm')
86
@Skip('Intended to run in analyze stage on stable SDK only, see mono_pkg.yaml')
97
import 'dart:io';
@@ -19,7 +17,7 @@ void main() {
1917
sdkVersion = Version(sdkVersion.major, sdkVersion.minor, 0);
2018

2119
var sdkConstraint = VersionConstraint.compatibleWith(sdkVersion);
22-
var pubspecSdkConstraint = pubspec.environment['sdk'];
20+
var pubspecSdkConstraint = pubspec.environment!['sdk']!;
2321
expect(sdkConstraint.allowsAll(pubspecSdkConstraint), true,
2422
reason:
2523
'Min sdk constraint is outdated. Please update SDK constraint in '

webdev/test/chrome_test.dart

+19-21
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@Timeout(Duration(seconds: 60))
86
import 'dart:async';
97
import 'dart:io';
@@ -15,28 +13,28 @@ import 'package:webdev/src/serve/chrome.dart';
1513
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
1614

1715
void main() {
18-
Chrome chrome;
16+
Chrome? chrome;
1917

20-
Future<void> launchChrome({int port, String userDataDir}) async {
18+
Future<void> launchChrome({int? port, String? userDataDir}) async {
2119
chrome = await Chrome.start([_googleUrl],
2220
port: port ?? 0, userDataDir: userDataDir);
2321
}
2422

2523
Future<void> openTab(String url) =>
26-
chrome.chromeConnection.getUrl(_openTabUrl(url));
24+
chrome!.chromeConnection.getUrl(_openTabUrl(url));
2725

2826
Future<void> closeTab(ChromeTab tab) =>
29-
chrome.chromeConnection.getUrl(_closeTabUrl(tab.id));
27+
chrome!.chromeConnection.getUrl(_closeTabUrl(tab.id));
3028

3129
Future<WipConnection> connectToTab(String url) async {
32-
var tab = await chrome.chromeConnection.getTab((t) => t.url.contains(url));
30+
var tab = await chrome!.chromeConnection.getTab((t) => t.url.contains(url));
3331
expect(tab, isNotNull);
34-
return tab.connect();
32+
return tab!.connect();
3533
}
3634

3735
group('chrome with temp data dir', () {
3836
tearDown(() async {
39-
var tabs = await chrome?.chromeConnection?.getTabs();
37+
var tabs = await chrome?.chromeConnection.getTabs();
4038
if (tabs != null) {
4139
for (var tab in tabs) {
4240
await closeTab(tab);
@@ -53,7 +51,7 @@ void main() {
5351

5452
test('has a working debugger', () async {
5553
await launchChrome();
56-
var tabs = await chrome.chromeConnection.getTabs();
54+
var tabs = await chrome!.chromeConnection.getTabs();
5755
expect(
5856
tabs,
5957
contains(const TypeMatcher<ChromeTab>()
@@ -62,7 +60,7 @@ void main() {
6260

6361
test('uses open debug port if provided port is 0', () async {
6462
await launchChrome(port: 0);
65-
expect(chrome.debugPort, isNot(equals(0)));
63+
expect(chrome!.debugPort, isNot(equals(0)));
6664
});
6765

6866
test('has correct profile path', () async {
@@ -84,16 +82,16 @@ void main() {
8482
});
8583

8684
group('chrome with user data dir', () {
87-
Directory dataDir;
88-
StreamController<String> logController;
89-
Stream<String> logStream;
85+
late Directory dataDir;
86+
late StreamController<String> logController;
87+
late Stream<String> logStream;
9088

9189
setUp(() {
9290
logController = StreamController<String>();
9391
logStream = logController.stream;
9492

9593
void _logWriter(Level level, String message,
96-
{String error, String loggerName, String stackTrace}) {
94+
{String? error, String? loggerName, String? stackTrace}) {
9795
if (level >= Level.INFO) {
9896
logController.add('[$level] $loggerName: $message');
9997
}
@@ -104,7 +102,7 @@ void main() {
104102
});
105103

106104
tearDown(() async {
107-
var tabs = await chrome?.chromeConnection?.getTabs();
105+
var tabs = await chrome?.chromeConnection.getTabs();
108106
if (tabs != null) {
109107
for (var tab in tabs) {
110108
await closeTab(tab);
@@ -121,7 +119,7 @@ void main() {
121119
'.*chrome_user_data_copy')));
122120
await logController.close();
123121
}
124-
dataDir?.deleteSync(recursive: true);
122+
dataDir.deleteSync(recursive: true);
125123
});
126124

127125
test('works with debug port', () async {
@@ -132,7 +130,7 @@ void main() {
132130
test('has a working debugger', () async {
133131
await launchChrome(userDataDir: dataDir.path);
134132

135-
var tabs = await chrome.chromeConnection.getTabs();
133+
var tabs = await chrome!.chromeConnection.getTabs();
136134
expect(
137135
tabs,
138136
contains(const TypeMatcher<ChromeTab>()
@@ -160,7 +158,7 @@ void main() {
160158
var userDataDir = autoDetectChromeUserDataDirectory();
161159
expect(userDataDir, isNotNull);
162160

163-
expect(Directory(userDataDir).existsSync(), isTrue);
161+
expect(Directory(userDataDir!).existsSync(), isTrue);
164162

165163
await launchChrome(userDataDir: userDataDir);
166164
await openTab(_chromeVersionUrl);
@@ -188,14 +186,14 @@ String _openTabUrl(String url) => '/json/new?$url';
188186
String _closeTabUrl(String id) => '/json/close/$id';
189187

190188
Future<String> _evaluateExpression(WipPage page, String expression) async {
191-
var result = '';
189+
String? result = '';
192190
while (result == null || result.isEmpty) {
193191
await Future.delayed(const Duration(milliseconds: 100));
194192
var wipResponse = await page.sendCommand(
195193
'Runtime.evaluate',
196194
params: {'expression': expression},
197195
);
198-
result = wipResponse.json['result']['result']['value'] as String;
196+
result = wipResponse.json['result']['result']['value'] as String?;
199197
}
200198
return result;
201199
}

webdev/test/configuration_test.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'package:args/args.dart';
86
import 'package:test/test.dart';
97
import 'package:webdev/src/command/configuration.dart';
108

119
void main() {
12-
ArgParser argParser;
10+
late ArgParser argParser;
1311
setUp(() {
1412
argParser = ArgParser()
1513
..addFlag('release')

webdev/test/daemon/app_domain_test.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@Timeout(Duration(minutes: 2))
86
import 'dart:convert';
97
import 'dart:io';
@@ -14,7 +12,7 @@ import '../test_utils.dart';
1412
import 'utils.dart';
1513

1614
void main() {
17-
String exampleDirectory;
15+
late String exampleDirectory;
1816

1917
setUpAll(() async {
2018
exampleDirectory = await prepareWorkspace();

webdev/test/daemon/daemon_domain_test.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@Timeout(Duration(minutes: 2))
86

97
import 'dart:convert';
@@ -14,7 +12,7 @@ import '../test_utils.dart';
1412
import 'utils.dart';
1513

1614
void main() {
17-
String exampleDirectory;
15+
late String exampleDirectory;
1816

1917
setUpAll(() async {
2018
exampleDirectory = await prepareWorkspace();

webdev/test/daemon/launch_app_test.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@Timeout(Duration(minutes: 2))
86
import 'package:test/test.dart';
97

108
import '../test_utils.dart';
119
import 'utils.dart';
1210

1311
void main() {
14-
String exampleDirectory;
12+
late String exampleDirectory;
1513

1614
setUpAll(() async {
1715
exampleDirectory = await prepareWorkspace();

webdev/test/daemon/utils.dart

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
import 'dart:async';
86
import 'dart:convert';
97

@@ -50,7 +48,7 @@ Future<String> prepareWorkspace() async {
5048
return exampleDirectory;
5149
}
5250

53-
String getDebugServiceUri(String line) {
51+
String? getDebugServiceUri(String line) {
5452
var regex = RegExp(r'Debug service listening on (?<wsUri>[^\s^\\]*)');
5553
var match = regex.firstMatch(line);
5654
if (match != null) {
@@ -62,8 +60,8 @@ String getDebugServiceUri(String line) {
6260

6361
Future<int> findBreakpointLine(VmService vmService, String breakpointId,
6462
String isolateId, ScriptRef scriptRef) async {
65-
var script = await vmService.getObject(isolateId, scriptRef.id) as Script;
66-
var lines = LineSplitter.split(script.source).toList();
63+
var script = await vmService.getObject(isolateId, scriptRef.id!) as Script;
64+
var lines = LineSplitter.split(script.source!).toList();
6765
var lineNumber =
6866
lines.indexWhere((l) => l.endsWith('// Breakpoint: $breakpointId'));
6967
if (lineNumber == -1) {

0 commit comments

Comments
 (0)