Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bin/addons-linter
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var path = require('path');
var absoluteAppRoot = path.resolve(__dirname);
global.appRoot = path.relative(process.cwd(), absoluteAppRoot);

var AddonLinter = require('../dist/addons-linter').createInstance();
AddonLinter.run();
require('../dist/addons-linter')
.createInstance({runAsBinary: true})
.run();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"markdown-it-anchor": "2.3.3",
"markdown-it-emoji": "1.1.0",
"mocha": "2.3.4",
"shelljs": "0.5.3",
"sinon": "1.17.2",
"webpack": "1.12.9",
"webpack-dev-server": "1.14.0"
Expand Down
15 changes: 14 additions & 1 deletion src/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,12 @@ export default class Linter {
})
.then(() => {
this.print();
return;
// This is skipped in the code coverage because the
// test runs against un-instrumented code.
/* istanbul ignore if */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is skipped in the code coverage because the test runs against un-instrumented code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Can you add this in as an inline comment?

if (this.config.runAsBinary === true) {
process.exit(this.output.errors.length > 0 ? 1 : 0);
}
})
.catch((err) => {
this.handleError(err, deps._console);
Expand All @@ -449,6 +454,14 @@ export default class Linter {
run(deps={}) {
if (this.config.metadata === true) {
return this.extractMetadata(deps)
.then(() => {
// This is skipped in the code coverage because the
// test runs against un-instrumented code.
/* istanbul ignore if */
if (this.config.runAsBinary === true) {
process.exit(this.output.errors.length > 0 ? 1 : 0);
}
})
.catch((err) => {
log.debug(err);
this.handleError(err, deps._console);
Expand Down
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import log from 'logger';

import 'babel-polyfill';

export function createInstance(config=cli.argv) {
export function createInstance({config=cli.argv, runAsBinary=false} = {}) {
log.level(config.logLevel);
log.info('Creating new linter instance', { config: config });
config.runAsBinary = runAsBinary;
return new Linter(config);
}
Binary file added tests/fixtures/badmeta.xpi
Binary file not shown.
Binary file added tests/fixtures/good.xpi
Binary file not shown.
55 changes: 55 additions & 0 deletions tests/test.cli-process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Tests running the process via the CLI.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! This is awesome and I was thinking we should be doing this 👍

*
*/

import shell from 'shelljs';


describe('Process', function() {

it('should exit with exit code 0 when no errors.', (done) => {
let cmd = 'bin/addons-linter tests/fixtures/good.xpi --output json';
shell.exec(cmd, {silent: true}, (code, output) => {
assert.doesNotThrow(() => {
JSON.parse(output);
});
assert.equal(code, 0, output);
done();
});
});

it('should exit with exit code 1 when errors found.', (done) => {
let cmd = 'bin/addons-linter tests/fixtures/example.xpi --output json';
shell.exec(cmd, {silent: true}, (code, output) => {
assert.doesNotThrow(() => {
JSON.parse(output);
});
assert.equal(code, 1, output);
done();
});
});

it('should exit with exit code 0 when no errors for metadata.', (done) => {
let cmd = 'bin/addons-linter tests/fixtures/good.xpi --metadata';
shell.exec(cmd, {silent: true}, (code, output) => {
assert.doesNotThrow(() => {
JSON.parse(output);
});
assert.equal(code, 0, output);
done();
});
});

it('should exit with exit code 1 when errors for metadata', (done) => {
let cmd = 'bin/addons-linter tests/fixtures/badmeta.xpi --metadata';
shell.exec(cmd, {silent: true}, (code, output) => {
assert.doesNotThrow(() => {
JSON.parse(output);
});
assert.equal(code, 1, output);
done();
});
});

});