diff --git a/frontend_server_client/test/frontend_sever_client_test.dart b/frontend_server_client/test/frontend_server_client_test.dart similarity index 56% rename from frontend_server_client/test/frontend_sever_client_test.dart rename to frontend_server_client/test/frontend_server_client_test.dart index 4deab4fac..95ecf81e9 100644 --- a/frontend_server_client/test/frontend_sever_client_test.dart +++ b/frontend_server_client/test/frontend_server_client_test.dart @@ -58,123 +58,135 @@ String get message => p.join('hello', 'world'); await client.shutdown(); }); - test('can compile, recompile, and hot reload a vm app', () async { - var entrypoint = p.join(packageRoot, 'bin', 'main.dart'); - client = await FrontendServerClient.start( - entrypoint, p.join(packageRoot, 'out.dill'), vmPlatformDill); - var result = await client.compile(); - client.accept(); - expect(result.compilerOutputLines, isEmpty); - expect(result.errorCount, 0); - expect( - result.newSources, - containsAll([ - File(entrypoint).uri, - packageConfig.resolve(Uri.parse('package:path/path.dart')), - ])); - expect(result.removedSources, isEmpty); - expect(result.dillOutput, isNotNull); - expect(File(result.dillOutput!).existsSync(), true); - var process = await Process.start(Platform.resolvedExecutable, [ - '--observe', - '--no-pause-isolates-on-exit', - '--pause-isolates-on-start', - result.dillOutput! - ]); - addTearDown(process.kill); - var stdoutLines = StreamQueue( - process.stdout.transform(utf8.decoder).transform(const LineSplitter())); - - var observatoryLine = await stdoutLines.next; - var observatoryUri = - '${observatoryLine.split(' ').last.replaceFirst('http', 'ws')}ws'; - var vmService = await vmServiceConnectUri(observatoryUri); - var isolate = await waitForIsolatesAndResume(vmService); - - await expectLater(stdoutLines, emitsThrough(p.join('hello', 'world'))); - - var appFile = File(entrypoint); - var originalContent = await appFile.readAsString(); - var newContent = originalContent.replaceFirst('hello', 'goodbye'); - await appFile.writeAsString(newContent); - - result = await client.compile([File(entrypoint).uri]); - - client.accept(); - expect(result.newSources, isEmpty); - expect(result.removedSources, isEmpty); - expect(result.compilerOutputLines, isEmpty); - expect(result.errorCount, 0); - expect(result.dillOutput, endsWith('.incremental.dill')); - - await vmService.reloadSources(isolate.id!, rootLibUri: result.dillOutput); - - expect(await stdoutLines.next, p.join('goodbye', 'world')); - expect(await process.exitCode, 0); - }); - - test('can handle compile errors and reload fixes', () async { - var entrypoint = p.join(packageRoot, 'bin', 'main.dart'); - var entrypointFile = File(entrypoint); - var originalContent = await entrypointFile.readAsString(); - // append two compile errors to the bottom - await entrypointFile - .writeAsString('$originalContent\nint foo = 1.0;\nString bar = 4;'); - - client = await FrontendServerClient.start( - entrypoint, p.join(packageRoot, 'out.dill'), vmPlatformDill); - var result = await client.compile(); - - client.accept(); - expect(result.errorCount, 2); - expect(result.compilerOutputLines, - allOf(contains('int foo = 1.0;'), contains('String bar = 4;'))); - expect( - result.newSources, - containsAll([ - File(entrypoint).uri, - packageConfig.resolve(Uri.parse('package:path/path.dart')), - ])); - expect(result.removedSources, isEmpty); - expect(result.dillOutput, isNotNull); - expect(File(result.dillOutput!).existsSync(), true); - - var process = await Process.start(Platform.resolvedExecutable, [ - '--observe', - '--no-pause-isolates-on-exit', - '--pause-isolates-on-start', - result.dillOutput! - ]); - addTearDown(process.kill); - var stdoutLines = StreamQueue( - process.stdout.transform(utf8.decoder).transform(const LineSplitter())); - - var observatoryLine = await stdoutLines.next; - var observatoryUri = - '${observatoryLine.split(' ').last.replaceFirst('http', 'ws')}ws'; - var vmService = await vmServiceConnectUri(observatoryUri); - var isolate = await waitForIsolatesAndResume(vmService); - - // The program actually runs regardless of the errors, as they don't affect - // the runtime behavior. - await expectLater(stdoutLines, emitsThrough(p.join('hello', 'world'))); - - await entrypointFile - .writeAsString(originalContent.replaceFirst('hello', 'goodbye')); - result = await client.compile([entrypointFile.uri]); - client.accept(); - expect(result.errorCount, 0); - expect(result.compilerOutputLines, isEmpty); - expect(result.newSources, isEmpty); - expect(result.removedSources, isEmpty); - expect(result.dillOutput, isNotNull); - expect(File(result.dillOutput!).existsSync(), true); - - await vmService.reloadSources(isolate.id!, rootLibUri: result.dillOutput); - - expect(await stdoutLines.next, p.join('goodbye', 'world')); - expect(await process.exitCode, 0); - }); + test( + 'can compile, recompile, and hot reload a vm app', + () async { + var entrypoint = p.join(packageRoot, 'bin', 'main.dart'); + client = await FrontendServerClient.start( + entrypoint, p.join(packageRoot, 'out.dill'), vmPlatformDill); + var result = await client.compile(); + client.accept(); + expect(result.compilerOutputLines, isEmpty); + expect(result.errorCount, 0); + expect( + result.newSources, + containsAll([ + File(entrypoint).uri, + packageConfig.resolve(Uri.parse('package:path/path.dart')), + ])); + expect(result.removedSources, isEmpty); + expect(result.dillOutput, isNotNull); + expect(File(result.dillOutput!).existsSync(), true); + var process = await Process.start(Platform.resolvedExecutable, [ + '--observe', + '--no-pause-isolates-on-exit', + '--pause-isolates-on-start', + result.dillOutput! + ]); + addTearDown(process.kill); + var stdoutLines = StreamQueue(process.stdout + .transform(utf8.decoder) + .transform(const LineSplitter())); + + var observatoryLine = await stdoutLines.next; + var observatoryUri = + '${observatoryLine.split(' ').last.replaceFirst('http', 'ws')}ws'; + var vmService = await vmServiceConnectUri(observatoryUri); + var isolate = await waitForIsolatesAndResume(vmService); + + await expectLater(stdoutLines, emitsThrough(p.join('hello', 'world'))); + + var appFile = File(entrypoint); + var originalContent = await appFile.readAsString(); + var newContent = originalContent.replaceFirst('hello', 'goodbye'); + await appFile.writeAsString(newContent); + + result = await client.compile([File(entrypoint).uri]); + + client.accept(); + expect(result.newSources, isEmpty); + expect(result.removedSources, isEmpty); + expect(result.compilerOutputLines, isEmpty); + expect(result.errorCount, 0); + expect(result.dillOutput, endsWith('.incremental.dill')); + + await vmService.reloadSources(isolate.id!, rootLibUri: result.dillOutput); + + expect(await stdoutLines.next, p.join('goodbye', 'world')); + expect(await process.exitCode, 0); + }, + // Issue: https://github.com/dart-lang/webdev/issues/2377 + skip: Platform.isWindows, + ); + + test( + 'can handle compile errors and reload fixes', + () async { + var entrypoint = p.join(packageRoot, 'bin', 'main.dart'); + var entrypointFile = File(entrypoint); + var originalContent = await entrypointFile.readAsString(); + // append two compile errors to the bottom + await entrypointFile + .writeAsString('$originalContent\nint foo = 1.0;\nString bar = 4;'); + + client = await FrontendServerClient.start( + entrypoint, p.join(packageRoot, 'out.dill'), vmPlatformDill); + var result = await client.compile(); + + client.accept(); + expect(result.errorCount, 2); + expect(result.compilerOutputLines, + allOf(contains('int foo = 1.0;'), contains('String bar = 4;'))); + expect( + result.newSources, + containsAll([ + File(entrypoint).uri, + packageConfig.resolve(Uri.parse('package:path/path.dart')), + ])); + expect(result.removedSources, isEmpty); + expect(result.dillOutput, isNotNull); + expect(File(result.dillOutput!).existsSync(), true); + + var process = await Process.start(Platform.resolvedExecutable, [ + '--observe', + '--no-pause-isolates-on-exit', + '--pause-isolates-on-start', + result.dillOutput! + ]); + addTearDown(process.kill); + var stdoutLines = StreamQueue(process.stdout + .transform(utf8.decoder) + .transform(const LineSplitter())); + + var observatoryLine = await stdoutLines.next; + var observatoryUri = + '${observatoryLine.split(' ').last.replaceFirst('http', 'ws')}ws'; + var vmService = await vmServiceConnectUri(observatoryUri); + var isolate = await waitForIsolatesAndResume(vmService); + + // The program actually runs regardless of the errors, as they don't affect + // the runtime behavior. + await expectLater(stdoutLines, emitsThrough(p.join('hello', 'world'))); + + await entrypointFile + .writeAsString(originalContent.replaceFirst('hello', 'goodbye')); + result = await client.compile([entrypointFile.uri]); + client.accept(); + expect(result.errorCount, 0); + expect(result.compilerOutputLines, isEmpty); + expect(result.newSources, isEmpty); + expect(result.removedSources, isEmpty); + expect(result.dillOutput, isNotNull); + expect(File(result.dillOutput!).existsSync(), true); + + await vmService.reloadSources(isolate.id!, rootLibUri: result.dillOutput); + + expect(await stdoutLines.next, p.join('goodbye', 'world')); + expect(await process.exitCode, 0); + }, + // Issue: https://github.com/dart-lang/webdev/issues/2377 + skip: Platform.isWindows, + ); test('can compile and recompile a dartdevc app', () async { var entrypoint =