|
| 1 | +// Copyright JS Foundation and other contributors, http://js.foundation |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import { getOptionsFromArgs } from '../cli'; |
| 16 | +import { |
| 17 | + DEFAULT_DEBUGGER_HOST, |
| 18 | + DEFAULT_DEBUGGER_PORT, |
| 19 | +} from '../../lib/debugger-client'; |
| 20 | +import { |
| 21 | + DEFAULT_SERVER_HOST, |
| 22 | + DEFAULT_SERVER_PORT, |
| 23 | +} from '../../lib/cdt-proxy'; |
| 24 | + |
| 25 | +describe('getOptionsFromArgs', () => { |
| 26 | + |
| 27 | + function getOptionsFromUserArgs(userArgs: string[]) { |
| 28 | + return getOptionsFromArgs(['node', 'jerry-debugger.js'].concat(userArgs)); |
| 29 | + } |
| 30 | + |
| 31 | + it('works without --inspect-brk', () => { |
| 32 | + const opt = getOptionsFromUserArgs([]); |
| 33 | + expect(opt.proxyAddress.host).toEqual(DEFAULT_SERVER_HOST); |
| 34 | + expect(opt.proxyAddress.port).toEqual(DEFAULT_SERVER_PORT); |
| 35 | + }); |
| 36 | + |
| 37 | + it('parses --inspect-brk with port only', () => { |
| 38 | + const opt = getOptionsFromUserArgs(['--inspect-brk=1234']); |
| 39 | + expect(opt.proxyAddress.host).toEqual(undefined); |
| 40 | + expect(opt.proxyAddress.port).toEqual(1234); |
| 41 | + }); |
| 42 | + |
| 43 | + it('parses --inspect-brk with no port', () => { |
| 44 | + const opt = getOptionsFromUserArgs(['--inspect-brk=10.10.10.10:']); |
| 45 | + expect(opt.proxyAddress.host).toEqual('10.10.10.10'); |
| 46 | + expect(opt.proxyAddress.port).toEqual(undefined); |
| 47 | + }); |
| 48 | + |
| 49 | + it('parses --inspect-brk with no host', () => { |
| 50 | + const opt = getOptionsFromUserArgs(['--inspect-brk=:1234']); |
| 51 | + expect(opt.proxyAddress.host).toEqual(undefined); |
| 52 | + expect(opt.proxyAddress.port).toEqual(1234); |
| 53 | + }); |
| 54 | + |
| 55 | + it('parses --inspect-brk with host and port', () => { |
| 56 | + const opt = getOptionsFromUserArgs(['--inspect-brk=10.10.10.10:1234']); |
| 57 | + expect(opt.proxyAddress.host).toEqual('10.10.10.10'); |
| 58 | + expect(opt.proxyAddress.port).toEqual(1234); |
| 59 | + }); |
| 60 | + |
| 61 | + it('works without --jerry-remote', () => { |
| 62 | + const opt = getOptionsFromUserArgs([]); |
| 63 | + expect(opt.remoteAddress.host).toEqual(DEFAULT_DEBUGGER_HOST); |
| 64 | + expect(opt.remoteAddress.port).toEqual(DEFAULT_DEBUGGER_PORT); |
| 65 | + }); |
| 66 | + |
| 67 | + it('parses --jerry-remote with port only', () => { |
| 68 | + const opt = getOptionsFromUserArgs(['--jerry-remote=1234']); |
| 69 | + expect(opt.remoteAddress.host).toEqual(undefined); |
| 70 | + expect(opt.remoteAddress.port).toEqual(1234); |
| 71 | + }); |
| 72 | + |
| 73 | + it('parses --jerry-remote with host and port', () => { |
| 74 | + const opt = getOptionsFromUserArgs(['--jerry-remote=10.10.10.10:1234']); |
| 75 | + expect(opt.remoteAddress.host).toEqual('10.10.10.10'); |
| 76 | + expect(opt.remoteAddress.port).toEqual(1234); |
| 77 | + }); |
| 78 | + |
| 79 | + it('verbose defaults to false', () => { |
| 80 | + const opt = getOptionsFromUserArgs([]); |
| 81 | + expect(opt.verbose).toEqual(false); |
| 82 | + }); |
| 83 | + |
| 84 | + it('parses verbose flag', () => { |
| 85 | + const opt = getOptionsFromUserArgs(['--verbose']); |
| 86 | + expect(opt.verbose).toEqual(true); |
| 87 | + }); |
| 88 | + |
| 89 | + it('parses v alias for verbose', () => { |
| 90 | + const opt = getOptionsFromUserArgs(['-v']); |
| 91 | + expect(opt.verbose).toEqual(true); |
| 92 | + }); |
| 93 | + |
| 94 | + it('jsfile defaults to untitled.js', () => { |
| 95 | + const opt = getOptionsFromUserArgs([]); |
| 96 | + expect(opt.jsfile).toEqual('untitled.js'); |
| 97 | + }); |
| 98 | + |
| 99 | + it('returns client source as jsfile', () => { |
| 100 | + const opt = getOptionsFromUserArgs(['foo/bar.js']); |
| 101 | + expect(opt.jsfile).toEqual('foo/bar.js'); |
| 102 | + }); |
| 103 | + |
| 104 | +}); |
0 commit comments