debug.test.ts 5.0 KB
Newer Older
I
isidor 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
7
import { debug, workspace, Disposable } from 'vscode';
8
import { disposeAll } from '../utils';
9
// import { basename } from 'path';
I
isidor 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

suite('Debug', function () {

	test('breakpoints', async function () {
		assert.equal(debug.breakpoints.length, 0);
		let onDidChangeBreakpointsCounter = 0;
		const toDispose: Disposable[] = [];

		toDispose.push(debug.onDidChangeBreakpoints(() => {
			onDidChangeBreakpointsCounter++;
		}));

		debug.addBreakpoints([{ id: '1', enabled: true }, { id: '2', enabled: false, condition: '2 < 5' }]);
		assert.equal(onDidChangeBreakpointsCounter, 1);
		assert.equal(debug.breakpoints.length, 2);
		assert.equal(debug.breakpoints[0].id, '1');
		assert.equal(debug.breakpoints[1].id, '2');
		assert.equal(debug.breakpoints[1].condition, '2 < 5');

		debug.removeBreakpoints([{ id: '1', enabled: true }]);
		assert.equal(onDidChangeBreakpointsCounter, 2);
		assert.equal(debug.breakpoints.length, 1);

		debug.removeBreakpoints([{ id: '2', enabled: false }]);
		assert.equal(onDidChangeBreakpointsCounter, 3);
		assert.equal(debug.breakpoints.length, 0);

		disposeAll(toDispose);
	});

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
	// test('start debugging', async function () {
	// 	assert.equal(debug.activeDebugSession, undefined);
	// 	let stoppedEvents = 0;
	// 	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: () => ({
	// 			onDidSendMessage: m => {
	// 				if (m.event === 'stopped') {
	// 					stoppedEvents++;
	// 				}
	// 				if (m.type === 'response' && m.command === 'variables') {
	// 					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);
	// 	// Do not await debug start to return due to https://github.com/microsoft/vscode/issues/90134
	// 	debug.startDebugging(workspace.workspaceFolders![0], 'Launch debug.js');
	// 	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 => variablesReceived = resolve);
	// 	await commands.executeCommand('workbench.action.debug.stepOver');
	// 	await secondVariablesRetrieved;
	// 	assert.equal(stoppedEvents, 2);
	// 	const editor = window.activeTextEditor;
	// 	assert.notEqual(editor, undefined);
	// 	assert.equal(basename(editor!.document.fileName), 'debug.js');

	// 	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 => variablesReceived = resolve);
	// 	await commands.executeCommand('workbench.action.debug.stepInto');
	// 	await fourthVariablesRetrieved;
	// 	assert.equal(stoppedEvents, 4);

	// 	const fifthVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve);
	// 	await commands.executeCommand('workbench.action.debug.stepOut');
	// 	await fifthVariablesRetrieved;
	// 	assert.equal(stoppedEvents, 5);

	// 	let sessionTerminated: () => void;
	// 	toDispose.push(debug.onDidTerminateDebugSession(() => {
	// 		sessionTerminated();
	// 	}));
	// 	const sessionTerminatedPromise = new Promise<void>(resolve => sessionTerminated = resolve);
	// 	await commands.executeCommand('workbench.action.debug.stop');
	// 	await sessionTerminatedPromise;
	// 	assert.equal(debug.activeDebugSession, undefined);

	// 	disposeAll(toDispose);
	// });
I
isidor 已提交
121 122 123 124 125 126 127 128 129 130 131

	test('start debugging failure', async function () {
		let errorCount = 0;
		try {
			await debug.startDebugging(workspace.workspaceFolders![0], 'non existent');
		} catch (e) {
			errorCount++;
		}
		assert.equal(errorCount, 1);
	});
});