Skip to content

Commit 19ff864

Browse files
jakra-mbgithub-actions[bot]
authored andcommitted
Improved output in render test HTML files.
GitOrigin-RevId: 4e4e738c90ce174aecb1b8d0cc061d8f37f31943
1 parent f102521 commit 19ff864

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

test/integration/render-tests/index.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function loadPngFromUrl(url: string): Promise<ImageDataWithCanvas> {
6868
});
6969
}
7070

71-
async function getExpectedImages(currentTestName: string, renderTest: Record<string, unknown>): Promise<ImageDataWithCanvas[]> {
71+
async function getExpectedImages(currentTestName: string, renderTest: Record<string, unknown>): Promise<Array<ImageDataWithCanvas & {src: string}>> {
7272
const urls: string[] = [];
7373
for (const prop in renderTest) {
7474
if (prop.indexOf('expected') > -1) {
@@ -80,12 +80,16 @@ async function getExpectedImages(currentTestName: string, renderTest: Record<str
8080
urls.push(url);
8181
}
8282
}
83-
return Promise.all(urls.map(loadPngFromUrl));
83+
return Promise.all(urls.map(async (url) => {
84+
const result = await loadPngFromUrl(url);
85+
return Object.assign({}, result, {src: url});
86+
}));
8487
}
8588

8689
type TestMetadata = {
8790
name: string;
8891
minDiff: number;
92+
allowed: number;
8993
status: string;
9094
actual?: string;
9195
expected?: string;
@@ -118,11 +122,12 @@ const getTest = (renderTestName: string) => async () => {
118122
throw new Error(`No expected images found for ${renderTestName}. Please run the test with UPDATE=true to generate expected images.`);
119123
}
120124

121-
const {minDiff, minDiffImage, expectedIndex, minImageSrc} = calculateDiff(actualImageData, expectedImages.map(({imageData}) => imageData), {w, h}, options['diff-calculation-threshold']);
125+
const {minDiff, minDiffImage, expectedIndex, minImageSrc} = calculateDiff(actualImageData, expectedImages.map(({imageData, src}) => ({data: imageData.data, src})), {w, h}, options['diff-calculation-threshold']);
122126
const pass = minDiff <= options.allowed;
123127
const testMetaData: TestMetadata = {
124128
name: renderTestName,
125129
minDiff: Math.round(100000 * minDiff) / 100000,
130+
allowed: options.allowed,
126131
status: pass ? 'passed' : 'failed',
127132
};
128133

test/util/html_generator.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const generateResultHTML = template(`
1111
<% } else { %>
1212
<input type="checkbox" id="<%- r.id %>">
1313
<% } %>
14-
<label class="tab-label" style="background: <%- r.color %>" for="<%- r.id %>"><p class="status-container"><span class="status"><%- r.status %></span> - <%- r.name %> <% if (r.attempt !== 0) { %>retry <%- r.attempt + 1 %><% } %> diff: <%- r.minDiff %></p></label>
14+
<label class="tab-label" style="background: <%- r.color %>" for="<%- r.id %>"><p class="status-container"><span class="status"><%- r.status %></span> - <%- r.name %> <% if (r.attempt !== 0) { %>retry <%- r.attempt + 1 %><% } %></p></label>
1515
<div class="tab-content">
1616
<% if (r.actual || r.expected) { %>
1717
<span class="img-hover-container">
@@ -31,6 +31,15 @@ const generateResultHTML = template(`
3131
<img title="diff" src="<%- r.imgDiff %>">
3232
</span>
3333
<% } %>
34+
<% if (r.allowed !== undefined) { %>
35+
<p class="diff"><strong>Allowed:</strong> <%- r.allowed %></p>
36+
<% } %>
37+
<% if (r.minDiff !== undefined) { %>
38+
<p class="diff"><strong>Diff:</strong> <%- r.minDiff === 0 ? 'none' : r.minDiff %></p>
39+
<% } %>
40+
<% if (r.expectedPath) { %>
41+
<p class="diff"><strong>Expected image path:</strong> <%- r.expectedPath %></p>
42+
<% } %>
3443
<% if (r.jsonDiff) { %>
3544
<details>
3645
<summary><strong style="color: red">JSON Diff</strong></summary>

0 commit comments

Comments
 (0)