This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathadapter.test.ts
More file actions
562 lines (434 loc) · 16.3 KB
/
adapter.test.ts
File metadata and controls
562 lines (434 loc) · 16.3 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import assert = require('assert');
import * as Path from 'path';
import * as FS from 'fs';
import * as CP from 'child_process';
import * as PathUtils from '../node/pathUtilities';
import {DebugProtocol} from 'vscode-debugprotocol';
import {DebugClient} from 'vscode-debugadapter-testsupport';
suite('Node Debug Adapter', () => {
const DEBUG_ADAPTER = './out/node/nodeDebug.js';
const PROJECT_ROOT = Path.join(__dirname, '../../');
const DATA_ROOT = Path.join(PROJECT_ROOT, 'testdata/');
let env;
let dc: DebugClient;
setup( () => {
if (!env) {
env = process.env;
// make sure that the debug adapter finds a version of node on the PATH
// that supports the "legacy" protocol.
// If not, we use the LEGACY_NODE_PATH from the environment.
const result = CP.spawnSync('node', ['--version']);
const semVerString = result.stdout ? result.stdout.toString() : undefined;
if (semVerString) {
const match = semVerString.trim().match(/v(\d+)\.(\d+)\.(\d+)/);
if (match && match.length === 4 && parseInt(match[1]) >= 8) {
env = PathUtils.extendObject({}, process.env);
if (process.platform === 'win32') {
env.Path = env.LEGACY_NODE_PATH || `${env.NVM_HOME}\\v7.9.0;${env.Path}`;
} else {
env.PATH = env.LEGACY_NODE_PATH || `${env.NVM_DIR}/versions/node/v7.9.0/bin:${env.PATH}`;
}
}
}
}
dc = new DebugClient('node', DEBUG_ADAPTER, 'legacy-node', { env: env });
return dc.start(); // add port to run as server
});
teardown( () => dc.stop() );
suite('basic', () => {
test('unknown request should produce error', done => {
dc.send('illegal_request').then(() => {
done(new Error('does not report error on unknown request'));
}).catch(() => {
done();
});
});
});
suite('initialize', () => {
test('should return supported features', () => {
return dc.initializeRequest().then(response => {
response.body = response.body || {};
assert.equal(response.body.supportsConfigurationDoneRequest, true);
});
});
test('should produce error for invalid \'pathFormat\'', done => {
dc.initializeRequest({
adapterID: 'mock',
linesStartAt1: true,
columnsStartAt1: true,
pathFormat: 'url'
}).then(response => {
done(new Error('does not report error on invalid \'pathFormat\' attribute'));
}).catch(err => {
// error expected
done();
});
});
});
suite('launch', () => {
test('should run program to the end', () => {
const PROGRAM = Path.join(DATA_ROOT, 'program.js');
return Promise.all([
dc.configurationSequence(),
dc.launch({ program: PROGRAM }),
dc.waitForEvent('terminated')
]);
});
if (process.platform === 'win32') {
const sysRoot = process.env['SystemRoot'] ||'C:\\WINDOWS';
const bash32bitPath = Path.join(sysRoot, 'SYSNATIVE', 'bash.exe');
const bash64bitPath = Path.join(sysRoot, 'System32', 'bash.exe');
if (FS.existsSync(bash32bitPath) || FS.existsSync(bash64bitPath)) {
test('should run program using WSL', () => {
const PROGRAM = Path.join(DATA_ROOT, 'program.js');
return Promise.all([
dc.configurationSequence(),
dc.launch({ program: PROGRAM, useWSL: true }),
dc.waitForEvent('terminated')
]);
});
}
}
test('should stop on entry', () => {
const PROGRAM = Path.join(DATA_ROOT, 'program.js');
const ENTRY_LINE = 1;
return Promise.all([
dc.configurationSequence(),
dc.launch({ program: PROGRAM, stopOnEntry: true }),
dc.assertStoppedLocation('entry', { path: PROGRAM, line: ENTRY_LINE } )
]);
});
test('should stop on debugger statement', () => {
const PROGRAM = Path.join(DATA_ROOT, 'programWithDebugger.js');
const DEBUGGER_LINE = 6;
return Promise.all([
dc.configurationSequence(),
dc.launch({ program: PROGRAM }),
dc.assertStoppedLocation('debugger_statement', { path: PROGRAM, line: DEBUGGER_LINE } )
]);
});
test('should stop on debugger statement in first line', () => {
const PROGRAM = Path.join(DATA_ROOT, 'programWithDebugger1.js');
const DEBUGGER_LINE = 1;
return Promise.all([
dc.configurationSequence(),
dc.launch({ program: PROGRAM }),
dc.assertStoppedLocation('debugger_statement', { path: PROGRAM, line: DEBUGGER_LINE } )
]);
});
});
suite('setBreakpoints', () => {
test('should stop on a breakpoint', () => {
const PROGRAM = Path.join(DATA_ROOT, 'program.js');
const BREAKPOINT_LINE = 2;
return dc.hitBreakpoint({ program: PROGRAM }, { path: PROGRAM, line: BREAKPOINT_LINE} );
});
test('should stop on a breakpoint in file with spaces in its name', () => {
const PROGRAM = Path.join(DATA_ROOT, 'folder with spaces', 'file with spaces.js');
const BREAKPOINT_LINE = 2;
return dc.hitBreakpoint({ program: PROGRAM }, { path: PROGRAM, line: BREAKPOINT_LINE} );
});
test('should stop on a breakpoint identical to the entrypoint', () => { // verifies the 'hide break on entry point' logic
const PROGRAM = Path.join(DATA_ROOT, 'program.js');
const ENTRY_LINE = 1;
return dc.hitBreakpoint({ program: PROGRAM }, { path: PROGRAM, line: ENTRY_LINE } );
});
test('should break on a specific column in a single line program', () => {
const SINGLE_LINE_PROGRAM = Path.join(DATA_ROOT, 'programSingleLine.js');
const LINE = 1;
const COLUMN = 55;
return dc.hitBreakpoint({ program: SINGLE_LINE_PROGRAM }, { path: SINGLE_LINE_PROGRAM, line: LINE, column: COLUMN } );
});
test('should stop on a conditional breakpoint', () => {
const PROGRAM = Path.join(DATA_ROOT, 'program.js');
const COND_BREAKPOINT_LINE = 13;
const COND_BREAKPOINT_COLUMN = 2;
return Promise.all([
dc.waitForEvent('initialized').then(event => {
return dc.setBreakpointsRequest({
breakpoints: [ { line: COND_BREAKPOINT_LINE, condition: 'i === 3' } ],
source: { path: PROGRAM }
});
}).then(response => {
const bp = response.body.breakpoints[0];
assert.equal(bp.verified, true, 'breakpoint verification mismatch: verified');
assert.equal(bp.line, COND_BREAKPOINT_LINE, 'breakpoint verification mismatch: line');
assert.equal(bp.column, COND_BREAKPOINT_COLUMN, 'breakpoint verification mismatch: column');
return dc.configurationDoneRequest();
}),
dc.launch({ program: PROGRAM }),
dc.assertStoppedLocation('breakpoint', { path: PROGRAM, line: COND_BREAKPOINT_LINE } ).then(response => {
const frame = response.body.stackFrames[0];
return dc.evaluateRequest({ context: 'watch', frameId: frame.id, expression: 'x' }).then(response => {
assert.equal(response.body.result, 9, 'x !== 9');
return response;
});
})
]);
});
test('should stop on <node_internals> module', () => {
const PROGRAM = Path.join(DATA_ROOT, 'programWithInternal.js');
return dc.hitBreakpoint({ program: PROGRAM }, { path: '<node_internals>/assert.js', line: 110 });
});
test('should stop on debugger statement in eval', () => {
const PROGRAM = Path.join(DATA_ROOT, 'programWithDebuggerEval.js');
const DEBUGGER_LINE = 2;
return Promise.all([
dc.configurationSequence(),
dc.launch({ program: PROGRAM }),
dc.assertStoppedLocation('debugger_statement', { path: /^<node_internals>\/VM[0-9]+$/, line: DEBUGGER_LINE } )
]);
});
});
suite('setBreakpoints in TypeScript', () => {
test('should stop at entry point', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-entrypoint/index.ts');
const TS_LINE = 3;
return Promise.all([
dc.configurationSequence(),
dc.launch({ program: PROGRAM, stopOnEntry: true }),
dc.assertStoppedLocation('entry', { path: PROGRAM, line: TS_LINE } )
]);
});
test('should stop on a breakpoint in source (all files top level)', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-simple/classes.js');
const TS_SOURCE = Path.join(DATA_ROOT, 'sourcemaps-simple/classes.ts');
const TS_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
runtimeArgs: [ '--nolazy' ]
}, {
path: TS_SOURCE,
line: TS_LINE
});
});
test('should stop on a breakpoint in source (all files top level, missing sourceMappingURL)', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-simple-no-sourceMappingURL/classes.js');
const TS_SOURCE = Path.join(DATA_ROOT, 'sourcemaps-simple-no-sourceMappingURL/classes.ts');
const TS_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
runtimeArgs: [ '--nolazy' ]
}, {
path: TS_SOURCE,
line: TS_LINE
});
});
test('should stop on a breakpoint in source (outDir)', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-inline/src/classes.ts');
const OUT_DIR = Path.join(DATA_ROOT, 'sourcemaps-inline/dist');
const BREAKPOINT_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
outDir: OUT_DIR,
runtimeArgs: [ '--nolazy' ]
}, {
path: PROGRAM,
line: BREAKPOINT_LINE
});
});
test('should stop on a breakpoint in source (outFiles)', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-inline/src/classes.ts');
const OUT_FILES = Path.join(DATA_ROOT, 'sourcemaps-inline/dist/**/*.js');
const BREAKPOINT_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
outFiles: [ OUT_FILES ],
runtimeArgs: [ '--nolazy' ]
}, {
path: PROGRAM,
line: BREAKPOINT_LINE
});
});
test('should stop on a breakpoint in source with spaces in paths (outDir)', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps with spaces', 'the source/classes.ts');
const OUT_DIR = Path.join(DATA_ROOT, 'sourcemaps with spaces/the distribution');
const BREAKPOINT_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
outDir: OUT_DIR,
runtimeArgs: [ '--nolazy' ]
}, {
path: PROGRAM,
line: BREAKPOINT_LINE
});
});
test('should stop on a breakpoint in source with spaces in paths (outFiles)', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps with spaces', 'the source/classes.ts');
const OUT_FILES = Path.join(DATA_ROOT, 'sourcemaps with spaces/the distribution/**/*.js');
const BREAKPOINT_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
outFiles: [ OUT_FILES ],
runtimeArgs: [ '--nolazy' ]
}, {
path: PROGRAM,
line: BREAKPOINT_LINE
});
});
test('should stop on a breakpoint in source - Microsoft/vscode#2574', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-2574/out/classes.js');
const OUT_DIR = Path.join(DATA_ROOT, 'sourcemaps-2574/out');
const TS_SOURCE = Path.join(DATA_ROOT, 'sourcemaps-2574/src/classes.ts');
const TS_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
outDir: OUT_DIR,
runtimeArgs: [ '--nolazy' ]
}, {
path: TS_SOURCE,
line: TS_LINE
});
});
test('should stop on a breakpoint in source (sourceMappingURL missing)', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemap-no-sourceMappingURL/out/classes.js');
const OUT_DIR = Path.join(DATA_ROOT, 'sourcemap-no-sourceMappingURL/out');
const TS_SOURCE = Path.join(DATA_ROOT, 'sourcemap-no-sourceMappingURL/src/classes.ts');
const TS_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
outDir: OUT_DIR,
runtimeArgs: [ '--nolazy' ]
}, {
path: TS_SOURCE,
line: TS_LINE
});
});
test('should stop on a breakpoint in source even if breakpoint was set in JavaScript - Microsoft/vscode-node-debug#43', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-2574/out/classes.js');
const OUT_DIR = Path.join(DATA_ROOT, 'sourcemaps-2574/out');
const JS_SOURCE = PROGRAM;
const JS_LINE = 21;
const TS_SOURCE = Path.join(DATA_ROOT, 'sourcemaps-2574/src/classes.ts');
const TS_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
outDir: OUT_DIR,
runtimeArgs: [ '--nolazy' ]
}, {
path: JS_SOURCE,
line: JS_LINE
}, {
path: TS_SOURCE,
line: TS_LINE
});
});
test('should stop on a breakpoint in source even if program\'s entry point is in JavaScript', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-js-entrypoint/out/entry.js');
const OUT_DIR = Path.join(DATA_ROOT, 'sourcemaps-js-entrypoint/out');
const TS_SOURCE = Path.join(DATA_ROOT, 'sourcemaps-js-entrypoint/src/classes.ts');
const TS_LINE = 17;
return dc.hitBreakpoint({
program: PROGRAM,
sourceMaps: true,
outDir: OUT_DIR,
runtimeArgs: [ '--nolazy' ]
}, { path: TS_SOURCE, line: TS_LINE } );
});
test('should stop on an explicit breakpoint at entry point', () => {
const PROGRAM = Path.join(DATA_ROOT, 'sourcemaps-entrypoint/index.ts');
const TS_LINE = 3;
return dc.hitBreakpoint({
program: PROGRAM,
sourceMaps: true,
outFiles: [],
runtimeArgs: [ '--nolazy' ]
}, { path: PROGRAM, line: TS_LINE } );
});
});
suite('function setBreakpoints', () => {
const PROGRAM = Path.join(DATA_ROOT, 'programWithFunction.js');
const FUNCTION_NAME_1 = 'foo';
const FUNCTION_LINE_1 = 4;
const FUNCTION_NAME_2 = 'bar';
const FUNCTION_LINE_2 = 8;
const FUNCTION_NAME_3 = 'xyz';
test('should stop on a function breakpoint', () => {
return Promise.all<DebugProtocol.ProtocolMessage>([
dc.launch({ program: PROGRAM }),
dc.configurationSequence(),
// since we can only set a function breakpoint for *known* functions,
// we use the program output as an indication that function 'foo' has been defined.
dc.assertOutput('stdout', 'foo defined').then(event => {
return dc.setFunctionBreakpointsRequest({
breakpoints: [ { name: FUNCTION_NAME_2 } ]
}).then(() => {
return dc.setFunctionBreakpointsRequest({
breakpoints: [ { name: FUNCTION_NAME_1 }, { name: FUNCTION_NAME_2 }, { name: FUNCTION_NAME_3 } ]
}).then(response => {
const bp1 = response.body.breakpoints[0];
assert.equal(bp1.verified, true);
assert.equal(bp1.line, FUNCTION_LINE_1);
const bp2 = response.body.breakpoints[1];
assert.equal(bp2.verified, true);
assert.equal(bp2.line, FUNCTION_LINE_2);
const bp3 = response.body.breakpoints[2];
assert.equal(bp3.verified, false);
return response;
});
});
}),
dc.assertStoppedLocation('breakpoint', { path: PROGRAM, line: FUNCTION_LINE_1 } )
]);
});
});
suite('setExceptionBreakpoints', () => {
const PROGRAM = Path.join(DATA_ROOT, 'programWithException.js');
test('should not stop on an exception', () => {
return Promise.all<DebugProtocol.ProtocolMessage>([
dc.waitForEvent('initialized').then(event => {
return dc.setExceptionBreakpointsRequest({
filters: [ ]
});
}).then(response => {
return dc.configurationDoneRequest();
}),
dc.launch({ program: PROGRAM }),
dc.waitForEvent('terminated')
]);
});
test('should stop on a caught exception', () => {
const EXCEPTION_LINE = 6;
return Promise.all([
dc.waitForEvent('initialized').then(event => {
return dc.setExceptionBreakpointsRequest({
filters: [ 'all' ]
});
}).then(response => {
return dc.configurationDoneRequest();
}),
dc.launch({ program: PROGRAM }),
dc.assertStoppedLocation('exception', { path: PROGRAM, line: EXCEPTION_LINE } )
]);
});
test('should stop on uncaught exception', () => {
const UNCAUGHT_EXCEPTION_LINE = 12;
return Promise.all([
dc.waitForEvent('initialized').then(event => {
return dc.setExceptionBreakpointsRequest({
filters: [ 'uncaught' ]
});
}).then(response => {
return dc.configurationDoneRequest();
}),
dc.launch({ program: PROGRAM }),
dc.assertStoppedLocation('exception', { path: PROGRAM, line: UNCAUGHT_EXCEPTION_LINE } )
]);
});
});
suite('output events', () => {
const PROGRAM = Path.join(DATA_ROOT, 'programWithOutput.js');
test('stdout and stderr events should be complete and in correct order', () => {
return Promise.all([
dc.configurationSequence(),
dc.launch({ program: PROGRAM }),
dc.assertOutput('stdout', 'Hello stdout 0\nHello stdout 1\nHello stdout 2\n'),
//dc.assertOutput('stderr', 'Hello stderr 0\nHello stderr 1\nHello stderr 2\n')
]);
});
});
});