saveE2E method

Future<void> saveE2E({
  1. required PubspecData pubspecData,
  2. required String className,
  3. int? index,
})

Implementation

Future<void> saveE2E({
  required PubspecData pubspecData,
  required String className,
  int? index,
}) async {
  try {
    FileSystemEntity file = File(PathUtils.flowsPath);
    if (!file.existsSync()) {
      wtLog.error(
        'Welltested.dart file not found at ${file.path}.\n Please read our docs to learn more.',
      );
      return;
    }
    AnalysisContextCollection collection = AnalysisContextCollection(
      includedPaths: [
        PathUtils.integrationTestPath,
        File(PathUtils.flowsPath).absolute.path,
      ],
      resourceProvider: PhysicalResourceProvider.INSTANCE,
    );
    final dartServerRepository = DartServerRepository();
    await dartServerRepository.initialize();

    final libDirectory = Directory(PathUtils.libPath);
    final testDirectory = Directory(PathUtils.testPath);
    await dartServerRepository.addFilesToRoot(
        [libDirectory.absolute.path, testDirectory.absolute.path]);

    await processSaveIntegrationRequest(
      file,
      collection,
      pubspecData,
      dartServerRepository: dartServerRepository,
      className: className,
      index: index,
    );
    dartServerRepository.dispose();
  } catch (e, stackTrace) {
    //TODO: Dart Server Repository should still be disposed. (including in unit, widget, integration)
    wtTelemetry.trackError(
        severity: Severity.error, error: e, stackTrace: stackTrace);
    wtLog.warning("Error saving integration tests");
    wtLog.log(e.toString());
  }
}