Skip to content

Commit 5ca6a20

Browse files
authored
test(dart_frog_cli): dart_frog create e2e tests (#73)
1 parent e7cddf7 commit 5ca6a20

File tree

7 files changed

+104
-3
lines changed

7 files changed

+104
-3
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'dart:io';
2+
3+
import 'package:path/path.dart' as path;
4+
import 'package:test/test.dart';
5+
6+
import 'helpers/helpers.dart';
7+
8+
/// Objectives:
9+
///
10+
/// * Generate a new Dart Frog project via `dart_frog create`
11+
/// * Ensure the code is formatted (`dart format .`)
12+
/// * Ensure the code has no warnings/errors (`dart analyze .`)
13+
/// * Ensure the tests pass (`dart test`)
14+
void main() {
15+
group('dart_frog create', () {
16+
const projectName = 'example';
17+
final tempDirectory = Directory.systemTemp.createTempSync();
18+
final projectDirectory = Directory(
19+
path.join(tempDirectory.path, projectName),
20+
);
21+
22+
setUpAll(() async {
23+
await dartFrogCreate(projectName: projectName, directory: tempDirectory);
24+
});
25+
26+
tearDownAll(() async {
27+
await tempDirectory.delete(recursive: true);
28+
});
29+
30+
test('generates a well-formatted project', () {
31+
expect(dartFormat(projectDirectory), completes);
32+
});
33+
34+
test('generates a project that has no analysis errors/warnings', () {
35+
expect(dartAnalyze(projectDirectory), completes);
36+
});
37+
38+
test('generates a project in which all tests pass', () {
39+
expect(dartTest(projectDirectory), completes);
40+
});
41+
});
42+
}

packages/dart_frog_cli/e2e/test/dev_smoke_test.dart renamed to packages/dart_frog_cli/e2e/test/dart_frog_dev_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'helpers/helpers.dart';
1212
/// * Run the dev server via `dart_frog dev`
1313
/// * Ensure the server responds accordingly for built-in endpoints
1414
void main() {
15-
group('Dev Server Smoke Test', () {
15+
group('dart_frog dev', () {
1616
const projectName = 'example';
1717
final tempDirectory = Directory.systemTemp.createTempSync();
1818

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'dart:io';
2+
3+
Future<void> dartAnalyze(Directory directory) async {
4+
final result = await Process.run(
5+
'dart',
6+
['analyze', '.'],
7+
workingDirectory: directory.path,
8+
runInShell: true,
9+
);
10+
11+
if (result.exitCode != 0) {
12+
throw Exception('dart analyze . exited with code ${result.exitCode}');
13+
}
14+
15+
final output = result.stdout as String;
16+
if (!output.contains('No issues found!')) {
17+
throw Exception('dart analyze reported problems:\n$output');
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'dart:io';
2+
3+
Future<void> dartFormat(Directory directory) async {
4+
final result = await Process.run(
5+
'dart',
6+
['format', '--set-exit-if-changed', '.'],
7+
workingDirectory: directory.path,
8+
runInShell: true,
9+
);
10+
11+
if (result.exitCode != 0) {
12+
throw Exception(
13+
'dart format --set-exit-if-changed . exited with code ${result.exitCode}',
14+
);
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'dart:io';
2+
3+
Future<void> dartTest(Directory directory) async {
4+
final result = await Process.run(
5+
'dart',
6+
['test'],
7+
workingDirectory: directory.path,
8+
runInShell: true,
9+
);
10+
11+
if (result.exitCode != 0) {
12+
throw Exception('dart test exited with code ${result.exitCode}');
13+
}
14+
15+
final errors = result.stderr as String;
16+
if (errors.isNotEmpty) {
17+
throw Exception('dart test reported errors:\n$errors');
18+
}
19+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
export 'dart_analyze.dart';
2+
export 'dart_format.dart';
13
export 'dart_frog_create.dart';
24
export 'dart_frog_dev.dart';
5+
export 'dart_tst.dart';
36
export 'kill_dart_frog_server.dart';
47
export 'test_server.dart';

packages/dart_frog_cli/e2e/test/helpers/kill_dart_frog_server.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ Future<void> killDartFrogServer(int pid) async {
88
runInShell: true,
99
);
1010
if (result.exitCode != 0) {
11-
throw Exception('taskkill /F /T /PID $pid exited with code $exitCode');
11+
throw Exception(
12+
'taskkill /F /T /PID $pid exited with code ${result.exitCode}',
13+
);
1214
}
1315
return;
1416
}
1517

1618
if (Platform.isLinux || Platform.isMacOS) {
1719
final result = await Process.run('pkill', ['-f', 'dart_frog']);
1820
if (result.exitCode != 0) {
19-
throw Exception('pkill -f dart_frog exited with code $exitCode');
21+
throw Exception('pkill -f dart_frog exited with code ${result.exitCode}');
2022
}
2123
return;
2224
}

0 commit comments

Comments
 (0)