Skip to content

Commit

Permalink
Update Logging in Test Beats (#200)
Browse files Browse the repository at this point in the history
* Add logger setup

* Refine basic logging messages

* Fix failing test

* Update Readme with NodeJS minimum version

* Remove unused imports

* Remove colors and restore formatting

* Revert fomat issue
  • Loading branch information
leelaprasadv authored Jun 28, 2024
1 parent ab05e5e commit d65da76
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 62 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ dist
.DS_STORE

# test
results
results


# ignore test/override config files
override-config*.json
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
![Downloads](https://img.shields.io/npm/dt/test-results-reporter?logo=npm&label=downloads-old)
![Downloads](https://img.shields.io/npm/dt/testbeats?logo=npm)
![Size](https://img.shields.io/bundlephobia/minzip/testbeats)
![NodeJs](https://img.shields.io/badge/NodeJS-%3E%3D14.0.0-brightgreen?logo=node.js)


[![Stars](https://img.shields.io/github/stars/test-results-reporter/testbeats?style=social)](https://github.com/test-results-reporter/testbeats/stargazers)
![Downloads](https://img.shields.io/github/downloads/test-results-reporter/testbeats/total?logo=github)
Expand Down
85 changes: 30 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"pretty-ms": "^7.0.1",
"rosters": "0.0.1",
"sade": "^1.8.1",
"semver": "^7.6.2",
"test-results-parser": "latest"
},
"devDependencies": {
Expand All @@ -64,5 +65,9 @@
"mocha-multi-reporters": "^1.5.1",
"pactum": "^3.2.3",
"pkg": "^5.8.0"
}
},
"engines": {
"node": ">=14.0.0"
},
"engineStrict": true
}
2 changes: 1 addition & 1 deletion src/beats/beats.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Beats {

async #publishTestResults() {
if (!this.config.api_key) {
logger.warn('😿 No API key provided, skipping publishing results to TestBeats Portal');
logger.warn('😿 No API key provided, skipping publishing results to TestBeats Portal...');
return;
}
logger.info("🚀 Publishing results to TestBeats Portal...");
Expand Down
9 changes: 7 additions & 2 deletions src/commands/publish.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const target_manager = require('../targets');
const logger = require('../utils/logger');
const { processData } = require('../helpers/helper');
const pkg = require('../../package.json');
const {checkEnvDetails} = require('../helpers/helper');

class PublishCommand {

Expand All @@ -20,6 +21,11 @@ class PublishCommand {

async publish() {
logger.info(`🥁 TestBeats v${pkg.version}`);

const envDetails = checkEnvDetails();
// Check OS and NodeJS version
logger.info(`💻 ${envDetails}`);

this.#buildConfig();
this.#validateOptions();
this.#setConfigFromFile();
Expand Down Expand Up @@ -52,8 +58,7 @@ class PublishCommand {
const config_json = require(path.join(cwd, this.opts.config));
this.opts.config = config_json;
} catch (error) {
logger.error({ error }, `Failed to read config file: '${file_path}' with error: '${error.message}'`);
throw new Error(`Config file not found: ${file_path}`);
throw new Error(`Failed to read config file: '${file_path}' with error: '${error.message}'`);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ const URLS = Object.freeze({
QUICK_CHART: 'https://quickchart.io'
});

const MIN_NODE_VERSION = '14.0.0'

module.exports = Object.freeze({
STATUS,
HOOK,
TARGET,
EXTENSION,
URLS
URLS,
MIN_NODE_VERSION
});
16 changes: 16 additions & 0 deletions src/helpers/helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const pretty_ms = require('pretty-ms');
const os = require('os');
const semver = require('semver');
const {MIN_NODE_VERSION } = require('./constants');

const DATA_REF_PATTERN = /(\{[^\}]+\})/g;
const ALLOWED_CONDITIONS = new Set(['pass', 'fail', 'passorfail']);
Expand Down Expand Up @@ -71,6 +74,18 @@ function getResultText({ result }) {
return `${result.passed} / ${result.total} Passed (${percentage}%)`;
}

/**
* Checks Environment/System details
* OS Version, NodeJS Version
*/
function checkEnvDetails() {
if (!semver.gte(process.version, MIN_NODE_VERSION)) {
throw new Error(`❌ Supported NodeJS version is >= v${MIN_NODE_VERSION}. Current version is ${process.version}`)
}

return `Environment Details - NodeJS ${process.version}, OS: ${os.platform()}, Version: ${os.release()}, arch: ${os.machine()}`
}

/**
*
* @param {object} param0
Expand Down Expand Up @@ -99,4 +114,5 @@ module.exports = {
getTitleText,
getResultText,
checkCondition,
checkEnvDetails,
}
2 changes: 1 addition & 1 deletion test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Config', () => {
} catch (err) {
e = err;
}
assert.match(e.message, /Config file not found:/);
assert.match(e.message, /Failed to read config file:/);
});

it('should not allow empty config', async () => {
Expand Down

0 comments on commit d65da76

Please sign in to comment.