|
| 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 vscode from 'vscode'; |
| 7 | +import reportIssue from '../../../src/shared/reportIssue'; |
| 8 | +import { FakeMonoResolver, fakeMonoInfo } from '../../omnisharpUnitTests/fakes/fakeMonoResolver'; |
| 9 | +import { FakeDotnetResolver } from '../../omnisharpUnitTests/fakes/fakeDotnetResolver'; |
| 10 | +import { DotnetInfo } from '../../../src/shared/utils/dotnetInfo'; |
| 11 | +import { getFakeVsCode } from '../../../test/unitTests/fakes'; |
| 12 | + |
| 13 | +jest.resetAllMocks(); |
| 14 | +jest.mock('vscode', () => ({ |
| 15 | + workspace: { |
| 16 | + getConfiguration: jest.fn((_) => { |
| 17 | + return { |
| 18 | + get: jest.fn((_) => { |
| 19 | + console.log('test1'); |
| 20 | + return undefined; |
| 21 | + }), |
| 22 | + }; |
| 23 | + }), |
| 24 | + executeCommand: jest.fn((command: string, ...rest: any[]) => { |
| 25 | + console.log('test2'); |
| 26 | + return undefined; |
| 27 | + }), |
| 28 | + }, |
| 29 | + extensions: { |
| 30 | + all: [ |
| 31 | + { |
| 32 | + packageJSON: { |
| 33 | + name: 'name1', |
| 34 | + publisher: 'publisher1', |
| 35 | + version: 'version1', |
| 36 | + isBuiltin: true, |
| 37 | + }, |
| 38 | + id: 'id1', |
| 39 | + extensionPath: 'c:/extensions/abc-x64', |
| 40 | + }, |
| 41 | + { |
| 42 | + packageJSON: { |
| 43 | + name: 'name2', |
| 44 | + publisher: 'publisher2', |
| 45 | + version: 'version2', |
| 46 | + isBuiltin: false, |
| 47 | + }, |
| 48 | + id: 'id2', |
| 49 | + extensionPath: 'c:/extensions/xyz-x64', |
| 50 | + }, |
| 51 | + ], |
| 52 | + }, |
| 53 | +})); |
| 54 | + |
| 55 | +describe(`${reportIssue.name}`, () => { |
| 56 | + const vscodeVersion = 'myVersion'; |
| 57 | + const csharpExtVersion = 'csharpExtVersion'; |
| 58 | + const isValidForMono = true; |
| 59 | + |
| 60 | + const fakeDotnetInfo: DotnetInfo = { |
| 61 | + FullInfo: 'myDotnetInfo', |
| 62 | + Version: '1.0.x', |
| 63 | + RuntimeId: 'win10-x64', |
| 64 | + Runtimes: {}, |
| 65 | + }; |
| 66 | + |
| 67 | + let fakeMonoResolver: FakeMonoResolver; |
| 68 | + let fakeDotnetResolver: FakeDotnetResolver; |
| 69 | + const getDotnetInfo = async () => Promise.resolve(fakeDotnetInfo); |
| 70 | + let issueBody: string; |
| 71 | + |
| 72 | + beforeEach(() => { |
| 73 | + //jest.resetAllMocks(); |
| 74 | + // jest.mock('vscode', () => ({ |
| 75 | + // workspace: { |
| 76 | + // getConfiguration: jest.fn((_) => { |
| 77 | + // return { |
| 78 | + // get: jest.fn((_) => { |
| 79 | + // console.log('test1'); |
| 80 | + // return undefined; |
| 81 | + // }), |
| 82 | + // }; |
| 83 | + // }), |
| 84 | + // executeCommand: jest.fn((command: string, ...rest: any[]) => { |
| 85 | + // issueBody = rest[0].issueBody; |
| 86 | + // return undefined; |
| 87 | + // }), |
| 88 | + // }, |
| 89 | + // extensions: { |
| 90 | + // all: [ |
| 91 | + // { |
| 92 | + // packageJSON: { |
| 93 | + // name: 'name1', |
| 94 | + // publisher: 'publisher1', |
| 95 | + // version: 'version1', |
| 96 | + // isBuiltin: true, |
| 97 | + // }, |
| 98 | + // id: 'id1', |
| 99 | + // extensionPath: 'c:/extensions/abc-x64', |
| 100 | + // }, |
| 101 | + // { |
| 102 | + // packageJSON: { |
| 103 | + // name: 'name2', |
| 104 | + // publisher: 'publisher2', |
| 105 | + // version: 'version2', |
| 106 | + // isBuiltin: false, |
| 107 | + // }, |
| 108 | + // id: 'id2', |
| 109 | + // extensionPath: 'c:/extensions/xyz-x64', |
| 110 | + // }, |
| 111 | + // ], |
| 112 | + // }, |
| 113 | + // })); |
| 114 | + |
| 115 | + fakeMonoResolver = new FakeMonoResolver(); |
| 116 | + fakeDotnetResolver = new FakeDotnetResolver(); |
| 117 | + }); |
| 118 | + |
| 119 | + describe('The body is passed to the vscode clipboard and', () => { |
| 120 | + test('it contains the vscode version', async () => { |
| 121 | + await reportIssue( |
| 122 | + vscode, |
| 123 | + csharpExtVersion, |
| 124 | + getDotnetInfo, |
| 125 | + isValidForMono, |
| 126 | + fakeDotnetResolver, |
| 127 | + fakeMonoResolver |
| 128 | + ); |
| 129 | + expect(issueBody).toContain(`**VSCode version**: ${vscodeVersion}`); |
| 130 | + }); |
| 131 | + |
| 132 | + test('it contains the csharp extension version', async () => { |
| 133 | + await reportIssue( |
| 134 | + vscode, |
| 135 | + csharpExtVersion, |
| 136 | + getDotnetInfo, |
| 137 | + isValidForMono, |
| 138 | + fakeDotnetResolver, |
| 139 | + fakeMonoResolver |
| 140 | + ); |
| 141 | + expect(issueBody).toContain(`**C# Extension**: ${csharpExtVersion}`); |
| 142 | + }); |
| 143 | + |
| 144 | + test('it contains dotnet info', async () => { |
| 145 | + await reportIssue( |
| 146 | + vscode, |
| 147 | + csharpExtVersion, |
| 148 | + getDotnetInfo, |
| 149 | + isValidForMono, |
| 150 | + fakeDotnetResolver, |
| 151 | + fakeMonoResolver |
| 152 | + ); |
| 153 | + expect(issueBody).toContain(fakeDotnetInfo.FullInfo); |
| 154 | + }); |
| 155 | + |
| 156 | + test('mono information is obtained when it is a valid mono platform', async () => { |
| 157 | + await reportIssue( |
| 158 | + vscode, |
| 159 | + csharpExtVersion, |
| 160 | + getDotnetInfo, |
| 161 | + isValidForMono, |
| 162 | + fakeDotnetResolver, |
| 163 | + fakeMonoResolver |
| 164 | + ); |
| 165 | + expect(fakeMonoResolver.getMonoCalled).toEqual(true); |
| 166 | + }); |
| 167 | + |
| 168 | + test('mono version is put in the body when it is a valid mono platform', async () => { |
| 169 | + await reportIssue( |
| 170 | + vscode, |
| 171 | + csharpExtVersion, |
| 172 | + getDotnetInfo, |
| 173 | + isValidForMono, |
| 174 | + fakeDotnetResolver, |
| 175 | + fakeMonoResolver |
| 176 | + ); |
| 177 | + expect(fakeMonoResolver.getMonoCalled).toEqual(true); |
| 178 | + expect(issueBody).toEqual(fakeMonoInfo.version); |
| 179 | + }); |
| 180 | + |
| 181 | + test('mono information is not obtained when it is not a valid mono platform', async () => { |
| 182 | + await reportIssue(vscode, csharpExtVersion, getDotnetInfo, false, fakeDotnetResolver, fakeMonoResolver); |
| 183 | + expect(fakeMonoResolver.getMonoCalled).toEqual(false); |
| 184 | + }); |
| 185 | + |
| 186 | + test('The url contains the name, publisher and version for all the extensions that are not builtin', async () => { |
| 187 | + await reportIssue( |
| 188 | + vscode, |
| 189 | + csharpExtVersion, |
| 190 | + getDotnetInfo, |
| 191 | + isValidForMono, |
| 192 | + fakeDotnetResolver, |
| 193 | + fakeMonoResolver |
| 194 | + ); |
| 195 | + expect(issueBody).toContain(getFakeVsCode().extensions.all[2].packageJSON.name); |
| 196 | + expect(issueBody).toContain(getFakeVsCode().extensions.all[2].packageJSON.publisher); |
| 197 | + expect(issueBody).toContain(getFakeVsCode().extensions.all[2].packageJSON.version); |
| 198 | + expect(issueBody).toContain(getFakeVsCode().extensions.all[1].packageJSON.name); |
| 199 | + expect(issueBody).toContain(getFakeVsCode().extensions.all[1].packageJSON.publisher); |
| 200 | + expect(issueBody).toContain(getFakeVsCode().extensions.all[1].packageJSON.version); |
| 201 | + }); |
| 202 | + }); |
| 203 | +}); |
0 commit comments