@rettangoli/vt 0.0.4 → 0.0.6
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/package.json +1 -1
- package/src/cli/report.js +34 -0
- package/src/common.js +24 -1
package/package.json
CHANGED
package/src/cli/report.js
CHANGED
|
@@ -32,6 +32,34 @@ function getAllFiles(dir, fileList = []) {
|
|
|
32
32
|
return fileList;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
function extractParts(p) {
|
|
36
|
+
const dir = path.dirname(p);
|
|
37
|
+
const filename = path.basename(p, '.webp');
|
|
38
|
+
const lastHyphenIndex = filename.lastIndexOf('-');
|
|
39
|
+
|
|
40
|
+
if (lastHyphenIndex > -1) {
|
|
41
|
+
const suffix = filename.substring(lastHyphenIndex + 1);
|
|
42
|
+
const number = parseInt(suffix);
|
|
43
|
+
|
|
44
|
+
if (!isNaN(number) && String(number) === suffix) {
|
|
45
|
+
const name = path.join(dir, filename.substring(0, lastHyphenIndex));
|
|
46
|
+
return { name, number };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// -1 is for the first file (as it will result in the first index when sorting)
|
|
50
|
+
return { name: path.join(dir, filename), number: -1 };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function sortPaths(a, b) {
|
|
54
|
+
const partsA = extractParts(a);
|
|
55
|
+
const partsB = extractParts(b);
|
|
56
|
+
|
|
57
|
+
if (partsA.name < partsB.name) return -1;
|
|
58
|
+
if (partsA.name > partsB.name) return 1;
|
|
59
|
+
|
|
60
|
+
return partsA.number - partsB.number;
|
|
61
|
+
}
|
|
62
|
+
|
|
35
63
|
async function compareImages(artifactPath, goldPath) {
|
|
36
64
|
try {
|
|
37
65
|
const {equal, diffBounds, diffClusters} = await looksSame(artifactPath, goldPath, {
|
|
@@ -122,6 +150,8 @@ async function main(options = {}) {
|
|
|
122
150
|
...new Set([...candidateRelativePaths, ...referenceRelativePaths]),
|
|
123
151
|
];
|
|
124
152
|
|
|
153
|
+
allPaths.sort(sortPaths);
|
|
154
|
+
|
|
125
155
|
for (const relativePath of allPaths) {
|
|
126
156
|
const candidatePath = path.join(candidateDir, relativePath);
|
|
127
157
|
const referencePath = path.join(originalReferenceDir, relativePath);
|
|
@@ -206,6 +236,10 @@ async function main(options = {}) {
|
|
|
206
236
|
templatePath,
|
|
207
237
|
outputPath,
|
|
208
238
|
});
|
|
239
|
+
if(mismatchingItems.length > 0){
|
|
240
|
+
console.error("Error: there are more than 0 mismatching item.")
|
|
241
|
+
process.exit(1);
|
|
242
|
+
}
|
|
209
243
|
} catch (error) {
|
|
210
244
|
console.error("Error reading directories:", error);
|
|
211
245
|
}
|
package/src/common.js
CHANGED
|
@@ -263,7 +263,7 @@ async function takeScreenshots(
|
|
|
263
263
|
const screenshotPath = join(screenshotsDir, `${finalPath}.webp`);
|
|
264
264
|
ensureDirectoryExists(dirname(screenshotPath));
|
|
265
265
|
|
|
266
|
-
await page.screenshot({ path: tempPngPath, fullPage: true
|
|
266
|
+
await page.screenshot({ path: tempPngPath, fullPage: true});
|
|
267
267
|
await sharp(tempPngPath).webp({ quality: 85 }).toFile(screenshotPath);
|
|
268
268
|
|
|
269
269
|
if (existsSync(tempPngPath)) {
|
|
@@ -313,6 +313,12 @@ async function takeScreenshots(
|
|
|
313
313
|
case "rclick":
|
|
314
314
|
await page.mouse.click(Number(args[0]), Number(args[1]), { button: "right" });
|
|
315
315
|
break;
|
|
316
|
+
case "mouseDown":
|
|
317
|
+
await page.mouse.down();
|
|
318
|
+
break;
|
|
319
|
+
case "mouseUp":
|
|
320
|
+
await page.mouse.up();
|
|
321
|
+
break;
|
|
316
322
|
case "keypress":
|
|
317
323
|
await page.keyboard.press(args[0]);
|
|
318
324
|
break;
|
|
@@ -324,6 +330,23 @@ async function takeScreenshots(
|
|
|
324
330
|
const screenshotPath = await takeAndSaveScreenshot(page, `${baseName}-${screenshotIndex}`);
|
|
325
331
|
console.log(`Screenshot saved: ${screenshotPath}`);
|
|
326
332
|
break;
|
|
333
|
+
case "customEvent":
|
|
334
|
+
//Use to dispatch custom event for the test evironment to listen to
|
|
335
|
+
//customEvent <eventName> <...parameters>
|
|
336
|
+
//To listen to the event use
|
|
337
|
+
//window.addEventListener(<eventName>,(event)=>{
|
|
338
|
+
// console.log("The params that you pass through: ",event.detail)
|
|
339
|
+
//})
|
|
340
|
+
const [eventName, ...params] = args;
|
|
341
|
+
const payload = {};
|
|
342
|
+
params.forEach(param => {
|
|
343
|
+
const [key, value] = param.split('=');
|
|
344
|
+
payload[key] = value;
|
|
345
|
+
});
|
|
346
|
+
await page.evaluate(({eventName,payload}) => {
|
|
347
|
+
window.dispatchEvent(new CustomEvent(eventName, { detail: payload }));
|
|
348
|
+
},{eventName,payload});
|
|
349
|
+
break;
|
|
327
350
|
}
|
|
328
351
|
}
|
|
329
352
|
completed++;
|