Skip to content

Commit

Permalink
Merge pull request #206 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.3.5
  • Loading branch information
AmsterGet authored Sep 11, 2024
2 parents 77cd03e + 5a2c1f5 commit 179bb53
Show file tree
Hide file tree
Showing 8 changed files with 638 additions and 404 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Added
- `videoCompression` option. Allows compressing Cypress videos before uploading them to the ReportPortal. Check the readme for details. Thanks to [ashvinjaiswal](https://github.com/ashvinjaiswal).

## [5.3.4] - 2024-08-29
### Fixed
Expand Down
53 changes: 27 additions & 26 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.4
5.3.5-SNAPSHOT
4 changes: 3 additions & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@ class Reporter {
}

async sendVideo(suiteInfo) {
const { waitForVideoTimeout, waitForVideoInterval, videosFolder } = this.config;
const { waitForVideoTimeout, waitForVideoInterval, videosFolder, videoCompression } =
this.config;
const { testFileName, tempId, title } = suiteInfo;
const file = await getVideoFile(
testFileName,
videoCompression,
videosFolder,
waitForVideoTimeout,
waitForVideoInterval,
Expand Down
40 changes: 40 additions & 0 deletions lib/utils/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const ffmpeg = require('fluent-ffmpeg');
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffprobeStatic = require('ffprobe-static');

ffmpeg.setFfmpegPath(ffmpegInstaller.path);
ffmpeg.setFfprobePath(ffprobeStatic.path);

const fsPromises = fs.promises;

const DEFAULT_WAIT_FOR_FILE_TIMEOUT = 10000;
const DEFAULT_WAIT_FOR_FILE_INTERVAL = 500;
const DEFAULT_CRF = 32;
const MIN_CRF = 1;
const MAX_CRF = 52;

const getScreenshotAttachment = async (absolutePath) => {
if (!absolutePath) return absolutePath;
Expand Down Expand Up @@ -96,8 +105,28 @@ const waitForVideoFile = (
checkFileExistsAndReady().catch(reject);
});

const compressVideo = (filePath, crfValue) => {
return new Promise((resolve, reject) => {
const outputFilePath = path.join(
path.dirname(filePath),
`compressed_${path.basename(filePath)}`,
);

ffmpeg(filePath)
.outputOptions(`-crf ${crfValue}`)
.save(outputFilePath)
.on('end', () => {
resolve(outputFilePath);
})
.on('error', (err) => {
reject(err);
});
});
};

const getVideoFile = async (
specFileName,
videoCompression = false,
videosFolder = '**',
timeout = DEFAULT_WAIT_FOR_FILE_TIMEOUT,
interval = DEFAULT_WAIT_FOR_FILE_INTERVAL,
Expand All @@ -113,6 +142,16 @@ const getVideoFile = async (

try {
videoFilePath = await waitForVideoFile(globFilePath, timeout, interval);

if (typeof videoCompression === 'boolean' && videoCompression) {
videoFilePath = await compressVideo(videoFilePath, DEFAULT_CRF);
} else if (
typeof videoCompression === 'number' &&
videoCompression >= MIN_CRF &&
videoCompression < MAX_CRF
) {
videoFilePath = await compressVideo(videoFilePath, videoCompression);
}
} catch (e) {
console.warn(e.message);
return null;
Expand All @@ -131,4 +170,5 @@ module.exports = {
waitForVideoFile,
getFilePathByGlobPattern,
checkVideoFileReady,
compressVideo,
};
Loading

0 comments on commit 179bb53

Please sign in to comment.