forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapabilities.test.ts
More file actions
101 lines (91 loc) · 4.29 KB
/
capabilities.test.ts
File metadata and controls
101 lines (91 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
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
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:no-suspicious-comment max-func-body-length no-invalid-this no-var-requires no-require-imports no-any
import { expect } from 'chai';
import { ChildProcess, spawn } from 'child_process';
import * as getFreePort from 'get-port';
import { Socket } from 'net';
import * as path from 'path';
import { PassThrough } from 'stream';
import { Message } from 'vscode-debugadapter/lib/messages';
import { DebugProtocol } from 'vscode-debugprotocol';
import { EXTENSION_ROOT_DIR } from '../../client/common/constants';
import { sleep } from '../../client/common/core.utils';
import { createDeferred } from '../../client/common/helpers';
import { PTVSD_PATH } from '../../client/debugger/Common/constants';
import { ProtocolParser } from '../../client/debugger/Common/protocolParser';
import { ProtocolMessageWriter } from '../../client/debugger/Common/protocolWriter';
import { PythonDebugger } from '../../client/debugger/mainV2';
import { PYTHON_PATH } from '../common';
import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize';
class Request extends Message implements DebugProtocol.InitializeRequest {
// tslint:disable-next-line:no-banned-terms
public arguments: any;
constructor(public command: string, args: any) {
super('request');
this.arguments = args;
}
}
const fileToDebug = path.join(EXTENSION_ROOT_DIR, 'src', 'testMultiRootWkspc', 'workspace5', 'remoteDebugger-start-with-ptvsd.py');
suite('Debugging - Capabilities', () => {
let disposables: { dispose?: Function; destroy?: Function }[];
let proc: ChildProcess;
setup(async function () {
if (!IS_MULTI_ROOT_TEST || !TEST_DEBUGGER) {
this.skip();
}
this.timeout(30000);
disposables = [];
});
teardown(() => {
disposables.forEach(disposable => {
try {
disposable.dispose!();
// tslint:disable-next-line:no-empty
} catch { }
try {
disposable.destroy!();
// tslint:disable-next-line:no-empty
} catch { }
});
try {
proc.kill();
// tslint:disable-next-line:no-empty
} catch { }
});
test('Compare capabilities', async () => {
const protocolWriter = new ProtocolMessageWriter();
const initializeRequest: DebugProtocol.InitializeRequest = new Request('initialize', { pathFormat: 'path' });
const debugClient = new PythonDebugger(undefined as any);
const inStream = new PassThrough();
const outStream = new PassThrough();
disposables.push(inStream);
disposables.push(outStream);
debugClient.start(inStream, outStream);
const debugClientProtocolParser = new ProtocolParser();
debugClientProtocolParser.connect(outStream);
disposables.push(debugClientProtocolParser);
const expectedResponsePromise = new Promise<DebugProtocol.InitializeResponse>(resolve => debugClientProtocolParser.once('response_initialize', resolve));
protocolWriter.write(inStream, initializeRequest);
const expectedResponse = await expectedResponsePromise;
const host = 'localhost';
const port = await getFreePort({ host, port: 3000 });
const env = { ...process.env };
env.PYTHONPATH = PTVSD_PATH;
proc = spawn(PYTHON_PATH, ['-m', 'ptvsd', '--server', '--port', `${port}`, '--file', fileToDebug], { cwd: path.dirname(fileToDebug), env });
await sleep(3000);
const connected = createDeferred();
const socket = new Socket();
socket.on('error', connected.reject.bind(connected));
socket.connect({ port, host }, () => connected.resolve(socket));
await connected.promise;
const protocolParser = new ProtocolParser();
protocolParser.connect(socket!);
disposables.push(protocolParser);
const actualResponsePromise = new Promise<DebugProtocol.InitializeResponse>(resolve => protocolParser.once('response_initialize', resolve));
protocolWriter.write(socket!, initializeRequest);
const actualResponse = await actualResponsePromise;
expect(actualResponse.body).to.deep.equal(expectedResponse.body);
});
});