|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +import * as sinon from 'sinon'; |
| 7 | +import * as fs from 'fs-extra'; |
| 8 | +import * as path from 'path'; |
| 9 | +import { Uri } from 'vscode'; |
| 10 | +import { assert } from 'chai'; |
| 11 | +import { getConfigurationsForWorkspace } from '../../../../../client/debugger/extension/configuration/launch.json/launchJsonReader'; |
| 12 | +import * as vscodeApis from '../../../../../client/common/vscodeApis/workspaceApis'; |
| 13 | + |
| 14 | +suite('Launch Json Reader', () => { |
| 15 | + let pathExistsStub: sinon.SinonStub; |
| 16 | + let readFileStub: sinon.SinonStub; |
| 17 | + let getConfigurationStub: sinon.SinonStub; |
| 18 | + const workspacePath = 'path/to/workspace'; |
| 19 | + const workspaceFolder = { |
| 20 | + name: 'workspace', |
| 21 | + uri: Uri.file(workspacePath), |
| 22 | + index: 0, |
| 23 | + }; |
| 24 | + |
| 25 | + setup(() => { |
| 26 | + pathExistsStub = sinon.stub(fs, 'pathExists'); |
| 27 | + readFileStub = sinon.stub(fs, 'readFile'); |
| 28 | + getConfigurationStub = sinon.stub(vscodeApis, 'getConfiguration'); |
| 29 | + }); |
| 30 | + |
| 31 | + teardown(() => { |
| 32 | + sinon.restore(); |
| 33 | + }); |
| 34 | + |
| 35 | + test('Return the config in the launch.json file', async () => { |
| 36 | + const launchPath = path.join(workspaceFolder.uri.fsPath, '.vscode', 'launch.json'); |
| 37 | + pathExistsStub.withArgs(launchPath).resolves(true); |
| 38 | + const launchJson = `{ |
| 39 | + "version": "0.1.0", |
| 40 | + "configurations": [ |
| 41 | + { |
| 42 | + "name": "Python: Launch.json", |
| 43 | + "type": "python", |
| 44 | + "request": "launch", |
| 45 | + "purpose": ["debug-test"], |
| 46 | + }, |
| 47 | + ] |
| 48 | + }`; |
| 49 | + readFileStub.withArgs(launchPath, 'utf-8').returns(launchJson); |
| 50 | + |
| 51 | + const config = await getConfigurationsForWorkspace(workspaceFolder); |
| 52 | + |
| 53 | + assert.deepStrictEqual(config, [ |
| 54 | + { |
| 55 | + name: 'Python: Launch.json', |
| 56 | + type: 'python', |
| 57 | + request: 'launch', |
| 58 | + purpose: ['debug-test'], |
| 59 | + }, |
| 60 | + ]); |
| 61 | + }); |
| 62 | + |
| 63 | + test('If there is no launch.json return the config in the workspace file', async () => { |
| 64 | + getConfigurationStub.withArgs('launch').returns({ |
| 65 | + configurations: [ |
| 66 | + { |
| 67 | + name: 'Python: Workspace File', |
| 68 | + type: 'python', |
| 69 | + request: 'launch', |
| 70 | + purpose: ['debug-test'], |
| 71 | + }, |
| 72 | + ], |
| 73 | + }); |
| 74 | + |
| 75 | + const config = await getConfigurationsForWorkspace(workspaceFolder); |
| 76 | + |
| 77 | + assert.deepStrictEqual(config, [ |
| 78 | + { |
| 79 | + name: 'Python: Workspace File', |
| 80 | + type: 'python', |
| 81 | + request: 'launch', |
| 82 | + purpose: ['debug-test'], |
| 83 | + }, |
| 84 | + ]); |
| 85 | + }); |
| 86 | +}); |
0 commit comments