2016-08-03 15:38:20 +03:00
|
|
|
import { getConfig, terminalWidth } from 'cli';
|
2015-09-25 20:38:16 +03:00
|
|
|
|
|
|
|
|
2017-08-11 17:49:06 +03:00
|
|
|
let cli;
|
2015-09-25 20:38:16 +03:00
|
|
|
|
2017-08-11 17:49:06 +03:00
|
|
|
describe('Basic CLI tests', function cliCallback() {
|
2015-09-25 21:59:08 +03:00
|
|
|
beforeEach(() => {
|
|
|
|
// Override yargs fail func so we can introspect the right errors
|
|
|
|
// are happening when we hand it bogus input.
|
|
|
|
this.fakeFail = sinon.stub();
|
2016-08-03 15:38:20 +03:00
|
|
|
cli = getConfig().exitProcess(false).fail(this.fakeFail);
|
2015-09-25 21:59:08 +03:00
|
|
|
});
|
|
|
|
|
2015-10-16 14:58:22 +03:00
|
|
|
it('should default logLevel type to "fatal"', () => {
|
|
|
|
// This means by default there won't be any output.
|
2017-08-11 17:49:06 +03:00
|
|
|
const args = cli.parse(['foo/bar.zip']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.logLevel).toEqual('fatal');
|
|
|
|
expect(args['log-level']).toEqual('fatal');
|
2015-10-16 14:58:22 +03:00
|
|
|
});
|
|
|
|
|
2015-11-11 23:21:52 +03:00
|
|
|
it('should default metadata option to false', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const args = cli.parse(['foo/bar.zip']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.metadata).toEqual(false);
|
2015-11-11 23:21:52 +03:00
|
|
|
});
|
|
|
|
|
2015-09-25 20:38:16 +03:00
|
|
|
it('should default add-on output to "text"', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const args = cli.parse(['foo/bar.zip']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.output).toEqual('text');
|
|
|
|
expect(args.o).toEqual('text');
|
2015-09-25 20:38:16 +03:00
|
|
|
});
|
|
|
|
|
2015-09-29 20:59:32 +03:00
|
|
|
it('should default stack to false', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const args = cli.parse(['foo/bar.zip']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.stack).toEqual(false);
|
2015-09-29 20:59:32 +03:00
|
|
|
});
|
|
|
|
|
2015-10-02 11:28:48 +03:00
|
|
|
it('should default pretty to false', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const args = cli.parse(['foo/bar.zip']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.pretty).toEqual(false);
|
2015-10-02 11:28:48 +03:00
|
|
|
});
|
|
|
|
|
2015-09-25 20:38:16 +03:00
|
|
|
it('should default boring to false', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const args = cli.parse(['foo/bar.zip']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.boring).toEqual(false);
|
2015-09-25 20:38:16 +03:00
|
|
|
});
|
|
|
|
|
2017-01-15 04:30:04 +03:00
|
|
|
it('should support a --scan-file option', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
let args = cli.parse(['foo/', '--scan-file', 'dir/test1.txt']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.scanFile).toEqual('dir/test1.txt');
|
2017-01-15 04:30:04 +03:00
|
|
|
|
2017-08-11 17:49:06 +03:00
|
|
|
args = cli.parse([
|
2017-01-15 04:30:04 +03:00
|
|
|
'foo/', '--scan-file', 'dir/test1.txt',
|
|
|
|
'--scan-file', 'dir/test2.txt',
|
|
|
|
]);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.scanFile).toEqual(['dir/test1.txt', 'dir/test2.txt']);
|
2017-01-15 04:30:04 +03:00
|
|
|
|
|
|
|
args = cli.parse(['foo/']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.scanFile).toEqual(undefined);
|
2017-01-15 04:30:04 +03:00
|
|
|
});
|
|
|
|
|
2016-10-27 21:50:09 +03:00
|
|
|
it('should default warnings-as-errors to false', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const args = cli.parse(['foo/bar.zip']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(args.warningsAsErrors).toEqual(false);
|
2016-10-27 21:50:09 +03:00
|
|
|
});
|
|
|
|
|
2015-09-25 20:38:16 +03:00
|
|
|
it('should show error on missing xpi', () => {
|
2015-09-25 21:59:08 +03:00
|
|
|
cli.parse([]);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(this.fakeFail.calledWithMatch(
|
|
|
|
'Not enough non-option arguments')).toBeTruthy();
|
2015-09-25 20:38:16 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show error if incorrect output', () => {
|
2015-09-25 21:59:08 +03:00
|
|
|
cli.parse(['-o', 'false', 'whatevs']);
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(this.fakeFail.calledWithMatch(
|
|
|
|
'Invalid values:\n Argument: output, Given: "false"')).toBeTruthy();
|
2015-09-25 20:38:16 +03:00
|
|
|
});
|
|
|
|
|
2015-10-14 22:16:37 +03:00
|
|
|
it('should use 78 as a width if process.stdout.columns is undefined', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
let fakeProcess = null;
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(terminalWidth(fakeProcess)).toEqual(78);
|
2017-08-11 17:49:06 +03:00
|
|
|
fakeProcess = { stdout: null };
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(terminalWidth(fakeProcess)).toEqual(78);
|
2017-08-11 17:49:06 +03:00
|
|
|
fakeProcess = { stdout: { columns: null } };
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(terminalWidth(fakeProcess)).toEqual(78);
|
2015-10-14 22:16:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should always use a positive terminal width', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const fakeProcess = {
|
|
|
|
stdout: {
|
|
|
|
columns: 1,
|
|
|
|
},
|
|
|
|
};
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(terminalWidth(fakeProcess)).toEqual(10);
|
2015-10-14 22:16:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not use a width under 10 columns', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
let fakeProcess = {
|
|
|
|
stdout: {
|
|
|
|
columns: 12,
|
|
|
|
},
|
|
|
|
};
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(terminalWidth(fakeProcess)).toEqual(10);
|
2017-08-11 17:49:06 +03:00
|
|
|
fakeProcess = {
|
|
|
|
stdout: {
|
|
|
|
columns: 11,
|
|
|
|
},
|
|
|
|
};
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(terminalWidth(fakeProcess)).toEqual(10);
|
2015-10-14 22:16:37 +03:00
|
|
|
|
2017-08-11 17:49:06 +03:00
|
|
|
fakeProcess = {
|
|
|
|
stdout: {
|
|
|
|
columns: 79,
|
|
|
|
},
|
|
|
|
};
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(terminalWidth(fakeProcess)).toEqual(77);
|
2015-10-14 22:16:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should use a terminal width of $COLUMNS - 2', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const fakeProcess = {
|
|
|
|
stdout: {
|
|
|
|
columns: 170,
|
|
|
|
},
|
|
|
|
};
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(terminalWidth(fakeProcess)).toEqual(168);
|
2015-10-14 22:16:37 +03:00
|
|
|
});
|
|
|
|
|
2016-08-03 15:38:20 +03:00
|
|
|
it('should have a default config when called via CLI', () => {
|
2017-08-11 17:49:06 +03:00
|
|
|
const config = getConfig({ useCLI: true }).argv;
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(Object.keys(config).length).toBeGreaterThan(0);
|
2016-08-03 15:38:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should error when requesting CLI config in library mode', () => {
|
2017-06-08 12:31:25 +03:00
|
|
|
expect(() => {
|
2017-08-11 17:49:06 +03:00
|
|
|
getConfig({ useCLI: false });
|
2017-06-08 12:31:25 +03:00
|
|
|
}).toThrow('Cannot request config from CLI in library mode');
|
2016-08-03 15:38:20 +03:00
|
|
|
});
|
2015-09-25 20:38:16 +03:00
|
|
|
});
|