diff --git a/CHANGELOG.md b/CHANGELOG.md index 90fd3b5..d83ac83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0 + + - Migrate to null-safety. + ## 0.1.10 - Support `webkit_inspection_protocol` version `^1.0.0`. diff --git a/lib/src/chrome.dart b/lib/src/chrome.dart index 04d0262..1391884 100644 --- a/lib/src/chrome.dart +++ b/lib/src/chrome.dart @@ -18,7 +18,7 @@ const _windowsExecutable = r'Google\Chrome\Application\chrome.exe'; String get _executable { for (var chromeEnv in _chromeEnvironments) { if (Platform.environment.containsKey(chromeEnv)) { - return Platform.environment[chromeEnv]; + return Platform.environment[chromeEnv]!; } } if (Platform.isLinux) return _linuxExecutable; @@ -34,7 +34,7 @@ String get _executable { if (prefix == null) return false; final path = p.join(prefix, _windowsExecutable); return File(path).existsSync(); - }, orElse: () => '.'), + }, orElse: () => '.')!, _windowsExecutable, ); } @@ -43,15 +43,19 @@ String get _executable { /// Manager for an instance of Chrome. class Chrome { - Chrome._(this.debugPort, this.chromeConnection, - {Process process, Directory dataDir, this.deleteDataDir = false}) - : _process = process, + Chrome._( + this.debugPort, + this.chromeConnection, { + Process? process, + Directory? dataDir, + this.deleteDataDir = false, + }) : _process = process, _dataDir = dataDir; final int debugPort; final ChromeConnection chromeConnection; - final Process _process; - final Directory _dataDir; + final Process? _process; + final Directory? _dataDir; final bool deleteDataDir; /// Connects to an instance of Chrome with an open debug port. @@ -61,17 +65,19 @@ class Chrome { /// Starts Chrome with the given arguments and a specific port. /// /// Each url in [urls] will be loaded in a separate tab. - static Future startWithDebugPort(List urls, - {int debugPort, bool headless = false, String userDataDir}) async { + static Future startWithDebugPort( + List urls, { + int debugPort = 0, + bool headless = false, + String? userDataDir, + }) async { Directory dataDir; if (userDataDir == null) { dataDir = Directory.systemTemp.createTempSync(); } else { dataDir = Directory(userDataDir); } - final port = debugPort == null || debugPort == 0 - ? await findUnusedPort() - : debugPort; + final port = debugPort == 0 ? await findUnusedPort() : debugPort; final args = [ // Using a tmp directory ensures that a new instance of chrome launches // allowing for the remote debug port to be enabled. @@ -117,7 +123,7 @@ class Chrome { ChromeConnection('localhost', port), process: process, dataDir: dataDir, - deleteDataDir: userDataDir = null, + deleteDataDir: userDataDir == null, )); } diff --git a/pubspec.yaml b/pubspec.yaml index ad72432..7233840 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,17 +1,17 @@ name: browser_launcher description: Provides a standardized way to launch web browsers for testing and tools. -version: 0.1.10 +version: 1.0.0 homepage: https://github.com/dart-lang/browser_launcher environment: - sdk: '>=2.2.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: - path: ^1.6.2 + path: ^1.8.0 webkit_inspection_protocol: ^1.0.0 dev_dependencies: - pedantic: ^1.5.0 - test: ^1.0.0 + pedantic: ^1.11.0 + test: ^1.17.3 diff --git a/test/chrome_test.dart b/test/chrome_test.dart index a63220f..0263225 100644 --- a/test/chrome_test.dart +++ b/test/chrome_test.dart @@ -10,9 +10,9 @@ import 'package:test/test.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; void main() { - Chrome chrome; + Chrome? chrome; - Future launchChromeWithDebugPort({int port}) async { + Future launchChromeWithDebugPort({int port = 0}) async { chrome = await Chrome.startWithDebugPort([_googleUrl], debugPort: port); } @@ -37,7 +37,7 @@ void main() { test('debugger is working', () async { await launchChromeWithDebugPort(); - var tabs = await chrome.chromeConnection.getTabs(); + var tabs = await chrome!.chromeConnection.getTabs(); expect( tabs, contains(const TypeMatcher() @@ -46,13 +46,13 @@ void main() { test('uses open debug port if provided port is 0', () async { await launchChromeWithDebugPort(port: 0); - expect(chrome.debugPort, isNot(equals(0))); + expect(chrome!.debugPort, isNot(equals(0))); }); test('can provide a specific debug port', () async { var port = await findUnusedPort(); await launchChromeWithDebugPort(port: port); - expect(chrome.debugPort, port); + expect(chrome!.debugPort, port); }); }