forked from microsoft/vscode-python-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunchJsonReader.unit.test.ts
More file actions
113 lines (93 loc) · 4.49 KB
/
launchJsonReader.unit.test.ts
File metadata and controls
113 lines (93 loc) · 4.49 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
'use strict';
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as typemoq from 'typemoq';
import * as fs from 'fs-extra';
import { WorkspaceFolder, Uri, WorkspaceConfiguration } from 'vscode';
import {
getConfigurationsForWorkspace,
getConfigurationsFromSettings,
} from '../../../../extension/debugger/configuration/launch.json/launchJsonReader';
import * as vscodeapi from '../../../../extension/common/vscodeapi';
suite('Debugging - launchJsonReader', () => {
let sandbox: sinon.SinonSandbox;
setup(() => {
sandbox = sinon.createSandbox();
});
teardown(() => {
sandbox.restore();
});
suite('getConfigurationsForWorkspace', () => {
test('Should return configurations from launch.json if it exists', async () => {
const workspace = typemoq.Mock.ofType<WorkspaceFolder>();
workspace.setup((w) => w.uri).returns(() => Uri.file('/path/to/workspace'));
const launchJsonContent = `{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"type": "python",
"request": "launch",
"program": "${workspace.object.uri}/app.py"
}
]
}`;
sandbox.stub(fs, 'pathExists').resolves(true);
sandbox.stub(fs, 'readFile').resolves(launchJsonContent);
const configurations = await getConfigurationsForWorkspace(workspace.object);
assert.strictEqual(configurations.length, 1);
assert.strictEqual(configurations[0].name, 'Launch Program');
});
test('Should return configurations from settings.json if launch.json does not exist', async () => {
const workspace = typemoq.Mock.ofType<WorkspaceFolder>();
workspace.setup((w) => w.uri).returns(() => Uri.file('/path/to/workspace'));
const mockConfig = typemoq.Mock.ofType<WorkspaceConfiguration>();
mockConfig
.setup((c) => c.configurations)
.returns(() => [
{
name: 'Launch Program 2',
type: 'python',
request: 'launch',
program: '${workspaceFolder}/app.py',
},
]);
sandbox.stub(fs, 'pathExists').resolves(false);
sandbox.stub(vscodeapi, 'getConfiguration').returns(mockConfig.object);
const configurations = await getConfigurationsForWorkspace(workspace.object);
assert.strictEqual(configurations.length, 1);
assert.strictEqual(configurations[0].name, 'Launch Program 2');
});
});
suite('getConfigurationsFromSettings', () => {
test('Should return configurations from settings.json', () => {
const workspace = typemoq.Mock.ofType<WorkspaceFolder>();
workspace.setup((w) => w.uri).returns(() => Uri.file('/path/to/workspace'));
const mockConfig = typemoq.Mock.ofType<WorkspaceConfiguration>();
mockConfig
.setup((c) => c.configurations)
.returns(() => [
{
name: 'Launch Program 3',
type: 'python',
request: 'launch',
program: '${workspaceFolder}/app.py',
},
]);
sandbox.stub(vscodeapi, 'getConfiguration').returns(mockConfig.object);
const configurations = getConfigurationsFromSettings(workspace.object);
assert.strictEqual(configurations.length, 1);
assert.strictEqual(configurations[0].name, 'Launch Program 3');
});
test('Should return empty array if no configurations in settings.json', () => {
const workspace = typemoq.Mock.ofType<WorkspaceFolder>();
workspace.setup((w) => w.uri).returns(() => Uri.file('/path/to/workspace'));
const mockConfig = typemoq.Mock.ofType<WorkspaceConfiguration>();
mockConfig.setup((c) => c.get('configurations')).returns(() => []);
mockConfig.setup((c) => c.configurations).returns(() => []);
sandbox.stub(vscodeapi, 'getConfiguration').returns(mockConfig.object);
const configurations = getConfigurationsFromSettings(workspace.object);
assert.strictEqual(configurations.length, 0);
});
});
});