Skip to content

Commit 63e1746

Browse files
committed
Add the unit test
1 parent c2c2e7e commit 63e1746

File tree

3 files changed

+133
-37
lines changed

3 files changed

+133
-37
lines changed

src/features/fileIssue.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ function generateExtensionTable(extensions: Extension<any>[]) {
6565
}
6666

6767
const tableHeader = `|Extension|Author|Version|\n|---|---|---|`;
68-
const table = extensions.map((e) => {
69-
if (e.packageJSON.isBuiltin === false) {
70-
return `|${e.packageJSON.name}|${e.packageJSON.publisher}|${e.packageJSON.version}|`;
71-
}
72-
}).join("\n");
68+
const table = extensions.map((e) => `|${e.packageJSON.name}|${e.packageJSON.publisher}|${e.packageJSON.version}|`).join("\n");
7369

7470
const extensionTable = `
7571
${tableHeader}\n${table};

src/vscodeAdapter.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -902,40 +902,9 @@ interface Thenable<T> {
902902
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
903903
}
904904

905-
export interface Extension<T> {
906-
907-
/**
908-
* The canonical extension identifier in the form of: `publisher.name`.
909-
*/
905+
export interface Extension<T>{
910906
readonly id: string;
911-
912-
/**
913-
* The absolute file path of the directory containing this extension.
914-
*/
915-
readonly extensionPath: string;
916-
917-
/**
918-
* `true` if the extension has been activated.
919-
*/
920-
readonly isActive: boolean;
921-
922-
/**
923-
* The parsed contents of the extension's package.json.
924-
*/
925907
readonly packageJSON: any;
926-
927-
/**
928-
* The public API exported by this extension. It is an invalid action
929-
* to access this field before this extension has been activated.
930-
*/
931-
readonly exports: T;
932-
933-
/**
934-
* Activates this extension and returns its public API.
935-
*
936-
* @return A promise that will resolve when this extension has been activated.
937-
*/
938-
activate(): Thenable<T>;
939908
}
940909

941910
export interface vscode {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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 { getFakeVsCode } from "../testAssets/Fakes";
7+
import fileIssue from "../../../src/features/fileIssue";
8+
import { EventStream } from "../../../src/EventStream";
9+
import TestEventBus from "../testAssets/TestEventBus";
10+
import { expect } from "chai";
11+
import { ReportIssue } from "../../../src/omnisharp/loggingEvents";
12+
import { vscode } from "../../../src/vscodeAdapter";
13+
14+
suite("File Issue", () => {
15+
const vscodeVersion = "myVersion";
16+
const csharpExtVersion = "csharpExtVersion";
17+
const monoInfo = "myMonoInfo";
18+
const dotnetInfo = "myDotnetInfo";
19+
const isValidForMono = true;
20+
let vscode: vscode;
21+
const extension1 = {
22+
packageJSON: {
23+
name: "name1",
24+
publisher: "publisher1",
25+
version: "version1",
26+
isBuiltin: true
27+
},
28+
id: "id1"
29+
};
30+
31+
const extension2 = {
32+
packageJSON: {
33+
name: "name2",
34+
publisher: "publisher2",
35+
version: "version2",
36+
isBuiltin: false
37+
},
38+
id:"id2"
39+
};
40+
41+
let eventStream: EventStream;
42+
let eventBus: TestEventBus;
43+
let execCommands: Array<string>;
44+
let execChildProcess = (command: string, workingDir?: string) => {
45+
execCommands.push(command);
46+
if (command == "dotnet --info") {
47+
return Promise.resolve(dotnetInfo);
48+
}
49+
else if (command == "mono --version") {
50+
return Promise.resolve(monoInfo);
51+
}
52+
else {
53+
return Promise.resolve("randomValue");
54+
}
55+
};
56+
57+
setup(() => {
58+
vscode = getFakeVsCode();
59+
vscode.extensions.getExtension = () => {
60+
return {
61+
packageJSON: {
62+
version: csharpExtVersion
63+
},
64+
id: ""
65+
};
66+
};
67+
vscode.version = vscodeVersion;
68+
vscode.extensions.all = [extension1, extension2];
69+
eventStream = new EventStream();
70+
eventBus = new TestEventBus(eventStream);
71+
execCommands = [];
72+
});
73+
74+
test(`${ReportIssue.name} event is created`, async () => {
75+
await fileIssue(vscode, eventStream, execChildProcess, isValidForMono);
76+
let events = eventBus.getEvents();
77+
expect(events).to.have.length(1);
78+
expect(events[0].constructor.name).to.be.equal(`${ReportIssue.name}`);
79+
});
80+
81+
test("${ReportIssue.name} event is created with the omnisharp-vscode github repo issues url", async () => {
82+
await fileIssue(vscode, eventStream, execChildProcess, false);
83+
expect(execCommands).to.not.contain("mono --version");
84+
let event = <ReportIssue>eventBus.getEvents()[0];
85+
expect(event.url).to.be.equal("https://github.com/OmniSharp/omnisharp-vscode/issues/new");
86+
});
87+
88+
test("The body contains the vscode version", async () => {
89+
await fileIssue(vscode, eventStream, execChildProcess, isValidForMono);
90+
let event = <ReportIssue>eventBus.getEvents()[0];
91+
expect(event.body).to.contain(`VSCode version: ${vscodeVersion}`);
92+
});
93+
94+
test("The body contains the csharp extension version", async () => {
95+
await fileIssue(vscode, eventStream, execChildProcess, isValidForMono);
96+
let event = <ReportIssue>eventBus.getEvents()[0];
97+
expect(event.body).to.contain(`C# Extension: ${csharpExtVersion}`);
98+
});
99+
100+
test("dotnet info is obtained and put into the body", async() => {
101+
await fileIssue(vscode, eventStream, execChildProcess, isValidForMono);
102+
expect(execCommands).to.contain("dotnet --info");
103+
let event = <ReportIssue>eventBus.getEvents()[0];
104+
expect(event.body).to.contain(dotnetInfo);
105+
});
106+
107+
test("mono information is obtained when it is a valid mono platform", async () => {
108+
await fileIssue(vscode, eventStream, execChildProcess, isValidForMono);
109+
expect(execCommands).to.contain("mono --version");
110+
let event = <ReportIssue>eventBus.getEvents()[0];
111+
expect(event.body).to.contain(monoInfo);
112+
});
113+
114+
test("mono information is obtained when it is not a valid mono platform", async () => {
115+
await fileIssue(vscode, eventStream, execChildProcess, false);
116+
expect(execCommands).to.not.contain("mono --version");
117+
let event = <ReportIssue>eventBus.getEvents()[0];
118+
expect(event.body).to.not.contain(monoInfo);
119+
});
120+
121+
test("The body contains all the name, publisher and version for the extensions that are not builtin", async () => {
122+
await fileIssue(vscode, eventStream, execChildProcess, isValidForMono);
123+
let event = <ReportIssue>eventBus.getEvents()[0];
124+
expect(event.body).to.contain(extension2.packageJSON.name);
125+
expect(event.body).to.contain(extension2.packageJSON.publisher);
126+
expect(event.body).to.contain(extension2.packageJSON.version);
127+
expect(event.body).to.not.contain(extension1.packageJSON.name);
128+
expect(event.body).to.not.contain(extension1.packageJSON.publisher);
129+
expect(event.body).to.not.contain(extension1.packageJSON.version);
130+
});
131+
});

0 commit comments

Comments
 (0)