Skip to content

Commit

Permalink
Migrate rest of O# unit tests to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Oct 11, 2023
1 parent e650732 commit 1aba19b
Show file tree
Hide file tree
Showing 36 changed files with 294 additions and 326 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const config: Config = {
'<rootDir>/test/integrationTests/jest.config.ts',
'<rootDir>/test/razorIntegrationTests/jest.config.ts',
'<rootDir>/test/razorTests/jest.config.ts',
'<rootDir>/omnisharptest/omnisharpJestTests/jest.config.ts',
'<rootDir>/omnisharptest/omnisharpUnitTests/jest.config.ts',
],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { expect, should } from 'chai';
import { describe, test, expect, beforeEach } from '@jest/globals';
import { StatusBarItem } from '../../../src/vscodeAdapter';
import { OmnisharpBackgroundDiagnosticStatus } from '../../../src/omnisharp/loggingEvents';
import { BackgroundWorkStatusBarObserver } from '../../../src/observers/backgroundWorkStatusBarObserver';
import { BackgroundDiagnosticStatus } from '../../../src/omnisharp/protocol';

suite('BackgroundWorkStatusBarObserver', () => {
suiteSetup(() => should());

describe('BackgroundWorkStatusBarObserver', () => {
let showCalled: boolean;
let hideCalled: boolean;
const statusBarItem = <StatusBarItem>{
Expand All @@ -24,7 +22,7 @@ suite('BackgroundWorkStatusBarObserver', () => {
};
const observer = new BackgroundWorkStatusBarObserver(statusBarItem);

setup(() => {
beforeEach(() => {
showCalled = false;
hideCalled = false;
});
Expand All @@ -37,9 +35,9 @@ suite('BackgroundWorkStatusBarObserver', () => {
NumberProjects: 0,
});
observer.post(event);
expect(hideCalled).to.be.false;
expect(showCalled).to.be.true;
expect(statusBarItem.text).to.contain('Analyzing');
expect(hideCalled).toBe(false);
expect(showCalled).toBe(true);
expect(statusBarItem.text).toContain('Analyzing');
});

test('OmnisharpBackgroundDiagnosticStatus.Ready: Hide processing message', () => {
Expand All @@ -50,8 +48,8 @@ suite('BackgroundWorkStatusBarObserver', () => {
NumberProjects: 0,
});
observer.post(event);
expect(hideCalled).to.be.true;
expect(showCalled).to.be.false;
expect(statusBarItem.text).to.be.equal('');
expect(hideCalled).toBe(true);
expect(showCalled).toBe(false);
expect(statusBarItem.text).toEqual('');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { should, expect } from 'chai';
import { describe, test, expect } from '@jest/globals';
import { getNullChannel } from '../../../test/unitTests/fakes';
import { CsharpChannelObserver } from '../../../src/shared/observers/csharpChannelObserver';
import {
Expand All @@ -16,8 +16,7 @@ import {
IntegrityCheckFailure,
} from '../../../src/omnisharp/loggingEvents';

suite('CsharpChannelObserver', () => {
suiteSetup(() => should());
describe('CsharpChannelObserver', () => {
[
new InstallationFailure('someStage', 'someError'),
new DebuggerNotInstalledFailure(),
Expand All @@ -38,8 +37,8 @@ suite('CsharpChannelObserver', () => {
});

observer.post(event);
expect(hasShown).to.be.true;
expect(preserveFocus).to.be.true;
expect(hasShown).toBe(true);
expect(preserveFocus).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { should, expect } from 'chai';
import { describe, test, expect, beforeEach } from '@jest/globals';
import { getNullChannel } from '../../../test/unitTests/fakes';
import { CsharpLoggerObserver } from '../../../src/shared/observers/csharpLoggerObserver';
import { PlatformInformation } from '../../../src/shared/platform';
import * as Event from '../../../src/omnisharp/loggingEvents';
import { PackageError } from '../../../src/packageManager/packageError';
import { Package } from '../../../src/packageManager/package';

suite('CsharpLoggerObserver', () => {
suiteSetup(() => should());

describe('CsharpLoggerObserver', () => {
let logOutput = '';
const observer = new CsharpLoggerObserver({
...getNullChannel(),
Expand All @@ -29,30 +27,30 @@ suite('CsharpLoggerObserver', () => {
architectures: [],
};

setup(() => {
beforeEach(() => {
logOutput = '';
});

test('PlatformInfo: Logs contain the Platform and Architecture', () => {
const event = new Event.LogPlatformInfo(new PlatformInformation('linux', 'MyArchitecture'));
observer.post(event);
expect(logOutput).to.contain('linux');
expect(logOutput).to.contain('MyArchitecture');
expect(logOutput).toContain('linux');
expect(logOutput).toContain('MyArchitecture');
});

suite('InstallationFailure', () => {
describe('InstallationFailure', () => {
test('Stage and Error is logged if not a PackageError', () => {
const event = new Event.InstallationFailure('someStage', new Error('someError'));
observer.post(event);
expect(logOutput).to.contain(event.stage);
expect(logOutput).to.contain(event.error.toString());
expect(logOutput).toContain(event.stage);
expect(logOutput).toContain(event.error.toString());
});

test('Stage and Error is logged if a PackageError without inner error', () => {
const event = new Event.InstallationFailure('someStage', new PackageError('someError', pkg, undefined));
observer.post(event);
expect(logOutput).to.contain(event.stage);
expect(logOutput).to.contain(event.error.message);
expect(logOutput).toContain(event.stage);
expect(logOutput).toContain(event.error.message);
});

test('Stage and Inner error is logged if a PackageError without inner error', () => {
Expand All @@ -61,12 +59,12 @@ suite('CsharpLoggerObserver', () => {
new PackageError('someError', pkg, new Error('innerError'))
);
observer.post(event);
expect(logOutput).to.contain(event.stage);
expect(logOutput).to.contain(event.error.innerError.toString());
expect(logOutput).toContain(event.stage);
expect(logOutput).toContain(event.error.innerError.toString());
});
});

suite('Download', () => {
describe('Download', () => {
const packageName = 'somePackage';
[
{
Expand Down Expand Up @@ -155,7 +153,7 @@ suite('CsharpLoggerObserver', () => {
});

element.events.forEach((message: Event.BaseEvent) => observer.post(message));
expect(logOutput).to.be.equal(element.expected);
expect(logOutput).toEqual(element.expected);
});
});
});
Expand All @@ -172,66 +170,66 @@ suite('CsharpLoggerObserver', () => {
].forEach((element) =>
test(`${element.message.constructor.name} is shown`, () => {
observer.post(element.message);
expect(logOutput).to.contain(element.expected);
expect(logOutput).toContain(element.expected);
})
);

test(`ActivationFailure: Some message is logged`, () => {
const event = new Event.ActivationFailure();
observer.post(event);
expect(logOutput).to.not.be.empty;
expect(logOutput).toBeTruthy();
});

test(`ProjectJsonDeprecatedWarning: Some message is logged`, () => {
const event = new Event.ProjectJsonDeprecatedWarning();
observer.post(event);
expect(logOutput).to.not.be.empty;
expect(logOutput).toBeTruthy();
});

test(`InstallationSuccess: Some message is logged`, () => {
const event = new Event.InstallationSuccess();
observer.post(event);
expect(logOutput).to.not.be.empty;
expect(logOutput).toBeTruthy();
});

test(`InstallationProgress: Progress message is logged`, () => {
const event = new Event.InstallationStart('somPackage');
observer.post(event);
expect(logOutput).to.contain(event.packageDescription);
expect(logOutput).toContain(event.packageDescription);
});

test('PackageInstallation: Package name is logged', () => {
const event = new Event.PackageInstallation('somePackage');
observer.post(event);
expect(logOutput).to.contain(event.packageInfo);
expect(logOutput).toContain(event.packageInfo);
});

test('DownloadFallBack: The fallbackurl is logged', () => {
const event = new Event.DownloadFallBack('somrurl');
observer.post(event);
expect(logOutput).to.contain(event.fallbackUrl);
expect(logOutput).toContain(event.fallbackUrl);
});

test(`${Event.IntegrityCheckFailure.name}: Package Description is logged when we are retrying`, () => {
const description = 'someDescription';
const url = 'someUrl';
const event = new Event.IntegrityCheckFailure(description, url, true);
observer.post(event);
expect(logOutput).to.contain(description);
expect(logOutput).toContain(description);
});

test(`${Event.IntegrityCheckFailure.name}: Package Description and url are logged when we are not retrying`, () => {
const description = 'someDescription';
const url = 'someUrl';
const event = new Event.IntegrityCheckFailure(description, url, false);
observer.post(event);
expect(logOutput).to.contain(description);
expect(logOutput).to.contain(url);
expect(logOutput).toContain(description);
expect(logOutput).toContain(url);
});

test(`${Event.IntegrityCheckSuccess.name}: Some message is logged`, () => {
const event = new Event.IntegrityCheckSuccess();
observer.post(event);
expect(logOutput).to.not.be.empty;
expect(logOutput).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { should, expect } from 'chai';
import { describe, test, expect, beforeEach } from '@jest/globals';
import { DotNetChannelObserver } from '../../../src/observers/dotnetChannelObserver';
import { getNullChannel } from '../../../test/unitTests/fakes';
import { CommandDotNetRestoreStart } from '../../../src/omnisharp/loggingEvents';

suite('DotnetChannelObserver', () => {
suiteSetup(() => should());
describe('DotnetChannelObserver', () => {
let hasShown: boolean;
let hasCleared: boolean;

Expand All @@ -23,15 +22,15 @@ suite('DotnetChannelObserver', () => {
},
});

setup(() => {
beforeEach(() => {
hasShown = false;
hasCleared = false;
});

test(`CommandDotNetRestoreStart : Clears and shows the channel`, () => {
const event = new CommandDotNetRestoreStart();
observer.post(event);
expect(hasCleared).to.be.true;
expect(hasShown).to.be.true;
expect(hasCleared).toBe(true);
expect(hasShown).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { should, expect } from 'chai';
import { describe, test, expect } from '@jest/globals';
import { getNullChannel } from '../../../test/unitTests/fakes';
import { DotnetLoggerObserver } from '../../../src/observers/dotnetLoggerObserver';
import {
Expand All @@ -13,9 +13,7 @@ import {
EventWithMessage,
} from '../../../src/omnisharp/loggingEvents';

suite('DotnetLoggerObserver', () => {
suiteSetup(() => should());

describe('DotnetLoggerObserver', () => {
[
new CommandDotNetRestoreProgress('Some message'),
new CommandDotNetRestoreSucceeded('Some message'),
Expand All @@ -31,7 +29,7 @@ suite('DotnetLoggerObserver', () => {
});

observer.post(event);
expect(appendedMessage).to.contain(event.message);
expect(appendedMessage).toContain(event.message);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { expect } from 'chai';
import { describe, test, expect, beforeEach } from '@jest/globals';
import { getNullChannel } from '../../../test/unitTests/fakes';
import {
BaseEvent,
Expand All @@ -15,7 +15,7 @@ import {
} from '../../../src/omnisharp/loggingEvents';
import DotnetTestChannelObserver from '../../../src/observers/dotnetTestChannelObserver';

suite('DotnetTestChannelObserver', () => {
describe('DotnetTestChannelObserver', () => {
let hasShown: boolean;
let preserveFocus: boolean;

Expand All @@ -27,7 +27,7 @@ suite('DotnetTestChannelObserver', () => {
},
});

setup(() => {
beforeEach(() => {
hasShown = false;
});

Expand All @@ -39,10 +39,10 @@ suite('DotnetTestChannelObserver', () => {
new DotNetTestsInClassDebugStart('someclass'),
].forEach((event: BaseEvent) => {
test(`${event.constructor.name}: Channel is shown and preserve focus is set to true`, () => {
expect(hasShown).to.be.false;
expect(hasShown).toBe(false);
observer.post(event);
expect(hasShown).to.be.true;
expect(preserveFocus).to.be.true;
expect(hasShown).toBe(true);
expect(preserveFocus).toBe(true);
});
});
});
Loading

0 comments on commit 1aba19b

Please sign in to comment.