| 
									
										
										
										
											2018-03-01 10:41:35 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2018-03-01 10:41:35 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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 14:19:01 -08:00
										 |  |  | import chai = require('chai'); | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  | import {parseArguments} from '../lib/cli'; | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('cli: parseArguments', () => { | 
					
						
							|  |  |  |   it('should show usage with error when supplied with no arguments', () => { | 
					
						
							| 
									
										
										
										
											2018-10-29 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments([]); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08: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 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments(['--help']); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08: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 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments(['input.d.ts']); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08: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 21:25:00 +01:00
										 |  |  |     const {mode, errors} = | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08: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 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments(['--out', 'output.d.ts']); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08: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 21:25:00 +01:00
										 |  |  |     const {mode, errors} = parseArguments(['--out', 'output.d.ts', 'first.d.ts', 'second.d.ts']); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08: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, []); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-02-25 13:05:49 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   it('should show usage with error when supplied with --autoDiscoverEntrypoints without --baseDir', | 
					
						
							|  |  |  |      () => { | 
					
						
							|  |  |  |        const {mode, errors} = | 
					
						
							|  |  |  |            parseArguments(['--autoDiscoverEntrypoints', '--outDir', 'something']); | 
					
						
							|  |  |  |        chai.assert.equal(mode, 'help'); | 
					
						
							|  |  |  |        chai.assert.deepEqual( | 
					
						
							|  |  |  |            errors, ['--rootDir must be provided with --autoDiscoverEntrypoints.']); | 
					
						
							|  |  |  |      }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should show usage with error when supplied with --autoDiscoverEntrypoints without --outDir/verifyDir', | 
					
						
							|  |  |  |      () => { | 
					
						
							|  |  |  |        const {mode, errors} = | 
					
						
							|  |  |  |            parseArguments(['--autoDiscoverEntrypoints', '--rootDir', 'something']); | 
					
						
							|  |  |  |        chai.assert.equal(mode, 'help'); | 
					
						
							|  |  |  |        chai.assert.deepEqual( | 
					
						
							|  |  |  |            errors, ['--outDir or --verifyDir must be used with --autoDiscoverEntrypoints.']); | 
					
						
							|  |  |  |      }); | 
					
						
							| 
									
										
										
										
											2018-03-02 14:19:01 -08:00
										 |  |  | }); |