Skip to content

Commit

Permalink
fix up env test
Browse files Browse the repository at this point in the history
  • Loading branch information
j4qfrost committed Jun 7, 2024
1 parent 3320d07 commit c28fbe1
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions packages/cli/test/build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -70,27 +70,23 @@ 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",
"test_project/",
]);
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);
Expand All @@ -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);
});
}

0 comments on commit c28fbe1

Please sign in to comment.