Skip to content

Commit fc7bc5c

Browse files
committed
feat: ndjson reporting - gherkin document is not just feature but other properties too. Need to expose original feature pickle since it does not independently generate json but is part of a bigger object.
1 parent 890d940 commit fc7bc5c

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

cucumber_cpp/library/engine/FeatureInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ namespace cucumber_cpp::library::engine
7575
return scenarios;
7676
}
7777

78-
std::string FeatureInfo::ToJson() const
78+
const cucumber::messages::feature& FeatureInfo::Pickle() const
7979
{
80-
return feature.to_json();
80+
return feature;
8181
}
8282

8383

cucumber_cpp/library/engine/FeatureInfo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace cucumber_cpp::library::engine
3636
[[nodiscard]] std::vector<std::unique_ptr<ScenarioInfo>>& Scenarios();
3737
[[nodiscard]] const std::vector<std::unique_ptr<ScenarioInfo>>& Scenarios() const;
3838

39-
[[nodiscard]] std::string ToJson() const;
39+
[[nodiscard]] const cucumber::messages::feature& Pickle() const;
4040

4141
private:
4242

cucumber_cpp/library/report/NdjsonReport.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "NdjsonReport.hpp"
22
#include "Environment.h"
3+
#include <cucumber/messages/gherkin_document.hpp>
34
#include <cucumber/messages/meta.hpp>
45
#include <cucumber_cpp/library/engine/SourceInfo.hpp>
56
#include <fstream>
@@ -22,7 +23,6 @@ namespace cucumber_cpp::library::report
2223
outStream.close();
2324
}
2425

25-
2626
/*
2727
* Unlike XML reporter, where a single document is built up over time and then has to be flushed out in the end all at once,
2828
* NDJSON is a series of individual json objects appended one after another as the test run progresses.
@@ -51,20 +51,27 @@ namespace cucumber_cpp::library::report
5151
}
5252
}
5353

54-
void NdjsonReport::CreateMeta()
54+
void NdjsonReport::RecordMeta()
5555
{
5656
// Makeup own metadata since https://github.com/cucumber/ci-environment does not have c++ version (yet)
5757
cucumber::messages::meta meta (MESSAGES_PROTOCOL_VERSION);
58+
meta.ci = cucumber::messages::ci("name", "url", "build_number");
59+
meta.ci->git = cucumber::messages::git("remote", "revision", "branch", "tag");
60+
outStream << "{\"meta\":" << meta.to_json() << "}\n";
5861
}
5962

6063

6164
void NdjsonReport::FeatureStart(const engine::FeatureInfo& featureInfo)
6265
{
6366
InitReportDirectory();
64-
CreateMeta();
67+
RecordMeta();
6568

6669
outStream << "{\"source\":" << featureInfo.SourceInfo()->ToJson() << "}\n";
67-
outStream << "{\"gherkinDocument\":" << featureInfo.ToJson() << "}\n";
70+
71+
cucumber::messages::gherkin_document gherkinDocument;
72+
gherkinDocument.feature = featureInfo.Pickle();
73+
74+
outStream << "{\"gherkinDocument\":" << gherkinDocument.to_json() << "}\n";
6875
// TODO testRunStarted
6976
}
7077

cucumber_cpp/library/report/NdjsonReport.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace cucumber_cpp::library::report
2929

3030
std::ofstream outStream;
3131
void InitReportDirectory();
32-
static void CreateMeta() ;
32+
void RecordMeta() ;
3333

3434
};
3535

0 commit comments

Comments
 (0)