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