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

feat: add logging #34

Merged
merged 3 commits into from
Aug 14, 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
14 changes: 14 additions & 0 deletions helpers/logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +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`;

fs.appendFile(logFilePath, logMessage, (err) => {
if (err) {
console.error('Failed to write to log file:', err);
}
});
};
36 changes: 22 additions & 14 deletions helpers/rpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@ const { STATUSES } = require('../constants/statuses');
const fs = require('fs');
const path = require('path');
const RestClient = require('./restClient');
const logToFile = require('./logging');
const debug = require('debug')('codeceptjs:reportportal');
const restClient = new RestClient();
const { output, event } = codeceptjs;
let rpClient;

async function startLaunch(config, suiteTitle) {
rpClient = new RPClient({
apiKey: config.token,
endpoint: config.endpoint,
project: config.projectName,
debug: config.debug,
});
try {
rpClient = new RPClient({
apiKey: config.token,
endpoint: config.endpoint,
project: config.projectName,
debug: config.debug,
});

return rpClient.startLaunch({
name: config.launchName || suiteTitle,
description: config.launchDescription,
attributes: config.launchAttributes,
rerun: config.rerun,
rerunOf: config.rerunOf,
mode: LAUNCH_MODES.DEFAULT,
});
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,
});
return launchObj;
} catch (e) {
logToFile(`Could not start launch due to: ${e.message}`);
}
}

async function finishLaunch(launchObj, launchStatus) {
Expand Down
Loading
Loading