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