|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 | 6 | import * as assert from 'assert';
|
7 |
| -import { debug, workspace, Disposable } from 'vscode'; |
| 7 | +import { debug, workspace, Disposable, commands, window } from 'vscode'; |
8 | 8 | import { disposeAll } from '../utils';
|
| 9 | +import { basename } from 'path'; |
9 | 10 |
|
10 | 11 | suite('Debug', function () {
|
11 | 12 |
|
@@ -36,86 +37,87 @@ suite('Debug', function () {
|
36 | 37 | disposeAll(toDispose);
|
37 | 38 | });
|
38 | 39 |
|
39 |
| - // test('start debugging', async function () { |
40 |
| - // assert.equal(debug.activeDebugSession, undefined); |
41 |
| - // let stoppedEvents = 0; |
42 |
| - // let variablesReceived: () => void; |
43 |
| - // let capabilitiesReceived: () => void; |
44 |
| - // let initializedReceived: () => void; |
45 |
| - // let configurationDoneReceived: () => void; |
46 |
| - |
47 |
| - // const firstVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
48 |
| - // const toDispose: Disposable[] = []; |
49 |
| - // toDispose.push(debug.registerDebugAdapterTrackerFactory('node2', { |
50 |
| - // createDebugAdapterTracker: () => ({ |
51 |
| - // onDidSendMessage: m => { |
52 |
| - // if (m.event === 'stopped') { |
53 |
| - // stoppedEvents++; |
54 |
| - // } |
55 |
| - // if (m.type === 'response' && m.command === 'variables') { |
56 |
| - // variablesReceived(); |
57 |
| - // } |
58 |
| - // if (m.event === 'capabilities') { |
59 |
| - // capabilitiesReceived(); |
60 |
| - // } |
61 |
| - // if (m.event === 'initialized') { |
62 |
| - // initializedReceived(); |
63 |
| - // } |
64 |
| - // if (m.command === 'configurationDone') { |
65 |
| - // configurationDoneReceived(); |
66 |
| - // } |
67 |
| - // } |
68 |
| - // }) |
69 |
| - // })); |
70 |
| - |
71 |
| - // const capabilitiesPromise = new Promise<void>(resolve => capabilitiesReceived = resolve); |
72 |
| - // const initializedPromise = new Promise<void>(resolve => initializedReceived = resolve); |
73 |
| - // const configurationDonePromise = new Promise<void>(resolve => configurationDoneReceived = resolve); |
74 |
| - // await commands.executeCommand('workbench.action.debug.start'); |
75 |
| - // await capabilitiesPromise; |
76 |
| - // await initializedPromise; |
77 |
| - // await configurationDonePromise; |
78 |
| - |
79 |
| - // assert.notEqual(debug.activeDebugSession, undefined); |
80 |
| - // assert.equal(debug.activeDebugSession?.name, 'Launch debug.js'); |
81 |
| - |
82 |
| - // await firstVariablesRetrieved; |
83 |
| - // assert.equal(stoppedEvents, 1); |
84 |
| - |
85 |
| - // const secondVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
86 |
| - // await commands.executeCommand('workbench.action.debug.stepOver'); |
87 |
| - // await secondVariablesRetrieved; |
88 |
| - // assert.equal(stoppedEvents, 2); |
89 |
| - // const editor = window.activeTextEditor; |
90 |
| - // assert.notEqual(editor, undefined); |
91 |
| - // assert.equal(basename(editor!.document.fileName), 'debug.js'); |
92 |
| - |
93 |
| - // const thirdVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
94 |
| - // await commands.executeCommand('workbench.action.debug.stepOver'); |
95 |
| - // await thirdVariablesRetrieved; |
96 |
| - // assert.equal(stoppedEvents, 3); |
97 |
| - |
98 |
| - // const fourthVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
99 |
| - // await commands.executeCommand('workbench.action.debug.stepInto'); |
100 |
| - // await fourthVariablesRetrieved; |
101 |
| - // assert.equal(stoppedEvents, 4); |
102 |
| - |
103 |
| - // const fifthVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
104 |
| - // await commands.executeCommand('workbench.action.debug.stepOut'); |
105 |
| - // await fifthVariablesRetrieved; |
106 |
| - // assert.equal(stoppedEvents, 5); |
107 |
| - |
108 |
| - // let sessionTerminated: () => void; |
109 |
| - // toDispose.push(debug.onDidTerminateDebugSession(() => { |
110 |
| - // sessionTerminated(); |
111 |
| - // })); |
112 |
| - // const sessionTerminatedPromise = new Promise<void>(resolve => sessionTerminated = resolve); |
113 |
| - // await commands.executeCommand('workbench.action.debug.stop'); |
114 |
| - // await sessionTerminatedPromise; |
115 |
| - // assert.equal(debug.activeDebugSession, undefined); |
116 |
| - |
117 |
| - // disposeAll(toDispose); |
118 |
| - // }); |
| 40 | + test('start debugging', async function () { |
| 41 | + assert.equal(debug.activeDebugSession, undefined); |
| 42 | + let stoppedEvents = 0; |
| 43 | + let variablesReceived: () => void; |
| 44 | + let capabilitiesReceived: () => void; |
| 45 | + let initializedReceived: () => void; |
| 46 | + let configurationDoneReceived: () => void; |
| 47 | + |
| 48 | + const firstVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
| 49 | + const toDispose: Disposable[] = []; |
| 50 | + toDispose.push(debug.registerDebugAdapterTrackerFactory('node2', { |
| 51 | + createDebugAdapterTracker: () => ({ |
| 52 | + onDidSendMessage: m => { |
| 53 | + if (m.event === 'stopped') { |
| 54 | + stoppedEvents++; |
| 55 | + } |
| 56 | + if (m.type === 'response' && m.command === 'variables') { |
| 57 | + variablesReceived(); |
| 58 | + } |
| 59 | + if (m.event === 'capabilities') { |
| 60 | + capabilitiesReceived(); |
| 61 | + } |
| 62 | + if (m.event === 'initialized') { |
| 63 | + initializedReceived(); |
| 64 | + } |
| 65 | + if (m.command === 'configurationDone') { |
| 66 | + configurationDoneReceived(); |
| 67 | + } |
| 68 | + } |
| 69 | + }) |
| 70 | + })); |
| 71 | + |
| 72 | + const capabilitiesPromise = new Promise<void>(resolve => capabilitiesReceived = resolve); |
| 73 | + const initializedPromise = new Promise<void>(resolve => initializedReceived = resolve); |
| 74 | + const configurationDonePromise = new Promise<void>(resolve => configurationDoneReceived = resolve); |
| 75 | + // Do not await debug start to return due to https://github.com/microsoft/vscode/issues/90134 |
| 76 | + debug.startDebugging(workspace.workspaceFolders![0], 'Launch debug.js'); |
| 77 | + await capabilitiesPromise; |
| 78 | + await initializedPromise; |
| 79 | + await configurationDonePromise; |
| 80 | + |
| 81 | + assert.notEqual(debug.activeDebugSession, undefined); |
| 82 | + assert.equal(debug.activeDebugSession?.name, 'Launch debug.js'); |
| 83 | + |
| 84 | + await firstVariablesRetrieved; |
| 85 | + assert.equal(stoppedEvents, 1); |
| 86 | + |
| 87 | + const secondVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
| 88 | + await commands.executeCommand('workbench.action.debug.stepOver'); |
| 89 | + await secondVariablesRetrieved; |
| 90 | + assert.equal(stoppedEvents, 2); |
| 91 | + const editor = window.activeTextEditor; |
| 92 | + assert.notEqual(editor, undefined); |
| 93 | + assert.equal(basename(editor!.document.fileName), 'debug.js'); |
| 94 | + |
| 95 | + const thirdVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
| 96 | + await commands.executeCommand('workbench.action.debug.stepOver'); |
| 97 | + await thirdVariablesRetrieved; |
| 98 | + assert.equal(stoppedEvents, 3); |
| 99 | + |
| 100 | + const fourthVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
| 101 | + await commands.executeCommand('workbench.action.debug.stepInto'); |
| 102 | + await fourthVariablesRetrieved; |
| 103 | + assert.equal(stoppedEvents, 4); |
| 104 | + |
| 105 | + const fifthVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve); |
| 106 | + await commands.executeCommand('workbench.action.debug.stepOut'); |
| 107 | + await fifthVariablesRetrieved; |
| 108 | + assert.equal(stoppedEvents, 5); |
| 109 | + |
| 110 | + let sessionTerminated: () => void; |
| 111 | + toDispose.push(debug.onDidTerminateDebugSession(() => { |
| 112 | + sessionTerminated(); |
| 113 | + })); |
| 114 | + const sessionTerminatedPromise = new Promise<void>(resolve => sessionTerminated = resolve); |
| 115 | + await commands.executeCommand('workbench.action.debug.stop'); |
| 116 | + await sessionTerminatedPromise; |
| 117 | + assert.equal(debug.activeDebugSession, undefined); |
| 118 | + |
| 119 | + disposeAll(toDispose); |
| 120 | + }); |
119 | 121 |
|
120 | 122 | test('start debugging failure', async function () {
|
121 | 123 | let errorCount = 0;
|
|
0 commit comments