Skip to content

Commit

Permalink
Extend Continuous Testing page by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ueberfuhr committed Sep 5, 2024
1 parent 80190e8 commit d5c493f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.platform.commons.annotation.Testable;
import org.junit.platform.engine.FilterResult;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestExecutionResult;
import org.junit.platform.engine.TestSource;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.*;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.engine.reporting.ReportEntry;
import org.junit.platform.engine.support.descriptor.ClassSource;
Expand Down Expand Up @@ -258,8 +254,9 @@ public void executionSkipped(TestIdentifier testIdentifier, String reason) {
if (testClass != null) {
Map<UniqueId, TestResult> results = resultsByClass.computeIfAbsent(testClass.getName(),
s -> new HashMap<>());
TestResult result = new TestResult(displayName, testClass.getName(), id,
TestExecutionResult.aborted(null),
TestResult result = new TestResult(displayName, testClass.getName(),
toTagList(testIdentifier),
id, TestExecutionResult.aborted(null),
logHandler.captureOutput(), testIdentifier.isTest(), runId, 0, true);
results.put(id, result);
if (result.isTest()) {
Expand Down Expand Up @@ -312,8 +309,9 @@ public void executionFinished(TestIdentifier testIdentifier,
}
Map<UniqueId, TestResult> results = resultsByClass.computeIfAbsent(testClassName,
s -> new HashMap<>());
TestResult result = new TestResult(displayName, testClassName, id,
testExecutionResult,
TestResult result = new TestResult(displayName, testClassName,
toTagList(testIdentifier),
id, testExecutionResult,
logHandler.captureOutput(), testIdentifier.isTest(), runId,
System.currentTimeMillis() - startTimes.get(testIdentifier), true);
if (!results.containsKey(id)) {
Expand All @@ -332,6 +330,7 @@ public void executionFinished(TestIdentifier testIdentifier,
results.put(id,
new TestResult(currentNonDynamicTest.get().getDisplayName(),
result.getTestClass(),
toTagList(testIdentifier),
currentNonDynamicTest.get().getUniqueIdObject(),
TestExecutionResult.failed(failure), List.of(), false, runId, 0,
false));
Expand All @@ -349,6 +348,7 @@ public void executionFinished(TestIdentifier testIdentifier,
for (TestIdentifier child : children) {
UniqueId childId = UniqueId.parse(child.getUniqueId());
result = new TestResult(child.getDisplayName(), testClassName,
toTagList(testIdentifier),
childId,
testExecutionResult,
logHandler.captureOutput(), child.isTest(), runId,
Expand Down Expand Up @@ -419,6 +419,15 @@ public void reportingEntryPublished(TestIdentifier testIdentifier, ReportEntry e
}
}

private static List<String> toTagList(TestIdentifier testIdentifier) {
return testIdentifier
.getTags()
.stream()
.map(TestTag::getName)
.sorted()
.toList();
}

private Class<?> getTestClassFromSource(Optional<TestSource> optionalTestSource) {
if (optionalTestSource.isPresent()) {
var testSource = optionalTestSource.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class TestResult {

final String displayName;
final String testClass;
final List<String> tags;
final UniqueId uniqueId;
final TestExecutionResult testExecutionResult;
final List<String> logOutput;
Expand All @@ -20,10 +21,12 @@ public class TestResult {
final List<Throwable> problems;
final boolean reportable;

public TestResult(String displayName, String testClass, UniqueId uniqueId, TestExecutionResult testExecutionResult,
public TestResult(String displayName, String testClass, List<String> tags, UniqueId uniqueId,
TestExecutionResult testExecutionResult,
List<String> logOutput, boolean test, long runId, long time, boolean reportable) {
this.displayName = displayName;
this.testClass = testClass;
this.tags = tags;
this.uniqueId = uniqueId;
this.testExecutionResult = testExecutionResult;
this.logOutput = logOutput;
Expand Down Expand Up @@ -58,6 +61,10 @@ public String getTestClass() {
return testClass;
}

public List<String> getTags() {
return tags;
}

public UniqueId getUniqueId() {
return uniqueId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ export class QwcContinuousTesting extends QwcHotReloadElement {
}}"
${gridRowDetailsRenderer(this._descriptionRenderer, [])}
>
<vaadin-grid-sort-column path="tags" header="Tags" ${columnBodyRenderer((prop) => this._tagsRenderer(prop), [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="testClass" header="Test Class" ${columnBodyRenderer((prop) => this._testRenderer(prop), [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="displayName" header="Name" ${columnBodyRenderer((prop) => this._nameRenderer(prop), [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="time" header="Time" ${columnBodyRenderer((prop) => this._timeRenderer(prop), [])}>></vaadin-grid-sort-column>
Expand Down Expand Up @@ -286,6 +287,36 @@ export class QwcContinuousTesting extends QwcHotReloadElement {
)}`;
}

_tagToColor(tag){
// Step 1: Convert the string to a numeric hash value
let hash = 0;
for (let i = 0; i < tag.length; i++) {
hash = tag.charCodeAt(i) + ((hash << 5) - hash);
}

// Step 2: Convert the numeric hash value to a hex color code
let color = '#';
const normalizeFactor = 0.2; // cut 20% light and dark values
for (let i = 0; i < 3; i++) {
const value = Math.round(((hash >> (i * 8)) & 0xFF) * (1-2*normalizeFactor) + 255*normalizeFactor);
color += ('00' + value.toString(16)).slice(-2);
}

return color;
}

_tagsRenderer(testLine){
return html`${testLine.tags.map((tag) => {
let color = this._tagToColor(tag);
<!-- style="color:${color};background-color:${color}40" -->
return html`<qui-badge small pill color="${color}" background="${color}40"
aria-label="${tag}" title="${tag}">
<span>${"io.quarkus.test.junit.QuarkusTest" === tag ? "Q" : tag}</span>
</qui-badge> `
}
)}`;
}

_testRenderer(testLine){
let level = testLine.testExecutionResult.status.toLowerCase();

Expand Down

0 comments on commit d5c493f

Please sign in to comment.