Skip to content

Migrate webdev tests to null safety #1761

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 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions webdev/test/build/min_sdk_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')
@Skip('Intended to run in analyze stage on stable SDK only, see mono_pkg.yaml')
import 'dart:io';
Expand All @@ -19,7 +17,7 @@ void main() {
sdkVersion = Version(sdkVersion.major, sdkVersion.minor, 0);

var sdkConstraint = VersionConstraint.compatibleWith(sdkVersion);
var pubspecSdkConstraint = pubspec.environment['sdk'];
var pubspecSdkConstraint = pubspec.environment!['sdk']!;
expect(sdkConstraint.allowsAll(pubspecSdkConstraint), true,
reason:
'Min sdk constraint is outdated. Please update SDK constraint in '
Expand Down
40 changes: 19 additions & 21 deletions webdev/test/chrome_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

@Timeout(Duration(seconds: 60))
import 'dart:async';
import 'dart:io';
Expand All @@ -15,28 +13,28 @@ import 'package:webdev/src/serve/chrome.dart';
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';

void main() {
Chrome chrome;
Chrome? chrome;

Future<void> launchChrome({int port, String userDataDir}) async {
Future<void> launchChrome({int? port, String? userDataDir}) async {
chrome = await Chrome.start([_googleUrl],
port: port ?? 0, userDataDir: userDataDir);
}

Future<void> openTab(String url) =>
chrome.chromeConnection.getUrl(_openTabUrl(url));
chrome!.chromeConnection.getUrl(_openTabUrl(url));

Future<void> closeTab(ChromeTab tab) =>
chrome.chromeConnection.getUrl(_closeTabUrl(tab.id));
chrome!.chromeConnection.getUrl(_closeTabUrl(tab.id));

Future<WipConnection> connectToTab(String url) async {
var tab = await chrome.chromeConnection.getTab((t) => t.url.contains(url));
var tab = await chrome!.chromeConnection.getTab((t) => t.url.contains(url));
expect(tab, isNotNull);
return tab.connect();
return tab!.connect();
}

group('chrome with temp data dir', () {
tearDown(() async {
var tabs = await chrome?.chromeConnection?.getTabs();
var tabs = await chrome?.chromeConnection.getTabs();
if (tabs != null) {
for (var tab in tabs) {
await closeTab(tab);
Expand All @@ -53,7 +51,7 @@ void main() {

test('has a working debugger', () async {
await launchChrome();
var tabs = await chrome.chromeConnection.getTabs();
var tabs = await chrome!.chromeConnection.getTabs();
expect(
tabs,
contains(const TypeMatcher<ChromeTab>()
Expand All @@ -62,7 +60,7 @@ void main() {

test('uses open debug port if provided port is 0', () async {
await launchChrome(port: 0);
expect(chrome.debugPort, isNot(equals(0)));
expect(chrome!.debugPort, isNot(equals(0)));
});

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

group('chrome with user data dir', () {
Directory dataDir;
StreamController<String> logController;
Stream<String> logStream;
late Directory dataDir;
late StreamController<String> logController;
late Stream<String> logStream;

setUp(() {
logController = StreamController<String>();
logStream = logController.stream;

void _logWriter(Level level, String message,
{String error, String loggerName, String stackTrace}) {
{String? error, String? loggerName, String? stackTrace}) {
if (level >= Level.INFO) {
logController.add('[$level] $loggerName: $message');
}
Expand All @@ -104,7 +102,7 @@ void main() {
});

tearDown(() async {
var tabs = await chrome?.chromeConnection?.getTabs();
var tabs = await chrome?.chromeConnection.getTabs();
if (tabs != null) {
for (var tab in tabs) {
await closeTab(tab);
Expand All @@ -121,7 +119,7 @@ void main() {
'.*chrome_user_data_copy')));
await logController.close();
}
dataDir?.deleteSync(recursive: true);
dataDir.deleteSync(recursive: true);
});

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

var tabs = await chrome.chromeConnection.getTabs();
var tabs = await chrome!.chromeConnection.getTabs();
expect(
tabs,
contains(const TypeMatcher<ChromeTab>()
Expand Down Expand Up @@ -160,7 +158,7 @@ void main() {
var userDataDir = autoDetectChromeUserDataDirectory();
expect(userDataDir, isNotNull);

expect(Directory(userDataDir).existsSync(), isTrue);
expect(Directory(userDataDir!).existsSync(), isTrue);

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

Future<String> _evaluateExpression(WipPage page, String expression) async {
var result = '';
String? result = '';
while (result == null || result.isEmpty) {
await Future.delayed(const Duration(milliseconds: 100));
var wipResponse = await page.sendCommand(
'Runtime.evaluate',
params: {'expression': expression},
);
result = wipResponse.json['result']['result']['value'] as String;
result = wipResponse.json['result']['result']['value'] as String?;
}
return result;
}
Expand Down
4 changes: 1 addition & 3 deletions webdev/test/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// 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

import 'package:args/args.dart';
import 'package:test/test.dart';
import 'package:webdev/src/command/configuration.dart';

void main() {
ArgParser argParser;
late ArgParser argParser;
setUp(() {
argParser = ArgParser()
..addFlag('release')
Expand Down
4 changes: 1 addition & 3 deletions webdev/test/daemon/app_domain_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

@Timeout(Duration(minutes: 2))
import 'dart:convert';
import 'dart:io';
Expand All @@ -14,7 +12,7 @@ import '../test_utils.dart';
import 'utils.dart';

void main() {
String exampleDirectory;
late String exampleDirectory;

setUpAll(() async {
exampleDirectory = await prepareWorkspace();
Expand Down
4 changes: 1 addition & 3 deletions webdev/test/daemon/daemon_domain_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

@Timeout(Duration(minutes: 2))

import 'dart:convert';
Expand All @@ -14,7 +12,7 @@ import '../test_utils.dart';
import 'utils.dart';

void main() {
String exampleDirectory;
late String exampleDirectory;

setUpAll(() async {
exampleDirectory = await prepareWorkspace();
Expand Down
4 changes: 1 addition & 3 deletions webdev/test/daemon/launch_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// 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

@Timeout(Duration(minutes: 2))
import 'package:test/test.dart';

import '../test_utils.dart';
import 'utils.dart';

void main() {
String exampleDirectory;
late String exampleDirectory;

setUpAll(() async {
exampleDirectory = await prepareWorkspace();
Expand Down
8 changes: 3 additions & 5 deletions webdev/test/daemon/utils.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

import 'dart:async';
import 'dart:convert';

Expand Down Expand Up @@ -50,7 +48,7 @@ Future<String> prepareWorkspace() async {
return exampleDirectory;
}

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

Future<int> findBreakpointLine(VmService vmService, String breakpointId,
String isolateId, ScriptRef scriptRef) async {
var script = await vmService.getObject(isolateId, scriptRef.id) as Script;
var lines = LineSplitter.split(script.source).toList();
var script = await vmService.getObject(isolateId, scriptRef.id!) as Script;
var lines = LineSplitter.split(script.source!).toList();
var lineNumber =
lines.indexWhere((l) => l.endsWith('// Breakpoint: $breakpointId'));
if (lineNumber == -1) {
Expand Down
Loading