From c28fbe1a1211606b0ca6be59e26b12bd4d4f6d1f Mon Sep 17 00:00:00 2001 From: AnhQuan Nguyen Date: Thu, 6 Jun 2024 19:32:45 -0500 Subject: [PATCH] fix up env test --- packages/cli/test/build_test.dart | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/cli/test/build_test.dart b/packages/cli/test/build_test.dart index 823a83c3d..117c45cad 100644 --- a/packages/cli/test/build_test.dart +++ b/packages/cli/test/build_test.dart @@ -2,8 +2,8 @@ import 'dart:io'; import 'package:fs_test_agent/dart_project_agent.dart'; import 'package:fs_test_agent/working_directory_agent.dart'; -import 'package:path/path.dart'; import 'package:test/test.dart'; +import 'package:http/http.dart' as http; import 'not_tests/cli_helpers.dart'; @@ -70,16 +70,16 @@ void main() { }); test("Build works with define", () async { - final File mainFile = File( - join(cli.agent.workingDirectory.path, "test_project/bin/main.dart")); + final File mainFile = File(cli.agent.workingDirectory.uri + .resolve("test_project/lib/channel.dart") + .toFilePath(windows: Platform.isWindows)); await mainFile.readAsString().then((String source) { mainFile.writeAsStringSync(source.replaceFirst( - 'await app.startOnCurrentIsolate();', - 'if (String.fromEnvironment("FOO").isNotEmpty) throw "";await app.startOnCurrentIsolate();')); + 'return Response.ok({"key": "value"});', + '''const lit = String.fromEnvironment("FOO"); + return Response.ok({"key": lit});''')); }); - print(mainFile.readAsStringSync()); - final res = await cli.run("build", [ "--define=FOO=BAR", "--directory", @@ -87,10 +87,6 @@ void main() { ]); expect(res, 0); - print(File( - join(cli.agent.workingDirectory.path, "/test_project/test_project.aot"), - )); - final binPath = cli.agent.workingDirectory.uri .resolve("test_project/test_project.aot") .toFilePath(windows: Platform.isWindows); @@ -103,9 +99,10 @@ void main() { final binRes = await Process.start(binPath, []); pids.add(binRes.pid); - - expect(String.fromCharCodes(await binRes.stdout.first), isEmpty); - expect(await binRes.exitCode, 1); + expect(String.fromCharCodes(await binRes.stdout.first), + contains("[INFO] conduit: Server conduit/1 started.")); + final response = await http.get(Uri.parse('http://0.0.0.0:8888/example')); + expect(response.body, contains("BAR")); Process.killPid(binRes.pid); }); }