generateForFlow method

Future<void> generateForFlow({
  1. required IntegrationTestInput testInput,
  2. required List<IntegrationTestInput> allTests,
  3. required int index,
  4. required PubspecData pubspecData,
  5. required AnalysisContextCollection collection,
  6. required TestRunInfo testRunInfo,
})

Implementation

Future<void> generateForFlow(
    {required IntegrationTestInput testInput,
    required List<IntegrationTestInput> allTests,
    required int index,
    required PubspecData pubspecData,
    required AnalysisContextCollection collection,
    required TestRunInfo testRunInfo}) async {
  final testName =
      '${testInput.moduleName} -> ${index + 1}. ${(testInput.testFlows[index])}';
  try {
    wtLog.startSpinner("Generating Test for ${testName}...");
    testRunInfo.pushFunctionInQueue(testName);
    IntegrationRequestData integrationRequestData =
        await IntegrationExecutor().prepareRequest(
      testInput,
      allTests,
      index,
      pubspecData,
    );

    final response = await generationRepository
        .buildIntegrationTests(integrationRequestData);
    final file =
        PathUtils.correspondingIntegrationTestFile(testInput.moduleName);
    final integrationTest = response['integration_test'] as String;
    final List<HelperAction> helper_actions = (response['actions'] as List)
        .map((e) => HelperAction(
            filePath: e['file_path'],
            kind: 'static', //TODO
            className: e['class_name'],
            methodName: e['method_name'],
            method: e['method']))
        .toList();
    final integrationAppendAgent = IntegrationAppendAgent(writerExecutor);
    for (final action in helper_actions) {
      await integrationAppendAgent.appendMethod(
        action,
      );
    }
    await integrationAppendAgent.appendNewTest(
        existingTestFile: file,
        incomingTest: integrationTest,
        currentFlow: testInput.testFlows[index]);
    testRunInfo.incrementFromAction(TestGenerationStatus.create, testName);
  } catch (e, stackTrace) {
    wtTelemetry.trackError(
        severity: Severity.error, error: e, stackTrace: stackTrace);
    wtLog.warning(
        "Error generating integration tests: Module: ${testInput.moduleName} | TestFlow: ${testInput.testFlows[index]}");
    wtLog.log('Cause: ${e.toString()}');
    testRunInfo.incrementFromAction(TestGenerationStatus.failed, testName);
  }
}