Skip to content

Commit

Permalink
fix: lint issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Aug 14, 2024
1 parent 9894e3b commit 2e281cf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
19 changes: 9 additions & 10 deletions helpers/logging.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const fs = require('fs');
const path = require('path');


module.exports = function logToFile(message) {
const logFilePath = path.join(output_dir, 'codeceptjs-reportportal.log');
const timestamp = new Date().toISOString();
const logMessage = `[${timestamp}] ${message}\n`;
const logFilePath = path.join(output_dir, 'codeceptjs-reportportal.log');
const timestamp = new Date().toISOString();
const logMessage = `[${timestamp}] ${message}\n`;

fs.appendFile(logFilePath, logMessage, (err) => {
if (err) {
console.error('Failed to write to log file:', err);
}
});
}
fs.appendFile(logFilePath, logMessage, (err) => {
if (err) {
console.error('Failed to write to log file:', err);
}
});
};
17 changes: 8 additions & 9 deletions helpers/rpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { STATUSES } = require('../constants/statuses');
const fs = require('fs');
const path = require('path');
const RestClient = require('./restClient');
const logToFile = require("./logging");
const logToFile = require('./logging');
const debug = require('debug')('codeceptjs:reportportal');
const restClient = new RestClient();
const { output, event } = codeceptjs;
Expand All @@ -23,16 +23,15 @@ async function startLaunch(config, suiteTitle) {
logToFile(`Creating new RP Client: ${JSON.stringify(rpClient, null, 2)}`);

const launchObj = rpClient.startLaunch({
name: config.launchName || suiteTitle,
description: config.launchDescription,
attributes: config.launchAttributes,
rerun: config.rerun,
rerunOf: config.rerunOf,
mode: LAUNCH_MODES.DEFAULT,
});
name: config.launchName || suiteTitle,
description: config.launchDescription,
attributes: config.launchAttributes,
rerun: config.rerun,
rerunOf: config.rerunOf,
mode: LAUNCH_MODES.DEFAULT,
});
return launchObj;
} catch (e) {
throw Error(`Could not start launch due to: ${e.message}`);
logToFile(`Could not start launch due to: ${e.message}`);
}
}
Expand Down
25 changes: 15 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
const { finishTestItem } = require('./helpers/rpHelpers');
const { version } = require('./package.json');
const deepMerge = require('lodash.merge');
const logToFile = require("./helpers/logging");
const logToFile = require('./helpers/logging');

const helpers = container.helpers();
let helper;
Expand Down Expand Up @@ -160,7 +160,8 @@ module.exports = (passedConfig) => {
suite,
TEST_ITEM_TYPES.SUITE,
);
suiteObj.status = testArr.failed.length > 0 ? STATUSES.FAILED : STATUSES.PASSED;
suiteObj.status =
testArr.failed.length > 0 ? STATUSES.FAILED : STATUSES.PASSED;
suiteTempIdArr.push({
suiteTitle: suite,
suiteTempId: suiteObj.tempId,
Expand Down Expand Up @@ -277,10 +278,12 @@ module.exports = (passedConfig) => {
: PREFIX_PASSED_STEP;
const stepTitle = stepArgs
? `${prefix}: ${step.actor} ${step.name} ${JSON.stringify(
stepArgs
.map((item) => (item?._secret ? '*****' : JSON.stringify(item)))
.join(' '),
)}`
stepArgs
.map((item) =>
item?._secret ? '*****' : JSON.stringify(item),
)
.join(' '),
)}`
: `${prefix}: - ${step.actor} ${step.name}`;

await sleep(1);
Expand All @@ -293,7 +296,9 @@ module.exports = (passedConfig) => {
);

stepObj.status =
step.status === STATUSES.FAILED ? STATUSES.FAILED : STATUSES.PASSED;
step.status === STATUSES.FAILED
? STATUSES.FAILED
: STATUSES.PASSED;

if (stepObj.status === STATUSES.FAILED) {
let stepMessage;
Expand Down Expand Up @@ -345,10 +350,8 @@ module.exports = (passedConfig) => {
logToFile(`Could not start launch due to: ${e.message}`);
}
} catch (e) {
throw Error(`Could not start launch due to: ${e.message}`);
logToFile(`Could not start launch due to: ${e.message}`);
}

}

async function startMetaSteps(step, parentTitle) {
Expand Down Expand Up @@ -390,7 +393,9 @@ module.exports = (passedConfig) => {
metaStep.tempId
}: The stepId '${metaStep.toString()}' is started. Nested: ${isNested}`,
);
logToFile(`Metastep started: ${metaStep.toString()} - Nested: ${isNested}`);
logToFile(
`Metastep started: ${metaStep.toString()} - Nested: ${isNested}`,
);
}

currentMetaSteps = metaSteps;
Expand Down

0 comments on commit 2e281cf

Please sign in to comment.