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.4 #204

Merged
merged 9 commits into from
Aug 29, 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
4 changes: 2 additions & 2 deletions .github/workflows/CI-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ jobs:
run: npm install
- name: Run lint
run: npm run lint
# - name: Run tests and check coverage
# run: npm run test:coverage
- name: Run tests and check coverage
run: npm run test:coverage
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
run: npm install
- name: Run lint
run: npm run lint
# - name: Run tests and check coverage
# run: npm run test:coverage
- name: Run tests and check coverage
run: npm run test:coverage

publish-to-npm-and-gpr:
needs: build
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Fixed
- Video attachment won't play after downloading, resolves [#202](https://github.com/reportportal/agent-js-cypress/issues/202). Thanks to [ashvinjaiswal](https://github.com/ashvinjaiswal).

## [5.3.3] - 2024-08-15
### Added
Expand Down
52 changes: 26 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.3
5.3.4-SNAPSHOT
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
'!lib/ipcServer.js',
'!lib/testStatuses.js',
'!lib/worker.js',
'!lib/utils/attachments.js',
],
coverageThreshold: {
global: {
Expand Down
6 changes: 3 additions & 3 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ class Reporter {
}

finishSuiteWithVideo(suiteInfo, suiteFinishObj) {
const uploadVideoOnPasses = this.config.uploadVideoOnPasses || false;
const uploadVideoForNonFailedSpec = this.config.uploadVideoForNonFailedSpec || false;
const suiteFailed = suiteFinishObj.status === testItemStatuses.FAILED;

// do not upload video if root suite passes and uploadVideoOnPasses is false
if ((!suiteFailed && !uploadVideoOnPasses) || !suiteInfo.testFileName) {
// do not upload video if root suite not failed and uploadVideoForNonFailedSpec is false
if ((!suiteFailed && !uploadVideoForNonFailedSpec) || !suiteInfo.testFileName) {
this.finishSuite(suiteFinishObj, suiteInfo.tempId);
} else {
const sendVideoPromise = this.sendVideo(suiteInfo).finally(() => {
Expand Down
134 changes: 134 additions & 0 deletions lib/utils/attachments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const fs = require('fs');
const glob = require('glob');
const path = require('path');

const fsPromises = fs.promises;

const DEFAULT_WAIT_FOR_FILE_TIMEOUT = 10000;
const DEFAULT_WAIT_FOR_FILE_INTERVAL = 500;

const getScreenshotAttachment = async (absolutePath) => {
if (!absolutePath) return absolutePath;
const name = absolutePath.split(path.sep).pop();
return {
name,
type: 'image/png',
content: await fsPromises.readFile(absolutePath, { encoding: 'base64' }),
};
};

async function getFilePathByGlobPattern(globFilePattern) {
const files = await glob.glob(globFilePattern);

if (files.length) {
return files[0];
}

return null;
}
/*
* The moov atom in an MP4 file is a crucial part of the file’s structure. It contains metadata about the video, such as the duration, display characteristics, and timing information.
* Function check for the moov atom in file content and ensure is video file ready.
*/
const checkVideoFileReady = async (videoFilePath) => {
try {
const fileData = await fsPromises.readFile(videoFilePath);

if (fileData.includes('moov')) {
return true;
}
} catch (e) {
throw new Error(`Error reading file: ${e.message}`);
}

return false;
};

const waitForVideoFile = (
globFilePattern,
timeout = DEFAULT_WAIT_FOR_FILE_TIMEOUT,
interval = DEFAULT_WAIT_FOR_FILE_INTERVAL,
) =>
new Promise((resolve, reject) => {
let filePath = null;
let totalFileWaitingTime = 0;

async function checkFileExistsAndReady() {
if (!filePath) {
filePath = await getFilePathByGlobPattern(globFilePattern);
}
let isVideoFileReady = false;

if (filePath) {
isVideoFileReady = await checkVideoFileReady(filePath);
}

if (isVideoFileReady) {
resolve(filePath);
} else if (totalFileWaitingTime >= timeout) {
reject(
new Error(
`Timeout of ${timeout}ms reached, file ${globFilePattern} not found or not ready yet.`,
),
);
} else {
totalFileWaitingTime += interval;
setTimeout(checkFileExistsAndReady, interval);
}
}

checkFileExistsAndReady().catch(reject);
});

const getVideoFile = async (
specFileName,
videosFolder = '**',
timeout = DEFAULT_WAIT_FOR_FILE_TIMEOUT,
interval = DEFAULT_WAIT_FOR_FILE_INTERVAL,
) => {
if (!specFileName) {
return null;
}
const fileName = specFileName.toLowerCase().endsWith('.mp4')
? specFileName
: `${specFileName}.mp4`;
const globFilePath = `**/${videosFolder}/${fileName}`;
let videoFilePath;

try {
videoFilePath = await waitForVideoFile(globFilePath, timeout, interval);
} catch (e) {
console.warn(e.message);
return null;
}

return {
name: fileName,
type: 'video/mp4',
content: await fsPromises.readFile(videoFilePath, { encoding: 'base64' }),
};
};

module.exports = {
getScreenshotAttachment,
getVideoFile,
waitForVideoFile,
getFilePathByGlobPattern,
checkVideoFileReady,
};
22 changes: 22 additions & 0 deletions lib/utils/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const getCodeRef = (testItemPath, testFileName) =>
`${testFileName.replace(/\\/g, '/')}/${testItemPath.join('/')}`;

module.exports = {
getCodeRef,
};
27 changes: 27 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const attachmentUtils = require('./attachments');
const commonUtils = require('./common');
const objectCreators = require('./objectCreators');
const specCountCalculation = require('./specCountCalculation');

module.exports = {
...attachmentUtils,
...commonUtils,
...objectCreators,
...specCountCalculation,
};
Loading