diff --git a/jerry-debugger/src/lib/__tests__/debugger-client.test.ts b/jerry-debugger/src/lib/__tests__/debugger-client.test.ts new file mode 100644 index 0000000000..8007ef67c0 --- /dev/null +++ b/jerry-debugger/src/lib/__tests__/debugger-client.test.ts @@ -0,0 +1,70 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { JerryDebugger, DEFAULT_DEBUGGER_HOST, DEFAULT_DEBUGGER_PORT } from '../debugger-client'; +import WebSocket from 'ws'; + +//const mockOn = jest.fn(); +jest.mock('ws', () => { + return jest.fn().mockImplementation(() => { + return {}; + }); +}); + +describe('JerryDebugger constructor', () => { + it ('uses supplied option values', () => { + const jd = new JerryDebugger({ + host: '10.10.10.10', + port: 4096, + verbose: true, + }); + expect(jd.host).toEqual('10.10.10.10'); + expect(jd.port).toEqual(4096); + expect(jd.verbose).toEqual(true); + }); + + it('supplies option defaults when missing', () => { + const jd = new JerryDebugger({}); + expect(jd.host).toEqual(DEFAULT_DEBUGGER_HOST); + expect(jd.port).toEqual(DEFAULT_DEBUGGER_PORT); + expect(jd.verbose).toEqual(false); + }); +}); + +describe('JerryDebugger.connect', () => { + beforeEach(() => { + }); + + it('creates a websocket', () => { + const jd = new JerryDebugger({}); + jd.connect(); + expect(WebSocket).toHaveBeenCalledTimes(1); + }); + + it('returns a resolving promise when already connected', () => { + const jd = new JerryDebugger({}); + jd.connect(); + expect(WebSocket).toHaveBeenCalledTimes(1); + const p2 = jd.connect(); + console.log('here1'); + return expect(p2).resolves.toBe(undefined); + }); + + it('returned promise resolves when socket connects', () => { + const jd = new JerryDebugger({}); + const p = jd.connect(); + console.log('here2'); + expect(p).resolves.toBe(undefined); + }); +});