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

[ISSUE-261] Don't show Artifacts error message duplicates #293

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions lib/adapter/codecept.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const debug = require('debug')('@testomatio/reporter:adapter:codeceptjs');
const chalk = require('chalk');
const TestomatClient = require('../client');
const { STATUS, APP_PREFIX, TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
const { STATUS, TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
const upload = require('../fileUploader');
const { parseTest: getIdFromTestTitle, fileSystem } = require('../utils/utils');
const { services } = require('../services');
Expand Down Expand Up @@ -130,12 +130,13 @@ function CodeceptReporter(config) {
await Promise.all(reportTestPromises);

if (upload.isArtifactsEnabled()) {
uploadAttachments(client, videos, '🎞️ Uploading', 'video');
uploadAttachments(client, traces, '📁 Uploading', 'trace');
await uploadAttachments(client, videos, '🎞️ Uploading', 'video');
await uploadAttachments(client, traces, '📁 Uploading', 'trace');
}

const status = failedTests.length === 0 ? STATUS.PASSED : STATUS.FAILED;
client.updateRunStatus(status);

await client.updateRunStatus(status);
});

event.dispatcher.on(event.test.passed, test => {
Expand Down Expand Up @@ -311,7 +312,7 @@ function CodeceptReporter(config) {

async function uploadAttachments(client, attachments, messagePrefix, attachmentType) {
if (attachments.length > 0) {
console.log(APP_PREFIX, `Attachments: ${messagePrefix} ${attachments.length} ${attachmentType}/-s ...`);
debug(`Attachments: ${messagePrefix} ${attachments.length} ${attachmentType}/-s ...`);

const promises = attachments.map(async attachment => {
const { testId, title, path, type } = attachment;
Expand Down
2 changes: 1 addition & 1 deletion lib/adapter/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class JestReporter {

const { numFailedTests } = results;
const status = numFailedTests === 0 ? STATUS.PASSED : STATUS.FAILED;
this.client.updateRunStatus(status);
this.client.updateRunStatus(status); // TODO: it necessary use await?
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/adapter/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ function MochaReporter(runner, opts) {
});
});

runner.on(EVENT_RUN_END, () => {
runner.on(EVENT_RUN_END, async () => {
const status = failures === 0 ? STATUS.PASSED : STATUS.FAILED;
console.log(chalk.bold(status), `${passes} passed, ${failures} failed, ${skipped} skipped`);
client.updateRunStatus(status);
await client.updateRunStatus(status);
});
}

Expand Down
5 changes: 3 additions & 2 deletions lib/adapter/playwright.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const debug = require('debug')('@testomatio/reporter:adapter:playwright');
const chalk = require('chalk');
const crypto = require('crypto');
const os = require('os');
const path = require('path');
const fs = require('fs');
const { APP_PREFIX, STATUS: Status, TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
const { STATUS: Status, TESTOMAT_TMP_STORAGE_DIR } = require('../constants');
const TestomatioClient = require('../client');
const { isArtifactsEnabled } = require('../fileUploader');
const { parseTest, fileSystem } = require('../utils/utils');
Expand Down Expand Up @@ -79,7 +80,7 @@ class PlaywrightReporter {
await Promise.all(reportTestPromises);

if (this.uploads.length && isArtifactsEnabled()) {
console.log(APP_PREFIX, `🎞️ Uploading ${this.uploads.length} files...`);
debug(`🎞️ Uploading ${this.uploads.length} files...`);

const promises = [];

Expand Down
50 changes: 44 additions & 6 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Client {
this.pipes = pipesFactory(params, store);
this.queue = Promise.resolve();
this.totalUploaded = 0;
this.uploadError = {};
this.version = JSON.parse(fs.readFileSync(join(__dirname, '..', 'package.json')).toString()).version;
this.executionList = Promise.resolve();

Expand Down Expand Up @@ -167,8 +168,12 @@ class Client {

// global.testomatioArtifacts = [];

this.totalUploaded += uploadedFiles.filter(n => n).length;

// additional download file processing
this.uploadError =
artifacts.find(artifact => Object.prototype.hasOwnProperty.call(artifact, "uploadError"));
this.totalUploaded +=
artifacts.filter(artifact => !Object.prototype.hasOwnProperty.call(artifact, "uploadError") && artifact).length;

const data = {
files,
steps,
Expand All @@ -194,7 +199,11 @@ class Client {
this.pipes.map(async p => {
try {
const result = await p.addTest(data);
return { pipe: p.toString(), result };

return {
pipe: p.toString(),
result
};
} catch (err) {
console.log(APP_PREFIX, p.toString(), err);
}
Expand Down Expand Up @@ -222,15 +231,44 @@ class Client {
this.queue = this.queue
.then(() => Promise.all(this.pipes.map(p => p.finishRun(runParams))))
.then(() => {
const isArtifactsEnabled = upload.isArtifactsEnabled();

debug('TOTAL artifacts', this.totalUploaded);
if (this.totalUploaded && !upload.isArtifactsEnabled())
debug('isArtifactsEnabled', isArtifactsEnabled);

if(!this.totalUploaded && this.uploadError?.uploadError) {
console.log(APP_PREFIX,
`${chalk.bold('🚨 The artifact files were not uploaded because there was problem: ')}
${this.uploadError?.uploadError}`
);

return;
}

if (this.totalUploaded && !isArtifactsEnabled) {
debug(`${this.totalUploaded} artifacts are not uploaded, because artifacts uploading is not enabled`);
console.log(APP_PREFIX, `To ${chalk.bold('disable')} artifact uploads set: TESTOMATIO_DISABLE_ARTIFACTS=1`);

return;
}

if (this.totalUploaded && isArtifactsEnabled) {
const isBucketPrivate = !!+process.env.TESTOMATIO_PRIVATE_ARTIFACTS;

if (!isBucketPrivate) {
console.log(APP_PREFIX, `To enable ${chalk.bold('PRIVATE')} uploads set: TESTOMATIO_PRIVATE_ARTIFACTS=1`);
}

console.log(
APP_PREFIX,
`To enable ${chalk.bold('PUBLIC')} uploads remove TESTOMATIO_PRIVATE_ARTIFACTS env variable`,
);
console.log(APP_PREFIX, '---------------');

if (this.totalUploaded && upload.isArtifactsEnabled()) {
console.log(
APP_PREFIX,
`🗄️ ${this.totalUploaded} artifacts ${
process.env.TESTOMATIO_PRIVATE_ARTIFACTS ? 'privately' : chalk.bold('publicly')
isBucketPrivate ? 'privately' : chalk.bold('publicly')
} uploaded to S3 bucket`,
);
}
Expand Down
49 changes: 17 additions & 32 deletions lib/fileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,13 @@ const uploadUsingS3 = async (filePath, runId) => {

return await getS3LocationLink(out);
}
catch (e) {
debug('S3 file uploading error: ', e);

console.log(APP_PREFIX, `To ${chalk.bold('disable')} artifact uploads set: TESTOMATIO_DISABLE_ARTIFACTS=1`);

if (!TESTOMATIO_PRIVATE_ARTIFACTS) {
console.log(APP_PREFIX, `To enable ${chalk.bold('PRIVATE')} uploads set: TESTOMATIO_PRIVATE_ARTIFACTS=1`);
}
else {
console.log(
APP_PREFIX,
`To enable ${chalk.bold('PUBLIC')} uploads remove TESTOMATIO_PRIVATE_ARTIFACTS env variable`,
);
catch (err) {
debug('S3 file uploading error: ', err);
debug(APP_PREFIX, '---------------');

return {
uploadError: err
}
console.log(APP_PREFIX, '---------------');
}
};

Expand Down Expand Up @@ -204,20 +196,13 @@ const uploadUsingS3AsBuffer = async (buffer, fileName, runId) => {

return await getS3LocationLink(out);
}
catch (e) {
debug('S3 buffer uploading error: ', e);

console.log(APP_PREFIX, `To ${chalk.bold('disable')} artifact uploads set: TESTOMATIO_DISABLE_ARTIFACTS=1`);
catch (err) {
debug('S3 buffer uploading error: ', err);
debug(APP_PREFIX, '---------------');

if (!TESTOMATIO_PRIVATE_ARTIFACTS) {
console.log(APP_PREFIX, `To enable ${chalk.bold('PRIVATE')} uploads set: TESTOMATIO_PRIVATE_ARTIFACTS=1`);
} else {
console.log(
APP_PREFIX,
`To enable ${chalk.bold('PUBLIC')} uploads remove TESTOMATIO_PRIVATE_ARTIFACTS env variable`,
);
return {
uploadError: err
}
console.log(APP_PREFIX, '---------------');
}
};

Expand All @@ -226,10 +211,10 @@ const uploadFileByPath = async (filePath, runId) => {
if (isArtifactsEnabled()) {
return uploadUsingS3(filePath, runId);
}
} catch (e) {
debug(e);
} catch (err) {
debug(err);

console.error(chalk.red('Error occurred while uploading artifacts! '), e);
console.error(chalk.red('Error occurred while uploading artifacts! '));
}
};

Expand All @@ -238,10 +223,10 @@ const uploadFileAsBuffer = async (buffer, fileName, runId) => {
if (isArtifactsEnabled()) {
return uploadUsingS3AsBuffer(buffer, fileName, runId);
}
} catch (e) {
debug(e);
} catch (err) {
debug(err);

console.error(chalk.red('Error occurred while uploading artifacts! '), e);
console.error(chalk.red('Error occurred while uploading artifacts! '));
}
};

Expand Down
4 changes: 3 additions & 1 deletion tests/pipes/html_pipe_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ describe('HTML report tests', () => {
after(async () => {
try {
await fs.promises.rm(testOutputDir, { recursive: true });
// remove default html-report/ folder
await fs.promises.rm(path.resolve(__dirname, '../..', 'html-report'), { recursive: true });
} catch (err) {
console.error(`Unknown error while deleting ${dir}.`);
console.error(`Unknown error while deleting "html-report" folder. Error: ${err}`);
}
});
it('buildReport function should save HTML report based on the testomatio.hbs template' +
Expand Down
Loading