Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 5.3.5 #206

Merged
merged 5 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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