diff --git a/dwds/test/build_daemon_breakpoint_test.dart b/dwds/test/build_daemon_breakpoint_test.dart index 8dd6fe192..2af540472 100644 --- a/dwds/test/build_daemon_breakpoint_test.dart +++ b/dwds/test/build_daemon_breakpoint_test.dart @@ -6,24 +6,16 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; 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/project.dart'; -final context = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', -); +final context = TestContext(TestProject.testPackageWithSoundNullSafety()); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; +ChromeProxyService get service => context.service; void main() { group('shared context', () { diff --git a/dwds/test/build_daemon_callstack_test.dart b/dwds/test/build_daemon_callstack_test.dart index eee6161cc..e98f02ee5 100644 --- a/dwds/test/build_daemon_callstack_test.dart +++ b/dwds/test/build_daemon_callstack_test.dart @@ -6,40 +6,13 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; - -class TestSetup { - static final contextUnsound = TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - static final contextSound = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - TestContext context; - - TestSetup.sound() : context = contextSound; - - TestSetup.unsound() : context = contextUnsound; - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - WipConnection get tabConnection => context.tabConnection; -} +import 'fixtures/project.dart'; void main() { group( @@ -50,10 +23,8 @@ void main() { for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { - final soundNullSafety = nullSafety == NullSafety.sound; - final setup = - soundNullSafety ? TestSetup.sound() : TestSetup.unsound(); - final context = setup.context; + final project = TestProject.testPackage(nullSafety: nullSafety); + final context = TestContext(project); setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -79,7 +50,7 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = setup.service; + service = context.service; vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); scripts = await service.getScripts(isolate.id!); @@ -87,9 +58,7 @@ void main() { await service.streamListen('Debug'); stream = service.onEvent('Debug'); - final testPackage = - soundNullSafety ? '_test_package_sound' : '_test_package'; - + final testPackage = project.packageName; mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); testLibraryScript = scripts.scripts!.firstWhere((each) => @@ -108,8 +77,8 @@ void main() { final script = breakpoint.script; final line = await context.findBreakpointLine(bpId, isolate.id!, script); - bp = await setup.service - .addBreakpointWithScriptUri(isolate.id!, script.uri!, line); + bp = await service.addBreakpointWithScriptUri( + isolate.id!, script.uri!, line); expect(bp, isNotNull); expect(bp.location, _matchBpLocation(script, line, 0)); @@ -121,7 +90,7 @@ void main() { } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await setup.service.removeBreakpoint(isolate.id!, bp.id!); + await service.removeBreakpoint(isolate.id!, bp.id!); } } } diff --git a/dwds/test/build_daemon_circular_evaluate_test.dart b/dwds/test/build_daemon_circular_evaluate_test.dart index 2be53bb26..db3192365 100644 --- a/dwds/test/build_daemon_circular_evaluate_test.dart +++ b/dwds/test/build_daemon_circular_evaluate_test.dart @@ -9,6 +9,7 @@ import 'package:test/test.dart'; import 'evaluate_circular_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/build_daemon_evaluate_test.dart b/dwds/test/build_daemon_evaluate_test.dart index 06cdb5a8f..6c0bde0b7 100644 --- a/dwds/test/build_daemon_evaluate_test.dart +++ b/dwds/test/build_daemon_evaluate_test.dart @@ -9,6 +9,7 @@ import 'package:test/test.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/chrome_proxy_service_test.dart b/dwds/test/chrome_proxy_service_test.dart index 68695b461..4a860fe9c 100644 --- a/dwds/test/chrome_proxy_service_test.dart +++ b/dwds/test/chrome_proxy_service_test.dart @@ -21,12 +21,11 @@ import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety(); - -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); +final context = TestContext(TestProject.testWithSoundNullSafety); +ChromeProxyService get service => context.service; WipConnection get tabConnection => context.tabConnection; void main() { diff --git a/dwds/test/dart_uri_file_uri_test.dart b/dwds/test/dart_uri_file_uri_test.dart index 8dd3388f3..293501f41 100644 --- a/dwds/test/dart_uri_file_uri_test.dart +++ b/dwds/test/dart_uri_file_uri_test.dart @@ -10,22 +10,18 @@ import 'package:path/path.dart' as p; import 'package:test/test.dart'; import 'fixtures/context.dart'; -import 'fixtures/utilities.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', -); +final testProject = TestProject.testWithSoundNullSafety; +final testPackageProject = TestProject.testPackageWithSoundNullSafety(); +final context = TestContext(testPackageProject); /// The directory for the general _test package. -final testDir = absolutePath(pathFromFixtures: p.join('_testSound')); +final testDir = testProject.absolutePackageDirectory; /// The directory for the _testPackage package (contained within dwds), which /// imports _test. -final testPackageDir = - absolutePath(pathFromFixtures: p.join('_testPackageSound')); +final testPackageDir = testPackageProject.absolutePackageDirectory; // This tests converting file Uris into our internal paths. // @@ -41,17 +37,17 @@ void main() { ? 'web/main.dart' : 'main.dart'; - final serverPath = - compilationMode == CompilationMode.frontendServer && - useDebuggerModuleNames - ? 'packages/_testPackageSound/lib/test_library.dart' - : 'packages/_test_package_sound/test_library.dart'; + final serverPath = compilationMode == + CompilationMode.frontendServer && + useDebuggerModuleNames + ? 'packages/${testPackageProject.packageDirectory}/lib/test_library.dart' + : 'packages/${testPackageProject.packageName}/test_library.dart'; final anotherServerPath = compilationMode == CompilationMode.frontendServer && useDebuggerModuleNames - ? 'packages/_testSound/lib/library.dart' - : 'packages/_test_sound/library.dart'; + ? 'packages/${testProject.packageDirectory}/lib/library.dart' + : 'packages/${testProject.packageName}/library.dart'; setUpAll(() async { await context.setUp( diff --git a/dwds/test/debug_extension_test.dart b/dwds/test/debug_extension_test.dart index cadc04d90..4df26f09f 100644 --- a/dwds/test/debug_extension_test.dart +++ b/dwds/test/debug_extension_test.dart @@ -18,6 +18,7 @@ import 'package:test/test.dart'; import 'package:webdriver/io.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; import 'fixtures/utilities.dart'; // Instructions for running: @@ -30,7 +31,7 @@ import 'fixtures/utilities.dart'; // Remove the key before pushing code to GitHub. // See go/extension-identification. -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); void main() async { Future waitForDartDevToolsWithRetry({ @@ -204,7 +205,7 @@ void main() async { } group('With encoding', () { - final context = TestContext.withSoundNullSafety(); + final context = TestContext(TestProject.testWithSoundNullSafety); setUp(() async { await context.setUp( enableDebugExtension: true, @@ -225,7 +226,7 @@ void main() async { }); group('With "any" hostname', () { - final context = TestContext.withSoundNullSafety(); + final context = TestContext(TestProject.testWithSoundNullSafety); final uriPattern = RegExp(r'dartExtensionUri = "([^"]+)";'); setUp(() async { diff --git a/dwds/test/debug_service_test.dart b/dwds/test/debug_service_test.dart index 4fd90cb93..9db319331 100644 --- a/dwds/test/debug_service_test.dart +++ b/dwds/test/debug_service_test.dart @@ -11,8 +11,9 @@ import 'dart:io'; import 'package:test/test.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); void main() { setUpAll(() async { diff --git a/dwds/test/debugger_test.dart b/dwds/test/debugger_test.dart index 4585404a8..ce55a2fa2 100644 --- a/dwds/test/debugger_test.dart +++ b/dwds/test/debugger_test.dart @@ -21,8 +21,9 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' import 'fixtures/context.dart'; import 'fixtures/debugger_data.dart'; import 'fixtures/fakes.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); late AppInspector inspector; late Debugger debugger; late FakeWebkitDebugger webkitDebugger; diff --git a/dwds/test/devtools_test.dart b/dwds/test/devtools_test.dart index 56d01c8fb..58024df59 100644 --- a/dwds/test/devtools_test.dart +++ b/dwds/test/devtools_test.dart @@ -12,8 +12,9 @@ import 'package:vm_service/vm_service.dart'; import 'package:webdriver/io.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); 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 f7a0a450b..43ec19915 100644 --- a/dwds/test/evaluate_circular_common.dart +++ b/dwds/test/evaluate_circular_common.dart @@ -6,52 +6,12 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; - -class TestSetup { - static TestContext contextUnsound(String index) => - TestContext.withWeakNullSafety( - packageName: '_testCircular2', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: index, - ); - - static TestContext contextSound(String index) => - TestContext.withSoundNullSafety( - packageName: '_testCircular2Sound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: index, - ); - - TestContext context; - - TestSetup.sound(IndexBaseMode baseMode) - : context = contextSound(_index(baseMode)); - - TestSetup.unsound(IndexBaseMode baseMode) - : context = contextUnsound(_index(baseMode)); - - factory TestSetup.create(NullSafety? nullSafety, IndexBaseMode baseMode) => - nullSafety == NullSafety.sound - ? TestSetup.sound(baseMode) - : TestSetup.unsound(baseMode); - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - WipConnection get tabConnection => context.tabConnection; - - static String _index(IndexBaseMode baseMode) => - baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html'; -} +import 'fixtures/project.dart'; void testAll({ CompilationMode compilationMode = CompilationMode.buildDaemon, @@ -65,8 +25,11 @@ void testAll({ throw StateError( 'build daemon scenario does not support non-empty base in index file'); } - final setup = TestSetup.create(nullSafety, indexBaseMode); - final context = setup.context; + + final project1 = TestProject.testCircular1(nullSafety: nullSafety); + final project2 = TestProject.testCircular2( + nullSafety: nullSafety, baseMode: indexBaseMode); + final context = TestContext(project2); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { @@ -74,13 +37,13 @@ void testAll({ try { final line = await context.findBreakpointLine(breakPointId, isolate, script); - bp = await setup.service + bp = await context.service .addBreakpointWithScriptUri(isolate, script.uri!, line); await body(); } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await setup.service.removeBreakpoint(isolate, bp.id!); + await context.service.removeBreakpoint(isolate, bp.id!); } } } @@ -113,19 +76,16 @@ void testAll({ setUp(() async { setCurrentLogWriter(debug: debug); - vm = await setup.service.getVM(); - isolate = await setup.service.getIsolate(vm.isolates!.first.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - scripts = await setup.service.getScripts(isolateId); + scripts = await context.service.getScripts(isolateId); - await setup.service.streamListen('Debug'); - stream = setup.service.onEvent('Debug'); + await context.service.streamListen('Debug'); + stream = context.service.onEvent('Debug'); - final soundNullSafety = nullSafety == NullSafety.sound; - final test1 = - soundNullSafety ? '_test_circular1_sound' : '_test_circular1'; - final test2 = - soundNullSafety ? '_test_circular2_sound' : '_test_circular2'; + final test1 = project1.packageName; + final test2 = project2.packageName; test1LibraryScript = scripts.scripts!.firstWhere( (each) => each.uri!.contains('package:$test1/library1.dart')); @@ -134,7 +94,7 @@ void testAll({ }); tearDown(() async { - await setup.service.resume(isolateId); + await context.service.resume(isolateId); }); test('evaluate expression in _test_circular1/library', () async { @@ -143,7 +103,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'a'); expect( @@ -160,7 +120,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'true'); expect( diff --git a/dwds/test/evaluate_common.dart b/dwds/test/evaluate_common.dart index 2143864ee..f889a6e7b 100644 --- a/dwds/test/evaluate_common.dart +++ b/dwds/test/evaluate_common.dart @@ -6,52 +6,12 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; - -class TestSetup { - static TestContext contextUnsound(String index) => - TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: index, - ); - - static TestContext contextSound(String index) => - TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: index, - ); - - TestContext context; - - TestSetup.sound(IndexBaseMode baseMode) - : context = contextSound(_index(baseMode)); - - TestSetup.unsound(IndexBaseMode baseMode) - : context = contextUnsound(_index(baseMode)); - - factory TestSetup.create(NullSafety? nullSafety, IndexBaseMode baseMode) => - nullSafety == NullSafety.sound - ? TestSetup.sound(baseMode) - : TestSetup.unsound(baseMode); - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - WipConnection get tabConnection => context.tabConnection; - - static String _index(IndexBaseMode baseMode) => - baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html'; -} +import 'fixtures/project.dart'; void testAll({ CompilationMode compilationMode = CompilationMode.buildDaemon, @@ -65,8 +25,10 @@ void testAll({ throw StateError( 'build daemon scenario does not support non-empty base in index file'); } - final setup = TestSetup.create(nullSafety, indexBaseMode); - final context = setup.context; + final testProject = TestProject.test(nullSafety: nullSafety); + final testPackageProject = + TestProject.testPackage(nullSafety: nullSafety, baseMode: indexBaseMode); + final context = TestContext(testPackageProject); Future onBreakPoint(String isolate, ScriptRef script, String breakPointId, Future Function() body) async { @@ -74,13 +36,13 @@ void testAll({ try { final line = await context.findBreakpointLine(breakPointId, isolate, script); - bp = await setup.service + bp = await context.service .addBreakpointWithScriptUri(isolate, script.uri!, line); await body(); } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await setup.service.removeBreakpoint(isolate, bp.id!); + await context.service.removeBreakpoint(isolate, bp.id!); } } } @@ -115,18 +77,16 @@ void testAll({ setUp(() async { setCurrentLogWriter(debug: debug); - vm = await setup.service.getVM(); - isolate = await setup.service.getIsolate(vm.isolates!.first.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - scripts = await setup.service.getScripts(isolateId); + scripts = await context.service.getScripts(isolateId); - await setup.service.streamListen('Debug'); - stream = setup.service.onEvent('Debug'); + await context.service.streamListen('Debug'); + stream = context.service.onEvent('Debug'); - final soundNullSafety = nullSafety == NullSafety.sound; - final testPackage = - soundNullSafety ? '_test_package_sound' : '_test_package'; - final test = soundNullSafety ? '_test_sound' : '_test'; + final testPackage = testPackageProject.packageName; + final test = testProject.packageName; mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); testLibraryScript = scripts.scripts!.firstWhere((each) => @@ -138,7 +98,7 @@ void testAll({ }); tearDown(() async { - await setup.service.resume(isolateId); + await context.service.resume(isolateId); }); test('uses correct null safety mode', () async { @@ -148,7 +108,7 @@ void testAll({ final isNullSafetyEnabled = '() { const sound = !([] is List); return sound; } ()'; - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, isNullSafetyEnabled); expect( @@ -163,10 +123,11 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'stream'); final instanceId = (result as InstanceRef).id!; - final instance = await setup.service.getObject(isolateId, instanceId); + final instance = + await context.service.getObject(isolateId, instanceId); expect( instance, @@ -180,11 +141,11 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final object = await setup.service.evaluateInFrame( + final object = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'MainClass(1,0)'); final param = object as InstanceRef; - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 't.toString()', @@ -206,7 +167,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'local'); expect( @@ -219,7 +180,7 @@ void testAll({ test('Type does not show native JavaScript object fields', () async { await onBreakPoint(isolateId, mainScript, 'printLocal', () async { Future getInstance(InstanceRef ref) async { - final result = await setup.service.getObject(isolateId, ref.id!); + final result = await context.service.getObject(isolateId, ref.id!); expect(result, isA()); return result as Instance; } @@ -227,7 +188,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'Type'); expect(result, isA()); final instanceRef = result as InstanceRef; @@ -265,7 +226,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'instance.field'); expect( @@ -281,7 +242,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'instance._field'); expect( @@ -296,7 +257,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'instance._field'); expect( @@ -312,10 +273,10 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final instanceRef = await setup.service.evaluateInFrame( + final instanceRef = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'instance') as InstanceRef; - final instance = await setup.service + final instance = await context.service .getObject(isolateId, instanceRef.id!) as Instance; final field = instance.fields!.firstWhere( @@ -333,7 +294,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'testLibraryValue'); expect( @@ -348,7 +309,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'print(local)'); expect( @@ -363,7 +324,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'testLibraryFunction(42)'); expect( @@ -378,7 +339,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'testLibraryFunction(local)'); expect( @@ -393,7 +354,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame( + final result = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'testLibraryPartFunction(42)'); expect( @@ -408,7 +369,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service.evaluateInFrame(isolateId, + final result = await context.service.evaluateInFrame(isolateId, event.topFrame!.index!, 'testLibraryPartFunction(local)'); expect( @@ -424,7 +385,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'item'); expect( @@ -440,7 +401,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'formal'); expect( @@ -457,7 +418,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'this.field'); expect( @@ -475,7 +436,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'this.field'); expect( @@ -491,7 +452,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index! + 1, 'local'); expect( @@ -506,7 +467,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final result = await setup.service + final result = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'a'); expect( @@ -521,7 +482,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final error = await setup.service + final error = await context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'typo'); expect( @@ -536,7 +497,7 @@ void testAll({ final event = await stream .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); - final error = await setup.service.evaluateInFrame( + final error = await context.service.evaluateInFrame( isolateId, event.topFrame!.index!, 'd.deferredPrintLocal()'); expect( @@ -552,7 +513,7 @@ void testAll({ .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); await expectLater( - setup.service + context.service .evaluateInFrame('bad', event.topFrame!.index!, 'local'), throwsSentinelException); }); @@ -566,20 +527,20 @@ void testAll({ setUp(() async { setCurrentLogWriter(debug: debug); - vm = await setup.service.getVM(); - isolate = await setup.service.getIsolate(vm.isolates!.first.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - await setup.service.streamListen('Debug'); + await context.service.streamListen('Debug'); }); tearDown(() async {}); test('in parallel (in a batch)', () async { final library = isolate.rootLib!; - final evaluation1 = setup.service + final evaluation1 = context.service .evaluate(isolateId, library.id!, 'MainClass(1,0).toString()'); - final evaluation2 = setup.service + final evaluation2 = context.service .evaluate(isolateId, library.id!, 'MainClass(1,1).toString()'); final results = await Future.wait([evaluation1, evaluation2]); @@ -597,9 +558,9 @@ void testAll({ test('in parallel (in a batch) handles errors', () async { final library = isolate.rootLib!; final missingLibId = ''; - final evaluation1 = setup.service + final evaluation1 = context.service .evaluate(isolateId, missingLibId, 'MainClass(1,0).toString()'); - final evaluation2 = setup.service + final evaluation2 = context.service .evaluate(isolateId, library.id!, 'MainClass(1,1).toString()'); final results = await Future.wait([evaluation1, evaluation2]); @@ -622,11 +583,11 @@ void testAll({ test('with scope override', () async { final library = isolate.rootLib!; - final object = await setup.service + final object = await context.service .evaluate(isolateId, library.id!, 'MainClass(1,0)'); final param = object as InstanceRef; - final result = await setup.service.evaluate( + final result = await context.service.evaluate( isolateId, library.id!, 't.toString()', scope: {'t': param.id!}); @@ -638,7 +599,7 @@ void testAll({ test('uses symbol from the same library', () async { final library = isolate.rootLib!; - final result = await setup.service + final result = await context.service .evaluate(isolateId, library.id!, 'MainClass(1,0).toString()'); expect( @@ -649,7 +610,7 @@ void testAll({ test('uses symbol from another library', () async { final library = isolate.rootLib!; - final result = await setup.service.evaluate( + final result = await context.service.evaluate( isolateId, library.id!, 'TestLibraryClass(0,1).toString()'); expect( @@ -662,7 +623,7 @@ void testAll({ test('closure call', () async { final library = isolate.rootLib!; - final result = await setup.service + final result = await context.service .evaluate(isolateId, library.id!, '(() => 42)()'); expect( @@ -698,20 +659,20 @@ void testAll({ late Stream stream; setUp(() async { - vm = await setup.service.getVM(); - isolate = await setup.service.getIsolate(vm.isolates!.first.id!); + vm = await context.service.getVM(); + isolate = await context.service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; - scripts = await setup.service.getScripts(isolateId); + scripts = await context.service.getScripts(isolateId); - await setup.service.streamListen('Debug'); - stream = setup.service.onEvent('Debug'); + await context.service.streamListen('Debug'); + stream = context.service.onEvent('Debug'); mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); }); tearDown(() async { - await setup.service.resume(isolateId); + await context.service.resume(isolateId); }); test('cannot evaluate expression', () async { @@ -720,7 +681,7 @@ void testAll({ .firstWhere((event) => event.kind == EventKind.kPauseBreakpoint); await expectLater( - setup.service + context.service .evaluateInFrame(isolateId, event.topFrame!.index!, 'local'), throwsRPCError); }); diff --git a/dwds/test/events_test.dart b/dwds/test/events_test.dart index 4453a2444..31faad5a2 100644 --- a/dwds/test/events_test.dart +++ b/dwds/test/events_test.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'dart:io'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/events.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/utilities/server.dart'; @@ -14,16 +13,13 @@ import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'package:webdriver/async_core.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); +final context = TestContext(TestProject.testWithSoundNullSafety); -WipConnection get tabConnection => context.tabConnection; - -final context = TestContext.withSoundNullSafety(); +ChromeProxyService get service => context.service; void main() { group('serve requests', () { diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 3fcd2a836..5b7f174c5 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -19,6 +19,7 @@ import 'package:dwds/src/loaders/frontend_server_require.dart'; import 'package:dwds/src/loaders/require.dart'; import 'package:dwds/src/loaders/strategy.dart'; import 'package:dwds/src/readers/proxy_server_asset_reader.dart'; +import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/services/expression_compiler_service.dart'; import 'package:dwds/src/utilities/dart_uri.dart'; import 'package:dwds/src/utilities/server.dart'; @@ -38,6 +39,7 @@ import 'package:vm_service/vm_service.dart'; import 'package:webdriver/io.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; +import 'project.dart'; import 'server.dart'; import 'utilities.dart'; @@ -51,38 +53,36 @@ final Matcher throwsSentinelException = throwsA(isSentinelException); enum CompilationMode { buildDaemon, frontendServer } -enum IndexBaseMode { noBase, base } - -enum NullSafety { weak, sound } - class TestContext { - final String packageName; - final String webAssetsPath; - final String dartEntryFileName; - final String htmlEntryFileName; + final TestProject project; 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); + String get workingDirectory => + absolutePath(pathFromFixtures: project.packageDirectory); /// The directory to build and serve, e.g. "example". - String get directoryToServe => p.split(webAssetsPath).first; + String get directoryToServe => p.split(project.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( + final pathParts = p.split(project.webAssetsPath).where( (pathPart) => pathPart != directoryToServe, ); - return webCompatiblePath([...pathParts, htmlEntryFileName]); + return webCompatiblePath([...pathParts, project.htmlEntryFileName]); } /// The path to the Dart entry file, e.g, /// "/workstation/webdev/fixtures/_testSound/example/hello_world/main.dart": String get _dartEntryFilePath => absolutePath( pathFromFixtures: p.joinAll( - [packageName, webAssetsPath, dartEntryFileName], + [ + project.packageDirectory, + project.webAssetsPath, + project.dartEntryFileName, + ], ), ); @@ -135,47 +135,20 @@ class TestContext { final _logger = logging.Logger('Context'); - 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, - ); + /// Internal VM service. + /// + /// Prefer using [vmService] instead in tests when possible, to include testing + /// of the VmServerConnection (bypassed when using [service]). + ChromeProxyService get service => fetchChromeProxyService(debugConnection); - TestContext._({ - required this.packageName, - required this.webAssetsPath, - required this.dartEntryFileName, - required this.htmlEntryFileName, - required this.nullSafety, - }) { - // 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('/')); + /// External VM service. + VmServiceInterface get vmService => debugConnection.vmService; + TestContext(this.project) : nullSafety = project.nullSafety { DartUri.currentDirectory = workingDirectory; + project.validate(); + _logger.info('Serving: $directoryToServe/$filePathToServe'); _logger.info('Project: $workingDirectory'); _logger.info('Packages: $_packageConfigFile'); @@ -316,7 +289,8 @@ class TestContext { { _logger.warning('Index: $filePathToServe'); - final entry = p.toUri(p.join(webAssetsPath, dartEntryFileName)); + final entry = p.toUri( + p.join(project.webAssetsPath, project.dartEntryFileName)); final fileSystem = LocalFileSystem(); final packageUriMapper = await PackageUriMapper.create( fileSystem, diff --git a/dwds/test/fixtures/project.dart b/dwds/test/fixtures/project.dart new file mode 100644 index 000000000..e1a5c6100 --- /dev/null +++ b/dwds/test/fixtures/project.dart @@ -0,0 +1,178 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'utilities.dart'; + +enum NullSafety { weak, sound } + +enum IndexBaseMode { noBase, base } + +/// Project definitions from projects defined in webdev/fixtures. +class TestProject { + final String packageName; + final String packageDirectory; + final String webAssetsPath; + final String dartEntryFileName; + final String htmlEntryFileName; + final NullSafety nullSafety; + + String get absolutePackageDirectory => + absolutePath(pathFromFixtures: packageDirectory); + + const TestProject.testPackageWithSoundNullSafety( + {IndexBaseMode baseMode = IndexBaseMode.noBase}) + : this._( + packageName: '_test_package_sound', + packageDirectory: '_testPackageSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html', + nullSafety: NullSafety.sound, + ); + + const TestProject.testPackageWithWeakNullSafety( + {IndexBaseMode baseMode = IndexBaseMode.noBase}) + : this._( + packageName: '_test_package', + packageDirectory: '_testPackage', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html', + nullSafety: NullSafety.weak, + ); + + factory TestProject.testPackage({ + NullSafety nullSafety = NullSafety.sound, + IndexBaseMode baseMode = IndexBaseMode.noBase, + }) => + nullSafety == NullSafety.sound + ? TestProject.testPackageWithSoundNullSafety(baseMode: baseMode) + : TestProject.testPackageWithWeakNullSafety(baseMode: baseMode); + + static const testCircular1WithSoundNullSafety = TestProject._( + packageName: '_test_circular1_sound', + packageDirectory: '_testCircular1Sound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + static const testCircular1WithWeakNullSafety = TestProject._( + packageName: '_test_circular1', + packageDirectory: '_testCircular1', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.weak, + ); + + factory TestProject.testCircular1( + {NullSafety nullSafety = NullSafety.sound}) => + nullSafety == NullSafety.sound + ? TestProject.testCircular1WithSoundNullSafety + : TestProject.testCircular1WithWeakNullSafety; + + const TestProject.testCircular2WithSoundNullSafety( + {IndexBaseMode baseMode = IndexBaseMode.noBase}) + : this._( + packageName: '_test_circular2_sound', + packageDirectory: '_testCircular2Sound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html', + nullSafety: NullSafety.sound, + ); + + const TestProject.testCircular2WithWeakNullSafety( + {IndexBaseMode baseMode = IndexBaseMode.noBase}) + : this._( + packageName: '_test_circular2', + packageDirectory: '_testCircular2', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: + baseMode == IndexBaseMode.base ? 'base_index.html' : 'index.html', + nullSafety: NullSafety.weak, + ); + + factory TestProject.testCircular2({ + NullSafety nullSafety = NullSafety.sound, + IndexBaseMode baseMode = IndexBaseMode.noBase, + }) => + nullSafety == NullSafety.sound + ? TestProject.testCircular2WithSoundNullSafety(baseMode: baseMode) + : TestProject.testCircular2WithWeakNullSafety(baseMode: baseMode); + + static const testWithSoundNullSafety = TestProject._( + packageName: '_test_sound', + packageDirectory: '_testSound', + webAssetsPath: 'example/hello_world', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + static const testWithWeakNullSafety = TestProject._( + packageName: '_test', + packageDirectory: '_test', + webAssetsPath: 'example/hello_world', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.weak, + ); + + factory TestProject.test({NullSafety nullSafety = NullSafety.sound}) => + nullSafety == NullSafety.sound + ? TestProject.testWithSoundNullSafety + : TestProject.testWithWeakNullSafety; + + static final testScopesWithSoundNullSafety = TestProject._( + packageName: '_test_sound', + packageDirectory: '_testSound', + webAssetsPath: webCompatiblePath(['example', 'scopes']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'scopes.html', + nullSafety: NullSafety.sound, + ); + + static final testAppendBodyWithSoundNullSafety = TestProject._( + packageName: '_test_sound', + packageDirectory: '_testSound', + webAssetsPath: webCompatiblePath(['example', 'append_body']), + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + static const testExperimentWithSoundNullSafety = TestProject._( + packageName: '_experiment_sound', + packageDirectory: '_experimentSound', + webAssetsPath: 'web', + dartEntryFileName: 'main.dart', + htmlEntryFileName: 'index.html', + nullSafety: NullSafety.sound, + ); + + const TestProject._({ + required this.packageName, + required this.packageDirectory, + required this.webAssetsPath, + required this.dartEntryFileName, + required this.htmlEntryFileName, + required this.nullSafety, + }); + + void validate() { + // Verify that the test fixtures package matches the null-safety mode: + final isSoundPackage = packageDirectory.toLowerCase().contains('sound'); + assert(nullSafety == NullSafety.sound ? isSoundPackage : !isSoundPackage); + + // Verify that the web assets path has no starting slash: + assert(!webAssetsPath.startsWith('/')); + } +} diff --git a/dwds/test/frontend_server_breakpoint_test.dart b/dwds/test/frontend_server_breakpoint_test.dart index f9498a353..4adc5fe3b 100644 --- a/dwds/test/frontend_server_breakpoint_test.dart +++ b/dwds/test/frontend_server_breakpoint_test.dart @@ -6,25 +6,17 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', -); +final context = TestContext(TestProject.testPackageWithSoundNullSafety()); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; +ChromeProxyService get service => context.service; void main() { // Enable verbose logging for debugging. diff --git a/dwds/test/frontend_server_callstack_test.dart b/dwds/test/frontend_server_callstack_test.dart index ec6566dfb..3159449d5 100644 --- a/dwds/test/frontend_server_callstack_test.dart +++ b/dwds/test/frontend_server_callstack_test.dart @@ -6,40 +6,13 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; - -class TestSetup { - static final contextUnsound = TestContext.withWeakNullSafety( - packageName: '_testPackage', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - static final contextSound = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - TestContext context; - - TestSetup.sound() : context = contextSound; - - TestSetup.unsound() : context = contextUnsound; - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); - WipConnection get tabConnection => context.tabConnection; -} +import 'fixtures/project.dart'; void main() { group('shared context |', () { @@ -48,9 +21,8 @@ void main() { for (var nullSafety in NullSafety.values) { group('${nullSafety.name} null safety |', () { - final soundNullSafety = nullSafety == NullSafety.sound; - final setup = soundNullSafety ? TestSetup.sound() : TestSetup.unsound(); - final context = setup.context; + final project = TestProject.testPackage(nullSafety: nullSafety); + final context = TestContext(project); setUpAll(() async { setCurrentLogWriter(debug: debug); @@ -76,7 +48,7 @@ void main() { setUp(() async { setCurrentLogWriter(debug: debug); - service = setup.service; + service = context.service; vm = await service.getVM(); isolate = await service.getIsolate(vm.isolates!.first.id!); isolateId = isolate.id!; @@ -85,9 +57,7 @@ void main() { await service.streamListen('Debug'); stream = service.onEvent('Debug'); - final testPackage = - soundNullSafety ? '_test_package_sound' : '_test_package'; - + final testPackage = project.packageName; mainScript = scripts.scripts! .firstWhere((each) => each.uri!.contains('main.dart')); testLibraryScript = scripts.scripts!.firstWhere((each) => @@ -106,7 +76,7 @@ void main() { final script = breakpoint.script; final line = await context.findBreakpointLine(bpId, isolateId, script); - bp = await setup.service + bp = await context.service .addBreakpointWithScriptUri(isolateId, script.uri!, line); expect(bp, isNotNull); @@ -119,7 +89,7 @@ void main() { } finally { // Remove breakpoint so it doesn't impact other tests or retries. if (bp != null) { - await setup.service.removeBreakpoint(isolateId, bp.id!); + await context.service.removeBreakpoint(isolateId, bp.id!); } } } diff --git a/dwds/test/frontend_server_circular_evaluate_test.dart b/dwds/test/frontend_server_circular_evaluate_test.dart index 896e6f4c3..437583be9 100644 --- a/dwds/test/frontend_server_circular_evaluate_test.dart +++ b/dwds/test/frontend_server_circular_evaluate_test.dart @@ -12,6 +12,7 @@ import 'package:test/test.dart'; import 'evaluate_circular_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/frontend_server_evaluate_sound_test.dart b/dwds/test/frontend_server_evaluate_sound_test.dart index 6877c481e..4642748fa 100644 --- a/dwds/test/frontend_server_evaluate_sound_test.dart +++ b/dwds/test/frontend_server_evaluate_sound_test.dart @@ -11,6 +11,7 @@ import 'package:test/test.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/frontend_server_evaluate_weak_test.dart b/dwds/test/frontend_server_evaluate_weak_test.dart index 113dea4d3..1b88cfb7a 100644 --- a/dwds/test/frontend_server_evaluate_weak_test.dart +++ b/dwds/test/frontend_server_evaluate_weak_test.dart @@ -11,6 +11,7 @@ import 'package:test/test.dart'; import 'evaluate_common.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; void main() async { // Enable verbose logging for debugging. diff --git a/dwds/test/handlers/asset_handler_test.dart b/dwds/test/handlers/asset_handler_test.dart index 4b6e5d585..ab2a34cea 100644 --- a/dwds/test/handlers/asset_handler_test.dart +++ b/dwds/test/handlers/asset_handler_test.dart @@ -9,10 +9,11 @@ import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; void main() { group('Asset handler', () { - final context = TestContext.withSoundNullSafety(); + final context = TestContext(TestProject.testWithSoundNullSafety); setUpAll(() async { setCurrentLogWriter(); diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index 10100f93b..894dc1684 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -16,15 +16,9 @@ import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -import 'fixtures/utilities.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety( - webAssetsPath: webCompatiblePath(['example', 'scopes']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'scopes.html', -); - -WipConnection get tabConnection => context.tabConnection; +final context = TestContext(TestProject.testScopesWithSoundNullSafety); void main() { late AppInspector inspector; diff --git a/dwds/test/instances/instance_inspection_test.dart b/dwds/test/instances/instance_inspection_test.dart index 082e8245d..7cf729015 100644 --- a/dwds/test/instances/instance_inspection_test.dart +++ b/dwds/test/instances/instance_inspection_test.dart @@ -5,30 +5,14 @@ @TestOn('vm') @Timeout(Duration(minutes: 2)) -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; import 'instance_inspection_common.dart'; -class TestSetup { - TestContext context; - - TestSetup.sound() - : context = TestContext.withSoundNullSafety( - packageName: '_testPackageSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -} - void main() async { // Enable verbose logging for debugging. final debug = false; @@ -45,8 +29,7 @@ Future _runTests({ required CompilationMode compilationMode, required bool debug, }) async { - final setup = TestSetup.sound(); - final context = setup.context; + final context = TestContext(TestProject.testPackageWithSoundNullSafety()); late VmServiceInterface service; late Stream stream; late String isolateId; @@ -77,8 +60,7 @@ Future _runTests({ verboseCompiler: debug, experiments: ['records'], ); - service = setup.service; - + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; final scripts = await service.getScripts(isolateId); @@ -109,8 +91,8 @@ Future _runTests({ // Offsets and counts are ignored for plain object fields. - // DevTools calls [getObject] with offset=0 and count=0 and - // expects all fields to be returned. + // DevTools calls [VmServiceInterface.getObject] with offset=0 + // and count=0 and expects all fields to be returned. expect(await getFields(instanceRef, offset: 0, count: 0), {'_field': 1, 'field': 2}); expect(await getFields(instanceRef, offset: 0), diff --git a/dwds/test/instances/instance_test.dart b/dwds/test/instances/instance_test.dart index 8a1e4d60c..d4072aa9a 100644 --- a/dwds/test/instances/instance_test.dart +++ b/dwds/test/instances/instance_test.dart @@ -14,13 +14,9 @@ import 'package:vm_service/vm_service.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import '../fixtures/context.dart'; -import '../fixtures/utilities.dart'; +import '../fixtures/project.dart'; -final context = TestContext.withSoundNullSafety( - webAssetsPath: webCompatiblePath(['example', 'scopes']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'scopes.html', -); +final context = TestContext(TestProject.testScopesWithSoundNullSafety); WipConnection get tabConnection => context.tabConnection; diff --git a/dwds/test/instances/record_inspection_test.dart b/dwds/test/instances/record_inspection_test.dart index 3990a385f..86fa0b18f 100644 --- a/dwds/test/instances/record_inspection_test.dart +++ b/dwds/test/instances/record_inspection_test.dart @@ -5,30 +5,14 @@ @TestOn('vm') @Timeout(Duration(minutes: 2)) -import 'package:dwds/src/connections/debug_connection.dart'; -import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; import 'instance_inspection_common.dart'; -class TestSetup { - TestContext context; - - TestSetup.sound() - : context = TestContext.withSoundNullSafety( - packageName: '_experimentSound', - webAssetsPath: 'web', - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', - ); - - ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -} - void main() async { // Enable verbose logging for debugging. final debug = false; @@ -45,15 +29,14 @@ Future _runTests({ required CompilationMode compilationMode, required bool debug, }) async { - final setup = TestSetup.sound(); - final context = setup.context; + final context = TestContext(TestProject.testExperimentWithSoundNullSafety); + final testInspector = TestInspector(context); + late VmServiceInterface service; late Stream stream; late String isolateId; late ScriptRef mainScript; - final testInspector = TestInspector(context); - onBreakPoint(breakPointId, body) => testInspector.onBreakPoint( stream, isolateId, mainScript, breakPointId, body); @@ -77,8 +60,7 @@ Future _runTests({ verboseCompiler: debug, experiments: ['records'], ); - service = setup.service; - + service = context.service; final vm = await service.getVM(); isolateId = vm.isolates!.first.id!; final scripts = await service.getScripts(isolateId); diff --git a/dwds/test/listviews_test.dart b/dwds/test/listviews_test.dart index db3c5b1fd..1ec528bda 100644 --- a/dwds/test/listviews_test.dart +++ b/dwds/test/listviews_test.dart @@ -7,8 +7,9 @@ import 'package:test/test.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); void main() { setUpAll(() async { diff --git a/dwds/test/package_uri_mapper_test.dart b/dwds/test/package_uri_mapper_test.dart index 9bf1f18bc..f4185b0a7 100644 --- a/dwds/test/package_uri_mapper_test.dart +++ b/dwds/test/package_uri_mapper_test.dart @@ -12,27 +12,27 @@ import 'package:file/local.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; -import 'fixtures/utilities.dart'; +import 'fixtures/project.dart'; void main() { + final project = TestProject.testPackageWithSoundNullSafety(); for (final useDebuggerModuleNames in [true, false]) { group( 'Package uri mapper with debugger module names: ' ' $useDebuggerModuleNames |', () { final fileSystem = LocalFileSystem(); - final packageUri = - Uri(scheme: 'package', path: '_test_package_sound/test_library.dart'); + final packageUri = Uri( + scheme: 'package', path: '${project.packageName}/test_library.dart'); final serverPath = useDebuggerModuleNames - ? 'packages/_testPackageSound/lib/test_library.dart' - : '/packages/_test_package_sound/test_library.dart'; + ? 'packages/${project.packageDirectory}/lib/test_library.dart' + : '/packages/${project.packageName}/test_library.dart'; final resolvedPath = - '/webdev/fixtures/_testPackageSound/lib/test_library.dart'; + '/webdev/fixtures/${project.packageDirectory}/lib/test_library.dart'; - final testPackageSoundPath = - absolutePath(pathFromFixtures: '_testPackageSound'); + final testPackageSoundPath = project.absolutePackageDirectory; final packageConfigFile = Uri.file(p.join( testPackageSoundPath, diff --git a/dwds/test/puppeteer/extension_test.dart b/dwds/test/puppeteer/extension_test.dart index 8731dfce5..70981d456 100644 --- a/dwds/test/puppeteer/extension_test.dart +++ b/dwds/test/puppeteer/extension_test.dart @@ -22,6 +22,7 @@ import 'package:test/test.dart'; import '../../debug_extension_mv3/web/data_serializers.dart'; import '../../debug_extension_mv3/web/data_types.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; import '../fixtures/utilities.dart'; import 'test_utils.dart'; @@ -34,7 +35,7 @@ import 'test_utils.dart'; // To run the MV2 tests only: // dart test test/puppeteer/extension_test.dart --r=expanded --no-retry --n="MV2 Debug Extension" -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); enum Panel { debugger, inspector } diff --git a/dwds/test/puppeteer/lifeline_test.dart b/dwds/test/puppeteer/lifeline_test.dart index 13a0359fd..dc4f95d37 100644 --- a/dwds/test/puppeteer/lifeline_test.dart +++ b/dwds/test/puppeteer/lifeline_test.dart @@ -10,9 +10,10 @@ import 'package:puppeteer/puppeteer.dart'; import 'package:test/test.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; import 'test_utils.dart'; -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); void main() async { late Worker worker; diff --git a/dwds/test/readers/proxy_server_asset_reader_test.dart b/dwds/test/readers/proxy_server_asset_reader_test.dart index eade1e6b0..b2363bb11 100644 --- a/dwds/test/readers/proxy_server_asset_reader_test.dart +++ b/dwds/test/readers/proxy_server_asset_reader_test.dart @@ -8,10 +8,11 @@ import 'package:dwds/src/readers/proxy_server_asset_reader.dart'; import 'package:test/test.dart'; import '../fixtures/context.dart'; +import '../fixtures/project.dart'; void main() { group('ProxyServerAssetReader', () { - final context = TestContext.withWeakNullSafety(); + final context = TestContext(TestProject.testWithSoundNullSafety); late ProxyServerAssetReader assetReader; setUpAll(() async { await context.setUp(); @@ -29,14 +30,14 @@ void main() { }); test('can read source maps', () async { - final result = await assetReader - .dartSourceContents('hello_world/main.unsound.ddc.js.map'); + final result = + await assetReader.dartSourceContents('hello_world/main.ddc.js.map'); expect(result, isNotNull); }); test('returns null if the source map path does not exist', () async { - final result = await assetReader - .dartSourceContents('hello_world/foo.unsound.ddc.js.map'); + final result = + await assetReader.dartSourceContents('hello_world/foo.ddc.js.map'); expect(result, isNull); }); }); diff --git a/dwds/test/refresh_test.dart b/dwds/test/refresh_test.dart index 2fc125b9e..e7d1eaf6a 100644 --- a/dwds/test/refresh_test.dart +++ b/dwds/test/refresh_test.dart @@ -10,18 +10,16 @@ library refresh_test; import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; 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/project.dart'; -final context = TestContext.withSoundNullSafety(); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; +final context = TestContext(TestProject.testWithSoundNullSafety); + +ChromeProxyService get service => context.service; void main() { group('fresh context', () { diff --git a/dwds/test/reload_test.dart b/dwds/test/reload_test.dart index bffa17e1d..5dd30e98a 100644 --- a/dwds/test/reload_test.dart +++ b/dwds/test/reload_test.dart @@ -10,13 +10,9 @@ import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; -import 'fixtures/utilities.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety( - webAssetsPath: webCompatiblePath(['example', 'append_body']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'index.html', -); +final context = TestContext(TestProject.testAppendBodyWithSoundNullSafety); const originalString = 'Hello World!'; const newString = 'Bonjour le monde!'; diff --git a/dwds/test/restore_breakpoints_test.dart b/dwds/test/restore_breakpoints_test.dart index d9313ce15..1629c22d6 100644 --- a/dwds/test/restore_breakpoints_test.dart +++ b/dwds/test/restore_breakpoints_test.dart @@ -11,14 +11,13 @@ import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:test_common/logging.dart'; import 'package:vm_service/vm_service.dart'; -import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety(); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); -WipConnection get tabConnection => context.tabConnection; +final context = TestContext(TestProject.testWithSoundNullSafety); + +ChromeProxyService get service => context.service; void main() { setUpAll(() async { diff --git a/dwds/test/run_request_test.dart b/dwds/test/run_request_test.dart index 5b461bdf7..8cb878396 100644 --- a/dwds/test/run_request_test.dart +++ b/dwds/test/run_request_test.dart @@ -5,17 +5,16 @@ @Timeout(Duration(minutes: 2)) import 'dart:async'; -import 'package:dwds/src/connections/debug_connection.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:test/test.dart'; import 'package:vm_service/vm_service.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); +ChromeProxyService get service => context.service; void main() { group('while debugger is attached', () { diff --git a/dwds/test/screenshot_test.dart b/dwds/test/screenshot_test.dart index 9410abf1e..84a2c4814 100644 --- a/dwds/test/screenshot_test.dart +++ b/dwds/test/screenshot_test.dart @@ -7,8 +7,9 @@ import 'package:test/test.dart'; import 'fixtures/context.dart'; +import 'fixtures/project.dart'; -final context = TestContext.withSoundNullSafety(); +final context = TestContext(TestProject.testWithSoundNullSafety); void main() { setUpAll(() async { diff --git a/dwds/test/variable_scope_test.dart b/dwds/test/variable_scope_test.dart index 19a7c7eb6..40c2c2cd0 100644 --- a/dwds/test/variable_scope_test.dart +++ b/dwds/test/variable_scope_test.dart @@ -4,7 +4,7 @@ @TestOn('vm') @Timeout(Duration(minutes: 2)) -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:test/test.dart'; @@ -12,15 +12,11 @@ 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.withSoundNullSafety( - webAssetsPath: webCompatiblePath(['example', 'scopes']), - dartEntryFileName: 'main.dart', - htmlEntryFileName: 'scopes.html', -); -ChromeProxyService get service => - fetchChromeProxyService(context.debugConnection); +import 'fixtures/project.dart'; + +final context = TestContext(TestProject.testScopesWithSoundNullSafety); + +ChromeProxyService get service => context.service; WipConnection get tabConnection => context.tabConnection; void main() {