Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/slash-test/testGen.java.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 * as path from 'path';
8
import { Intent } from '../../../src/extension/common/constants';
9
import { URI } from '../../../src/util/vs/base/common/uri';
10
import { ssuite, stest } from '../../base/stest';
11
import { forInline, simulateInlineChatWithStrategy } from '../inlineChatSimulator';
12
import { getFileContent } from '../outcomeValidators';
13
import { assertWorkspaceEdit, fromFixture } from '../stestUtil';
14
15
16
forInline((strategy, nonExtensionConfigurations, suffix) => {
17
18
ssuite({ title: `/tests${suffix}`, location: 'inline', language: 'java', nonExtensionConfigurations }, () => {
19
20
stest({ description: 'looks up pom.xml and junit framework info', }, (testingServiceCollection) => {
21
return simulateInlineChatWithStrategy(strategy, testingServiceCollection, {
22
workspaceFolders: [
23
URI.file(path.join(__dirname, '../test/simulation/fixtures/tests/java-example-project'))
24
],
25
files: [
26
fromFixture('tests/java-example-project', 'src/main/java/com/example/MyCalculator.java'),
27
],
28
queries: [{
29
file: 'src/main/java/com/example/MyCalculator.java',
30
selection: [4, 15],
31
query: '/tests',
32
expectedIntent: Intent.Tests,
33
validate: async (outcome, workspace, accessor) => {
34
assertWorkspaceEdit(outcome);
35
assert.strictEqual(outcome.files.length, 1, 'Expected one file to be created');
36
assert.ok(
37
getFileContent(outcome.files[0]).includes('import org.junit.jupiter.api.Test;') || // JUnit 5 -- TODO@ulugbekna: we can't yet parse versions of test frameworks
38
getFileContent(outcome.files[0]).includes('import org.junit.Test;') // JUnit 4
39
);
40
}
41
}],
42
});
43
});
44
45
stest({ description: 'looks up existing test file', nonExtensionConfigurations }, (testingServiceCollection) => {
46
return simulateInlineChatWithStrategy(strategy, testingServiceCollection, {
47
workspaceFolders: [
48
URI.file(path.join(__dirname, '../test/simulation/fixtures/tests/java-example-project-with-existing-test-file'))
49
],
50
files: [
51
fromFixture('tests/java-example-project-with-existing-test-file', 'src/main/java/com/example/MyCalculator.java'),
52
],
53
queries: [{
54
file: 'src/main/java/com/example/MyCalculator.java',
55
selection: [4, 15],
56
query: '/tests',
57
expectedIntent: Intent.Tests,
58
validate: async (outcome, workspace, accessor) => {
59
assertWorkspaceEdit(outcome);
60
assert.strictEqual(outcome.files.length, 1, 'Expected one file to be created');
61
assert.ok(
62
getFileContent(outcome.files[0]).includes('test #2')
63
);
64
}
65
}],
66
});
67
});
68
69
});
70
71
});
72
73