2018-03-01 13:41:35 -05:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2018-03-02 17:19:01 -05:00
|
|
|
import chai = require('chai');
|
2018-10-29 16:25:00 -04:00
|
|
|
import {parseArguments} from '../lib/cli';
|
2018-03-02 17:19:01 -05:00
|
|
|
|
|
|
|
describe('cli: parseArguments', () => {
|
|
|
|
it('should show usage with error when supplied with no arguments', () => {
|
2018-10-29 16:25:00 -04:00
|
|
|
const {mode, errors} = parseArguments([]);
|
2018-03-02 17:19:01 -05:00
|
|
|
chai.assert.equal(mode, 'help');
|
|
|
|
chai.assert.deepEqual(errors, ['No input file specified.']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show usage without error when supplied with --help', () => {
|
2018-10-29 16:25:00 -04:00
|
|
|
const {mode, errors} = parseArguments(['--help']);
|
2018-03-02 17:19:01 -05:00
|
|
|
chai.assert.equal(mode, 'help');
|
|
|
|
chai.assert.deepEqual(errors, []);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show usage with error when supplied with none of --out/verify[Dir]', () => {
|
2018-10-29 16:25:00 -04:00
|
|
|
const {mode, errors} = parseArguments(['input.d.ts']);
|
2018-03-02 17:19:01 -05:00
|
|
|
chai.assert.equal(mode, 'help');
|
|
|
|
chai.assert.deepEqual(errors, ['Specify either --out[Dir] or --verify[Dir]']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show usage with error when supplied with both of --out/verify[Dir]', () => {
|
2018-10-29 16:25:00 -04:00
|
|
|
const {mode, errors} =
|
2018-03-02 17:19:01 -05:00
|
|
|
parseArguments(['--out', 'out.d.ts', '--verifyDir', 'golden.d.ts', 'input.d.ts']);
|
|
|
|
chai.assert.equal(mode, 'help');
|
|
|
|
chai.assert.deepEqual(errors, ['Specify either --out[Dir] or --verify[Dir]']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show usage with error when supplied without input file', () => {
|
2018-10-29 16:25:00 -04:00
|
|
|
const {mode, errors} = parseArguments(['--out', 'output.d.ts']);
|
2018-03-02 17:19:01 -05:00
|
|
|
chai.assert.equal(mode, 'help');
|
|
|
|
chai.assert.deepEqual(errors, ['No input file specified.']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show usage with error when supplied without input file', () => {
|
2018-10-29 16:25:00 -04:00
|
|
|
const {mode, errors} = parseArguments(['--out', 'output.d.ts', 'first.d.ts', 'second.d.ts']);
|
2018-03-02 17:19:01 -05:00
|
|
|
chai.assert.equal(mode, 'help');
|
|
|
|
chai.assert.deepEqual(errors, ['More than one input specified. Use --outDir instead.']);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should use out mode when supplied with --out', () => {
|
|
|
|
const {argv, mode, errors} = parseArguments(['--out', 'out.d.ts', 'input.d.ts']);
|
|
|
|
chai.assert.equal(argv['out'], 'out.d.ts');
|
|
|
|
chai.assert.deepEqual(argv._, ['input.d.ts']);
|
|
|
|
chai.assert.equal(mode, 'out');
|
|
|
|
chai.assert.deepEqual(errors, []);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should use verify mode when supplied with --verify', () => {
|
|
|
|
const {argv, mode, errors} = parseArguments(['--verify', 'out.d.ts', 'input.d.ts']);
|
|
|
|
chai.assert.equal(argv['verify'], 'out.d.ts');
|
|
|
|
chai.assert.deepEqual(argv._, ['input.d.ts']);
|
|
|
|
chai.assert.equal(mode, 'verify');
|
|
|
|
chai.assert.deepEqual(errors, []);
|
|
|
|
});
|
|
|
|
});
|