Skip to content

Commit b71740c

Browse files
authored
Merge pull request #6521 from dibarbet/migrate_all_omnisharp_unit_tests
Migrate all omnisharp unit tests to jest
2 parents f4fbc51 + 43438ec commit b71740c

36 files changed

+499
-551
lines changed

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const config: Config = {
1010
'<rootDir>/test/integrationTests/jest.config.ts',
1111
'<rootDir>/test/razorIntegrationTests/jest.config.ts',
1212
'<rootDir>/test/razorTests/jest.config.ts',
13-
'<rootDir>/omnisharptest/omnisharpJestTests/jest.config.ts',
13+
'<rootDir>/omnisharptest/omnisharpUnitTests/jest.config.ts',
1414
],
1515
};
1616

omnisharptest/omnisharpUnitTests/absolutePath.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { expect } from 'chai';
6+
import { describe, test, expect, beforeEach, afterEach } from '@jest/globals';
77
import { AbsolutePath } from '../../src/packageManager/absolutePath';
88
import { TmpAsset, CreateTmpFile } from '../../src/createTmpAsset';
99
import { join } from 'path';
1010

11-
suite(AbsolutePath.name, () => {
11+
describe(AbsolutePath.name, () => {
1212
let tmpPath: TmpAsset;
1313

14-
setup(async () => {
14+
beforeEach(async () => {
1515
tmpPath = await CreateTmpFile();
1616
});
1717

18-
teardown(() => {
18+
afterEach(() => {
1919
tmpPath.dispose();
2020
});
2121

2222
test('Throws error when the passed value is not an absolute path', () => {
23-
expect(() => new AbsolutePath('somePath')).to.throw(Error);
23+
expect(() => new AbsolutePath('somePath')).toThrow(Error);
2424
});
2525

2626
test(`${AbsolutePath.getAbsolutePath.name}: Returns an absolute path based by resolving the path with the value to prepend`, () => {
2727
const absolutePath = AbsolutePath.getAbsolutePath(tmpPath.name, 'somePath');
28-
expect(absolutePath.value).to.be.equal(join(tmpPath.name, 'somePath'));
28+
expect(absolutePath.value).toEqual(join(tmpPath.name, 'somePath'));
2929
});
3030
});

omnisharptest/omnisharpUnitTests/installRuntimeDependencies.test.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { describe, test, expect, beforeEach } from '@jest/globals';
67
import { installRuntimeDependencies } from '../../src/installRuntimeDependencies';
78
import IInstallDependencies from '../../src/packageManager/IInstallDependencies';
89
import { EventStream } from '../../src/eventStream';
910
import { PlatformInformation } from '../../src/shared/platform';
10-
import * as chai from 'chai';
11-
import TestEventBus from './testAssets/testEventBus';
11+
import TestEventBus from '../omnisharpUnitTests/testAssets/testEventBus';
1212
import { AbsolutePathPackage } from '../../src/packageManager/absolutePathPackage';
1313
import { Package } from '../../src/packageManager/package';
1414
import { isNotNull } from '../testUtil';
1515

16-
const expect = chai.expect;
17-
18-
suite(`${installRuntimeDependencies.name}`, () => {
16+
describe(`${installRuntimeDependencies.name}`, () => {
1917
let packageJSON = {
2018
runtimeDependencies: [] as Package[],
2119
};
@@ -27,14 +25,14 @@ suite(`${installRuntimeDependencies.name}`, () => {
2725
const platformInfo = new PlatformInformation('linux', 'architecture1');
2826
const useFramework = true;
2927

30-
setup(() => {
28+
beforeEach(() => {
3129
eventStream = new EventStream();
3230
eventBus = new TestEventBus(eventStream);
3331
installDependencies = async () => Promise.resolve(true);
3432
});
3533

36-
suite('When all the dependencies already exist', () => {
37-
suiteSetup(() => {
34+
describe('When all the dependencies already exist', () => {
35+
beforeEach(() => {
3836
packageJSON = {
3937
runtimeDependencies: [],
4038
};
@@ -50,7 +48,7 @@ suite(`${installRuntimeDependencies.name}`, () => {
5048
useFramework,
5149
['Debugger', 'Omnisharp', 'Razor']
5250
);
53-
expect(installed).to.be.true;
51+
expect(installed).toBe(true);
5452
});
5553

5654
test("Doesn't log anything to the eventStream", async () => {
@@ -67,11 +65,11 @@ suite(`${installRuntimeDependencies.name}`, () => {
6765
useFramework,
6866
['Debugger', 'Omnisharp', 'Razor']
6967
);
70-
expect(eventBus.getEvents()).to.be.empty;
68+
expect(eventBus.getEvents()).toHaveLength(0);
7169
});
7270
});
7371

74-
suite('When there is a dependency to install', () => {
72+
describe('When there is a dependency to install', () => {
7573
const packageToInstall: Package = {
7674
id: 'myPackage',
7775
description: 'somePackage',
@@ -82,7 +80,7 @@ suite(`${installRuntimeDependencies.name}`, () => {
8280
architectures: [platformInfo.architecture],
8381
};
8482

85-
setup(() => {
83+
beforeEach(() => {
8684
packageJSON = {
8785
runtimeDependencies: [packageToInstall],
8886
};
@@ -104,10 +102,10 @@ suite(`${installRuntimeDependencies.name}`, () => {
104102
useFramework,
105103
['myPackage']
106104
);
107-
expect(installed).to.be.true;
105+
expect(installed).toBe(true);
108106
isNotNull(inputPackage!);
109-
expect(inputPackage).to.have.length(1);
110-
expect(inputPackage[0]).to.be.deep.equal(
107+
expect(inputPackage).toHaveLength(1);
108+
expect(inputPackage[0]).toStrictEqual(
111109
AbsolutePathPackage.getAbsolutePathPackage(packageToInstall, extensionPath)
112110
);
113111
});
@@ -123,7 +121,7 @@ suite(`${installRuntimeDependencies.name}`, () => {
123121
useFramework,
124122
['myPackage']
125123
);
126-
expect(installed).to.be.false;
124+
expect(installed).toBe(false);
127125
});
128126
});
129127
});

omnisharptest/omnisharpUnitTests/logging/backgroundWorkStatusBarObserver.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { expect, should } from 'chai';
6+
import { describe, test, expect, beforeEach } from '@jest/globals';
77
import { StatusBarItem } from '../../../src/vscodeAdapter';
88
import { OmnisharpBackgroundDiagnosticStatus } from '../../../src/omnisharp/loggingEvents';
99
import { BackgroundWorkStatusBarObserver } from '../../../src/observers/backgroundWorkStatusBarObserver';
1010
import { BackgroundDiagnosticStatus } from '../../../src/omnisharp/protocol';
1111

12-
suite('BackgroundWorkStatusBarObserver', () => {
13-
suiteSetup(() => should());
14-
12+
describe('BackgroundWorkStatusBarObserver', () => {
1513
let showCalled: boolean;
1614
let hideCalled: boolean;
1715
const statusBarItem = <StatusBarItem>{
@@ -24,7 +22,7 @@ suite('BackgroundWorkStatusBarObserver', () => {
2422
};
2523
const observer = new BackgroundWorkStatusBarObserver(statusBarItem);
2624

27-
setup(() => {
25+
beforeEach(() => {
2826
showCalled = false;
2927
hideCalled = false;
3028
});
@@ -37,9 +35,9 @@ suite('BackgroundWorkStatusBarObserver', () => {
3735
NumberProjects: 0,
3836
});
3937
observer.post(event);
40-
expect(hideCalled).to.be.false;
41-
expect(showCalled).to.be.true;
42-
expect(statusBarItem.text).to.contain('Analyzing');
38+
expect(hideCalled).toBe(false);
39+
expect(showCalled).toBe(true);
40+
expect(statusBarItem.text).toContain('Analyzing');
4341
});
4442

4543
test('OmnisharpBackgroundDiagnosticStatus.Ready: Hide processing message', () => {
@@ -50,8 +48,8 @@ suite('BackgroundWorkStatusBarObserver', () => {
5048
NumberProjects: 0,
5149
});
5250
observer.post(event);
53-
expect(hideCalled).to.be.true;
54-
expect(showCalled).to.be.false;
55-
expect(statusBarItem.text).to.be.equal('');
51+
expect(hideCalled).toBe(true);
52+
expect(showCalled).toBe(false);
53+
expect(statusBarItem.text).toEqual('');
5654
});
5755
});

omnisharptest/omnisharpUnitTests/logging/csharpChannelObserver.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { should, expect } from 'chai';
6+
import { describe, test, expect } from '@jest/globals';
77
import { getNullChannel } from '../../../test/unitTests/fakes';
88
import { CsharpChannelObserver } from '../../../src/shared/observers/csharpChannelObserver';
99
import {
@@ -16,8 +16,7 @@ import {
1616
IntegrityCheckFailure,
1717
} from '../../../src/omnisharp/loggingEvents';
1818

19-
suite('CsharpChannelObserver', () => {
20-
suiteSetup(() => should());
19+
describe('CsharpChannelObserver', () => {
2120
[
2221
new InstallationFailure('someStage', 'someError'),
2322
new DebuggerNotInstalledFailure(),
@@ -38,8 +37,8 @@ suite('CsharpChannelObserver', () => {
3837
});
3938

4039
observer.post(event);
41-
expect(hasShown).to.be.true;
42-
expect(preserveFocus).to.be.true;
40+
expect(hasShown).toBe(true);
41+
expect(preserveFocus).toBe(true);
4342
});
4443
});
4544
});

omnisharptest/omnisharpUnitTests/logging/csharpLoggerObserver.test.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { should, expect } from 'chai';
6+
import { describe, test, expect, beforeEach } from '@jest/globals';
77
import { getNullChannel } from '../../../test/unitTests/fakes';
88
import { CsharpLoggerObserver } from '../../../src/shared/observers/csharpLoggerObserver';
99
import { PlatformInformation } from '../../../src/shared/platform';
1010
import * as Event from '../../../src/omnisharp/loggingEvents';
1111
import { PackageError } from '../../../src/packageManager/packageError';
1212
import { Package } from '../../../src/packageManager/package';
1313

14-
suite('CsharpLoggerObserver', () => {
15-
suiteSetup(() => should());
16-
14+
describe('CsharpLoggerObserver', () => {
1715
let logOutput = '';
1816
const observer = new CsharpLoggerObserver({
1917
...getNullChannel(),
@@ -29,30 +27,30 @@ suite('CsharpLoggerObserver', () => {
2927
architectures: [],
3028
};
3129

32-
setup(() => {
30+
beforeEach(() => {
3331
logOutput = '';
3432
});
3533

3634
test('PlatformInfo: Logs contain the Platform and Architecture', () => {
3735
const event = new Event.LogPlatformInfo(new PlatformInformation('linux', 'MyArchitecture'));
3836
observer.post(event);
39-
expect(logOutput).to.contain('linux');
40-
expect(logOutput).to.contain('MyArchitecture');
37+
expect(logOutput).toContain('linux');
38+
expect(logOutput).toContain('MyArchitecture');
4139
});
4240

43-
suite('InstallationFailure', () => {
41+
describe('InstallationFailure', () => {
4442
test('Stage and Error is logged if not a PackageError', () => {
4543
const event = new Event.InstallationFailure('someStage', new Error('someError'));
4644
observer.post(event);
47-
expect(logOutput).to.contain(event.stage);
48-
expect(logOutput).to.contain(event.error.toString());
45+
expect(logOutput).toContain(event.stage);
46+
expect(logOutput).toContain(event.error.toString());
4947
});
5048

5149
test('Stage and Error is logged if a PackageError without inner error', () => {
5250
const event = new Event.InstallationFailure('someStage', new PackageError('someError', pkg, undefined));
5351
observer.post(event);
54-
expect(logOutput).to.contain(event.stage);
55-
expect(logOutput).to.contain(event.error.message);
52+
expect(logOutput).toContain(event.stage);
53+
expect(logOutput).toContain(event.error.message);
5654
});
5755

5856
test('Stage and Inner error is logged if a PackageError without inner error', () => {
@@ -61,12 +59,12 @@ suite('CsharpLoggerObserver', () => {
6159
new PackageError('someError', pkg, new Error('innerError'))
6260
);
6361
observer.post(event);
64-
expect(logOutput).to.contain(event.stage);
65-
expect(logOutput).to.contain(event.error.innerError.toString());
62+
expect(logOutput).toContain(event.stage);
63+
expect(logOutput).toContain(event.error.innerError.toString());
6664
});
6765
});
6866

69-
suite('Download', () => {
67+
describe('Download', () => {
7068
const packageName = 'somePackage';
7169
[
7270
{
@@ -155,7 +153,7 @@ suite('CsharpLoggerObserver', () => {
155153
});
156154

157155
element.events.forEach((message: Event.BaseEvent) => observer.post(message));
158-
expect(logOutput).to.be.equal(element.expected);
156+
expect(logOutput).toEqual(element.expected);
159157
});
160158
});
161159
});
@@ -172,66 +170,66 @@ suite('CsharpLoggerObserver', () => {
172170
].forEach((element) =>
173171
test(`${element.message.constructor.name} is shown`, () => {
174172
observer.post(element.message);
175-
expect(logOutput).to.contain(element.expected);
173+
expect(logOutput).toContain(element.expected);
176174
})
177175
);
178176

179177
test(`ActivationFailure: Some message is logged`, () => {
180178
const event = new Event.ActivationFailure();
181179
observer.post(event);
182-
expect(logOutput).to.not.be.empty;
180+
expect(logOutput).toBeTruthy();
183181
});
184182

185183
test(`ProjectJsonDeprecatedWarning: Some message is logged`, () => {
186184
const event = new Event.ProjectJsonDeprecatedWarning();
187185
observer.post(event);
188-
expect(logOutput).to.not.be.empty;
186+
expect(logOutput).toBeTruthy();
189187
});
190188

191189
test(`InstallationSuccess: Some message is logged`, () => {
192190
const event = new Event.InstallationSuccess();
193191
observer.post(event);
194-
expect(logOutput).to.not.be.empty;
192+
expect(logOutput).toBeTruthy();
195193
});
196194

197195
test(`InstallationProgress: Progress message is logged`, () => {
198196
const event = new Event.InstallationStart('somPackage');
199197
observer.post(event);
200-
expect(logOutput).to.contain(event.packageDescription);
198+
expect(logOutput).toContain(event.packageDescription);
201199
});
202200

203201
test('PackageInstallation: Package name is logged', () => {
204202
const event = new Event.PackageInstallation('somePackage');
205203
observer.post(event);
206-
expect(logOutput).to.contain(event.packageInfo);
204+
expect(logOutput).toContain(event.packageInfo);
207205
});
208206

209207
test('DownloadFallBack: The fallbackurl is logged', () => {
210208
const event = new Event.DownloadFallBack('somrurl');
211209
observer.post(event);
212-
expect(logOutput).to.contain(event.fallbackUrl);
210+
expect(logOutput).toContain(event.fallbackUrl);
213211
});
214212

215213
test(`${Event.IntegrityCheckFailure.name}: Package Description is logged when we are retrying`, () => {
216214
const description = 'someDescription';
217215
const url = 'someUrl';
218216
const event = new Event.IntegrityCheckFailure(description, url, true);
219217
observer.post(event);
220-
expect(logOutput).to.contain(description);
218+
expect(logOutput).toContain(description);
221219
});
222220

223221
test(`${Event.IntegrityCheckFailure.name}: Package Description and url are logged when we are not retrying`, () => {
224222
const description = 'someDescription';
225223
const url = 'someUrl';
226224
const event = new Event.IntegrityCheckFailure(description, url, false);
227225
observer.post(event);
228-
expect(logOutput).to.contain(description);
229-
expect(logOutput).to.contain(url);
226+
expect(logOutput).toContain(description);
227+
expect(logOutput).toContain(url);
230228
});
231229

232230
test(`${Event.IntegrityCheckSuccess.name}: Some message is logged`, () => {
233231
const event = new Event.IntegrityCheckSuccess();
234232
observer.post(event);
235-
expect(logOutput).to.not.be.empty;
233+
expect(logOutput).toBeTruthy();
236234
});
237235
});

0 commit comments

Comments
 (0)