Skip to content

Commit

Permalink
introduce suites, remove exporting of duplicates, fix duration for le…
Browse files Browse the repository at this point in the history
…ss than 1 second tests (via #21)
  • Loading branch information
kristfoograb authored Jul 8, 2020
1 parent 5474ae7 commit 77e055b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public TestResult format(final ExportMeta meta, final JsonNode node) {
if (Objects.nonNull(result.getStart())) {
if (node.has(DURATION)) {
final Double durationText = node.get(DURATION).get(VALUE).asDouble();
result.setStop(result.getStart() + TimeUnit.SECONDS.toMillis(durationText.longValue()));
long durationToMillis = (long) (durationText * 1000);
result.setStop(result.getStart() + durationToMillis);
}
if (result.getSteps().size() > 0) {
result.setStop(result.getSteps().get(result.getSteps().size() - 1).getStop());
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/io/eroshenkoam/xcresults/export/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ public class ExportCommand implements Runnable {

private static final String SUMMARY_REF = "summaryRef";

private static final String SUITE = "suite";

private static final String ID = "id";
private static final String TYPE = "_type";
private static final String NAME = "_name";
private static final String VALUE = "_value";
private static final String VALUES = "_values";
private static final String DISPLAY_NAME = "displayName";
private static final String IDENTIFIER = "identifier";
private static final String TARGET_NAME = "targetName";

private static final String TEST_REF = "testsRef";

Expand Down Expand Up @@ -108,19 +110,22 @@ private void runUnsafe() throws Exception {
testRefIds.put(action.get(ACTION_RESULT).get(TEST_REF).get(ID).get(VALUE).asText(), meta);
}
}

final Map<JsonNode, ExportMeta> testSummaries = new HashMap<>();
testRefIds.forEach((testRefId, meta) -> {
final JsonNode testRef = getReference(testRefId);
for (JsonNode summary : testRef.get(SUMMARIES).get(VALUES)) {
for (JsonNode testableSummary : summary.get(TESTABLE_SUMMARIES).get(VALUES)) {
final ExportMeta testMeta = getTestMeta(meta, testableSummary);
for (JsonNode test : testableSummary.get(TESTS).get(VALUES)) {
getTestSummaries(test).forEach(testSummary -> {
testSummaries.put(testSummary, testRefIds.get(testRefId));
testSummaries.put(testSummary, testMeta);
});
}
}
}
});

System.out.println(String.format("Export information about %s test summaries...", testSummaries.size()));
final Map<String, String> attachmentsRefs = new HashMap<>();
testSummaries.forEach((testSummary, meta) -> {
Expand All @@ -139,6 +144,17 @@ private void runUnsafe() throws Exception {
}
}

private ExportMeta getTestMeta(ExportMeta meta, JsonNode testableSummary) {
final ExportMeta exportMeta = new ExportMeta();
exportMeta.setStart(meta.getStart());
meta.getLabels().forEach((key, value) -> {
exportMeta.label(key, value);
});

exportMeta.label(SUITE, testableSummary.get(TARGET_NAME).get(VALUE).asText());
return exportMeta;
}

private void exportTestSummary(final ExportMeta meta, final JsonNode testSummary) {
Path testSummaryPath = null;
Object formattedResult = null;
Expand Down Expand Up @@ -190,10 +206,12 @@ private List<JsonNode> getTestSummaries(final JsonNode test) {
if (test.has(SUMMARY_REF)) {
final String ref = test.get(SUMMARY_REF).get(ID).get(VALUE).asText();
summaries.add(getReference(ref));
} else {
if (test.has(TYPE) && test.get(TYPE).get(NAME).textValue().equals("ActionTestMetadata")) {
summaries.add(test);
}
}
if (test.has(TYPE) && test.get(TYPE).get(NAME).textValue().equals("ActionTestMetadata")) {
summaries.add(test);
}

if (test.has(SUBTESTS)) {
for (final JsonNode subTest : test.get(SUBTESTS).get(VALUES)) {
summaries.addAll(getTestSummaries(subTest));
Expand Down

0 comments on commit 77e055b

Please sign in to comment.