debug integrations tests: better testing of starting of debug

This commit is contained in:
isidor
2020-02-04 16:39:10 +01:00
parent 5df43457e8
commit 491a17bd71

View File

@@ -59,8 +59,12 @@ suite('Debug', function () {
test('start debugging', async function () {
assert.equal(debug.activeDebugSession, undefined);
let stoppedEvents = 0;
let variablesRetrieved: () => void;
const firstVariablesRetrieved = new Promise<void>(resolve => variablesRetrieved = resolve);
let variablesReceived: () => void;
let capabilitiesReceived: () => void;
let initializedReceived: () => void;
let configurationDoneReceived: () => void;
const firstVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve);
const toDispose: Disposable[] = [];
toDispose.push(debug.registerDebugAdapterTrackerFactory('node2', {
createDebugAdapterTracker: () => ({
@@ -69,21 +73,37 @@ suite('Debug', function () {
stoppedEvents++;
}
if (m.type === 'response' && m.command === 'variables') {
variablesRetrieved();
variablesReceived();
}
if (m.event === 'capabilities') {
capabilitiesReceived();
}
if (m.event === 'initialized') {
initializedReceived();
}
if (m.command === 'configurationDone') {
configurationDoneReceived();
}
}
})
}));
const capabilitiesPromise = new Promise<void>(resolve => capabilitiesReceived = resolve);
const initializedPromise = new Promise<void>(resolve => initializedReceived = resolve);
const configurationDonePromise = new Promise<void>(resolve => configurationDoneReceived = resolve);
const success = await debug.startDebugging(workspace.workspaceFolders![0], 'Launch debug.js');
assert.equal(success, true);
await capabilitiesPromise;
await initializedPromise;
await configurationDonePromise;
assert.notEqual(debug.activeDebugSession, undefined);
assert.equal(debug.activeDebugSession?.name, 'Launch debug.js');
await firstVariablesRetrieved;
assert.equal(stoppedEvents, 1);
const secondVariablesRetrieved = new Promise<void>(resolve => variablesRetrieved = resolve);
const secondVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve);
await commands.executeCommand('workbench.action.debug.stepOver');
await secondVariablesRetrieved;
assert.equal(stoppedEvents, 2);
@@ -91,17 +111,17 @@ suite('Debug', function () {
assert.notEqual(editor, undefined);
assert.equal(basename(editor!.document.fileName), 'debug.js');
const thirdVariablesRetrieved = new Promise<void>(resolve => variablesRetrieved = resolve);
const thirdVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve);
await commands.executeCommand('workbench.action.debug.stepOver');
await thirdVariablesRetrieved;
assert.equal(stoppedEvents, 3);
const fourthVariablesRetrieved = new Promise<void>(resolve => variablesRetrieved = resolve);
const fourthVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve);
await commands.executeCommand('workbench.action.debug.stepInto');
await fourthVariablesRetrieved;
assert.equal(stoppedEvents, 4);
const fifthVariablesRetrieved = new Promise<void>(resolve => variablesRetrieved = resolve);
const fifthVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve);
await commands.executeCommand('workbench.action.debug.stepOut');
await fifthVariablesRetrieved;
assert.equal(stoppedEvents, 5);