Merge pull request #81 from muffinresearch/require-at-least-node-0.12.x

Require at least node 0.12.x
This commit is contained in:
Stuart Colville 2015-10-13 16:50:48 +01:00
Родитель 9eef5907a1 65a5129d2c
Коммит 284169c502
7 изменённых файлов: 58 добавлений и 3 удалений

1
.nvmrc Normal file
Просмотреть файл

@ -0,0 +1 @@
0.12

Просмотреть файл

@ -1,7 +1,7 @@
language: node_js
sudo: false
node_js:
- '0.10'
- '0.12'
script: npm test
notifications:
irc:

Просмотреть файл

@ -7,6 +7,12 @@
The Add-ons Validator, JS edition.
## Required node version
Node v0.12.x or greater is required. Using nvm is probably the easiest way
to manage multiple node versions side by side. See
[nvm on github](https://github.com/creationix/nvm) for more details.
## Install dependencies
Install dependencies with [npm](http://nodejs.org/):

Просмотреть файл

@ -47,6 +47,7 @@
"css": "2.2.1",
"es6-promisify": "3.0.0",
"eslint": "1.6.0",
"semver": "5.0.3",
"xmldom": "0.1.19",
"yargs": "3.27.0",
"yauzl": "2.3.1"

Просмотреть файл

@ -1,3 +1,5 @@
import semver from 'semver';
/*
* Implementation of String.endsWith, which errors in node.
*
@ -45,3 +47,19 @@ export function singleLineString(strings, ...vars) {
export function gettext(str) {
return str;
}
/*
* Check the minimum node version is met
*/
export function checkMinNodeVersion(minVersion, _process=process) {
return new Promise((resolve, reject) => {
minVersion = minVersion || '0.12.0';
if (!semver.gte(_process.version, minVersion)) {
reject(new Error(singleLineString`Node version must be ${minVersion} or
greater. You are using ${_process.version}.`));
} else {
resolve();
}
});
}

Просмотреть файл

@ -8,7 +8,7 @@ import promisify from 'es6-promisify';
import * as constants from 'const';
import * as exceptions from 'exceptions';
import * as messages from 'messages';
import { gettext as _, singleLineString } from 'utils';
import { checkMinNodeVersion, gettext as _, singleLineString } from 'utils';
import Collector from 'collector';
import CSSScanner from 'validators/css';
@ -221,7 +221,10 @@ export default class Validator {
scan(_Xpi=Xpi) {
return new Promise((resolve, reject) => {
this.checkFileExists(this.packagePath)
checkMinNodeVersion()
.then(() => {
return this.checkFileExists(this.packagePath);
})
.then(() => {
this.xpi = new _Xpi(this.packagePath);
return this.xpi.getFilesByExt('.js');

Просмотреть файл

@ -25,6 +25,7 @@ describe('utils.endsWith()', function() {
});
});
describe('utils.singleLineString()', function() {
it('reduce a multiline template string into one string', () => {
@ -59,3 +60,28 @@ describe('utils.singleLineString()', function() {
});
});
describe('utils.checkMinNodeVersion()', function() {
it('should reject if version is not high enough', () => {
var fakeProcess = {
version: 'v0.12.4',
};
return utils.checkMinNodeVersion('0.12.7', fakeProcess)
.then(() => {
assert.fail(null, null, 'Unexpected success');
})
.catch((err) => {
assert.include(err.message, 'Node version must be 0.12.7 or greater');
});
});
it('should not reject if version is not high enough', () => {
var fakeProcess = {
version: 'v4.1.2',
};
return utils.checkMinNodeVersion('0.12.7', fakeProcess);
});
});