Skip to content

Commit

Permalink
fix --version cli flag (#3397)
Browse files Browse the repository at this point in the history
  • Loading branch information
swrdfish authored Sep 23, 2022
1 parent 1446baf commit 1fc117b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const TimedCallback = require('./timed-callback.js');
const getFreePort = require('./getFreePort.js');
const requireModule = require('./requireModule.js');
const getAllClassMethodNames = require('./getAllClassMethodNames.js');
const {VERSION} = require('./version.js');
const VERSION = require('./version.js');
const printVersionInfo = require('./printVersionInfo.js');
const {filterStack, filterStackTrace, showStackTrace, stackTraceFilter, errorToStackTrace} = require('./stackTrace.js');
const beautifyStackTrace = require('./beautifyStackTrace.js');
Expand Down
22 changes: 6 additions & 16 deletions lib/utils/version.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
const readFileSync = require('fs').readFileSync;
const resolve = require('path').resolve;

class Version {
constructor(full) {
this.full = full;
this.major = full.split('.')[0];
this.minor = full.split('.')[1];
this.patch = full.split('.').slice(2).join('.');
}
}
const packageConfig = require(__dirname + '/../../package.json');
const fullVersion = packageConfig.version;

const VERSION = new Version(
require(__dirname + '/../../package.json').version
);

module.exports = {
VERSION
full: fullVersion,
major: fullVersion.split('.')[0],
minor: fullVersion.split('.')[1],
patch: fullVersion.split('.').slice(2).join('.')
};
22 changes: 22 additions & 0 deletions test/src/utils/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,26 @@ describe('test Utils', function() {
assert.strictEqual(Utils.SafeJSON.stringify(proxyObj), '"[Error]"');
});

it('test printVersionInfo', function() {
const semVerRegex = /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?/;

const oldConsole = console;
const logArgs = [];

// eslint-disable-next-line no-console
console.log = function(args) {
logArgs.push(args);
};

Utils.printVersionInfo();
const logString = logArgs.join('\n');

assert.match(logString, /Nightwatch:/);
assert.match(logString, /version:/);
assert.match(logString, /changelog: https:\/\/github.com\/nightwatchjs\/nightwatch\/releases\/tag\//);
assert.match(logString, semVerRegex);

// eslint-disable-next-line no-global-assign
console = oldConsole;
});
});

0 comments on commit 1fc117b

Please sign in to comment.