Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/debugCommandToConfig.stest.ts
13388 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import * as assert from 'assert';
6
import path from 'path';
7
import { DebugCommandToConfigConverter } from '../../src/extension/onboardDebug/node/commandToConfigConverter';
8
import { IGitExtensionService } from '../../src/platform/git/common/gitExtensionService';
9
import { API } from '../../src/platform/git/vscode/git';
10
import { TestingServiceCollection } from '../../src/platform/test/node/services';
11
import { TestWorkspaceService } from '../../src/platform/test/node/testWorkspaceService';
12
import { IWorkspaceService } from '../../src/platform/workspace/common/workspaceService';
13
import { CancellationToken } from '../../src/util/vs/base/common/cancellation';
14
import { Event } from '../../src/util/vs/base/common/event';
15
import { URI } from '../../src/util/vs/base/common/uri';
16
import { SyncDescriptor } from '../../src/util/vs/platform/instantiation/common/descriptors';
17
import { IInstantiationService } from '../../src/util/vs/platform/instantiation/common/instantiation';
18
import { rubric } from '../base/rubric';
19
import { ssuite, stest } from '../base/stest';
20
21
ssuite({ title: 'Debug config to command', location: 'context' }, () => {
22
23
const WORKSPACE_FOLDER = URI.file('/workspace');
24
25
async function score(testingServiceCollection: TestingServiceCollection, cwd: string, args: string[]) {
26
testingServiceCollection.define(IGitExtensionService, new SyncDescriptor(class implements IGitExtensionService {
27
_serviceBrand: undefined;
28
onDidChange = Event.None;
29
extensionAvailable: boolean = false;
30
getExtensionApi(): API | undefined {
31
return undefined;
32
}
33
}));
34
const accessor = testingServiceCollection.createTestingAccessor();
35
(accessor.get(IWorkspaceService) as TestWorkspaceService).getWorkspaceFolders().push(WORKSPACE_FOLDER);
36
37
const cvt = accessor.get(IInstantiationService).createInstance(DebugCommandToConfigConverter);
38
const result = await cvt.convert(cwd, args, CancellationToken.None);
39
if (!result.ok) {
40
throw new Error('Expected tools to be found');
41
}
42
43
return { accessor, r: result.config?.configurations[0] };
44
}
45
46
stest({ description: 'node test' }, async (testingServiceCollection) => {
47
const { accessor, r } = await score(testingServiceCollection, WORKSPACE_FOLDER.fsPath, ['node', 'index.js']);
48
49
rubric(accessor,
50
() => assert.ok(r?.type === 'node'),
51
() => assert.ok(r?.program.endsWith('index.js')),
52
() => assert.ok(!r?.cwd || r?.cwd === '${workspaceFolder}'),
53
);
54
});
55
56
stest({ description: 'node subdirectory and arg' }, async (testingServiceCollection) => {
57
const { accessor, r } = await score(testingServiceCollection, path.join(WORKSPACE_FOLDER.fsPath, 'foo'), ['node', 'index', '--my-arg']);
58
59
rubric(accessor,
60
() => assert.ok(r?.type === 'node'),
61
() => assert.ok(r?.program.endsWith('index.js')),
62
() => assert.ok(r?.cwd.endsWith('foo')),
63
() => assert.deepStrictEqual(r?.args, ['--my-arg']),
64
);
65
});
66
67
stest({ description: 'python3 subdirectory and arg' }, async (testingServiceCollection) => {
68
const { accessor, r } = await score(testingServiceCollection, path.join(WORKSPACE_FOLDER.fsPath, 'foo'), ['python3', 'cool.py', '--my-arg']);
69
70
rubric(accessor,
71
() => assert.ok(r?.type === 'python' || r?.type === 'debugpy'),
72
() => assert.ok(r?.program.endsWith('cool.py')),
73
() => assert.ok(r?.cwd.endsWith('foo')),
74
() => assert.deepStrictEqual(r?.args, ['--my-arg']),
75
);
76
});
77
78
stest({ description: 'opening a browser' }, async (testingServiceCollection) => {
79
const { accessor, r } = await score(testingServiceCollection, path.join(WORKSPACE_FOLDER.fsPath), ['chrome.exe', 'https://microsoft.com']);
80
81
rubric(accessor,
82
() => assert.ok(r?.type === 'chrome'),
83
() => assert.deepStrictEqual(r?.url, 'https://microsoft.com'),
84
);
85
});
86
87
stest({ description: 'cargo run platform-specific' }, async (testingServiceCollection) => {
88
const { accessor, r } = await score(testingServiceCollection, path.join(WORKSPACE_FOLDER.fsPath), ['cargo', 'run']);
89
90
rubric(accessor,
91
// test env service always advertises linux:
92
() => assert.strictEqual(r?.type, 'lldb'),
93
() => assert.ok(r?.program.includes('target/debug')),
94
);
95
});
96
});
97
98