Skip to content

Commit 920f08a

Browse files
authored
Merge pull request #6369 from dibarbet/option_integration_test_fixes
Cleanup and fix issues with option provider
2 parents d9f01b5 + 17e26fb commit 920f08a

File tree

56 files changed

+992
-1691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+992
-1691
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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 { jest, describe, test, expect, beforeEach } from '@jest/globals';
12+
13+
describe(`${reportIssue.name}`, () => {
14+
const vscodeVersion = 'myVersion';
15+
const csharpExtVersion = 'csharpExtVersion';
16+
const isValidForMono = true;
17+
const extension1 = {
18+
packageJSON: {
19+
name: 'name1',
20+
publisher: 'publisher1',
21+
version: 'version1',
22+
isBuiltin: true,
23+
},
24+
id: 'id1',
25+
extensionPath: 'c:/extensions/abc-x64',
26+
} as vscode.Extension<any>;
27+
28+
const extension2 = {
29+
packageJSON: {
30+
name: 'name2',
31+
publisher: 'publisher2',
32+
version: 'version2',
33+
isBuiltin: false,
34+
},
35+
id: 'id2',
36+
extensionPath: 'c:/extensions/xyz-x64',
37+
} as vscode.Extension<any>;
38+
39+
const fakeDotnetInfo: DotnetInfo = {
40+
FullInfo: 'myDotnetInfo',
41+
Version: '1.0.x',
42+
RuntimeId: 'win10-x64',
43+
Runtimes: {},
44+
};
45+
46+
let fakeMonoResolver: FakeMonoResolver;
47+
let fakeDotnetResolver: FakeDotnetResolver;
48+
const getDotnetInfo = async () => Promise.resolve(fakeDotnetInfo);
49+
let issueBody: string;
50+
51+
beforeEach(() => {
52+
jest.spyOn(vscode.workspace, 'getConfiguration').mockReturnValue({
53+
get: jest.fn((_config: string) => {
54+
return undefined;
55+
}),
56+
has: jest.fn(),
57+
inspect: jest.fn(),
58+
update: jest.fn(),
59+
} as vscode.WorkspaceConfiguration);
60+
61+
jest.spyOn(vscode.commands, 'executeCommand').mockImplementation(async (command: string, ...rest: any[]) => {
62+
issueBody = rest[0].issueBody;
63+
return {} as any;
64+
});
65+
jest.replaceProperty(vscode, 'extensions', {
66+
all: [extension1, extension2],
67+
getExtension: jest.fn(),
68+
onDidChange: jest.fn(),
69+
} as typeof vscode.extensions);
70+
71+
fakeMonoResolver = new FakeMonoResolver();
72+
fakeDotnetResolver = new FakeDotnetResolver();
73+
});
74+
75+
describe('The body is passed to the vscode clipboard and', () => {
76+
test('it contains the vscode version', async () => {
77+
await reportIssue(csharpExtVersion, getDotnetInfo, isValidForMono, fakeDotnetResolver, fakeMonoResolver);
78+
expect(issueBody).toContain(`**VSCode version**: ${vscodeVersion}`);
79+
});
80+
81+
test('it contains the csharp extension version', async () => {
82+
await reportIssue(csharpExtVersion, getDotnetInfo, isValidForMono, fakeDotnetResolver, fakeMonoResolver);
83+
expect(issueBody).toContain(`**C# Extension**: ${csharpExtVersion}`);
84+
});
85+
86+
test('it contains dotnet info', async () => {
87+
await reportIssue(csharpExtVersion, getDotnetInfo, isValidForMono, fakeDotnetResolver, fakeMonoResolver);
88+
expect(issueBody).toContain(fakeDotnetInfo.FullInfo);
89+
});
90+
91+
test('mono information is obtained when it is a valid mono platform', async () => {
92+
await reportIssue(csharpExtVersion, getDotnetInfo, isValidForMono, fakeDotnetResolver, fakeMonoResolver);
93+
expect(fakeMonoResolver.getMonoCalled).toEqual(true);
94+
});
95+
96+
test('mono version is put in the body when it is a valid mono platform', async () => {
97+
await reportIssue(csharpExtVersion, getDotnetInfo, isValidForMono, fakeDotnetResolver, fakeMonoResolver);
98+
expect(fakeMonoResolver.getMonoCalled).toEqual(true);
99+
expect(issueBody).toContain(fakeMonoInfo.version);
100+
});
101+
102+
test('mono information is not obtained when it is not a valid mono platform', async () => {
103+
await reportIssue(csharpExtVersion, getDotnetInfo, false, fakeDotnetResolver, fakeMonoResolver);
104+
expect(fakeMonoResolver.getMonoCalled).toEqual(false);
105+
});
106+
107+
test('The url contains the name, publisher and version for all the extensions that are not builtin', async () => {
108+
await reportIssue(csharpExtVersion, getDotnetInfo, isValidForMono, fakeDotnetResolver, fakeMonoResolver);
109+
expect(issueBody).toContain(extension2.packageJSON.name);
110+
expect(issueBody).toContain(extension2.packageJSON.publisher);
111+
expect(issueBody).toContain(extension2.packageJSON.version);
112+
expect(issueBody).not.toContain(extension1.packageJSON.name);
113+
expect(issueBody).not.toContain(extension1.packageJSON.publisher);
114+
expect(issueBody).not.toContain(extension1.packageJSON.version);
115+
});
116+
});
117+
});
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 { jest, describe, test, expect, beforeEach } from '@jest/globals';
8+
import { InformationMessageObserver } from '../../src/observers/informationMessageObserver';
9+
import { getUnresolvedDependenices, getWorkspaceConfiguration } from '../../test/unitTests/fakes';
10+
import { Subject, from as observableFrom } from 'rxjs';
11+
import { timeout } from 'rxjs/operators';
12+
13+
describe('InformationMessageObserver', () => {
14+
let doClickOk: () => void;
15+
let doClickCancel: () => void;
16+
let signalCommandDone: () => void;
17+
let commandDone: Promise<void> | undefined;
18+
const optionObservable = new Subject<void>();
19+
let infoMessage: string | undefined;
20+
let invokedCommand: string | undefined;
21+
const observer: InformationMessageObserver = new InformationMessageObserver(vscode);
22+
23+
beforeEach(() => {
24+
infoMessage = undefined;
25+
invokedCommand = undefined;
26+
commandDone = new Promise<void>((resolve) => {
27+
signalCommandDone = () => {
28+
resolve();
29+
};
30+
});
31+
32+
jest.spyOn(vscode.workspace, 'getConfiguration').mockReturnValue(getWorkspaceConfiguration());
33+
jest.spyOn(vscode.window, 'showInformationMessage').mockImplementation(
34+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
35+
//@ts-ignore
36+
async <T>(message: string, ...items: T[]) => {
37+
infoMessage = message;
38+
return new Promise<T | undefined>((resolve) => {
39+
doClickCancel = () => {
40+
resolve(undefined);
41+
};
42+
43+
doClickOk = () => {
44+
resolve(items[0]);
45+
};
46+
47+
return undefined;
48+
});
49+
}
50+
);
51+
jest.spyOn(vscode.commands, 'executeCommand').mockImplementation(async (command: string, ..._: any[]) => {
52+
invokedCommand = command;
53+
signalCommandDone();
54+
return undefined;
55+
});
56+
});
57+
58+
[
59+
{
60+
event: getUnresolvedDependenices('someFile'),
61+
expectedCommand: 'dotnet.restore.all',
62+
},
63+
].forEach((elem) => {
64+
describe(elem.event.constructor.name, () => {
65+
describe('Suppress Dotnet Restore Notification is true', () => {
66+
beforeEach(() => {
67+
vscode.workspace.getConfiguration().update('csharp.suppressDotnetRestoreNotification', true);
68+
optionObservable.next();
69+
});
70+
71+
test('The information message is not shown', () => {
72+
observer.post(elem.event);
73+
expect(infoMessage).toBeUndefined();
74+
});
75+
});
76+
77+
describe('Suppress Dotnet Restore Notification is false', () => {
78+
beforeEach(() => {
79+
vscode.workspace.getConfiguration().update('csharp.suppressDotnetRestoreNotification', false);
80+
optionObservable.next();
81+
});
82+
83+
test('The information message is shown', async () => {
84+
observer.post(elem.event);
85+
expect(infoMessage?.length).toBeGreaterThan(0);
86+
doClickOk();
87+
await commandDone;
88+
expect(invokedCommand).toEqual(elem.expectedCommand);
89+
});
90+
91+
test('Given an information message if the user clicks Restore, the command is executed', async () => {
92+
observer.post(elem.event);
93+
doClickOk();
94+
await commandDone;
95+
expect(invokedCommand).toEqual(elem.expectedCommand);
96+
});
97+
98+
test('Given an information message if the user clicks cancel, the command is not executed', async () => {
99+
observer.post(elem.event);
100+
doClickCancel();
101+
await expect(observableFrom(commandDone!).pipe(timeout(1)).toPromise()).rejects.toThrow();
102+
expect(invokedCommand).toBeUndefined();
103+
});
104+
});
105+
});
106+
});
107+
108+
afterEach(() => {
109+
commandDone = undefined;
110+
});
111+
});

