Skip to content

Commit 4dc9b6c

Browse files
authored
Merge pull request #6660 from dibarbet/remove_unnecessary_jestlib
Replace jestlib import with regular import
2 parents 6e35fe3 + 691eec9 commit 4dc9b6c

File tree

8 files changed

+223
-261
lines changed

8 files changed

+223
-261
lines changed

omnisharptest/omnisharpUnitTests/optionChangeObserver.test.ts

Lines changed: 49 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { timeout } from 'rxjs/operators';
77
import { from as observableFrom, Subject, BehaviorSubject } from 'rxjs';
88
import { registerOmnisharpOptionChanges } from '../../src/omnisharp/omnisharpOptionChanges';
99

10-
import * as jestLib from '@jest/globals';
10+
import { describe, beforeEach, test, expect } from '@jest/globals';
1111
import * as vscode from 'vscode';
1212
import { getVSCodeWithConfig, updateConfig } from '../../test/unitTests/fakes';
1313

14-
jestLib.describe('OmniSharpConfigChangeObserver', () => {
14+
describe('OmniSharpConfigChangeObserver', () => {
1515
let doClickOk: () => void;
1616
let doClickCancel: () => void;
1717
let signalCommandDone: () => void;
@@ -20,7 +20,7 @@ jestLib.describe('OmniSharpConfigChangeObserver', () => {
2020
let invokedCommand: string | undefined;
2121
let optionObservable: Subject<void>;
2222

23-
jestLib.beforeEach(() => {
23+
beforeEach(() => {
2424
resetMocks();
2525
optionObservable = new BehaviorSubject<void>(undefined);
2626
infoMessage = undefined;
@@ -40,80 +40,64 @@ jestLib.describe('OmniSharpConfigChangeObserver', () => {
4040
{ config: 'omnisharp', section: 'useModernNet', value: false },
4141
{ config: 'omnisharp', section: 'loggingLevel', value: 'verbose' },
4242
].forEach((elem) => {
43-
jestLib.describe(`When the ${elem.config} ${elem.section} changes`, () => {
44-
jestLib.beforeEach(() => {
45-
jestLib.expect(infoMessage).toBe(undefined);
46-
jestLib.expect(invokedCommand).toBe(undefined);
43+
describe(`When the ${elem.config} ${elem.section} changes`, () => {
44+
beforeEach(() => {
45+
expect(infoMessage).toBe(undefined);
46+
expect(invokedCommand).toBe(undefined);
4747
updateConfig(vscode, elem.config, elem.section, elem.value);
4848
optionObservable.next();
4949
});
5050

51-
jestLib.test(`The information message is shown`, async () => {
52-
jestLib
53-
.expect(infoMessage)
54-
.toEqual(
55-
'C# configuration has changed. Would you like to relaunch the Language Server with your changes?'
56-
);
51+
test(`The information message is shown`, async () => {
52+
expect(infoMessage).toEqual(
53+
'C# configuration has changed. Would you like to relaunch the Language Server with your changes?'
54+
);
5755
});
5856

59-
jestLib.test(
60-
'Given an information message if the user clicks cancel, the command is not executed',
61-
async () => {
62-
doClickCancel();
63-
const from = observableFrom(commandDone!).pipe(timeout(1));
64-
const fromPromise = from.toPromise();
65-
await jestLib.expect(fromPromise).rejects.toThrow();
66-
jestLib.expect(invokedCommand).toBe(undefined);
67-
}
68-
);
69-
70-
jestLib.test(
71-
'Given an information message if the user clicks Reload, the command is executed',
72-
async () => {
73-
doClickOk();
74-
await commandDone;
75-
jestLib.expect(invokedCommand).toEqual('o.restart');
76-
}
77-
);
57+
test('Given an information message if the user clicks cancel, the command is not executed', async () => {
58+
doClickCancel();
59+
const from = observableFrom(commandDone!).pipe(timeout(1));
60+
const fromPromise = from.toPromise();
61+
await expect(fromPromise).rejects.toThrow();
62+
expect(invokedCommand).toBe(undefined);
63+
});
64+
65+
test('Given an information message if the user clicks Reload, the command is executed', async () => {
66+
doClickOk();
67+
await commandDone;
68+
expect(invokedCommand).toEqual('o.restart');
69+
});
7870
});
7971
});
8072

8173
[{ config: 'dotnet', section: 'server.useOmnisharp', value: true }].forEach((elem) => {
82-
jestLib.describe(`When the ${elem.config} ${elem.section} changes`, () => {
83-
jestLib.beforeEach(() => {
84-
jestLib.expect(infoMessage).toBe(undefined);
85-
jestLib.expect(invokedCommand).toBe(undefined);
74+
describe(`When the ${elem.config} ${elem.section} changes`, () => {
75+
beforeEach(() => {
76+
expect(infoMessage).toBe(undefined);
77+
expect(invokedCommand).toBe(undefined);
8678
updateConfig(vscode, elem.config, elem.section, elem.value);
8779
optionObservable.next();
8880
});
8981

90-
jestLib.test(`The information message is shown`, async () => {
91-
jestLib
92-
.expect(infoMessage)
93-
.toEqual(
94-
'dotnet.server.useOmnisharp option has changed. Please reload the window to apply the change'
95-
);
82+
test(`The information message is shown`, async () => {
83+
expect(infoMessage).toEqual(
84+
'dotnet.server.useOmnisharp option has changed. Please reload the window to apply the change'
85+
);
9686
});
9787

98-
jestLib.test(
99-
'Given an information message if the user clicks cancel, the command is not executed',
100-
async () => {
101-
doClickCancel();
102-
const from = observableFrom(commandDone!).pipe(timeout(1));
103-
const fromPromise = from.toPromise();
104-
await jestLib.expect(fromPromise).rejects.toThrow();
105-
jestLib.expect(invokedCommand).toBe(undefined);
106-
}
107-
);
108-
109-
jestLib.test(
110-
'Given an information message if the user clicks Reload, the command is executed',
111-
async () => {
112-
doClickOk();
113-
await commandDone;
114-
jestLib.expect(invokedCommand).toEqual('workbench.action.reloadWindow');
115-
}
116-
);
88+
test('Given an information message if the user clicks cancel, the command is not executed', async () => {
89+
doClickCancel();
90+
const from = observableFrom(commandDone!).pipe(timeout(1));
91+
const fromPromise = from.toPromise();
92+
await expect(fromPromise).rejects.toThrow();
93+
expect(invokedCommand).toBe(undefined);
94+
});
95+
96+
test('Given an information message if the user clicks Reload, the command is executed', async () => {
97+
doClickOk();
98+
await commandDone;
99+
expect(invokedCommand).toEqual('workbench.action.reloadWindow');
100+
});
117101
});
118102
});
119103

@@ -127,12 +111,12 @@ jestLib.describe('OmniSharpConfigChangeObserver', () => {
127111
{ config: 'omnisharp', section: 'projectLoadTimeout', value: 1000 },
128112
{ config: 'omnisharp', section: 'autoStart', value: false },
129113
].forEach((elem) => {
130-
jestLib.test(`Information Message is not shown on change in ${elem.config}.${elem.section}`, () => {
131-
jestLib.expect(infoMessage).toBe(undefined);
132-
jestLib.expect(invokedCommand).toBe(undefined);
114+
test(`Information Message is not shown on change in ${elem.config}.${elem.section}`, () => {
115+
expect(infoMessage).toBe(undefined);
116+
expect(invokedCommand).toBe(undefined);
133117
updateConfig(vscode, elem.config, elem.section, elem.value);
134118
optionObservable.next();
135-
jestLib.expect(infoMessage).toBe(undefined);
119+
expect(infoMessage).toBe(undefined);
136120
});
137121
});
138122

test/integrationTests/lspInlayHints.integration.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
import * as path from 'path';
77
import * as vscode from 'vscode';
8-
import * as jestLib from '@jest/globals';
8+
import { describe, beforeAll, afterAll, test, expect } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from './integrationHelpers';
1111
import { InlayHint, InlayHintKind, Position } from 'vscode-languageserver-protocol';
1212

13-
jestLib.describe(`[${testAssetWorkspace.description}] Test LSP Inlay Hints `, function () {
14-
jestLib.beforeAll(async function () {
13+
describe(`[${testAssetWorkspace.description}] Test LSP Inlay Hints `, function () {
14+
beforeAll(async function () {
1515
const editorConfig = vscode.workspace.getConfiguration('editor');
1616
await editorConfig.update('inlayHints.enabled', true);
1717
const dotnetConfig = vscode.workspace.getConfiguration('dotnet');
@@ -34,11 +34,11 @@ jestLib.describe(`[${testAssetWorkspace.description}] Test LSP Inlay Hints `, fu
3434
await integrationHelpers.activateCSharpExtension();
3535
});
3636

37-
jestLib.afterAll(async () => {
37+
afterAll(async () => {
3838
await testAssetWorkspace.cleanupWorkspace();
3939
});
4040

41-
jestLib.test('Hints retrieved for region', async () => {
41+
test('Hints retrieved for region', async () => {
4242
const range = new vscode.Range(new vscode.Position(4, 8), new vscode.Position(15, 85));
4343
const activeDocument = vscode.window.activeTextEditor?.document.uri;
4444
if (!activeDocument) {
@@ -50,7 +50,7 @@ jestLib.describe(`[${testAssetWorkspace.description}] Test LSP Inlay Hints `, fu
5050
range
5151
);
5252

53-
jestLib.expect(hints).toHaveLength(6);
53+
expect(hints).toHaveLength(6);
5454

5555
assertInlayHintEqual(hints[0], InlayHint.create(Position.create(6, 12), 'InlayHints', InlayHintKind.Type));
5656
assertInlayHintEqual(hints[1], InlayHint.create(Position.create(7, 27), 'InlayHints', InlayHintKind.Type));
@@ -61,10 +61,10 @@ jestLib.describe(`[${testAssetWorkspace.description}] Test LSP Inlay Hints `, fu
6161

6262
function assertInlayHintEqual(actual: vscode.InlayHint, expected: InlayHint) {
6363
const actualLabel = actual.label as string;
64-
jestLib.expect(actualLabel).toBe(expected.label);
65-
jestLib.expect(actual.position.line).toBe(expected.position.line);
66-
jestLib.expect(actual.position.character).toBe(expected.position.character);
67-
jestLib.expect(actual.kind).toBe(expected.kind);
64+
expect(actualLabel).toBe(expected.label);
65+
expect(actual.position.line).toBe(expected.position.line);
66+
expect(actual.position.character).toBe(expected.position.character);
67+
expect(actual.kind).toBe(expected.kind);
6868
}
6969
});
7070
});

test/integrationTests/unitTests.integration.test.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,87 @@
55

66
import * as vscode from 'vscode';
77
import * as path from 'path';
8-
import * as jestLib from '@jest/globals';
8+
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import { activateCSharpExtension, openFileInWorkspaceAsync } from './integrationHelpers';
1111
import { TestProgress } from '../../src/lsptoolshost/roslynProtocol';
1212

13-
jestLib.describe(`[${testAssetWorkspace.description}] Test Unit Testing`, function () {
14-
jestLib.beforeAll(async function () {
13+
describe(`[${testAssetWorkspace.description}] Test Unit Testing`, function () {
14+
beforeAll(async function () {
1515
await activateCSharpExtension();
1616
});
1717

18-
jestLib.beforeEach(async function () {
18+
beforeEach(async function () {
1919
vscode.workspace
2020
.getConfiguration()
2121
.update('dotnet.unitTests.runSettingsPath', undefined, vscode.ConfigurationTarget.Workspace);
2222
const fileName = path.join('test', 'UnitTest1.cs');
2323
await openFileInWorkspaceAsync(fileName);
2424
});
2525

26-
jestLib.afterAll(async () => {
26+
afterAll(async () => {
2727
await testAssetWorkspace.cleanupWorkspace();
2828
});
2929

30-
jestLib.test('Unit test code lens items are displayed', async () => {
30+
test('Unit test code lens items are displayed', async () => {
3131
const codeLenses = await getCodeLensesAsync();
32-
jestLib.expect(codeLenses).toHaveLength(9);
32+
expect(codeLenses).toHaveLength(9);
3333

3434
const classRange = new vscode.Range(new vscode.Position(5, 17), new vscode.Position(5, 26));
3535

3636
// Class level debug all tests
37-
jestLib.expect(codeLenses[1].command?.command).toBe('dotnet.test.run');
38-
jestLib.expect(codeLenses[1].command?.title).toBe('Debug All Tests');
39-
jestLib.expect(codeLenses[1].command?.arguments![0].attachDebugger).toBe(true);
40-
jestLib.expect(codeLenses[1].range).toStrictEqual(classRange);
37+
expect(codeLenses[1].command?.command).toBe('dotnet.test.run');
38+
expect(codeLenses[1].command?.title).toBe('Debug All Tests');
39+
expect(codeLenses[1].command?.arguments![0].attachDebugger).toBe(true);
40+
expect(codeLenses[1].range).toStrictEqual(classRange);
4141

4242
// Class level run all tests
43-
jestLib.expect(codeLenses[2].command?.command).toBe('dotnet.test.run');
44-
jestLib.expect(codeLenses[2].command?.title).toBe('Run All Tests');
45-
jestLib.expect(codeLenses[2].command?.arguments![0].attachDebugger).toBe(false);
46-
jestLib.expect(codeLenses[2].range).toStrictEqual(classRange);
43+
expect(codeLenses[2].command?.command).toBe('dotnet.test.run');
44+
expect(codeLenses[2].command?.title).toBe('Run All Tests');
45+
expect(codeLenses[2].command?.arguments![0].attachDebugger).toBe(false);
46+
expect(codeLenses[2].range).toStrictEqual(classRange);
4747

4848
let methodRange = new vscode.Range(new vscode.Position(8, 20), new vscode.Position(8, 25));
4949
// Method level run and debug test
50-
jestLib.expect(codeLenses[4].command?.command).toBe('dotnet.test.run');
51-
jestLib.expect(codeLenses[4].command?.title).toBe('Debug Test');
52-
jestLib.expect(codeLenses[4].command?.arguments![0].attachDebugger).toBe(true);
53-
jestLib.expect(codeLenses[4].range).toStrictEqual(methodRange);
54-
jestLib.expect(codeLenses[5].command?.command).toBe('dotnet.test.run');
55-
jestLib.expect(codeLenses[5].command?.title).toBe('Run Test');
56-
jestLib.expect(codeLenses[5].command?.arguments![0].attachDebugger).toBe(false);
57-
jestLib.expect(codeLenses[5].range).toStrictEqual(methodRange);
50+
expect(codeLenses[4].command?.command).toBe('dotnet.test.run');
51+
expect(codeLenses[4].command?.title).toBe('Debug Test');
52+
expect(codeLenses[4].command?.arguments![0].attachDebugger).toBe(true);
53+
expect(codeLenses[4].range).toStrictEqual(methodRange);
54+
expect(codeLenses[5].command?.command).toBe('dotnet.test.run');
55+
expect(codeLenses[5].command?.title).toBe('Run Test');
56+
expect(codeLenses[5].command?.arguments![0].attachDebugger).toBe(false);
57+
expect(codeLenses[5].range).toStrictEqual(methodRange);
5858

5959
methodRange = new vscode.Range(new vscode.Position(15, 20), new vscode.Position(15, 25));
60-
jestLib.expect(codeLenses[7].command?.command).toBe('dotnet.test.run');
61-
jestLib.expect(codeLenses[7].command?.title).toBe('Debug Test');
62-
jestLib.expect(codeLenses[7].command?.arguments![0].attachDebugger).toBe(true);
63-
jestLib.expect(codeLenses[7].range).toStrictEqual(methodRange);
64-
jestLib.expect(codeLenses[8].command?.command).toBe('dotnet.test.run');
65-
jestLib.expect(codeLenses[8].command?.title).toBe('Run Test');
66-
jestLib.expect(codeLenses[8].command?.arguments![0].attachDebugger).toBe(false);
67-
jestLib.expect(codeLenses[8].range).toStrictEqual(methodRange);
60+
expect(codeLenses[7].command?.command).toBe('dotnet.test.run');
61+
expect(codeLenses[7].command?.title).toBe('Debug Test');
62+
expect(codeLenses[7].command?.arguments![0].attachDebugger).toBe(true);
63+
expect(codeLenses[7].range).toStrictEqual(methodRange);
64+
expect(codeLenses[8].command?.command).toBe('dotnet.test.run');
65+
expect(codeLenses[8].command?.title).toBe('Run Test');
66+
expect(codeLenses[8].command?.arguments![0].attachDebugger).toBe(false);
67+
expect(codeLenses[8].range).toStrictEqual(methodRange);
6868
});
6969

70-
jestLib.test('Code lens command executes tests', async () => {
70+
test('Code lens command executes tests', async () => {
7171
const codeLenses = await getCodeLensesAsync();
72-
jestLib.expect(codeLenses).toHaveLength(9);
72+
expect(codeLenses).toHaveLength(9);
7373

7474
const runAllTestsCommand = codeLenses[2].command!;
75-
jestLib.expect(runAllTestsCommand.title).toBe('Run All Tests');
75+
expect(runAllTestsCommand.title).toBe('Run All Tests');
7676

7777
const testResults = await vscode.commands.executeCommand<TestProgress | undefined>(
7878
runAllTestsCommand.command,
7979
runAllTestsCommand.arguments![0]
8080
);
81-
jestLib.expect(testResults).toBeDefined();
82-
jestLib.expect(testResults?.totalTests).toEqual(2);
83-
jestLib.expect(testResults?.testsPassed).toEqual(2);
84-
jestLib.expect(testResults?.testsFailed).toEqual(0);
85-
jestLib.expect(testResults?.testsSkipped).toEqual(0);
81+
expect(testResults).toBeDefined();
82+
expect(testResults?.totalTests).toEqual(2);
83+
expect(testResults?.testsPassed).toEqual(2);
84+
expect(testResults?.testsFailed).toEqual(0);
85+
expect(testResults?.testsSkipped).toEqual(0);
8686
});
8787

88-
jestLib.test('dotnet.test.runTestsInContext executes tests', async () => {
88+
test('dotnet.test.runTestsInContext executes tests', async () => {
8989
const activeEditor = vscode.window.activeTextEditor;
9090
if (!activeEditor) {
9191
throw new Error('No active editor');
@@ -97,31 +97,31 @@ jestLib.describe(`[${testAssetWorkspace.description}] Test Unit Testing`, functi
9797
'dotnet.test.runTestsInContext',
9898
activeEditor
9999
);
100-
jestLib.expect(testResults).toBeDefined();
101-
jestLib.expect(testResults?.totalTests).toEqual(1);
102-
jestLib.expect(testResults?.testsPassed).toEqual(1);
103-
jestLib.expect(testResults?.testsFailed).toEqual(0);
104-
jestLib.expect(testResults?.testsSkipped).toEqual(0);
100+
expect(testResults).toBeDefined();
101+
expect(testResults?.totalTests).toEqual(1);
102+
expect(testResults?.testsPassed).toEqual(1);
103+
expect(testResults?.testsFailed).toEqual(0);
104+
expect(testResults?.testsSkipped).toEqual(0);
105105
});
106106

107-
jestLib.test('Run tests uses .runsettings', async () => {
107+
test('Run tests uses .runsettings', async () => {
108108
await vscode.workspace.getConfiguration().update('dotnet.unitTests.runSettingsPath', '.runsettings');
109109

110110
const codeLenses = await getCodeLensesAsync();
111-
jestLib.expect(codeLenses).toHaveLength(9);
111+
expect(codeLenses).toHaveLength(9);
112112

113113
const runAllTestsCommand = codeLenses[2].command!;
114-
jestLib.expect(runAllTestsCommand.title).toBe('Run All Tests');
114+
expect(runAllTestsCommand.title).toBe('Run All Tests');
115115

116116
const testResults = await vscode.commands.executeCommand<TestProgress | undefined>(
117117
runAllTestsCommand.command,
118118
runAllTestsCommand.arguments![0]
119119
);
120-
jestLib.expect(testResults).toBeDefined();
121-
jestLib.expect(testResults?.totalTests).toEqual(1);
122-
jestLib.expect(testResults?.testsPassed).toEqual(1);
123-
jestLib.expect(testResults?.testsFailed).toEqual(0);
124-
jestLib.expect(testResults?.testsSkipped).toEqual(0);
120+
expect(testResults).toBeDefined();
121+
expect(testResults?.totalTests).toEqual(1);
122+
expect(testResults?.testsPassed).toEqual(1);
123+
expect(testResults?.testsFailed).toEqual(0);
124+
expect(testResults?.testsSkipped).toEqual(0);
125125
});
126126
});
127127

0 commit comments

Comments
 (0)