addons-linter/tests/test.cli.js

138 строки
3.9 KiB
JavaScript
Исходник Обычный вид История

import { getConfig, terminalWidth } from 'cli';
2015-09-25 20:38:16 +03:00
let cli;
2015-09-25 20:38:16 +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();
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.
const args = cli.parse(['foo/bar.zip']);
expect(args.logLevel).toEqual('fatal');
expect(args['log-level']).toEqual('fatal');
2015-10-16 14:58:22 +03:00
});
it('should default metadata option to false', () => {
const args = cli.parse(['foo/bar.zip']);
expect(args.metadata).toEqual(false);
});
2015-09-25 20:38:16 +03:00
it('should default add-on output to "text"', () => {
const args = cli.parse(['foo/bar.zip']);
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', () => {
const args = cli.parse(['foo/bar.zip']);
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', () => {
const args = cli.parse(['foo/bar.zip']);
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', () => {
const args = cli.parse(['foo/bar.zip']);
expect(args.boring).toEqual(false);
2015-09-25 20:38:16 +03:00
});
it('should support a --scan-file option', () => {
let args = cli.parse(['foo/', '--scan-file', 'dir/test1.txt']);
expect(args.scanFile).toEqual('dir/test1.txt');
args = cli.parse([
'foo/', '--scan-file', 'dir/test1.txt',
'--scan-file', 'dir/test2.txt',
]);
expect(args.scanFile).toEqual(['dir/test1.txt', 'dir/test2.txt']);
args = cli.parse(['foo/']);
expect(args.scanFile).toEqual(undefined);
});
it('should default warnings-as-errors to false', () => {
const args = cli.parse(['foo/bar.zip']);
expect(args.warningsAsErrors).toEqual(false);
});
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([]);
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']);
expect(this.fakeFail.calledWithMatch(
'Invalid values:\n Argument: output, Given: "false"')).toBeTruthy();
2015-09-25 20:38:16 +03:00
});
it('should use 78 as a width if process.stdout.columns is undefined', () => {
let fakeProcess = null;
expect(terminalWidth(fakeProcess)).toEqual(78);
fakeProcess = { stdout: null };
expect(terminalWidth(fakeProcess)).toEqual(78);
fakeProcess = { stdout: { columns: null } };
expect(terminalWidth(fakeProcess)).toEqual(78);
});
it('should always use a positive terminal width', () => {
const fakeProcess = {
stdout: {
columns: 1,
},
};
expect(terminalWidth(fakeProcess)).toEqual(10);
});
it('should not use a width under 10 columns', () => {
let fakeProcess = {
stdout: {
columns: 12,
},
};
expect(terminalWidth(fakeProcess)).toEqual(10);
fakeProcess = {
stdout: {
columns: 11,
},
};
expect(terminalWidth(fakeProcess)).toEqual(10);
fakeProcess = {
stdout: {
columns: 79,
},
};
expect(terminalWidth(fakeProcess)).toEqual(77);
});
it('should use a terminal width of $COLUMNS - 2', () => {
const fakeProcess = {
stdout: {
columns: 170,
},
};
expect(terminalWidth(fakeProcess)).toEqual(168);
});
it('should have a default config when called via CLI', () => {
const config = getConfig({ useCLI: true }).argv;
expect(Object.keys(config).length).toBeGreaterThan(0);
});
it('should error when requesting CLI config in library mode', () => {
expect(() => {
getConfig({ useCLI: false });
}).toThrow('Cannot request config from CLI in library mode');
});
2015-09-25 20:38:16 +03:00
});