This commit is contained in:
Stuart Colville 2015-09-25 18:38:16 +01:00
Родитель 62da0171e5
Коммит 58534e87bd
6 изменённых файлов: 153 добавлений и 2 удалений

4
bin/addons-validator Executable file
Просмотреть файл

@ -0,0 +1,4 @@
#!/usr/bin/env node
var cli = require('../dist/addons-validator').cli;
cli.argv;

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

@ -36,6 +36,7 @@
"webpack-dev-server": "1.11.0"
},
"dependencies": {
"yargs": "3.26.0",
"yauzl": "2.3.1"
}
}

81
src/cli.js Normal file
Просмотреть файл

@ -0,0 +1,81 @@
import argv from 'yargs';
import { version } from 'json!../package';
export var cli = argv
.usage('Usage: ./$0 [options] addon-package \n\n' +
'Add-ons Validator (JS Edition) v' + version)
// Addon type
.option('type', {
alias: 't',
describe: 'The type that you expect your add-on to be detected as.',
type: 'string',
default: 'any',
choices: [
'any', 'extension', 'theme',
'dictionary', 'languagepack',
'search', 'multi',
],
})
// Output type
.option('output', {
alias: 'o',
describe: 'The type of output to generate',
type: 'string',
default: 'text',
choices: ['json', 'text'],
})
// self-hosted add-on.
.option('selfhosted', {
describe: 'Indicates that the addon will not be hosted on ' +
'addons.mozilla.org. This allows the <em:updateURL> element ' +
'to be set.',
type: 'boolean',
default: false,
})
// Determined mode.
.option('determined', {
describe: 'This flag will continue running tests in successive ' +
'tests even if a lower tier fails',
type: 'boolean',
default: false,
})
// Boring mode
.option('boring', {
describe: 'Disables colorful shell output',
type: 'boolean',
default: false,
})
// target-maxversion
.option('target-maxversion', {
describe: "JSON string to override the package's " +
'targetapp_maxVersion for validation. The JSON object ' +
'should be a dict of versions keyed by application ' +
"GUID. For example, setting a package's max Firefox " +
'version to 5.*: ' +
'{"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "5.*"} ',
type: 'string',
})
// target-minversion
.option('target-minversion', {
describe: "JSON string to override the package's " +
'targetapp_minVersion for validation. The JSON object ' +
'should be a dict of versions keyed by application ' +
"GUID. For example, setting a package's min Firefox " +
'version to 5.*: ' +
'{"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "5.*"}',
type: 'string',
})
.option('for-appversions', {
describe: 'JSON string to run validation tests for ' +
'compatibility with a specific app/version. The JSON ' +
'object should be a dict of version lists keyed by ' +
'application GUID. For example, running Firefox 6.* ' +
'compatibility tests: ' +
'{"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": ["6.*"]',
type: 'string',
})
// Require one non-option.
.demand(1)
.help('help')
.alias('h', 'help')
.wrap(78);

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

@ -6,6 +6,10 @@ module.exports = {
build: {
// Use the default webpack options.
},
watch: {
watch: true,
keepalive: true,
},
test: {
entry: './tests/runner.js',
output: {

60
tests/test.cli.js Normal file
Просмотреть файл

@ -0,0 +1,60 @@
import { cli as cli_ } from 'cli';
// Sneaky way to make the cli throw so we can introspect the right errors
// are happening when we hand it bogus input.
var cli = cli_.exitProcess(false).fail(msg => {
throw new Error(msg);
});
describe('Basic CLI tests', function() {
it('should default Add-on type to "any"', () => {
var args = cli.parse(['foo/bar.xpi']);
assert.equal(args.type, 'any');
assert.equal(args.t, 'any');
});
it('should default add-on output to "text"', () => {
var args = cli.parse(['foo/bar.xpi']);
assert.equal(args.output, 'text');
assert.equal(args.o, 'text');
});
it('should default selfhosted to false', () => {
var args = cli.parse(['foo/bar.xpi']);
assert.equal(args.selfhosted, false);
});
it('should default determined to false', () => {
var args = cli.parse(['foo/bar.xpi']);
assert.equal(args.determined, false);
});
it('should default boring to false', () => {
var args = cli.parse(['foo/bar.xpi']);
assert.equal(args.boring, false);
});
it('should show error on missing xpi', () => {
assert.throws(() => {
cli.parse([]);
}, Error, 'Not enough non-option arguments');
});
it('should show error if incorrect type', () => {
assert.throws(() => {
cli.parse(['-t', 'false', 'whatevs']);
}, Error, 'Invalid values:\n Argument: type, Given: "false"');
});
it('should show error if incorrect output', () => {
assert.throws(() => {
cli.parse(['-o', 'false', 'whatevs']);
}, Error, 'Invalid values:\n Argument: output, Given: "false"');
});
});

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

@ -16,11 +16,12 @@ fs.readdirSync('node_modules')
module.exports = {
entry: './src/main.js',
entry: './src/cli.js',
target: 'node',
output: {
path: path.join(__dirname, 'dist'),
filename: 'addon-validator.js',
filename: 'addons-validator.js',
libraryTarget: 'commonjs2',
},
module: {
loaders: [