@vizzly-testing/cli 0.13.0 → 0.13.1
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.
|
@@ -1,54 +1,16 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { writeFileSync, readFileSync, existsSync } from 'fs';
|
|
3
3
|
import { join, resolve } from 'path';
|
|
4
|
+
import honeydiff from '@vizzly-testing/honeydiff';
|
|
4
5
|
import { createServiceLogger } from '../../utils/logger-factory.js';
|
|
5
6
|
import { TddService } from '../../services/tdd-service.js';
|
|
6
7
|
import { sanitizeScreenshotName, validateScreenshotProperties } from '../../utils/security.js';
|
|
7
8
|
import { detectImageInputType } from '../../utils/image-input-detector.js';
|
|
9
|
+
let {
|
|
10
|
+
getDimensionsSync
|
|
11
|
+
} = honeydiff;
|
|
8
12
|
const logger = createServiceLogger('TDD-HANDLER');
|
|
9
13
|
|
|
10
|
-
/**
|
|
11
|
-
* Detect PNG dimensions by reading the IHDR chunk header
|
|
12
|
-
* PNG spec (ISO/IEC 15948:2004) guarantees width/height at bytes 16-23
|
|
13
|
-
* @param {Buffer} buffer - PNG image buffer
|
|
14
|
-
* @returns {{ width: number, height: number } | null} Dimensions or null if not a valid PNG
|
|
15
|
-
*/
|
|
16
|
-
const detectPNGDimensions = buffer => {
|
|
17
|
-
// Full PNG signature (8 bytes): 89 50 4E 47 0D 0A 1A 0A
|
|
18
|
-
const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
19
|
-
|
|
20
|
-
// Need at least 24 bytes (8 signature + 4 length + 4 type + 8 width/height)
|
|
21
|
-
if (!buffer || buffer.length < 24) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Validate full 8-byte PNG signature
|
|
26
|
-
for (let i = 0; i < PNG_SIGNATURE.length; i++) {
|
|
27
|
-
if (buffer[i] !== PNG_SIGNATURE[i]) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Validate IHDR chunk type at bytes 12-15 (should be 'IHDR')
|
|
33
|
-
// 0x49484452 = 'IHDR' in ASCII
|
|
34
|
-
if (buffer[12] !== 0x49 || buffer[13] !== 0x48 || buffer[14] !== 0x44 || buffer[15] !== 0x52) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Read width and height from IHDR chunk (guaranteed positions per PNG spec)
|
|
39
|
-
const width = buffer.readUInt32BE(16); // Bytes 16-19
|
|
40
|
-
const height = buffer.readUInt32BE(20); // Bytes 20-23
|
|
41
|
-
|
|
42
|
-
// Sanity check: dimensions should be positive and reasonable
|
|
43
|
-
if (width <= 0 || height <= 0 || width > 65535 || height > 65535) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
width,
|
|
48
|
-
height
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
14
|
/**
|
|
53
15
|
* Group comparisons by screenshot name with variant structure
|
|
54
16
|
* Matches cloud product's grouping logic from comparison.js
|
|
@@ -349,18 +311,19 @@ export const createTddHandler = (config, workingDir, baselineBuild, baselineComp
|
|
|
349
311
|
};
|
|
350
312
|
}
|
|
351
313
|
|
|
352
|
-
// Auto-detect image dimensions
|
|
353
|
-
// This matches cloud API behavior but without requiring Sharp
|
|
314
|
+
// Auto-detect image dimensions if viewport not provided
|
|
354
315
|
if (!extractedProperties.viewport_width || !extractedProperties.viewport_height) {
|
|
355
|
-
|
|
356
|
-
|
|
316
|
+
try {
|
|
317
|
+
const dimensions = getDimensionsSync(imageBuffer);
|
|
357
318
|
if (!extractedProperties.viewport_width) {
|
|
358
319
|
extractedProperties.viewport_width = dimensions.width;
|
|
359
320
|
}
|
|
360
321
|
if (!extractedProperties.viewport_height) {
|
|
361
322
|
extractedProperties.viewport_height = dimensions.height;
|
|
362
323
|
}
|
|
363
|
-
logger.debug(`Auto-detected dimensions
|
|
324
|
+
logger.debug(`Auto-detected dimensions: ${dimensions.width}x${dimensions.height}`);
|
|
325
|
+
} catch (err) {
|
|
326
|
+
logger.debug(`Failed to auto-detect dimensions: ${err.message}`);
|
|
364
327
|
}
|
|
365
328
|
}
|
|
366
329
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizzly-testing/cli",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Visual review platform for UI developers and designers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visual-testing",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"registry": "https://registry.npmjs.org/"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@vizzly-testing/honeydiff": "^0.1.
|
|
82
|
+
"@vizzly-testing/honeydiff": "^0.1.1",
|
|
83
83
|
"commander": "^14.0.0",
|
|
84
84
|
"cosmiconfig": "^9.0.0",
|
|
85
85
|
"dotenv": "^17.2.1",
|