generateDartTestCode method

Future<void> generateDartTestCode(
  1. String path,
  2. String className, {
  3. String ext = "dart",
  4. String filter(
    1. String value
    )?,
})

Generate Dart test code in path.

You can edit the data inside with filter.

pathにDartテストコードを生成します。

filterで中身のデータを編集することができます。

Implementation

Future<void> generateDartTestCode(
  String path,
  String className, {
  String ext = "dart",
  String Function(String value)? filter,
}) async {
  final baseName = path.last();
  final trimedPath = CliCode._trimPathPrefix(path);
  final editClassName =
      className.split("/").distinct().join("_").toPascalCase();
  final dir = Directory(path.replaceAll("/$baseName", ""));
  if (!dir.existsSync()) {
    await dir.create(recursive: true);
  }
  final output = CliCode._removeCodeSnippetValue(
    test(trimedPath, baseName, editClassName),
  );
  await File("${path}_test.$ext")
      .writeAsString(filter?.call(output) ?? output);
}