visual-regression-ci 0.0.0-stage → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +953 -2
- package/package.json +76 -4
- package/src/ci/actionReport.js +340 -0
- package/src/ci/prComment.js +420 -0
- package/src/cli/capture.js +243 -0
- package/src/cli/compare.js +190 -0
- package/src/cli/config.js +287 -0
- package/src/cli/database.js +69 -0
- package/src/cli/display.js +119 -0
- package/src/cli/errors.js +17 -0
- package/src/cli/index.js +577 -0
- package/src/cli/installBrowsers.js +59 -0
- package/src/cli/invocation.js +66 -0
- package/src/cli/jsonTarget.js +100 -0
- package/src/cli/logger.js +15 -0
- package/src/cli/manifest.js +139 -0
- package/src/cli/naming.js +60 -0
- package/src/cli/reporter.js +172 -0
- package/src/cli/result.js +225 -0
- package/src/cli/serve.js +64 -0
- package/src/server/app.js +135 -0
- package/src/server/db.js +691 -0
- package/src/server/importRuns.js +837 -0
- package/src/server/paths.js +107 -0
- package/src/server/public/css/styles.css +2362 -0
- package/src/server/public/js/common.js +32 -0
- package/src/server/public/js/dashboard.js +140 -0
- package/src/server/public/js/import-upload.js +169 -0
- package/src/server/public/js/review-actions.js +379 -0
- package/src/server/public/js/shortcuts.js +242 -0
- package/src/server/public/js/slider.js +104 -0
- package/src/server/public/js/tabs.js +85 -0
- package/src/server/public/js/theme.js +83 -0
- package/src/server/routes/api.js +141 -0
- package/src/server/routes/views.js +68 -0
- package/src/server/security.js +79 -0
- package/src/server/uploadImport.js +227 -0
- package/src/server/urls.js +31 -0
- package/src/server/viewModels.js +366 -0
- package/src/server/views/history.ejs +111 -0
- package/src/server/views/index.ejs +283 -0
- package/src/server/views/layout.ejs +11 -0
- package/src/server/views/partials/footer.ejs +11 -0
- package/src/server/views/partials/header.ejs +93 -0
- package/src/server/views/run-detail.ejs +295 -0
- package/src/shared/packageSpec.js +49 -0
- package/src/shared/text.js +59 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the dashboard's ES modules.
|
|
3
|
+
* The server renders <html data-base="..." data-mode="...">; reading them here lets
|
|
4
|
+
* every module build URLs that work when the dashboard is served under a sub-path.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { dataset } = document.documentElement;
|
|
8
|
+
|
|
9
|
+
/** Base path the dashboard is served under ('' at the site root), without a trailing slash. */
|
|
10
|
+
export const base = (() => {
|
|
11
|
+
const b = (dataset.base || '').trim().replace(/\/+$/, '');
|
|
12
|
+
return b && !b.startsWith('/') ? `/${b}` : b;
|
|
13
|
+
})();
|
|
14
|
+
|
|
15
|
+
/** 'live' (Express server with a writable API) or 'static' (read-only build). */
|
|
16
|
+
export const mode = dataset.mode || 'live';
|
|
17
|
+
|
|
18
|
+
/** URL of an API endpoint, e.g. api('/snapshots/3/approve'). */
|
|
19
|
+
export function api(path) {
|
|
20
|
+
return `${base}/api${path}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Reads a message out to screen readers via the page's polite live region. */
|
|
24
|
+
export function announce(message) {
|
|
25
|
+
const region = document.getElementById('live-region');
|
|
26
|
+
if (!region) return;
|
|
27
|
+
// Clear first so repeating the same message is announced again.
|
|
28
|
+
region.textContent = '';
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
region.textContent = message;
|
|
31
|
+
}, 50);
|
|
32
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side interactivity for Visual CI Dashboard:
|
|
3
|
+
* - Real-time filtering by status toggle buttons (All, Passed, Approved, Failed; aria-pressed)
|
|
4
|
+
* - Search bar filter (Run ID, branch, commit)
|
|
5
|
+
* - Client-side table pagination
|
|
6
|
+
*
|
|
7
|
+
* Loaded as a module (deferred), so the DOM is already parsed when this runs.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
function initDashboard() {
|
|
11
|
+
const table = document.getElementById('test-runs-table');
|
|
12
|
+
if (!table) return;
|
|
13
|
+
|
|
14
|
+
const rows = Array.from(table.querySelectorAll('tbody tr[data-run-id]'));
|
|
15
|
+
const filterTabs = document.querySelectorAll('.filter-tab');
|
|
16
|
+
const searchInput = document.getElementById('dashboard-search');
|
|
17
|
+
const prevBtn = document.getElementById('prev-page-btn');
|
|
18
|
+
const nextBtn = document.getElementById('next-page-btn');
|
|
19
|
+
const pageInfo = document.getElementById('pagination-info');
|
|
20
|
+
const showingRange = document.getElementById('showing-range');
|
|
21
|
+
|
|
22
|
+
const PAGE_SIZE = 10;
|
|
23
|
+
let currentPage = 1;
|
|
24
|
+
let currentFilter = 'all';
|
|
25
|
+
let searchQuery = '';
|
|
26
|
+
|
|
27
|
+
function getFilteredRows() {
|
|
28
|
+
return rows.filter((row) => {
|
|
29
|
+
const status = row.getAttribute('data-status') || '';
|
|
30
|
+
const runId = row.getAttribute('data-run-id') || '';
|
|
31
|
+
const branch = row.getAttribute('data-branch') || '';
|
|
32
|
+
const commit = row.getAttribute('data-commit') || '';
|
|
33
|
+
|
|
34
|
+
// Status filter
|
|
35
|
+
let matchesStatus = true;
|
|
36
|
+
if (currentFilter === 'passed') {
|
|
37
|
+
matchesStatus = status === 'PASSED';
|
|
38
|
+
} else if (currentFilter === 'approved') {
|
|
39
|
+
matchesStatus = status === 'APPROVED';
|
|
40
|
+
} else if (currentFilter === 'failed') {
|
|
41
|
+
matchesStatus = status === 'FAILED' || status === 'REJECTED';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Search query filter
|
|
45
|
+
let matchesSearch = true;
|
|
46
|
+
if (searchQuery) {
|
|
47
|
+
const query = searchQuery.toLowerCase();
|
|
48
|
+
matchesSearch = runId.toLowerCase().includes(query) ||
|
|
49
|
+
branch.toLowerCase().includes(query) ||
|
|
50
|
+
commit.toLowerCase().includes(query);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return matchesStatus && matchesSearch;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function updateTable() {
|
|
58
|
+
const filtered = getFilteredRows();
|
|
59
|
+
const totalFiltered = filtered.length;
|
|
60
|
+
const totalPages = Math.max(1, Math.ceil(totalFiltered / PAGE_SIZE));
|
|
61
|
+
|
|
62
|
+
if (currentPage > totalPages) currentPage = totalPages;
|
|
63
|
+
if (currentPage < 1) currentPage = 1;
|
|
64
|
+
|
|
65
|
+
const startIdx = (currentPage - 1) * PAGE_SIZE;
|
|
66
|
+
const endIdx = startIdx + PAGE_SIZE;
|
|
67
|
+
|
|
68
|
+
rows.forEach((row) => {
|
|
69
|
+
row.style.display = 'none';
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const visibleRows = filtered.slice(startIdx, endIdx);
|
|
73
|
+
visibleRows.forEach((row) => {
|
|
74
|
+
row.style.display = '';
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Update pagination labels
|
|
78
|
+
if (pageInfo) {
|
|
79
|
+
pageInfo.textContent = `Page ${currentPage} of ${totalPages}`;
|
|
80
|
+
}
|
|
81
|
+
if (showingRange) {
|
|
82
|
+
if (totalFiltered === 0) {
|
|
83
|
+
showingRange.textContent = 'Showing 0 runs';
|
|
84
|
+
} else {
|
|
85
|
+
showingRange.textContent = `Showing ${startIdx + 1}–${Math.min(endIdx, totalFiltered)} of ${totalFiltered} run${totalFiltered === 1 ? '' : 's'}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (prevBtn) prevBtn.disabled = currentPage <= 1;
|
|
90
|
+
if (nextBtn) nextBtn.disabled = currentPage >= totalPages;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Filter buttons: toggle buttons (aria-pressed), exactly one pressed at a time
|
|
94
|
+
filterTabs.forEach((tab) => {
|
|
95
|
+
tab.addEventListener('click', () => {
|
|
96
|
+
filterTabs.forEach((t) => {
|
|
97
|
+
t.classList.toggle('active', t === tab);
|
|
98
|
+
t.setAttribute('aria-pressed', String(t === tab));
|
|
99
|
+
});
|
|
100
|
+
currentFilter = tab.getAttribute('data-filter');
|
|
101
|
+
currentPage = 1;
|
|
102
|
+
updateTable();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Search input change
|
|
107
|
+
if (searchInput) {
|
|
108
|
+
searchInput.addEventListener('input', (e) => {
|
|
109
|
+
searchQuery = e.target.value.trim();
|
|
110
|
+
currentPage = 1;
|
|
111
|
+
updateTable();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Prev / Next buttons
|
|
116
|
+
if (prevBtn) {
|
|
117
|
+
prevBtn.addEventListener('click', () => {
|
|
118
|
+
if (currentPage > 1) {
|
|
119
|
+
currentPage--;
|
|
120
|
+
updateTable();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (nextBtn) {
|
|
126
|
+
nextBtn.addEventListener('click', () => {
|
|
127
|
+
const filtered = getFilteredRows();
|
|
128
|
+
const totalPages = Math.ceil(filtered.length / PAGE_SIZE);
|
|
129
|
+
if (currentPage < totalPages) {
|
|
130
|
+
currentPage++;
|
|
131
|
+
updateTable();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Initial render
|
|
137
|
+
updateTable();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
initDashboard();
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Import CI run" on the dashboard: pick the visual-regression-diffs .zip with the button
|
|
3
|
+
* (the keyboard way) or drop it anywhere on the page, and it is uploaded to
|
|
4
|
+
* POST /api/imports. On success the page opens the imported run (or lists them when
|
|
5
|
+
* the artifact held several); errors go to the role="alert" region, never alert().
|
|
6
|
+
*
|
|
7
|
+
* Only loaded in live mode: the static (GitHub Pages) build has no server to import into.
|
|
8
|
+
*/
|
|
9
|
+
import { api, announce, base, mode } from './common.js';
|
|
10
|
+
|
|
11
|
+
const ZIP_TYPES = ['application/zip', 'application/x-zip-compressed'];
|
|
12
|
+
// Required by the server's CSRF check (see src/server/security.js)
|
|
13
|
+
const WRITE_HEADERS = { 'X-Requested-With': 'visual-ci-dashboard', 'Content-Type': 'application/zip' };
|
|
14
|
+
|
|
15
|
+
function formatBytes(bytes) {
|
|
16
|
+
if (bytes >= 1024 * 1024) return `${Math.round(bytes / (1024 * 1024))} MB`;
|
|
17
|
+
if (bytes >= 1024) return `${Math.round(bytes / 1024)} KB`;
|
|
18
|
+
return `${bytes} bytes`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function readJson(res) {
|
|
22
|
+
try {
|
|
23
|
+
return await res.json();
|
|
24
|
+
} catch {
|
|
25
|
+
return { success: false, error: `the server responded with HTTP ${res.status}` };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function initImport() {
|
|
30
|
+
const button = document.getElementById('import-run-btn');
|
|
31
|
+
const input = document.getElementById('import-file');
|
|
32
|
+
const control = button?.closest('.import-control');
|
|
33
|
+
const statusRegion = document.querySelector('[data-import-status]');
|
|
34
|
+
const errorRegion = document.querySelector('[data-import-error]');
|
|
35
|
+
const overlay = document.querySelector('[data-drop-overlay]');
|
|
36
|
+
if (mode === 'static' || !button || !input || !statusRegion || !errorRegion) return;
|
|
37
|
+
|
|
38
|
+
const label = button.querySelector('.import-label');
|
|
39
|
+
const idleLabel = label?.textContent || 'Import CI run';
|
|
40
|
+
const maxBytes = Number(control?.dataset.maxUploadBytes) || 0;
|
|
41
|
+
// How to run visual-ci where this dashboard runs (see cliCommand in src/cli/invocation.js).
|
|
42
|
+
const cliCommand = control?.dataset.cliCommand || 'visual-ci';
|
|
43
|
+
let uploading = false;
|
|
44
|
+
|
|
45
|
+
const setStatus = (content) => {
|
|
46
|
+
if (typeof content === 'string') statusRegion.textContent = content;
|
|
47
|
+
else statusRegion.replaceChildren(...content);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function showError(message) {
|
|
51
|
+
setStatus('');
|
|
52
|
+
const p = document.createElement('p');
|
|
53
|
+
p.textContent = message;
|
|
54
|
+
errorRegion.replaceChildren(p); // a new node each time, so a repeat is announced again
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function setBusy(busy) {
|
|
58
|
+
uploading = busy;
|
|
59
|
+
button.disabled = busy;
|
|
60
|
+
button.setAttribute('aria-busy', String(busy));
|
|
61
|
+
if (label) label.textContent = busy ? 'Importing…' : idleLabel;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function showRunLinks(runs) {
|
|
65
|
+
const intro = document.createElement('p');
|
|
66
|
+
intro.textContent = `Imported ${runs.length} runs:`;
|
|
67
|
+
const list = document.createElement('ul');
|
|
68
|
+
for (const run of runs) {
|
|
69
|
+
const item = document.createElement('li');
|
|
70
|
+
const link = document.createElement('a');
|
|
71
|
+
link.href = `${base}${run.url}`;
|
|
72
|
+
link.textContent = run.id;
|
|
73
|
+
item.append(link);
|
|
74
|
+
if (run.alreadyImported) item.append(' (already imported)');
|
|
75
|
+
else if (run.renamedFrom) item.append(` (renamed from ${run.renamedFrom})`);
|
|
76
|
+
list.append(item);
|
|
77
|
+
}
|
|
78
|
+
setStatus([intro, list]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function upload(file) {
|
|
82
|
+
if (uploading) {
|
|
83
|
+
announce('An import is already running.');
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
errorRegion.replaceChildren();
|
|
87
|
+
if (!file) return;
|
|
88
|
+
const isZip = /\.zip$/i.test(file.name) || ZIP_TYPES.includes(file.type);
|
|
89
|
+
if (!isZip) {
|
|
90
|
+
showError(`"${file.name}" is not a .zip file. Download the visual-regression-diffs artifact from the failed CI run and import that.`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (maxBytes && file.size > maxBytes) {
|
|
94
|
+
showError(`"${file.name}" is ${formatBytes(file.size)}; uploads are limited to ${formatBytes(maxBytes)}. Use the command line instead: ${cliCommand} import <file>`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
setBusy(true);
|
|
99
|
+
setStatus(`Importing ${file.name}…`);
|
|
100
|
+
let navigating = false;
|
|
101
|
+
try {
|
|
102
|
+
const res = await fetch(api('/imports'), { method: 'POST', headers: WRITE_HEADERS, body: file });
|
|
103
|
+
const data = await readJson(res);
|
|
104
|
+
if (!data.success) {
|
|
105
|
+
showError(`Import failed: ${data.error || `HTTP ${res.status}`}`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (data.runs.length === 1) {
|
|
109
|
+
const [run] = data.runs;
|
|
110
|
+
const done = run.alreadyImported ? `${run.id} was already imported` : `Imported ${run.id}`;
|
|
111
|
+
setStatus(`${done}. Opening it…`); // the status region announces it (once)
|
|
112
|
+
navigating = true;
|
|
113
|
+
window.location.assign(`${base}${run.url}`);
|
|
114
|
+
} else {
|
|
115
|
+
showRunLinks(data.runs); // announced by the status region
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
showError(`Import failed: network error (${err.message}).`);
|
|
119
|
+
} finally {
|
|
120
|
+
// While the next page loads the button stays disabled: no second upload.
|
|
121
|
+
if (!navigating) setBusy(false);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
button.addEventListener('click', () => input.click());
|
|
126
|
+
input.addEventListener('change', () => {
|
|
127
|
+
const [file] = input.files;
|
|
128
|
+
input.value = ''; // picking the same file again still fires "change"
|
|
129
|
+
upload(file);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Drag and drop anywhere on the page. The counter copes with dragenter/dragleave
|
|
133
|
+
// firing for every child element crossed.
|
|
134
|
+
const hasFiles = (e) => Array.from(e.dataTransfer?.types || []).includes('Files');
|
|
135
|
+
let depth = 0;
|
|
136
|
+
const showOverlay = (show) => {
|
|
137
|
+
if (overlay) overlay.hidden = !show;
|
|
138
|
+
};
|
|
139
|
+
document.addEventListener('dragenter', (e) => {
|
|
140
|
+
if (!hasFiles(e)) return;
|
|
141
|
+
e.preventDefault();
|
|
142
|
+
depth += 1;
|
|
143
|
+
showOverlay(true);
|
|
144
|
+
});
|
|
145
|
+
document.addEventListener('dragover', (e) => {
|
|
146
|
+
if (!hasFiles(e)) return;
|
|
147
|
+
e.preventDefault(); // allows the drop
|
|
148
|
+
e.dataTransfer.dropEffect = uploading ? 'none' : 'copy';
|
|
149
|
+
});
|
|
150
|
+
document.addEventListener('dragleave', (e) => {
|
|
151
|
+
if (!hasFiles(e)) return;
|
|
152
|
+
depth = Math.max(0, depth - 1);
|
|
153
|
+
if (depth === 0) showOverlay(false);
|
|
154
|
+
});
|
|
155
|
+
document.addEventListener('drop', (e) => {
|
|
156
|
+
if (!hasFiles(e)) return;
|
|
157
|
+
e.preventDefault(); // never let the browser navigate to the dropped file
|
|
158
|
+
depth = 0;
|
|
159
|
+
showOverlay(false);
|
|
160
|
+
const files = Array.from(e.dataTransfer.files || []);
|
|
161
|
+
if (files.length > 1) {
|
|
162
|
+
showError('Drop one .zip file at a time.');
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
upload(files[0]);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
initImport();
|