|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +// tslint:disable:no-suspicious-comment max-func-body-length no-invalid-this no-var-requires no-require-imports no-any |
| 7 | + |
| 8 | +import * as path from 'path'; |
| 9 | +import { DebugClient } from 'vscode-debugadapter-testsupport'; |
| 10 | +import { EXTENSION_ROOT_DIR } from '../../client/common/constants'; |
| 11 | +import { noop } from '../../client/common/core.utils'; |
| 12 | +import { IS_WINDOWS } from '../../client/common/platform/constants'; |
| 13 | +import { DebugOptions, LaunchRequestArguments } from '../../client/debugger/Common/Contracts'; |
| 14 | +import { sleep } from '../common'; |
| 15 | +import { IS_MULTI_ROOT_TEST, TEST_DEBUGGER } from '../initialize'; |
| 16 | +import { DEBUGGER_TIMEOUT } from './common/constants'; |
| 17 | +import { DebugClientEx } from './debugClient'; |
| 18 | + |
| 19 | +const testAdapterFilePath = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'debugger', 'mainV2.js'); |
| 20 | +const workspaceDirectory = path.join(EXTENSION_ROOT_DIR, 'src', 'testMultiRootWkspc', 'workspace5'); |
| 21 | +let testCounter = 0; |
| 22 | +const debuggerType = 'pythonExperimental'; |
| 23 | +suite(`Module Debugging - Misc tests: ${debuggerType}`, () => { |
| 24 | + let debugClient: DebugClient; |
| 25 | + setup(async function () { |
| 26 | + if (!IS_MULTI_ROOT_TEST || !TEST_DEBUGGER) { |
| 27 | + this.skip(); |
| 28 | + } |
| 29 | + await new Promise(resolve => setTimeout(resolve, 1000)); |
| 30 | + debugClient = createDebugAdapter(); |
| 31 | + debugClient.defaultTimeout = DEBUGGER_TIMEOUT; |
| 32 | + await debugClient.start(); |
| 33 | + }); |
| 34 | + teardown(async () => { |
| 35 | + // Wait for a second before starting another test (sometimes, sockets take a while to get closed). |
| 36 | + await sleep(1000); |
| 37 | + try { |
| 38 | + await debugClient.stop().catch(noop); |
| 39 | + // tslint:disable-next-line:no-empty |
| 40 | + } catch (ex) { } |
| 41 | + await sleep(1000); |
| 42 | + }); |
| 43 | + /** |
| 44 | + * Creates the debug adapter. |
| 45 | + * We do not need to support code coverage on AppVeyor, lets use the standard test adapter. |
| 46 | + * @returns {DebugClient} |
| 47 | + */ |
| 48 | + function createDebugAdapter(): DebugClient { |
| 49 | + if (IS_WINDOWS) { |
| 50 | + return new DebugClient('node', testAdapterFilePath, debuggerType); |
| 51 | + } else { |
| 52 | + const coverageDirectory = path.join(EXTENSION_ROOT_DIR, `debug_coverage${testCounter += 1}`); |
| 53 | + return new DebugClientEx(testAdapterFilePath, debuggerType, coverageDirectory, { cwd: EXTENSION_ROOT_DIR }); |
| 54 | + } |
| 55 | + } |
| 56 | + function buildLauncArgs(): LaunchRequestArguments { |
| 57 | + const env = {}; |
| 58 | + // tslint:disable-next-line:no-string-literal |
| 59 | + env['PYTHONPATH'] = `.${path.delimiter}${path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'experimental', 'ptvsd')}`; |
| 60 | + |
| 61 | + // tslint:disable-next-line:no-unnecessary-local-variable |
| 62 | + const options: LaunchRequestArguments = { |
| 63 | + module: 'mymod', |
| 64 | + program: '', |
| 65 | + cwd: workspaceDirectory, |
| 66 | + debugOptions: [DebugOptions.RedirectOutput], |
| 67 | + pythonPath: 'python', |
| 68 | + args: [], |
| 69 | + env, |
| 70 | + envFile: '', |
| 71 | + logToFile: false, |
| 72 | + type: debuggerType |
| 73 | + }; |
| 74 | + |
| 75 | + return options; |
| 76 | + } |
| 77 | + |
| 78 | + test('Test stdout output', async () => { |
| 79 | + await Promise.all([ |
| 80 | + debugClient.configurationSequence(), |
| 81 | + debugClient.launch(buildLauncArgs()), |
| 82 | + debugClient.waitForEvent('initialized'), |
| 83 | + debugClient.assertOutput('stdout', 'hello world'), |
| 84 | + debugClient.waitForEvent('exited'), |
| 85 | + debugClient.waitForEvent('terminated') |
| 86 | + ]); |
| 87 | + }); |
| 88 | +}); |
0 commit comments