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