Skip to content

Commit

Permalink
Merge pull request #6521 from dibarbet/migrate_all_omnisharp_unit_tests
Browse files Browse the repository at this point in the history
Migrate all omnisharp unit tests to jest
  • Loading branch information
dibarbet authored Oct 11, 2023
2 parents f4fbc51 + 43438ec commit b71740c
Show file tree
Hide file tree
Showing 36 changed files with 499 additions and 551 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
12 changes: 6 additions & 6 deletions omnisharptest/omnisharpUnitTests/absolutePath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { expect } from 'chai';
import { describe, test, expect, beforeEach, afterEach } from '@jest/globals';
import { AbsolutePath } from '../../src/packageManager/absolutePath';
import { TmpAsset, CreateTmpFile } from '../../src/createTmpAsset';
import { join } from 'path';

suite(AbsolutePath.name, () => {
describe(AbsolutePath.name, () => {
let tmpPath: TmpAsset;

setup(async () => {
beforeEach(async () => {
tmpPath = await CreateTmpFile();
});

teardown(() => {
afterEach(() => {
tmpPath.dispose();
});

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

test(`${AbsolutePath.getAbsolutePath.name}: Returns an absolute path based by resolving the path with the value to prepend`, () => {
const absolutePath = AbsolutePath.getAbsolutePath(tmpPath.name, 'somePath');
expect(absolutePath.value).to.be.equal(join(tmpPath.name, 'somePath'));
expect(absolutePath.value).toEqual(join(tmpPath.name, 'somePath'));
});
});
30 changes: 14 additions & 16 deletions omnisharptest/omnisharpUnitTests/installRuntimeDependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { describe, test, expect, beforeEach } from '@jest/globals';
import { installRuntimeDependencies } from '../../src/installRuntimeDependencies';
import IInstallDependencies from '../../src/packageManager/IInstallDependencies';
import { EventStream } from '../../src/eventStream';
import { PlatformInformation } from '../../src/shared/platform';
import * as chai from 'chai';
import TestEventBus from './testAssets/testEventBus';
import TestEventBus from '../omnisharpUnitTests/testAssets/testEventBus';
import { AbsolutePathPackage } from '../../src/packageManager/absolutePathPackage';
import { Package } from '../../src/packageManager/package';
import { isNotNull } from '../testUtil';

const expect = chai.expect;

suite(`${installRuntimeDependencies.name}`, () => {
describe(`${installRuntimeDependencies.name}`, () => {
let packageJSON = {
runtimeDependencies: [] as Package[],
};
Expand All @@ -27,14 +25,14 @@ suite(`${installRuntimeDependencies.name}`, () => {
const platformInfo = new PlatformInformation('linux', 'architecture1');
const useFramework = true;

setup(() => {
beforeEach(() => {
eventStream = new EventStream();
eventBus = new TestEventBus(eventStream);
installDependencies = async () => Promise.resolve(true);
});

suite('When all the dependencies already exist', () => {
suiteSetup(() => {
describe('When all the dependencies already exist', () => {
beforeEach(() => {
packageJSON = {
runtimeDependencies: [],
};
Expand All @@ -50,7 +48,7 @@ suite(`${installRuntimeDependencies.name}`, () => {
useFramework,
['Debugger', 'Omnisharp', 'Razor']
);
expect(installed).to.be.true;
expect(installed).toBe(true);
});

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

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

setup(() => {
beforeEach(() => {
packageJSON = {
runtimeDependencies: [packageToInstall],
};
Expand All @@ -104,10 +102,10 @@ suite(`${installRuntimeDependencies.name}`, () => {
useFramework,
['myPackage']
);
expect(installed).to.be.true;
expect(installed).toBe(true);
isNotNull(inputPackage!);
expect(inputPackage).to.have.length(1);
expect(inputPackage[0]).to.be.deep.equal(
expect(inputPackage).toHaveLength(1);
expect(inputPackage[0]).toStrictEqual(
AbsolutePathPackage.getAbsolutePathPackage(packageToInstall, extensionPath)
);
});
Expand All @@ -123,7 +121,7 @@ suite(`${installRuntimeDependencies.name}`, () => {
useFramework,
['myPackage']
);
expect(installed).to.be.false;
expect(installed).toBe(false);
});
});
});
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();
});
});
Loading

0 comments on commit b71740c

Please sign in to comment.