Update node version checks
MODIFY
lib/config.js
lib/config.js
@@ -5,20 +5,23 @@ import request from 'request-promise';
import { exec } from 'teen_process';
import { rootDir } from './utils';
import logger from './logger';
+import semver from 'semver';
+
+
+const npmPackage = require(path.resolve(rootDir, 'package.json'));
+const APPIUM_VER = npmPackage.version;
+const MIN_NODE_VERSION = npmPackage.engines.node;
-const APPIUM_VER = require(path.resolve(rootDir, 'package.json')).version;
const GIT_META_ROOT = '.git';
const GIT_BINARY = `git${system.isWindows() ? '.exe' : ''}`;
const GITHUB_API = 'https://api.github.com/repos/appium/appium';
+
const BUILD_INFO = {
version: APPIUM_VER,
};
function getNodeVersion () {
- // expect v<major>.<minor>.<patch>
- // we will pull out `major` and `minor`
- let version = process.version.match(/^v(\d+)\.(\d+)/);
- return [Number(version[1]), Number(version[2])];
+ return semver.coerce(process.version);
}
async function updateBuildInfo (useGithubApiFallback = false) {
@@ -109,20 +112,24 @@ function getBuildInfo () {
}
function checkNodeOk () {
- let [major, minor] = getNodeVersion();
- if (major < 6) {
- let msg = `Node version must be >= 6. Currently ${major}.${minor}`;
- logger.errorAndThrow(msg);
+ const version = getNodeVersion();
+ if (!semver.satisfies(version, MIN_NODE_VERSION)) {
+ logger.errorAndThrow(`Node version must be ${MIN_NODE_VERSION}. Currently ${version.version}`);
}
}
function warnNodeDeprecations () {
- let [major] = getNodeVersion();
- if (major < 8) {
- logger.warn('Appium support for versions of node < 8 has been ' +
- 'deprecated and will be removed in a future version. Please ' +
- 'upgrade!');
- }
+ /**
+ * Uncomment this section to get node version deprecation warnings
+ * Also add test cases to config-specs.js to cover the cases added
+ **/
+
+ // const version = getNodeVersion();
+ // if (version.major < 8) {
+ // logger.warn(`Appium support for versions of node < ${version.major} has been ` +
+ // 'deprecated and will be removed in a future version. Please ' +
+ // 'upgrade!');
+ // }
}
async function showConfig () {

MODIFY
test/config-specs.js
test/config-specs.js
@@ -142,28 +142,20 @@ describe('Config', function () {
process = _process; // eslint-disable-line no-global-assign
});
describe('checkNodeOk', function () {
- it('should fail if node is below 6', function () {
- process.version = 'v4.4.7';
- checkNodeOk.should.throw();
- process.version = 'v0.9.12';
- checkNodeOk.should.throw();
- process.version = 'v0.1';
- checkNodeOk.should.throw();
- process.version = 'v0.10.36';
- checkNodeOk.should.throw();
- process.version = 'v0.12.14';
- checkNodeOk.should.throw();
- process.version = 'v5.7.0';
+ describe('unsupported nodes', function () {
+ const unsupportedVersions = [
+ 'v0.1', 'v0.9.12', 'v0.10.36', 'v0.12.14',
+ 'v4.4.7', 'v5.7.0', 'v6.3.1', 'v7.1.1',
+ ];
+ for (const version of unsupportedVersions) {
+ it(`should fail if node is ${version}`, function () {
+ process.version = version;
checkNodeOk.should.throw();
});
- it('should succeed if node is 6+', function () {
- process.version = 'v6.3.1';
- checkNodeOk.should.not.throw();
- });
- it('should succeed if node is 7+', function () {
- process.version = 'v7.1.1';
- checkNodeOk.should.not.throw();
+ }
});
+
+ describe('supported nodes', function () {
it('should succeed if node is 8+', function () {
process.version = 'v8.1.2';
checkNodeOk.should.not.throw();
@@ -172,6 +164,15 @@ describe('Config', function () {
process.version = 'v9.1.2';
checkNodeOk.should.not.throw();
});
+ it('should succeed if node is 10+', function () {
+ process.version = 'v10.0.1';
+ checkNodeOk.should.not.throw();
+ });
+ it('should succeed if node is 11+', function () {
+ process.version = 'v11.6.0';
+ checkNodeOk.should.not.throw();
+ });
+ });
});
describe('warnNodeDeprecations', function () {
@@ -182,11 +183,6 @@ describe('Config', function () {
beforeEach(function () {
spy.resetHistory();
});
- it('should log a warning if node is below 8', function () {
- process.version = 'v7.10.1';
- warnNodeDeprecations();
- logger.warn.callCount.should.equal(1);
- });
it('should not log a warning if node is 8+', function () {
process.version = 'v8.0.0';
warnNodeDeprecations();

Update node version checks (#11996)