omnisharptest/omnisharpUnitTests/logging/omnisharpChannelObserver.test.ts renamed to omnisharptest/omnisharpJestTests/logging/omnisharpChannelObserver.test.ts

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
import { expect } from 'chai';
6-
import { vscode } from '../../../src/vscodeAdapter';
7-
import { getNullChannel, updateConfig, getVSCodeWithConfig } from '../../../test/unitTests/fakes';
5+
6+
import * as vscode from 'vscode';
7+
import { jest, describe, test, expect, beforeEach } from '@jest/globals';
8+
import { getNullChannel, getWorkspaceConfiguration } from '../../../test/unitTests/fakes';
89
import { OmnisharpChannelObserver } from '../../../src/observers/omnisharpChannelObserver';
910
import {
1011
OmnisharpFailure,
@@ -13,40 +14,34 @@ import {
1314
OmnisharpRestart,
1415
OmnisharpServerOnStdErr,
1516
} from '../../../src/omnisharp/loggingEvents';
16-
import OptionProvider from '../../../src/shared/observers/optionProvider';
1717
import { Subject } from 'rxjs';
18-
import { Options } from '../../../src/shared/options';
1918

20-
suite('OmnisharpChannelObserver', () => {
19+
describe('OmnisharpChannelObserver', () => {
2120
let hasShown: boolean;
2221
let hasCleared: boolean;
2322
let preserveFocus: boolean | undefined;
24-
let vscode: vscode;
25-
const optionObservable = new Subject<Options>();
26-
const optionProvider = new OptionProvider(optionObservable);
23+
const optionObservable = new Subject<void>();
2724
let observer: OmnisharpChannelObserver;
2825

29-
setup(() => {
26+
beforeEach(() => {
3027
hasShown = false;
3128
hasCleared = false;
3229
preserveFocus = false;
33-
vscode = getVSCodeWithConfig();
34-
observer = new OmnisharpChannelObserver(
35-
{
36-
...getNullChannel(),
37-
show: (preserve) => {
38-
hasShown = true;
39-
preserveFocus = preserve;
40-
},
41-
clear: () => {
42-
hasCleared = true;
43-
},
30+
observer = new OmnisharpChannelObserver({
31+
...getNullChannel(),
32+
show: (preserve) => {
33+
hasShown = true;
34+
preserveFocus = preserve;
35+
},
36+
clear: () => {
37+
hasCleared = true;
4438
},
45-
optionProvider
46-
);
39+
});
40+
41+
jest.spyOn(vscode.workspace, 'getConfiguration').mockReturnValue(getWorkspaceConfiguration());
4742

48-
updateConfig(vscode, 'csharp', 'showOmnisharpLogOnError', true);
49-
optionObservable.next(Options.Read(vscode));
43+
vscode.workspace.getConfiguration().update('csharp.showOmnisharpLogOnError', true);
44+
optionObservable.next();
5045
});
5146

5247
[
@@ -55,28 +50,28 @@ suite('OmnisharpChannelObserver', () => {
5550
new OmnisharpServerOnStdErr('std err'),
5651
].forEach((event: BaseEvent) => {
5752
test(`${event.constructor.name}: Channel is shown and preserveFocus is set to true`, () => {
58-
expect(hasShown).to.be.false;
53+
expect(hasShown).toEqual(false);
5954
observer.post(event);
60-
expect(hasShown).to.be.true;
61-
expect(preserveFocus).to.be.true;
55+
expect(hasShown).toEqual(true);
56+
expect(preserveFocus).toEqual(true);
6257
});
6358
});
6459

6560
test(`OmnisharpServerOnStdErr: Channel is not shown when disabled in configuration`, () => {
66-
updateConfig(vscode, 'csharp', 'showOmnisharpLogOnError', false);
67-
optionObservable.next(Options.Read(vscode));
61+
vscode.workspace.getConfiguration().update('csharp.showOmnisharpLogOnError', false);
62+
optionObservable.next();
6863

69-
expect(hasShown).to.be.false;
64+
expect(hasShown).toEqual(false);
7065
observer.post(new OmnisharpServerOnStdErr('std err'));
71-
expect(hasShown).to.be.false;
72-
expect(preserveFocus).to.be.false;
66+
expect(hasShown).toEqual(false);
67+
expect(preserveFocus).toEqual(false);
7368
});
7469

7570
[new OmnisharpRestart()].forEach((event: BaseEvent) => {
7671
test(`${event.constructor.name}: Channel is cleared`, () => {
77-
expect(hasCleared).to.be.false;
72+
expect(hasCleared).toEqual(false);
7873
observer.post(event);
79-
expect(hasCleared).to.be.true;
74+
expect(hasCleared).toEqual(true);
8075
});
8176
});
8277
});

0 commit comments

Comments
 (0)