Path: blob/main/extensions/copilot/test/simulation/slash-test/testGen.js.stest.ts
13394 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*--------------------------------------------------------------------------------------------*/45import * as assert from 'assert';6import { Intent } from '../../../src/extension/common/constants';7import { IRelativeFile } from '../../../src/platform/test/node/simulationWorkspace';8import { Uri } from '../../../src/vscodeTypes';9import { ssuite, stest } from '../../base/stest';10import { simulateInlineChat } from '../inlineChatSimulator';11import { assertNoStrings, assertSomeStrings, assertWorkspaceEdit, fromFixture } from '../stestUtil';12import { getFileContent } from '../outcomeValidators';1314ssuite({ title: '/tests', location: 'inline', language: 'js' }, () => {1516stest({ description: 'generate-jest', }, (testingServiceCollection) => {17return simulateInlineChat(testingServiceCollection, {18files: [19fromFixture('tests/generate-jest/', 'some/sum.test.js'),20fromFixture('tests/generate-jest/', 'some/sum.js'),21fromFixture('tests/generate-jest/', 'some/app.js'),22],23queries: [{24file: 'some/app.js',25selection: [3, 0, 7, 1],26query: '/tests',27expectedIntent: Intent.Tests,28validate: async (outcome, workspace, accessor) => {29assertWorkspaceEdit(outcome);3031assert.strictEqual(outcome.files.length, 1);3233const [first] = outcome.files;34assertSomeStrings(getFileContent(first), ['test', 'expect', 'toBe', 'sum', 'app.js']);35}36}],37});38});3940stest({ description: 'add another test to existing file', }, (testingServiceCollection) => {41return simulateInlineChat(testingServiceCollection, {42files: [43fromFixture('tests/generate-jest/', 'some/sum.test.js'),44fromFixture('tests/generate-jest/', 'some/sum.js'),45fromFixture('tests/generate-jest/', 'some/app.js'),46],47queries: [{48file: 'some/sum.js',49selection: [4, 20],50query: '/tests',51expectedIntent: Intent.Tests,52validate: async (outcome, workspace, accessor) => {53assertWorkspaceEdit(outcome);5455assert.strictEqual(outcome.files.length, 1);5657const [first] = outcome.files;58assert.strictEqual((<IRelativeFile>first).fileName, 'sum.test.js');59assertSomeStrings(getFileContent(first), ['test', 'expect', 'toBe', 'subtract']);60assertNoStrings(getFileContent(first), ['import']);6162}63}],64});65});6667stest({ description: '/tests: with package.json info', }, (testingServiceCollection) => {68return simulateInlineChat(testingServiceCollection, {69files: [70fromFixture('tests/simple-js-proj/src/index.js'),71fromFixture('tests/simple-js-proj/package.json'),72],73queries: [74{75file: 'index.js',76selection: [0, 0, 2, 1],77query: '/tests',78expectedIntent: Intent.Tests,79validate: async (outcome, workspace, accessor) => {80assert.strictEqual(outcome.type, 'workspaceEdit');81},82},83],84});85});8687stest({ description: 'issue #1261: Failed to create new test file when in an untitled file', }, (testingServiceCollection) => {88const uri = Uri.parse('untitled:Untitled-1');89return simulateInlineChat(testingServiceCollection, {90files: [{91kind: 'qualifiedFile',92uri,93fileContents: 'function sum(a, b) {\n\treturn a + b;\n}\n\n',94languageId: 'javascript'95}],96queries: [97{98file: uri,99selection: [4, 0],100query: 'Write a test for this function',101expectedIntent: Intent.Tests,102validate: async (outcome, workspace, accessor) => {103assertWorkspaceEdit(outcome);104assert.strictEqual(outcome.files.length, 1);105const file = outcome.files[0];106107// Check if it's the old format (with kind and uri)108if ('kind' in file && 'uri' in file) {109assert.strictEqual(file.kind, 'qualifiedFile');110assert.strictEqual(file.uri.scheme, 'untitled');111}112// Otherwise if it's the new format (with srcUri)113else if ('srcUri' in file) {114assert.ok(file.srcUri.startsWith('untitled:'), 'URI should be untitled scheme');115}116117// Use getFileContent to get the content regardless of format118const content = getFileContent(file);119assert.strictEqual(content.includes('// BEGIN:'), false);120assert.strictEqual(content.includes('// END:'), false);121},122},123],124});125});126127});128129130