@arghajit/dummy 0.3.31 → 0.3.33
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.
|
@@ -42,6 +42,7 @@ const path = __importStar(require("path"));
|
|
|
42
42
|
const crypto_1 = require("crypto");
|
|
43
43
|
const ua_parser_js_1 = __importDefault(require("ua-parser-js"));
|
|
44
44
|
const os = __importStar(require("os"));
|
|
45
|
+
const compression_utils_1 = require("../utils/compression-utils");
|
|
45
46
|
const convertStatus = (status, testCase) => {
|
|
46
47
|
if ((testCase === null || testCase === void 0 ? void 0 : testCase.expectedStatus) === "failed") {
|
|
47
48
|
return "failed";
|
|
@@ -325,7 +326,10 @@ class PlaywrightPulseReporter {
|
|
|
325
326
|
const relativeDestPath = path.join(ATTACHMENTS_SUBDIR, testSubfolder, uniqueFileName);
|
|
326
327
|
const absoluteDestPath = path.join(this.outputDir, relativeDestPath);
|
|
327
328
|
await this._ensureDirExists(path.dirname(absoluteDestPath));
|
|
329
|
+
// Copy file first
|
|
328
330
|
await fs.copyFile(attachment.path, absoluteDestPath);
|
|
331
|
+
// Compress in-place (preserves path/name)
|
|
332
|
+
await (0, compression_utils_1.compressAttachment)(absoluteDestPath, attachment.contentType);
|
|
329
333
|
if (attachment.contentType.startsWith("image/")) {
|
|
330
334
|
(_m = pulseResult.screenshots) === null || _m === void 0 ? void 0 : _m.push(relativeDestPath);
|
|
331
335
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compression utilities for images
|
|
3
|
+
* Uses sharp for image compression (works cross-platform with no external dependencies)
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Compress an image file in-place
|
|
7
|
+
* @param filePath - Absolute path to the image file
|
|
8
|
+
* @param options - Compression options
|
|
9
|
+
*/
|
|
10
|
+
export declare function compressImage(filePath: string, options?: {
|
|
11
|
+
quality?: number;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Compress an attachment file (auto-detects type)
|
|
15
|
+
* Note: Only compresses images. Videos are already compressed by Playwright.
|
|
16
|
+
* @param filePath - Absolute path to the file
|
|
17
|
+
* @param contentType - MIME content type
|
|
18
|
+
*/
|
|
19
|
+
export declare function compressAttachment(filePath: string, contentType: string): Promise<void>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/utils/compression-utils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Compression utilities for images
|
|
5
|
+
* Uses sharp for image compression (works cross-platform with no external dependencies)
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.compressImage = compressImage;
|
|
42
|
+
exports.compressAttachment = compressAttachment;
|
|
43
|
+
const fs = __importStar(require("fs/promises"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
/**
|
|
46
|
+
* Compress an image file in-place
|
|
47
|
+
* @param filePath - Absolute path to the image file
|
|
48
|
+
* @param options - Compression options
|
|
49
|
+
*/
|
|
50
|
+
async function compressImage(filePath, options = {}) {
|
|
51
|
+
try {
|
|
52
|
+
const sharp = require('sharp');
|
|
53
|
+
const quality = options.quality || 75;
|
|
54
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
55
|
+
// Read original file
|
|
56
|
+
const imageBuffer = await fs.readFile(filePath);
|
|
57
|
+
let compressedBuffer;
|
|
58
|
+
if (ext === '.png') {
|
|
59
|
+
// Compress PNG
|
|
60
|
+
compressedBuffer = await sharp(imageBuffer)
|
|
61
|
+
.png({ quality, compressionLevel: 9 })
|
|
62
|
+
.toBuffer();
|
|
63
|
+
}
|
|
64
|
+
else if (ext === '.jpg' || ext === '.jpeg') {
|
|
65
|
+
// Compress JPEG
|
|
66
|
+
compressedBuffer = await sharp(imageBuffer)
|
|
67
|
+
.jpeg({ quality, mozjpeg: true })
|
|
68
|
+
.toBuffer();
|
|
69
|
+
}
|
|
70
|
+
else if (ext === '.webp') {
|
|
71
|
+
// Compress WebP
|
|
72
|
+
compressedBuffer = await sharp(imageBuffer)
|
|
73
|
+
.webp({ quality })
|
|
74
|
+
.toBuffer();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Unsupported format, skip compression
|
|
78
|
+
console.log(`Compression skipped for unsupported format: ${ext}`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Only overwrite if compression actually reduced size
|
|
82
|
+
if (compressedBuffer.length < imageBuffer.length) {
|
|
83
|
+
await fs.writeFile(filePath, compressedBuffer);
|
|
84
|
+
const savedBytes = imageBuffer.length - compressedBuffer.length;
|
|
85
|
+
const savedPercent = ((savedBytes / imageBuffer.length) * 100).toFixed(1);
|
|
86
|
+
console.log(`Compressed ${path.basename(filePath)}: ${savedPercent}% smaller`);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.log(`Skipped ${path.basename(filePath)}: compression didn't reduce size`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.warn(`Failed to compress image ${filePath}:`, error.message);
|
|
94
|
+
// File remains unchanged
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Compress an attachment file (auto-detects type)
|
|
99
|
+
* Note: Only compresses images. Videos are already compressed by Playwright.
|
|
100
|
+
* @param filePath - Absolute path to the file
|
|
101
|
+
* @param contentType - MIME content type
|
|
102
|
+
*/
|
|
103
|
+
async function compressAttachment(filePath, contentType) {
|
|
104
|
+
if (contentType.startsWith('image/')) {
|
|
105
|
+
await compressImage(filePath, { quality: 75 });
|
|
106
|
+
}
|
|
107
|
+
// Videos are skipped - already compressed by Playwright as WebM
|
|
108
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arghajit/dummy",
|
|
3
3
|
"author": "Arghajit Singha",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.33",
|
|
5
5
|
"description": "A Playwright reporter and dashboard for visualizing test results.",
|
|
6
6
|
"homepage": "https://arghajit47.github.io/playwright-pulse/",
|
|
7
7
|
"repository": {
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"node-fetch": "^3.3.2",
|
|
74
74
|
"nodemailer": "^7.0.3",
|
|
75
75
|
"patch-package": "^8.0.0",
|
|
76
|
+
"sharp": "^0.33.5",
|
|
76
77
|
"ua-parser-js": "^1.0.41",
|
|
77
78
|
"zod": "^3.24.2"
|
|
78
79
|
},
|