Another intermediate state before I delete a bunch of stuff
This commit is contained in:
Родитель
2e8cecf36b
Коммит
cce4c76e94
|
@ -2,13 +2,15 @@
|
|||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import * as sinon from 'sinon';
|
||||
import * as mockery from 'mockery';
|
||||
import * as assert from 'assert';
|
||||
import * as testUtils from '../testUtils';
|
||||
|
||||
import {EventEmitter} from 'events';
|
||||
import * as assert from 'assert';
|
||||
|
||||
/** Utilities without mocks - use for type only */
|
||||
import * as testUtils from '../testUtils';
|
||||
import {WebKitConnection} from '../../webkit/webKitConnection';
|
||||
|
||||
/** Not mocked - use for type only */
|
||||
import {WebKitDebugAdapter as _WebKitDebugAdapter} from '../../webkit/webKitDebugAdapter';
|
||||
|
||||
const MODULE_UNDER_TEST = '../../webkit/webKitDebugAdapter';
|
||||
|
@ -31,10 +33,10 @@ suite('WebKitDebugAdapter', () => {
|
|||
'events']);
|
||||
|
||||
webKitConnectionMock = registerMockWebKitConnection();
|
||||
mockery.registerMock('os', { platform: () => 'win32' });
|
||||
mockery.registerMock('child_process', { });
|
||||
mockery.registerMock('url', { });
|
||||
mockery.registerMock('path', { });
|
||||
mockery.registerMock('os', { });
|
||||
mockery.registerMock('net', { });
|
||||
mockery.registerMock('fs', { });
|
||||
});
|
||||
|
@ -80,17 +82,46 @@ suite('WebKitDebugAdapter', () => {
|
|||
});
|
||||
});
|
||||
|
||||
class SomethingElse {
|
||||
/*public helper(arg: number): number {
|
||||
return 5;
|
||||
}*/
|
||||
}
|
||||
|
||||
class ToTest {
|
||||
public testMe(s: SomethingElse): number {
|
||||
return s.helper(1);
|
||||
}
|
||||
}
|
||||
|
||||
suite('asdf()', () => {
|
||||
test('sinontest', () => {
|
||||
var s: SomethingElse = new SomethingElse();
|
||||
var m = sinon.mock(s);
|
||||
m.expects('helper').once().returned(2);
|
||||
|
||||
assert.equal(new ToTest().testMe(s), 2);
|
||||
m.verify();
|
||||
});
|
||||
});
|
||||
|
||||
suite('setBreakpoints()', () => {
|
||||
test('works', () => {
|
||||
let mockInstance = new WebKitConnection();
|
||||
mockInstance['debugger_setBreakpoint'] =
|
||||
sinon.stub().returns(Promise.resolve({result: { breakpointId: "hi" } }));
|
||||
mockery.registerMock('./webKitConnection', { WebKitConnection: () => mockInstance });
|
||||
let mock = sinon.mock(mockInstance);
|
||||
|
||||
const wkda = instantiateWKDA();
|
||||
return attach(wkda).then(() => {
|
||||
webKitConnectionMock
|
||||
mock
|
||||
.expects('debugger_setBreakpoint')
|
||||
.withArgs({ scriptId: "id", lineNumber: 5, columnNumber: 0 });
|
||||
DefaultMockWebKitConnection.EE.emit('Debugger.scriptParsed', { id: "id", url: "a.js" });
|
||||
DefaultMockWebKitConnection.EE.emit('Debugger.scriptParsed', { id: "id", url: "file:///a.js" });
|
||||
return wkda.setBreakpoints({ source: { path: "a.js" }, lines: [5] });
|
||||
}).then(response => {
|
||||
webKitConnectionMock.verify();
|
||||
mock.verify();
|
||||
assert.deepEqual(response.breakpoints.length, 1);
|
||||
});
|
||||
});
|
||||
|
@ -143,10 +174,11 @@ function registerMockWebKitConnection(partialImpl?: any): Sinon.SinonMock {
|
|||
}
|
||||
|
||||
// Instantiate the mock type so we can wrap it in a sinon mock
|
||||
const mock = sinon.mock(new mockType());
|
||||
const mockInstance = new mockType();
|
||||
const mock = sinon.mock(mockInstance);
|
||||
|
||||
// Register a fake constructor so that our instance will be called when the adapter does 'new WebKitConnection'
|
||||
mockery.registerMock('./webKitConnection', { WebKitConnection: () => mock });
|
||||
mockery.registerMock('./webKitConnection', { WebKitConnection: () => mockInstance });
|
||||
|
||||
return mock;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
|
||||
return this._webKitConnection.attach(port)
|
||||
.then(
|
||||
() => this._eventHandler(new InitializedEvent()),
|
||||
() => this.fireEvent(new InitializedEvent()),
|
||||
e => {
|
||||
this.clearEverything();
|
||||
return Promise.reject(e);
|
||||
|
@ -137,12 +137,18 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
private fireEvent(event: DebugProtocol.Event): void {
|
||||
if (this._eventHandler) {
|
||||
this._eventHandler(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Chrome is closing, or error'd somehow, stop the debug session
|
||||
*/
|
||||
private terminateSession(): void {
|
||||
if (this._clientAttached) {
|
||||
this._eventHandler(new TerminatedEvent());
|
||||
this.fireEvent(new TerminatedEvent());
|
||||
}
|
||||
|
||||
this.clearEverything();
|
||||
|
@ -185,7 +191,7 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
reason = notification.hitBreakpoints.length ? 'breakpoint' : 'step';
|
||||
}
|
||||
|
||||
this._eventHandler(new StoppedEvent(reason, /*threadId=*/WebKitDebugAdapter.THREAD_ID, exceptionText));
|
||||
this.fireEvent(new StoppedEvent(reason, /*threadId=*/WebKitDebugAdapter.THREAD_ID, exceptionText));
|
||||
}
|
||||
|
||||
private onDebuggerResumed(): void {
|
||||
|
@ -194,7 +200,7 @@ export class WebKitDebugAdapter implements IDebugAdapter {
|
|||
|
||||
// This is a private undocumented event provided by VS Code to support the 'continue' button on a paused Chrome page
|
||||
let resumedEvent = new Event('running', { threadId: WebKitDebugAdapter.THREAD_ID });
|
||||
this._eventHandler(resumedEvent);
|
||||
this.fireEvent(resumedEvent);
|
||||
}
|
||||
|
||||
private onScriptParsed(script: WebKitProtocol.Debugger.Script): void {
|
||||
|
|
Загрузка…
Ссылка в новой задаче