forked from microsoft/vscode-node-debug2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSetup.ts
More file actions
52 lines (42 loc) · 1.76 KB
/
Copy pathtestSetup.ts
File metadata and controls
52 lines (42 loc) · 1.76 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as os from 'os';
import * as path from 'path';
import * as ts from 'vscode-chrome-debug-core-testsupport';
import * as findFreePort from 'find-free-port';
const NIGHTLY_NAME = os.platform() === 'win32' ? 'node-nightly.cmd' : 'node-nightly';
function findPort(): Promise<number> {
return new Promise(resolve => {
findFreePort(9000, (err, port) => {
if (err) return resolve(9229);
resolve(port);
});
});
}
async function patchLaunchArgs(launchArgs: any): Promise<void> {
launchArgs.trace = 'verbose';
if (process.version.startsWith('v6.2')) {
launchArgs.runtimeExecutable = NIGHTLY_NAME;
}
if (!launchArgs.port) {
launchArgs.port = await findPort();
launchArgs.runtimeArgs = launchArgs.runtimeArgs || [];
launchArgs.runtimeArgs.push(`--inspect=${launchArgs.port}`, '--debug-brk');
}
}
export function setup(_opts?: { port?: number, alwaysDumpLogs?: boolean }) {
const opts = Object.assign(<ts.ISetupOpts>{
entryPoint: './out/src/nodeDebug.js',
type: 'node2',
patchLaunchArgs
}, _opts);
return ts.setup(opts);
}
export function teardown() {
ts.teardown();
}
export const lowercaseDriveLetterDirname = __dirname.charAt(0).toLowerCase() + __dirname.substr(1);
export const PROJECT_ROOT = path.join(lowercaseDriveLetterDirname, '../../');
export const DATA_ROOT = path.join(PROJECT_ROOT, 'testdata/');