detectTestFramework method

Future<TestFramework> detectTestFramework(
  1. String path
)

Detects the test framework used in the project.

Implementation

Future<TestFramework> detectTestFramework(String path) async {
  if (await File('$path/pubspec.yaml').exists()) {
    return TestFramework.flutterTest;
  }

  if (await File('$path/package.json').exists()) {
    try {
      final content = await File('$path/package.json').readAsString();
      final data = jsonDecode(content) as Map<String, dynamic>;
      final deps = <String>{
        ...(data['devDependencies'] as Map<String, dynamic>? ?? {}).keys,
        ...(data['dependencies'] as Map<String, dynamic>? ?? {}).keys,
      };
      if (deps.contains('vitest')) return TestFramework.vitest;
      if (deps.contains('jest')) return TestFramework.jest;
      if (deps.contains('mocha')) return TestFramework.mocha;
    } catch (_) {}
  }

  if (await File('$path/pytest.ini').exists() ||
      await File('$path/conftest.py').exists() ||
      await File('$path/pyproject.toml').exists()) {
    return TestFramework.pytest;
  }

  if (await File('$path/Cargo.toml').exists()) {
    return TestFramework.cargoTest;
  }

  if (await File('$path/go.mod').exists()) {
    return TestFramework.goTest;
  }

  if (await File('$path/Gemfile').exists()) {
    return TestFramework.rspec;
  }

  return TestFramework.none;
}