diff --git a/dwds/test/build_daemon_breakpoint_test.dart b/dwds/test/build_daemon_breakpoint_test.dart index 21a71d372..8dd6fe192 100644 --- a/dwds/test/build_daemon_breakpoint_test.dart +++ b/dwds/test/build_daemon_breakpoint_test.dart @@ -8,18 +8,18 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext( - directory: p.join('..', 'fixtures', '_testPackageSound'), - entry: p.join('..', 'fixtures', '_testPackageSound', 'web', 'main.dart'), - path: 'index.html', - pathToServe: 'web'); +final context = TestContext.withSoundNullSafety( + packageName: '_testPackageSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', +); ChromeProxyService get service => fetchChromeProxyService(context.debugConnection); diff --git a/dwds/test/build_daemon_callstack_test.dart b/dwds/test/build_daemon_callstack_test.dart index 0e51f75c2..f3ee816ef 100644 --- a/dwds/test/build_daemon_callstack_test.dart +++ b/dwds/test/build_daemon_callstack_test.dart @@ -8,7 +8,6 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; @@ -18,20 +17,18 @@ import 'fixtures/logging.dart'; import 'utils/version_compatibility.dart'; class TestSetup { - static final contextUnsound = TestContext( - directory: p.join('..', 'fixtures', '_testPackage'), - entry: p.join('..', 'fixtures', '_testPackage', 'web', 'main.dart'), - path: 'index.html', - pathToServe: 'web', - nullSafety: NullSafety.weak, + static final contextUnsound = TestContext.withWeakNullSafety( + packageName: '_testPackage', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', ); - static final contextSound = TestContext( - directory: p.join('..', 'fixtures', '_testPackageSound'), - entry: p.join('..', 'fixtures', '_testPackageSound', 'web', 'main.dart'), - path: 'index.html', - pathToServe: 'web', - nullSafety: NullSafety.sound, + static final contextSound = TestContext.withSoundNullSafety( + packageName: '_testPackageSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', ); TestContext context; diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index b9f86a9df..2054485cc 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -21,7 +21,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; import 'fixtures/logging.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); ChromeProxyService get service => fetchChromeProxyService(context.debugConnection); diff --git a/dwds/test/dart_uri_file_uri_test.dart b/dwds/test/dart_uri_file_uri_test.dart index f19c3858f..346165ec2 100644 --- a/dwds/test/dart_uri_file_uri_test.dart +++ b/dwds/test/dart_uri_file_uri_test.dart @@ -13,21 +13,19 @@ import 'fixtures/context.dart'; import 'fixtures/utilities.dart'; import 'utils/version_compatibility.dart'; -final context = TestContext( - directory: p.join('..', 'fixtures', '_testPackage'), - entry: p.join('..', 'fixtures', '_testPackage', 'web', 'main.dart'), - path: 'index.html', - pathToServe: 'web', - nullSafety: NullSafety.weak, +final context = TestContext.withWeakNullSafety( + packageName: '_testPackage', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', ); /// The directory for the general _test package. -final testDir = absolutePath(pathFromDwds: p.join('..', 'fixtures', '_test')); +final testDir = absolutePath(pathFromFixtures: p.join('_test')); /// The directory for the _testPackage package (contained within dwds), which /// imports _test. -final testPackageDir = - absolutePath(pathFromDwds: p.join('..', 'fixtures', '_testPackage')); +final testPackageDir = absolutePath(pathFromFixtures: p.join('_testPackage')); // This tests converting file Uris into our internal paths. // diff --git a/dwds/test/debug_extension_test.dart b/dwds/test/debug_extension_test.dart index eea611621..97e63d783 100644 --- a/dwds/test/debug_extension_test.dart +++ b/dwds/test/debug_extension_test.dart @@ -29,7 +29,7 @@ import 'fixtures/utilities.dart'; // Remove the key before pushing code to GitHub. // See go/extension-identification. -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); void main() async { Future waitForDartDevToolsWithRetry({ @@ -203,7 +203,7 @@ void main() async { } group('With encoding', () { - final context = TestContext(); + final context = TestContext.withSoundNullSafety(); setUp(() async { await context.setUp( enableDebugExtension: true, @@ -224,7 +224,7 @@ void main() async { }); group('With "any" hostname', () { - final context = TestContext(); + final context = TestContext.withSoundNullSafety(); final uriPattern = RegExp(r'dartExtensionUri = "([^"]+)";'); setUp(() async { diff --git a/dwds/test/debug_service_test.dart b/dwds/test/debug_service_test.dart index 6ae1cd0b5..e165c1f1f 100644 --- a/dwds/test/debug_service_test.dart +++ b/dwds/test/debug_service_test.dart @@ -12,7 +12,7 @@ import 'package:test/test.dart'; import 'fixtures/context.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); void main() { setUpAll(() async { diff --git a/dwds/test/debugger_test.dart b/dwds/test/debugger_test.dart index de93f2517..4585404a8 100644 --- a/dwds/test/debugger_test.dart +++ b/dwds/test/debugger_test.dart @@ -22,7 +22,7 @@ import 'fixtures/context.dart'; import 'fixtures/debugger_data.dart'; import 'fixtures/fakes.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); late AppInspector inspector; late Debugger debugger; late FakeWebkitDebugger webkitDebugger; diff --git a/dwds/test/devtools_test.dart b/dwds/test/devtools_test.dart index 13a0f29e0..66422ce7f 100644 --- a/dwds/test/devtools_test.dart +++ b/dwds/test/devtools_test.dart @@ -13,9 +13,7 @@ import 'package:webdriver/io.dart'; import 'fixtures/context.dart'; -final context = TestContext( - path: 'append_body/index.html', -); +final context = TestContext.withSoundNullSafety(); Future _waitForPageReady(TestContext context) async { var attempt = 100; diff --git a/dwds/test/evaluate_circular_common.dart b/dwds/test/evaluate_circular_common.dart index 2184559c6..87bc97370 100644 --- a/dwds/test/evaluate_circular_common.dart +++ b/dwds/test/evaluate_circular_common.dart @@ -8,7 +8,6 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; @@ -17,21 +16,21 @@ import 'fixtures/context.dart'; import 'fixtures/logging.dart'; class TestSetup { - static TestContext createContext( - String index, String packageRoot, NullSafety nullSafety) => - TestContext( - directory: p.join('..', 'fixtures', packageRoot), - entry: p.join('..', 'fixtures', packageRoot, 'web', 'main.dart'), - path: index, - pathToServe: 'web', - nullSafety: nullSafety, - ); - static TestContext contextUnsound(String index) => - createContext(index, '_testCircular2', NullSafety.weak); + TestContext.withWeakNullSafety( + packageName: '_testCircular2', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: index, + ); static TestContext contextSound(String index) => - createContext(index, '_testCircular2Sound', NullSafety.sound); + TestContext.withSoundNullSafety( + packageName: '_testCircular2Sound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: index, + ); TestContext context; diff --git a/dwds/test/evaluate_common.dart b/dwds/test/evaluate_common.dart index a6dce398f..41b8cb51f 100644 --- a/dwds/test/evaluate_common.dart +++ b/dwds/test/evaluate_common.dart @@ -8,7 +8,6 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; @@ -17,20 +16,21 @@ import 'fixtures/context.dart'; import 'fixtures/logging.dart'; class TestSetup { - static TestContext createContext( - String index, String packageRoot, NullSafety nullSafety) => - TestContext( - directory: p.join('..', 'fixtures', packageRoot), - entry: p.join('..', 'fixtures', packageRoot, 'web', 'main.dart'), - path: index, - pathToServe: 'web', - nullSafety: nullSafety); - static TestContext contextUnsound(String index) => - createContext(index, '_testPackage', NullSafety.weak); + TestContext.withWeakNullSafety( + packageName: '_testPackage', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: index, + ); static TestContext contextSound(String index) => - createContext(index, '_testPackageSound', NullSafety.sound); + TestContext.withSoundNullSafety( + packageName: '_testPackageSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: index, + ); TestContext context; diff --git a/dwds/test/events_test.dart b/dwds/test/events_test.dart index eaa194aa4..51f1eb9f5 100644 --- a/dwds/test/events_test.dart +++ b/dwds/test/events_test.dart @@ -23,7 +23,7 @@ ChromeProxyService get service => WipConnection get tabConnection => context.tabConnection; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); void main() { group('serve requests', () { diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 94ed72905..ff62190ad 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -55,6 +55,46 @@ enum IndexBaseMode { noBase, base } enum NullSafety { weak, sound } class TestContext { + final String packageName; + final String webAssetsPath; + final String dartEntryFileName; + final String htmlEntryFileName; + final NullSafety nullSafety; + + /// Top level directory in which we run the test server, e.g. + /// "/workstation/webdev/fixtures/_testSound". + String get workingDirectory => absolutePath(pathFromFixtures: packageName); + + /// The directory to build and serve, e.g. "example". + String get directoryToServe => p.split(webAssetsPath).first; + + /// The path to the HTML file to serve, relative to the [directoryToServe], + /// e.g. "hello_world/index.html". + String get filePathToServe { + final pathParts = p.split(webAssetsPath).where( + (pathPart) => pathPart != directoryToServe, + ); + return webCompatiblePath([...pathParts, htmlEntryFileName]); + } + + /// The entry file is the Dart entry file, e.g, + /// "/workstation/webdev/fixtures/_testSound/example/hello_world/main.dart": + File get _entryFile => File( + absolutePath( + pathFromFixtures: p.joinAll( + [packageName, webAssetsPath, dartEntryFileName], + ), + ), + ); + + /// The contents of the Dart entry file: + String get _entryContents => _entryFile.readAsStringSync(); + + /// The URI for the package_config.json is located in: + /// /.dart_tool/package_config + Uri get _packageConfigFile => + p.toUri(p.join(workingDirectory, '.dart_tool', 'package_config.json')); + String get appUrl => _appUrl!; late String? _appUrl; @@ -96,58 +136,54 @@ class TestContext { late WipConnection extensionConnection; late AppConnection appConnection; late DebugConnection debugConnection; - late File _entryFile; - late Uri _packageConfigFile; - late Uri _projectDirectory; - late String _entryContents; final _logger = logging.Logger('Context'); - /// Top level directory in which we run the test server.. - late String workingDirectory; - - /// The path to build and serve. - String pathToServe; - - /// The path part of the application URL. - String path; - - NullSafety nullSafety; - - TestContext({ - String? directory, - String? entry, - this.nullSafety = NullSafety.sound, - this.path = 'hello_world/index.html', - this.pathToServe = 'example', + TestContext.withSoundNullSafety({ + String packageName = '_testSound', + String webAssetsPath = 'example/hello_world', + String dartEntryFileName = 'main.dart', + String htmlEntryFileName = 'index.html', + }) : this._( + nullSafety: NullSafety.sound, + packageName: packageName, + webAssetsPath: webAssetsPath, + dartEntryFileName: dartEntryFileName, + htmlEntryFileName: htmlEntryFileName, + ); + + TestContext.withWeakNullSafety({ + String packageName = '_test', + String webAssetsPath = 'example/hello_world', + String dartEntryFileName = 'main.dart', + String htmlEntryFileName = 'index.html', + }) : this._( + nullSafety: NullSafety.weak, + packageName: packageName, + webAssetsPath: webAssetsPath, + dartEntryFileName: dartEntryFileName, + htmlEntryFileName: htmlEntryFileName, + ); + + TestContext._({ + required this.packageName, + required this.webAssetsPath, + required this.dartEntryFileName, + required this.htmlEntryFileName, + required this.nullSafety, }) { - final pathParts = p.split(p.current); - assert(pathParts.contains('webdev')); - final defaultPackage = - nullSafety == NullSafety.sound ? '_testSound' : '_test'; - final defaultDirectory = p.join('..', 'fixtures', defaultPackage); - final defaultEntry = p.join('..', 'fixtures', defaultPackage, 'example', - 'hello_world', 'main.dart'); - - workingDirectory = - absolutePath(pathFromDwds: directory ?? defaultDirectory); + // Verify that the test fixtures package matches the null-safety mode: + final isSoundPackage = packageName.toLowerCase().contains('sound'); + assert(nullSafety == NullSafety.sound ? isSoundPackage : !isSoundPackage); + // Verify that the web assets path has no starting slash: + assert(!webAssetsPath.startsWith('/')); DartUri.currentDirectory = workingDirectory; - // package_config.json is located in /.dart_tool/package_config - _projectDirectory = p.toUri(workingDirectory); - _packageConfigFile = - p.toUri(p.join(workingDirectory, '.dart_tool/package_config.json')); - - final entryFilePath = absolutePath(pathFromDwds: entry ?? defaultEntry); - - _logger.info('Serving: $pathToServe/$path'); - _logger.info('Project: $_projectDirectory'); + _logger.info('Serving: $directoryToServe/$filePathToServe'); + _logger.info('Project: $workingDirectory'); _logger.info('Packages: $_packageConfigFile'); - _logger.info('Entry: $entryFilePath'); - - _entryFile = File(entryFilePath); - _entryContents = _entryFile.readAsStringSync(); + _logger.info('Entry: ${_entryFile.path}'); } Future setUp({ @@ -252,7 +288,7 @@ class TestContext { record.stackTrace); }); daemonClient.registerBuildTarget( - DefaultBuildTarget((b) => b..target = pathToServe)); + DefaultBuildTarget((b) => b..target = directoryToServe)); daemonClient.startBuild(); await daemonClient.buildResults @@ -262,10 +298,10 @@ class TestContext { final assetServerPort = daemonPort(workingDirectory); _assetHandler = proxyHandler( - 'http://localhost:$assetServerPort/$pathToServe/', + 'http://localhost:$assetServerPort/$directoryToServe/', client: client); assetReader = - ProxyServerAssetReader(assetServerPort, root: pathToServe); + ProxyServerAssetReader(assetServerPort, root: directoryToServe); if (enableExpressionEvaluation) { ddcService = ExpressionCompilerService( @@ -288,11 +324,9 @@ class TestContext { break; case CompilationMode.frontendServer: { - _logger.warning('Index: $path'); - - final entry = p.toUri(_entryFile.path - .substring(_projectDirectory.toFilePath().length + 1)); + _logger.warning('Index: $filePathToServe'); + final entry = p.toUri(p.join(webAssetsPath, dartEntryFileName)); final fileSystem = LocalFileSystem(); final packageUriMapper = await PackageUriMapper.create( fileSystem, @@ -303,10 +337,10 @@ class TestContext { _webRunner = ResidentWebRunner( entry, urlEncoder, - _projectDirectory, + p.toUri(workingDirectory), _packageConfigFile, packageUriMapper, - [_projectDirectory], + [p.toUri(workingDirectory)], 'org-dartlang-app', outputDir.path, nullSafety == NullSafety.sound, @@ -315,7 +349,7 @@ class TestContext { final assetServerPort = await findUnusedPort(); await webRunner.run(fileSystem, hostname, assetServerPort, - p.join(pathToServe, path)); + p.join(directoryToServe, filePathToServe)); if (enableExpressionEvaluation) { expressionCompiler = webRunner.expressionCompiler; @@ -376,7 +410,7 @@ class TestContext { assetHandler, assetReader, requireStrategy, - pathToServe, + directoryToServe, buildResults, () async => connection, serveDevTools, @@ -393,8 +427,8 @@ class TestContext { ); _appUrl = basePath.isEmpty - ? 'http://localhost:$port/$path' - : 'http://localhost:$port/$basePath/$path'; + ? 'http://localhost:$port/$filePathToServe' + : 'http://localhost:$port/$basePath/$filePathToServe'; if (launchChrome) { await _webDriver?.get(appUrl); diff --git a/dwds/test/fixtures/utilities.dart b/dwds/test/fixtures/utilities.dart index 2f1366a23..dacb24412 100644 --- a/dwds/test/fixtures/utilities.dart +++ b/dwds/test/fixtures/utilities.dart @@ -11,26 +11,61 @@ import 'package:path/path.dart' as p; const webdevDirName = 'webdev'; const dwdsDirName = 'dwds'; +const fixturesDirName = 'fixtures'; -/// The path to the DWDS directory in the local machine, e.g. -/// "/workstation/webdev/dwds". -String get dwdsPath { +/// The path to the webdev directory in the local machine, e.g. +/// '/workstation/webdev'. +String get webdevPath { final pathParts = p.split(p.current); // We expect all tests to be run from the webdev mono-repo: assert(pathParts.contains(webdevDirName)); return p.joinAll( - [ - ...pathParts.sublist(0, pathParts.lastIndexOf(webdevDirName) + 1), - dwdsDirName, - ], + pathParts.sublist(0, pathParts.lastIndexOf(webdevDirName) + 1), ); } -/// Given a [pathFromDwds], e.g. '../fixtures/_test', returns its absolute -/// path, e.g. '/workstation/webdev/fixtures/_test'. -String absolutePath({required String pathFromDwds}) => p.normalize( - p.join(dwdsPath, pathFromDwds), - ); +/// The path to the DWDS directory in the local machine, e.g. +/// '/workstation/webdev/dwds'. +String get dwdsPath { + return p.join(webdevPath, dwdsDirName); +} + +/// The path to the fixtures directory in the local machine, e.g. +/// '/workstation/webdev/fixtures'. +String get fixturesPath { + return p.join(webdevPath, fixturesDirName); +} + +// Creates a path compatible for web. +String webCompatiblePath(List pathParts) { + // Note: Replacing "\" with "/" is necessary because `joinAll` uses "\" if + // the platform is Windows. However, only "/" is expected by the browser. + return p.joinAll([...pathParts]).replaceAll('\\', '/'); +} + +/// Expects one of [pathFromWebdev], [pathFromDwds] or [pathFromFixtures] to be +/// provided. Returns the absolute path in the local machine to that path, e.g. +/// absolutePath(pathFromFixtures: '_test/example') -> +/// '/workstation/webdev/fixtures/_test/example' +String absolutePath({ + String? pathFromWebdev, + String? pathFromDwds, + String? pathFromFixtures, +}) { + if (pathFromWebdev != null) { + assert(pathFromDwds == null && pathFromFixtures == null); + return p.normalize(p.join(webdevPath, pathFromWebdev)); + } + if (pathFromDwds != null) { + assert(pathFromFixtures == null); + return p.normalize(p.join(dwdsPath, pathFromDwds)); + } + if (pathFromFixtures != null) { + assert(pathFromDwds == null && pathFromWebdev == null); + return p.normalize(p.join(fixturesPath, pathFromFixtures)); + } + throw Exception('Expected a path parameter.'); +} /// Connects to the `build_runner` daemon. Future connectClient(String workingDirectory, diff --git a/dwds/test/frontend_server_breakpoint_test.dart b/dwds/test/frontend_server_breakpoint_test.dart index 2df12d982..ba190c46d 100644 --- a/dwds/test/frontend_server_breakpoint_test.dart +++ b/dwds/test/frontend_server_breakpoint_test.dart @@ -8,7 +8,6 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; @@ -17,12 +16,11 @@ import 'fixtures/context.dart'; import 'fixtures/logging.dart'; import 'utils/version_compatibility.dart'; -final context = TestContext( - directory: p.join('..', 'fixtures', '_testPackage'), - entry: p.join('..', 'fixtures', '_testPackage', 'web', 'main.dart'), - path: 'index.html', - pathToServe: 'web', - nullSafety: NullSafety.weak, +final context = TestContext.withWeakNullSafety( + packageName: '_testPackage', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', ); ChromeProxyService get service => diff --git a/dwds/test/frontend_server_callstack_test.dart b/dwds/test/frontend_server_callstack_test.dart index b8ccf36ed..e1cb27c9a 100644 --- a/dwds/test/frontend_server_callstack_test.dart +++ b/dwds/test/frontend_server_callstack_test.dart @@ -8,7 +8,6 @@ import 'dart:async'; import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; @@ -18,20 +17,18 @@ import 'fixtures/logging.dart'; import 'utils/version_compatibility.dart'; class TestSetup { - static final contextUnsound = TestContext( - directory: p.join('..', 'fixtures', '_testPackage'), - entry: p.join('..', 'fixtures', '_testPackage', 'web', 'main.dart'), - path: 'index.html', - pathToServe: 'web', - nullSafety: NullSafety.weak, + static final contextUnsound = TestContext.withWeakNullSafety( + packageName: '_testPackage', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', ); - static final contextSound = TestContext( - directory: p.join('..', 'fixtures', '_testPackageSound'), - entry: p.join('..', 'fixtures', '_testPackageSound', 'web', 'main.dart'), - path: 'index.html', - pathToServe: 'web', - nullSafety: NullSafety.sound, + static final contextSound = TestContext.withSoundNullSafety( + packageName: '_testPackageSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', ); TestContext context; diff --git a/dwds/test/handlers/asset_handler_test.dart b/dwds/test/handlers/asset_handler_test.dart index 82043f06e..7cb468193 100644 --- a/dwds/test/handlers/asset_handler_test.dart +++ b/dwds/test/handlers/asset_handler_test.dart @@ -12,7 +12,7 @@ import '../fixtures/logging.dart'; void main() { group('Asset handler', () { - final context = TestContext(); + final context = TestContext.withSoundNullSafety(); setUpAll(() async { setCurrentLogWriter(); diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index 31fead67b..10100f93b 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -11,23 +11,18 @@ import 'package:dwds/src/debugging/debugger.dart'; import 'package:dwds/src/debugging/inspector.dart'; import 'package:dwds/src/loaders/strategy.dart'; import 'package:dwds/src/utilities/conversions.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/utilities.dart'; -final context = TestContext( - path: 'scopes/scopes.html', - entry: p.join( - '..', - 'fixtures', - '_testSound', - 'example', - 'scopes', - 'scopes_main.dart', - )); +final context = TestContext.withSoundNullSafety( + webAssetsPath: webCompatiblePath(['example', 'scopes']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'scopes.html', +); WipConnection get tabConnection => context.tabConnection; @@ -46,11 +41,11 @@ void main() { await context.tearDown(); }); - final url = 'org-dartlang-app:///example/scopes/scopes_main.dart'; + final url = 'org-dartlang-app:///example/scopes/main.dart'; /// A convenient way to get a library variable without boilerplate. String libraryVariableExpression(String variable) => - '${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("example/scopes/scopes_main")["$url"]["$variable"];'; + '${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("example/scopes/main")["$url"]["$variable"];'; Future libraryPublicFinal() => inspector.jsEvaluate(libraryVariableExpression('libraryPublicFinal')); @@ -236,27 +231,27 @@ void main() { } final jsMultiLineExceptionWithStackTrace = ''' -Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11 +Error: Assertion failed: org-dartlang-app:///example/scopes/main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" - at Object.assertFailed (org-dartlang-app:///example/scopes/scopes_main.dart.js:5297:15) + at Object.assertFailed (org-dartlang-app:///example/scopes/main.dart.js:5297:15) '''; final formattedMultiLineExceptionWithStackTrace = ''' -Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11 +Error: Assertion failed: org-dartlang-app:///example/scopes/main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" -org-dartlang-app:///example/scopes/scopes_main.dart.js 5297:15 assertFailed +org-dartlang-app:///example/scopes/main.dart.js 5297:15 assertFailed '''; final jsMultiLineExceptionNoStackTrace = ''' -Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11 +Error: Assertion failed: org-dartlang-app:///example/scopes/main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" '''; final formattedMultiLineExceptionNoStackTrace = ''' -Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11 +Error: Assertion failed: org-dartlang-app:///example/scopes/main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" '''; diff --git a/dwds/test/instance_test.dart b/dwds/test/instance_test.dart index f69c763c9..c5f279703 100644 --- a/dwds/test/instance_test.dart +++ b/dwds/test/instance_test.dart @@ -9,23 +9,18 @@ import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/debugger.dart'; import 'package:dwds/src/debugging/inspector.dart'; import 'package:dwds/src/loaders/strategy.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/utilities.dart'; -final context = TestContext( - path: 'scopes/scopes.html', - entry: p.join( - '..', - 'fixtures', - '_testSound', - 'example', - 'scopes', - 'scopes_main.dart', - )); +final context = TestContext.withSoundNullSafety( + webAssetsPath: webCompatiblePath(['example', 'scopes']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'scopes.html', +); WipConnection get tabConnection => context.tabConnection; @@ -44,10 +39,10 @@ void main() { await context.tearDown(); }); - final url = 'org-dartlang-app:///example/scopes/scopes_main.dart'; + final url = 'org-dartlang-app:///example/scopes/main.dart'; String libraryVariableExpression(String variable) => - '${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("example/scopes/scopes_main")' + '${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("example/scopes/main")' '["$url"]["$variable"];'; /// A reference to the the variable `libraryPublicFinal`, an instance of @@ -91,7 +86,7 @@ void main() { expect(classRef.name, 'MyTestClass'); expect( classRef.id, - 'classes|org-dartlang-app:///example/scopes/scopes_main.dart' + 'classes|org-dartlang-app:///example/scopes/main.dart' '|MyTestClass'); }); diff --git a/dwds/test/listviews_test.dart b/dwds/test/listviews_test.dart index b60aa1415..db3c5b1fd 100644 --- a/dwds/test/listviews_test.dart +++ b/dwds/test/listviews_test.dart @@ -8,7 +8,7 @@ import 'package:test/test.dart'; import 'fixtures/context.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); void main() { setUpAll(() async { diff --git a/dwds/test/package_uri_mapper_test.dart b/dwds/test/package_uri_mapper_test.dart index 69fd83cbf..9bf1f18bc 100644 --- a/dwds/test/package_uri_mapper_test.dart +++ b/dwds/test/package_uri_mapper_test.dart @@ -31,12 +31,8 @@ void main() { final resolvedPath = '/webdev/fixtures/_testPackageSound/lib/test_library.dart'; - final testPackageSoundPath = absolutePath( - pathFromDwds: p.join( - '..', - 'fixtures', - '_testPackageSound', - )); + final testPackageSoundPath = + absolutePath(pathFromFixtures: '_testPackageSound'); final packageConfigFile = Uri.file(p.join( testPackageSoundPath, diff --git a/dwds/test/puppeteer/extension_test.dart b/dwds/test/puppeteer/extension_test.dart index 66a62b15d..c54bc237d 100644 --- a/dwds/test/puppeteer/extension_test.dart +++ b/dwds/test/puppeteer/extension_test.dart @@ -24,7 +24,7 @@ import '../../debug_extension_mv3/web/data_types.dart'; import '../fixtures/context.dart'; import 'test_utils.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); enum Panel { debugger, inspector } diff --git a/dwds/test/puppeteer/lifeline_test.dart b/dwds/test/puppeteer/lifeline_test.dart index 600db189b..bd920dcc6 100644 --- a/dwds/test/puppeteer/lifeline_test.dart +++ b/dwds/test/puppeteer/lifeline_test.dart @@ -12,7 +12,7 @@ import 'package:test/test.dart'; import '../fixtures/context.dart'; import 'test_utils.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); void main() async { late Worker worker; diff --git a/dwds/test/readers/frontend_server_asset_reader_test.dart b/dwds/test/readers/frontend_server_asset_reader_test.dart index d9e53c299..62a82098f 100644 --- a/dwds/test/readers/frontend_server_asset_reader_test.dart +++ b/dwds/test/readers/frontend_server_asset_reader_test.dart @@ -14,9 +14,7 @@ import '../fixtures/context.dart'; import '../fixtures/utilities.dart'; import '../utils/version_compatibility.dart'; -final packagesDir = absolutePath( - pathFromDwds: p.join('..', 'fixtures', '_test'), -); +final packagesDir = absolutePath(pathFromFixtures: '_test'); final fixturesDir = absolutePath(pathFromDwds: p.join('test', 'fixtures')); diff --git a/dwds/test/readers/proxy_server_asset_reader_test.dart b/dwds/test/readers/proxy_server_asset_reader_test.dart index 86ed852d9..c9b76ccd0 100644 --- a/dwds/test/readers/proxy_server_asset_reader_test.dart +++ b/dwds/test/readers/proxy_server_asset_reader_test.dart @@ -12,7 +12,7 @@ import '../utils/version_compatibility.dart'; void main() { group('ProxyServerAssetReader', () { - final context = TestContext(nullSafety: NullSafety.weak); + final context = TestContext.withWeakNullSafety(); late ProxyServerAssetReader assetReader; setUpAll(() async { await context.setUp(); diff --git a/dwds/test/refresh_test.dart b/dwds/test/refresh_test.dart index 141df6faa..2fc125b9e 100644 --- a/dwds/test/refresh_test.dart +++ b/dwds/test/refresh_test.dart @@ -18,7 +18,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); ChromeProxyService get service => fetchChromeProxyService(context.debugConnection); WipConnection get tabConnection => context.tabConnection; diff --git a/dwds/test/reload_test.dart b/dwds/test/reload_test.dart index 970e3797e..9c0815fa1 100644 --- a/dwds/test/reload_test.dart +++ b/dwds/test/reload_test.dart @@ -6,17 +6,17 @@ @TestOn('vm') @Timeout(Duration(minutes: 5)) import 'package:dwds/src/loaders/strategy.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; import 'fixtures/logging.dart'; +import 'fixtures/utilities.dart'; -final context = TestContext( - path: 'append_body/index.html', - entry: p.join( - '..', 'fixtures', '_testSound', 'example', 'append_body', 'main.dart'), +final context = TestContext.withSoundNullSafety( + webAssetsPath: webCompatiblePath(['example', 'append_body']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', ); void main() { diff --git a/dwds/test/restore_breakpoints_test.dart b/dwds/test/restore_breakpoints_test.dart index d5079542d..e21c3e35a 100644 --- a/dwds/test/restore_breakpoints_test.dart +++ b/dwds/test/restore_breakpoints_test.dart @@ -15,7 +15,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; import 'fixtures/logging.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); ChromeProxyService get service => fetchChromeProxyService(context.debugConnection); WipConnection get tabConnection => context.tabConnection; diff --git a/dwds/test/run_request_test.dart b/dwds/test/run_request_test.dart index 9856c6665..5b461bdf7 100644 --- a/dwds/test/run_request_test.dart +++ b/dwds/test/run_request_test.dart @@ -12,7 +12,7 @@ import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); ChromeProxyService get service => fetchChromeProxyService(context.debugConnection); diff --git a/dwds/test/screenshot_test.dart b/dwds/test/screenshot_test.dart index 34f98bb74..9410abf1e 100644 --- a/dwds/test/screenshot_test.dart +++ b/dwds/test/screenshot_test.dart @@ -8,7 +8,7 @@ import 'package:test/test.dart'; import 'fixtures/context.dart'; -final context = TestContext(); +final context = TestContext.withSoundNullSafety(); void main() { setUpAll(() async { diff --git a/dwds/test/variable_scope_test.dart b/dwds/test/variable_scope_test.dart index 8ec92bf4c..19a7c7eb6 100644 --- a/dwds/test/variable_scope_test.dart +++ b/dwds/test/variable_scope_test.dart @@ -7,24 +7,18 @@ import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/debugging/dart_scope.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; -import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/utilities.dart'; -final context = TestContext( - path: 'scopes/scopes.html', - entry: p.join( - '..', - 'fixtures', - '_testSound', - 'example', - 'scopes', - 'scopes_main.dart', - )); - +final context = TestContext.withSoundNullSafety( + webAssetsPath: webCompatiblePath(['example', 'scopes']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'scopes.html', +); ChromeProxyService get service => fetchChromeProxyService(context.debugConnection); WipConnection get tabConnection => context.tabConnection; @@ -124,7 +118,7 @@ void main() { await service.streamListen('Debug'); stream = service.onEvent('Debug'); mainScript = scripts.scripts! - .firstWhere((each) => each.uri!.contains('scopes_main.dart')); + .firstWhere((each) => each.uri!.contains('main.dart')); }); tearDown(() async { diff --git a/fixtures/_test/example/scopes/scopes_main.dart b/fixtures/_test/example/scopes/main.dart similarity index 100% rename from fixtures/_test/example/scopes/scopes_main.dart rename to fixtures/_test/example/scopes/main.dart diff --git a/fixtures/_test/example/scopes/scopes.html b/fixtures/_test/example/scopes/scopes.html index 6c3307394..d93440a94 100644 --- a/fixtures/_test/example/scopes/scopes.html +++ b/fixtures/_test/example/scopes/scopes.html @@ -1,7 +1,7 @@ - + diff --git a/fixtures/_testSound/example/scopes/scopes_main.dart b/fixtures/_testSound/example/scopes/main.dart similarity index 100% rename from fixtures/_testSound/example/scopes/scopes_main.dart rename to fixtures/_testSound/example/scopes/main.dart diff --git a/fixtures/_testSound/example/scopes/scopes.html b/fixtures/_testSound/example/scopes/scopes.html index 6c3307394..d93440a94 100644 --- a/fixtures/_testSound/example/scopes/scopes.html +++ b/fixtures/_testSound/example/scopes/scopes.html @@ -1,7 +1,7 @@ - +