From 1aba19b60b782e0c4392ad6cd871f8160d871f3f Mon Sep 17 00:00:00 2001 From: David Barbet Date: Wed, 11 Oct 2023 13:13:20 -0700 Subject: [PATCH] Migrate rest of O# unit tests to jest --- jest.config.ts | 2 +- .../absolutePath.test.ts | 0 .../common.test.ts | 0 .../features/reportIssue.test.ts | 0 .../informationMessageObserver.test.ts | 0 .../installRuntimeDependencies.test.ts | 0 .../jest.config.ts | 0 .../backgroundWorkStatusBarObserver.test.ts | 20 +++-- .../logging/csharpChannelObserver.test.ts | 9 +-- .../logging/csharpLoggerObserver.test.ts | 52 ++++++------ .../logging/dotnetChannelObserver.test.ts | 11 ++- .../logging/dotnetLoggerObserver.test.ts | 8 +- .../logging/dotnetTestChannelObserver.test.ts | 12 +-- .../logging/dotnetTestLoggerObserver.test.ts | 48 +++++------ .../logging/errorMessageObserver.test.ts | 18 ++--- .../logging/omnisharpChannelObserver.test.ts | 0 .../omnisharpDebugModeLoggerObserver.test.ts | 54 ++++++------- .../logging/omnisharpLoggerObserver.test.ts | 0 .../omnisharpStatusBarObserver.test.ts | 79 +++++++++---------- .../logging/projectStatusBarObserver.test.ts | 36 ++++----- .../logging/razorLoggerObserver.test.ts | 13 ++- .../logging/warningMessageObserver.test.ts | 41 +++++----- .../omnisharp/omniSharpMonoResolver.test.ts | 0 .../omnisharpDownloader.test.ts | 0 .../omnisharpManager.test.ts | 0 .../omnisharpPackageCreator.test.ts | 26 ++++-- .../optionChangeObserver.test.ts | 0 .../optionStream.test.ts | 0 .../options.test.ts | 0 .../downloadAndInstallPackages.test.ts | 46 +++++------ .../packages/fileDownloader.test.ts | 32 ++++---- .../packages/isValidDownload.test.ts | 13 ++- .../packages/packageFilterer.test.ts | 47 +++++------ .../packages/zipInstaller.test.ts | 31 ++++---- .../platform.test.ts | 0 tasks/testTasks.ts | 22 +----- 36 files changed, 294 insertions(+), 326 deletions(-) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/absolutePath.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/common.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/features/reportIssue.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/informationMessageObserver.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/installRuntimeDependencies.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/jest.config.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/logging/omnisharpChannelObserver.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/logging/omnisharpLoggerObserver.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/omnisharp/omniSharpMonoResolver.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/omnisharpDownloader.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/omnisharpManager.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/omnisharpPackageCreator.test.ts (95%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/optionChangeObserver.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/optionStream.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/options.test.ts (100%) rename omnisharptest/{omnisharpJestTests => omnisharpUnitTests}/platform.test.ts (100%) diff --git a/jest.config.ts b/jest.config.ts index 701c6dccdc..38657fb423 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -10,7 +10,7 @@ const config: Config = { '/test/integrationTests/jest.config.ts', '/test/razorIntegrationTests/jest.config.ts', '/test/razorTests/jest.config.ts', - '/omnisharptest/omnisharpJestTests/jest.config.ts', + '/omnisharptest/omnisharpUnitTests/jest.config.ts', ], }; diff --git a/omnisharptest/omnisharpJestTests/absolutePath.test.ts b/omnisharptest/omnisharpUnitTests/absolutePath.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/absolutePath.test.ts rename to omnisharptest/omnisharpUnitTests/absolutePath.test.ts diff --git a/omnisharptest/omnisharpJestTests/common.test.ts b/omnisharptest/omnisharpUnitTests/common.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/common.test.ts rename to omnisharptest/omnisharpUnitTests/common.test.ts diff --git a/omnisharptest/omnisharpJestTests/features/reportIssue.test.ts b/omnisharptest/omnisharpUnitTests/features/reportIssue.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/features/reportIssue.test.ts rename to omnisharptest/omnisharpUnitTests/features/reportIssue.test.ts diff --git a/omnisharptest/omnisharpJestTests/informationMessageObserver.test.ts b/omnisharptest/omnisharpUnitTests/informationMessageObserver.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/informationMessageObserver.test.ts rename to omnisharptest/omnisharpUnitTests/informationMessageObserver.test.ts diff --git a/omnisharptest/omnisharpJestTests/installRuntimeDependencies.test.ts b/omnisharptest/omnisharpUnitTests/installRuntimeDependencies.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/installRuntimeDependencies.test.ts rename to omnisharptest/omnisharpUnitTests/installRuntimeDependencies.test.ts diff --git a/omnisharptest/omnisharpJestTests/jest.config.ts b/omnisharptest/omnisharpUnitTests/jest.config.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/jest.config.ts rename to omnisharptest/omnisharpUnitTests/jest.config.ts diff --git a/omnisharptest/omnisharpUnitTests/logging/backgroundWorkStatusBarObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/backgroundWorkStatusBarObserver.test.ts index 4927a47aad..a30c7c0ab4 100644 --- a/omnisharptest/omnisharpUnitTests/logging/backgroundWorkStatusBarObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/backgroundWorkStatusBarObserver.test.ts @@ -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 = { @@ -24,7 +22,7 @@ suite('BackgroundWorkStatusBarObserver', () => { }; const observer = new BackgroundWorkStatusBarObserver(statusBarItem); - setup(() => { + beforeEach(() => { showCalled = false; hideCalled = false; }); @@ -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', () => { @@ -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(''); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/csharpChannelObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/csharpChannelObserver.test.ts index aafae21262..5c82910986 100644 --- a/omnisharptest/omnisharpUnitTests/logging/csharpChannelObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/csharpChannelObserver.test.ts @@ -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 { @@ -16,8 +16,7 @@ import { IntegrityCheckFailure, } from '../../../src/omnisharp/loggingEvents'; -suite('CsharpChannelObserver', () => { - suiteSetup(() => should()); +describe('CsharpChannelObserver', () => { [ new InstallationFailure('someStage', 'someError'), new DebuggerNotInstalledFailure(), @@ -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); }); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/csharpLoggerObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/csharpLoggerObserver.test.ts index 87af2f3ade..b09c426499 100644 --- a/omnisharptest/omnisharpUnitTests/logging/csharpLoggerObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/csharpLoggerObserver.test.ts @@ -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, beforeEach } from '@jest/globals'; import { getNullChannel } from '../../../test/unitTests/fakes'; import { CsharpLoggerObserver } from '../../../src/shared/observers/csharpLoggerObserver'; import { PlatformInformation } from '../../../src/shared/platform'; @@ -11,9 +11,7 @@ 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(), @@ -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', () => { @@ -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'; [ { @@ -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); }); }); }); @@ -172,44 +170,44 @@ 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`, () => { @@ -217,7 +215,7 @@ suite('CsharpLoggerObserver', () => { 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`, () => { @@ -225,13 +223,13 @@ suite('CsharpLoggerObserver', () => { 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(); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/dotnetChannelObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/dotnetChannelObserver.test.ts index 17fb262106..88b7b569d7 100644 --- a/omnisharptest/omnisharpUnitTests/logging/dotnetChannelObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/dotnetChannelObserver.test.ts @@ -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; @@ -23,7 +22,7 @@ suite('DotnetChannelObserver', () => { }, }); - setup(() => { + beforeEach(() => { hasShown = false; hasCleared = false; }); @@ -31,7 +30,7 @@ suite('DotnetChannelObserver', () => { 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); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/dotnetLoggerObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/dotnetLoggerObserver.test.ts index 03f2a7b42b..529c9d1f12 100644 --- a/omnisharptest/omnisharpUnitTests/logging/dotnetLoggerObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/dotnetLoggerObserver.test.ts @@ -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 { @@ -13,9 +13,7 @@ import { EventWithMessage, } from '../../../src/omnisharp/loggingEvents'; -suite('DotnetLoggerObserver', () => { - suiteSetup(() => should()); - +describe('DotnetLoggerObserver', () => { [ new CommandDotNetRestoreProgress('Some message'), new CommandDotNetRestoreSucceeded('Some message'), @@ -31,7 +29,7 @@ suite('DotnetLoggerObserver', () => { }); observer.post(event); - expect(appendedMessage).to.contain(event.message); + expect(appendedMessage).toContain(event.message); }); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/dotnetTestChannelObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/dotnetTestChannelObserver.test.ts index 5e510d067c..ed0a473488 100644 --- a/omnisharptest/omnisharpUnitTests/logging/dotnetTestChannelObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/dotnetTestChannelObserver.test.ts @@ -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, @@ -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; @@ -27,7 +27,7 @@ suite('DotnetTestChannelObserver', () => { }, }); - setup(() => { + beforeEach(() => { hasShown = false; }); @@ -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); }); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/dotnetTestLoggerObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/dotnetTestLoggerObserver.test.ts index 81b9d24328..a5b74ae403 100644 --- a/omnisharptest/omnisharpUnitTests/logging/dotnetTestLoggerObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/dotnetTestLoggerObserver.test.ts @@ -3,8 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as chai from 'chai'; -import * as chaiString from 'chai-string'; +import { describe, test, expect, beforeEach } from '@jest/globals'; import { getNullChannel } from '../../../test/unitTests/fakes'; import { EventWithMessage, @@ -24,10 +23,7 @@ import { import DotNetTestLoggerObserver from '../../../src/observers/dotnetTestLoggerObserver'; import * as protocol from '../../../src/omnisharp/protocol'; -const expect = chai.expect; -chai.use(chaiString); - -suite(`${DotNetTestLoggerObserver.name}`, () => { +describe(`${DotNetTestLoggerObserver.name}`, () => { let appendedMessage: string; const observer = new DotNetTestLoggerObserver({ ...getNullChannel(), @@ -36,7 +32,7 @@ suite(`${DotNetTestLoggerObserver.name}`, () => { }, }); - setup(() => { + beforeEach(() => { appendedMessage = ''; }); @@ -44,33 +40,35 @@ suite(`${DotNetTestLoggerObserver.name}`, () => { (event: EventWithMessage) => { test(`${event.constructor.name}: Message is logged`, () => { observer.post(event); - expect(appendedMessage).to.contain(event.message); + expect(appendedMessage).toContain(event.message); }); } ); [new DotNetTestDebugStart('foo'), new DotNetTestRunStart('foo')].forEach((event: BaseEvent) => { test(`${event.constructor.name}: Test method is logged`, () => { - expect(appendedMessage).to.be.empty; + expect(appendedMessage).toBeFalsy(); observer.post(event); - expect(appendedMessage).to.contain('foo'); + expect(appendedMessage).toContain('foo'); }); }); [new DotNetTestsInClassDebugStart('foo'), new DotNetTestsInClassRunStart('foo')].forEach((event: BaseEvent) => { test(`${event.constructor.name}: Class name is logged`, () => { - expect(appendedMessage).to.be.empty; + expect(appendedMessage).toBeFalsy(); observer.post(event); - expect(appendedMessage).to.contain('foo'); + expect(appendedMessage).toContain('foo'); }); }); [new DotNetTestRunInContextStart('foo', 1, 2), new DotNetTestDebugInContextStart('foo', 1, 2)].forEach( (event: BaseEvent) => { test(`${event.constructor.name}: File name and line/column are logged`, () => { - expect(appendedMessage).to.be.empty; + expect(appendedMessage).toBeFalsy; observer.post(event); - expect(appendedMessage).to.contain('foo').and.contain('2').and.contain('3'); + expect(appendedMessage).toContain('foo'); + expect(appendedMessage).toContain('2'); + expect(appendedMessage).toContain('3'); }); } ); @@ -78,16 +76,16 @@ suite(`${DotNetTestLoggerObserver.name}`, () => { test(`${DotNetTestDebugProcessStart.name}: Target process id is logged`, () => { const event = new DotNetTestDebugProcessStart(111); observer.post(event); - expect(appendedMessage).to.contain(event.targetProcessId); + expect(appendedMessage).toContain(event.targetProcessId.toString()); }); test(`${DotNetTestDebugComplete.name}: Message is logged`, () => { const event = new DotNetTestDebugComplete(); observer.post(event); - expect(appendedMessage).to.not.be.empty; + expect(appendedMessage).toBeTruthy(); }); - suite(`${ReportDotNetTestResults.name}`, () => { + describe(`${ReportDotNetTestResults.name}`, () => { const event = new ReportDotNetTestResults([ getDotNetTestResults( 'foo', @@ -105,21 +103,23 @@ suite(`${DotNetTestLoggerObserver.name}`, () => { test(`Displays the outcome of each test`, () => { observer.post(event); event.results!.forEach((result) => { - expect(appendedMessage).to.containIgnoreCase(`${result.MethodName}:\n Outcome: ${result.Outcome}`); + expect(appendedMessage.toUpperCase()).toContain( + `${result.MethodName}:\n Outcome: ${result.Outcome}`.toUpperCase() + ); }); }); test(`Displays the total outcome`, () => { observer.post(event); - expect(appendedMessage).to.contain(`Total tests: 4. Passed: 1. Failed: 2. Skipped: 1`); + expect(appendedMessage).toContain(`Total tests: 4. Passed: 1. Failed: 2. Skipped: 1`); }); test('Displays the error message and error stack trace if any is present', () => { observer.post(event); - expect(appendedMessage).to.contain( + expect(appendedMessage).toContain( 'foo:\n Outcome: Failed\n Error Message:\n assertion failed\n Stack Trace:\n stacktrace1' ); - expect(appendedMessage).to.contain( + expect(appendedMessage).toContain( 'failinator:\n Outcome: Failed\n Error Message:\n error occurred\n Stack Trace:\n stacktrace2' ); }); @@ -127,20 +127,20 @@ suite(`${DotNetTestLoggerObserver.name}`, () => { test(`Displays the standard output messages if any`, () => { observer.post(event); event.results!.forEach((result) => { - result.StandardOutput.forEach((message) => expect(appendedMessage).to.contain(message)); + result.StandardOutput.forEach((message) => expect(appendedMessage).toContain(message)); }); }); test(`Displays the standard error messages if any`, () => { observer.post(event); event.results!.forEach((result) => { - result.StandardError.forEach((message) => expect(appendedMessage).to.contain(message)); + result.StandardError.forEach((message) => expect(appendedMessage).toContain(message)); }); }); test(`Can handle malformed results`, () => { observer.post(new ReportDotNetTestResults([])); - expect(appendedMessage).to.contain( + expect(appendedMessage).toContain( '----- Test Execution Summary -----\n\nTotal tests: 0. Passed: 0. Failed: 0. Skipped: 0' ); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/errorMessageObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/errorMessageObserver.test.ts index f1bcd1c0ed..be55666210 100644 --- a/omnisharptest/omnisharpUnitTests/logging/errorMessageObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/errorMessageObserver.test.ts @@ -3,7 +3,7 @@ * 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 { vscode } from '../../../src/vscodeAdapter'; import { ErrorMessageObserver } from '../../../src/observers/errorMessageObserver'; @@ -16,9 +16,7 @@ import { } from '../../../src/omnisharp/loggingEvents'; import { getFakeVsCode } from '../../../test/unitTests/fakes'; -suite('ErrorMessageObserver', () => { - suiteSetup(() => should()); - +describe('ErrorMessageObserver', () => { const vscode: vscode = getFakeVsCode(); let errorMessage: string | undefined; const observer = new ErrorMessageObserver(vscode); @@ -28,7 +26,7 @@ suite('ErrorMessageObserver', () => { return Promise.resolve('Done'); }; - setup(() => { + beforeEach(() => { errorMessage = undefined; }); @@ -39,18 +37,18 @@ suite('ErrorMessageObserver', () => { ].forEach((event: EventWithMessage) => { test(`${event.constructor.name}: Error message is shown`, () => { observer.post(event); - expect(errorMessage).to.be.contain(event.message); + expect(errorMessage).toContain(event.message); }); }); - suite(`${IntegrityCheckFailure.name}`, () => { + describe(`${IntegrityCheckFailure.name}`, () => { test('Package Description and url are logged when we are not retrying', () => { const description = 'someDescription'; const url = 'someUrl'; const event = new IntegrityCheckFailure(description, url, false); observer.post(event); - expect(errorMessage).to.contain(description); - expect(errorMessage).to.contain(url); + expect(errorMessage).toContain(description); + expect(errorMessage).toContain(url); }); test('Nothing is shown if we are retrying', () => { @@ -58,7 +56,7 @@ suite('ErrorMessageObserver', () => { const url = 'someUrl'; const event = new IntegrityCheckFailure(description, url, true); observer.post(event); - expect(errorMessage).to.be.undefined; + expect(errorMessage).toBe(undefined); }); }); }); diff --git a/omnisharptest/omnisharpJestTests/logging/omnisharpChannelObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/omnisharpChannelObserver.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/logging/omnisharpChannelObserver.test.ts rename to omnisharptest/omnisharpUnitTests/logging/omnisharpChannelObserver.test.ts diff --git a/omnisharptest/omnisharpUnitTests/logging/omnisharpDebugModeLoggerObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/omnisharpDebugModeLoggerObserver.test.ts index de2c5d5fe5..c5e3fee7d9 100644 --- a/omnisharptest/omnisharpUnitTests/logging/omnisharpDebugModeLoggerObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/omnisharpDebugModeLoggerObserver.test.ts @@ -2,8 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { use, should, expect } from 'chai'; -import * as chaiString from 'chai-string'; +import { describe, test, expect, beforeEach } from '@jest/globals'; import { getNullChannel } from '../../../test/unitTests/fakes'; import { OmnisharpServerVerboseMessage, @@ -18,10 +17,7 @@ import { } from '../../../src/omnisharp/loggingEvents'; import { OmnisharpDebugModeLoggerObserver } from '../../../src/observers/omnisharpDebugModeLoggerObserver'; -use(chaiString); - -suite('OmnisharpDebugModeLoggerObserver', () => { - suiteSetup(() => should()); +describe('OmnisharpDebugModeLoggerObserver', () => { let logOutput = ''; const observer = new OmnisharpDebugModeLoggerObserver({ ...getNullChannel(), @@ -30,45 +26,45 @@ suite('OmnisharpDebugModeLoggerObserver', () => { }, }); - setup(() => { + beforeEach(() => { logOutput = ''; }); [new OmnisharpServerVerboseMessage('server verbose message')].forEach((event: EventWithMessage) => { test(`${event.constructor.name}: Message is logged`, () => { observer.post(event); - expect(logOutput).to.contain(event.message); + expect(logOutput).toContain(event.message); }); }); test(`OmnisharpServerEnqueueRequest: Name and Command is logged`, () => { const event = new OmnisharpServerEnqueueRequest('foo', 'someCommand'); observer.post(event); - expect(logOutput).to.contain(event.queueName); - expect(logOutput).to.contain(event.command); + expect(logOutput).toContain(event.queueName); + expect(logOutput).toContain(event.command); }); test(`OmnisharpServerDequeueRequest: QueueName, QueueStatus, Command and Id is logged`, () => { const event = new OmnisharpServerDequeueRequest('foo', 'pending', 'someCommand', 1); observer.post(event); - expect(logOutput).to.contain(event.queueName); - expect(logOutput).to.contain(event.queueStatus); - expect(logOutput).to.contain(event.command); - expect(logOutput).to.contain(event.id); + expect(logOutput).toContain(event.queueName); + expect(logOutput).toContain(event.queueStatus); + expect(logOutput).toContain(event.command); + expect(logOutput).toContain(event.id?.toString()); }); test(`OmnisharpProcessRequestStart: Name and slots is logged`, () => { const event = new OmnisharpServerProcessRequestStart('foobar', 2); observer.post(event); - expect(logOutput).to.contain(event.name); - expect(logOutput).to.contain(event.availableRequestSlots); + expect(logOutput).toContain(event.name); + expect(logOutput).toContain(event.availableRequestSlots.toString()); }); test(`OmnisharpServerRequestCancelled: Name and Id is logged`, () => { const event = new OmnisharpServerRequestCancelled('foobar', 23); observer.post(event); - expect(logOutput).to.contain(event.command); - expect(logOutput).to.contain(event.id); + expect(logOutput).toContain(event.command); + expect(logOutput).toContain(event.id?.toString()); }); test(`OmnisharpServer messages increase and decrease indent`, () => { @@ -78,12 +74,12 @@ suite('OmnisharpDebugModeLoggerObserver', () => { observer.post(new OmnisharpServerProcessRequestComplete()); observer.post(new OmnisharpServerVerboseMessage('!indented_2')); - expect(logOutput).to.startWith(' !indented_1'); - expect(logOutput).to.contain('\n indented'); - expect(logOutput).to.contain('\n !indented_2'); + expect(logOutput.startsWith(' !indented_1')).toBe(true); + expect(logOutput).toContain('\n indented'); + expect(logOutput).toContain('\n !indented_2'); }); - suite('OmnisharpEventPacketReceived', () => { + describe('OmnisharpEventPacketReceived', () => { test(`Information messages with name OmniSharp.Middleware.LoggingMiddleware and follow pattern /^/[/w]+: 200 d+ms/ are logged`, () => { const event = new OmnisharpEventPacketReceived( 'INFORMATION', @@ -91,8 +87,8 @@ suite('OmnisharpDebugModeLoggerObserver', () => { '/codecheck: 200 339ms' ); observer.post(event); - expect(logOutput).to.contain(event.message); - expect(logOutput).to.contain(event.name); + expect(logOutput).toContain(event.message); + expect(logOutput).toContain(event.name); }); [ @@ -105,12 +101,12 @@ suite('OmnisharpDebugModeLoggerObserver', () => { ].forEach((event: OmnisharpEventPacketReceived) => { test(`${event.logLevel} messages are not logged`, () => { observer.post(event); - expect(logOutput).to.be.empty; + expect(logOutput).toBeFalsy(); }); }); }); - suite('OmnisharpRequestMessage', () => { + describe('OmnisharpRequestMessage', () => { test(`Request Command and Id is logged`, () => { const event = new OmnisharpRequestMessage( { @@ -125,8 +121,8 @@ suite('OmnisharpDebugModeLoggerObserver', () => { 1 ); observer.post(event); - expect(logOutput).to.contain(event.id); - expect(logOutput).to.contain(event.request.command); + expect(logOutput).toContain(event.id?.toString()); + expect(logOutput).toContain(event.request.command); }); test(`Request Data is logged when it is not empty`, () => { @@ -144,7 +140,7 @@ suite('OmnisharpDebugModeLoggerObserver', () => { 1 ); observer.post(event); - expect(logOutput).to.contain(event.request.data); + expect(logOutput).toContain(event.request.data); }); }); }); diff --git a/omnisharptest/omnisharpJestTests/logging/omnisharpLoggerObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/omnisharpLoggerObserver.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/logging/omnisharpLoggerObserver.test.ts rename to omnisharptest/omnisharpUnitTests/logging/omnisharpLoggerObserver.test.ts diff --git a/omnisharptest/omnisharpUnitTests/logging/omnisharpStatusBarObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/omnisharpStatusBarObserver.test.ts index 9e729936ee..5db4b97cf7 100644 --- a/omnisharptest/omnisharpUnitTests/logging/omnisharpStatusBarObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/omnisharpStatusBarObserver.test.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { describe, test, expect, beforeEach } from '@jest/globals'; import { StatusBarItem } from '../../../src/vscodeAdapter'; import { OmnisharpOnBeforeServerInstall, @@ -17,15 +18,13 @@ import { BaseEvent, InstallationSuccess, } from '../../../src/omnisharp/loggingEvents'; -import { expect, should } from 'chai'; import { OmnisharpStatusBarObserver, StatusBarColors } from '../../../src/observers/omnisharpStatusBarObserver'; -suite('OmnisharpStatusBarObserver', () => { - suiteSetup(() => should()); +describe('OmnisharpStatusBarObserver', () => { let showCalled: boolean; let hideCalled: boolean; - setup(() => { + beforeEach(() => { statusBarItem.text = ''; statusBarItem.color = undefined; statusBarItem.command = undefined; @@ -48,79 +47,79 @@ suite('OmnisharpStatusBarObserver', () => { [new OmnisharpServerOnServerError('someError')].forEach((event: BaseEvent) => { test(`${event.constructor.name}: Status bar is shown with the error text`, () => { observer.post(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`$(flame)`); - expect(statusBarItem.command).to.equal('o.showOutput'); - expect(statusBarItem.tooltip).to.equal('Error starting OmniSharp'); - expect(statusBarItem.color).to.equal(StatusBarColors.Red); + expect(showCalled).toBe(true); + expect(statusBarItem.text).toEqual(`$(flame)`); + expect(statusBarItem.command).toEqual('o.showOutput'); + expect(statusBarItem.tooltip).toEqual('Error starting OmniSharp'); + expect(statusBarItem.color).toEqual(StatusBarColors.Red); }); }); test(`${OmnisharpServerOnStdErr.name}: Status bar is shown with the error text`, () => { const event = new OmnisharpServerOnStdErr('std error'); observer.post(event); - expect(showCalled).to.be.true; - expect(statusBarItem.color).to.equal(StatusBarColors.Red); - expect(statusBarItem.text).to.equal(`$(flame)`); - expect(statusBarItem.command).to.equal('o.showOutput'); - expect(statusBarItem.tooltip).to.contain(event.message); + expect(showCalled).toBe(true); + expect(statusBarItem.color).toEqual(StatusBarColors.Red); + expect(statusBarItem.text).toEqual(`$(flame)`); + expect(statusBarItem.command).toEqual('o.showOutput'); + expect(statusBarItem.tooltip).toContain(event.message); }); test('OnBeforeServerInstall: Status bar is shown with the installation text', () => { const event = new OmnisharpOnBeforeServerInstall(); observer.post(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.be.equal('$(flame) Installing OmniSharp...'); - expect(statusBarItem.command).to.equal('o.showOutput'); + expect(showCalled).toBe(true); + expect(statusBarItem.text).toEqual('$(flame) Installing OmniSharp...'); + expect(statusBarItem.command).toEqual('o.showOutput'); }); test('OnBeforeServerStart: Status bar is shown with the starting text', () => { const event = new OmnisharpOnBeforeServerStart(); observer.post(event); - expect(showCalled).to.be.true; - expect(statusBarItem.color).to.equal(StatusBarColors.Yellow); - expect(statusBarItem.text).to.be.equal('$(flame)'); - expect(statusBarItem.command).to.equal('o.showOutput'); - expect(statusBarItem.tooltip).to.equal('Starting OmniSharp server'); + expect(showCalled).toBe(true); + expect(statusBarItem.color).toEqual(StatusBarColors.Yellow); + expect(statusBarItem.text).toEqual('$(flame)'); + expect(statusBarItem.command).toEqual('o.showOutput'); + expect(statusBarItem.tooltip).toEqual('Starting OmniSharp server'); }); test('OnServerStart: Status bar is shown with the flame and "Running" text', () => { const event = new OmnisharpServerOnStart(); observer.post(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.be.equal('$(flame)'); - expect(statusBarItem.command).to.equal('o.showOutput'); - expect(statusBarItem.tooltip).to.be.equal('OmniSharp server is running'); + expect(showCalled).toBe(true); + expect(statusBarItem.text).toEqual('$(flame)'); + expect(statusBarItem.command).toEqual('o.showOutput'); + expect(statusBarItem.tooltip).toEqual('OmniSharp server is running'); }); test('OnServerStop: Status bar is hidden and the attributes are set to undefined', () => { const event = new OmnisharpServerOnStop(); observer.post(event); - expect(hideCalled).to.be.true; - expect(statusBarItem.text).to.be.equal(''); - expect(statusBarItem.command).to.be.undefined; - expect(statusBarItem.color).to.be.undefined; + expect(hideCalled).toBe(true); + expect(statusBarItem.text).toEqual(''); + expect(statusBarItem.command).toBe(undefined); + expect(statusBarItem.color).toBe(undefined); }); test('DownloadStart: Text and tooltip are set ', () => { const event = new DownloadStart('somePackage'); observer.post(event); - expect(statusBarItem.text).to.contain('Downloading packages'); - expect(statusBarItem.tooltip).to.contain(event.packageDescription); + expect(statusBarItem.text).toContain('Downloading packages'); + expect(statusBarItem.tooltip).toContain(event.packageDescription); }); test('InstallationProgress: Text and tooltip are set', () => { const event = new InstallationStart('somePackage'); observer.post(event); - expect(statusBarItem.text).to.contain('Installing packages'); - expect(statusBarItem.tooltip).to.contain(event.packageDescription); + expect(statusBarItem.text).toContain('Installing packages'); + expect(statusBarItem.tooltip).toContain(event.packageDescription); }); test('DownloadProgress: Tooltip contains package description and download percentage', () => { const event = new DownloadProgress(50, 'somePackage'); observer.post(event); - expect(statusBarItem.tooltip).to.contain(event.packageDescription); - expect(statusBarItem.tooltip).to.contain(event.downloadPercentage); + expect(statusBarItem.tooltip).toContain(event.packageDescription); + expect(statusBarItem.tooltip).toContain(event.downloadPercentage.toString()); }); test('InstallationSuccess: Status bar is hidden and the attributes are set to undefined', () => { @@ -130,9 +129,9 @@ suite('OmnisharpStatusBarObserver', () => { const successEvent = new InstallationSuccess(); observer.post(successEvent); - expect(hideCalled).to.be.true; - expect(statusBarItem.text).to.be.equal(''); - expect(statusBarItem.command).to.be.undefined; - expect(statusBarItem.color).to.be.undefined; + expect(hideCalled).toBe(true); + expect(statusBarItem.text).toEqual(''); + expect(statusBarItem.command).toBe(undefined); + expect(statusBarItem.color).toBe(undefined); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/projectStatusBarObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/projectStatusBarObserver.test.ts index c88b12a227..b06f6070be 100644 --- a/omnisharptest/omnisharpUnitTests/logging/projectStatusBarObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/projectStatusBarObserver.test.ts @@ -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 { getWorkspaceInformationUpdated, getMSBuildWorkspaceInformation } from '../../../test/unitTests/fakes'; import { StatusBarItem } from '../../../src/vscodeAdapter'; import { ProjectStatusBarObserver } from '../../../src/observers/projectStatusBarObserver'; import { OmnisharpOnMultipleLaunchTargets, OmnisharpServerOnStop } from '../../../src/omnisharp/loggingEvents'; -suite('ProjectStatusBarObserver', () => { - suiteSetup(() => should()); - +describe('ProjectStatusBarObserver', () => { let showCalled: boolean; let hideCalled: boolean; const statusBarItem = { @@ -24,7 +22,7 @@ suite('ProjectStatusBarObserver', () => { }; const observer = new ProjectStatusBarObserver(statusBarItem); - setup(() => { + beforeEach(() => { showCalled = false; hideCalled = false; }); @@ -32,35 +30,35 @@ suite('ProjectStatusBarObserver', () => { test('OnServerStop: Status bar is hidden and the attributes are set to undefined', () => { const event = new OmnisharpServerOnStop(); observer.post(event); - expect(hideCalled).to.be.true; - expect(statusBarItem.text).to.be.equal(''); - expect(statusBarItem.command).to.be.undefined; - expect(statusBarItem.color).to.be.undefined; + expect(hideCalled).toBe(true); + expect(statusBarItem.text).toEqual(''); + expect(statusBarItem.command).toBe(undefined); + expect(statusBarItem.color).toBe(undefined); }); test('OnMultipleLaunchTargets: Status bar is shown with the select project option and the comand to pick a project', () => { const event = new OmnisharpOnMultipleLaunchTargets([]); observer.post(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.contain('Select project'); - expect(statusBarItem.command).to.equal('o.pickProjectAndStart'); + expect(showCalled).toBe(true); + expect(statusBarItem.text).toContain('Select project'); + expect(statusBarItem.command).toEqual('o.pickProjectAndStart'); }); - suite('WorkspaceInformationUpdated', () => { + describe('WorkspaceInformationUpdated', () => { test('Project status is hidden if there is no MSBuild Object', () => { const event = getWorkspaceInformationUpdated(undefined); observer.post(event); - expect(hideCalled).to.be.true; - expect(statusBarItem.text).to.be.equal(''); - expect(statusBarItem.command).to.be.undefined; + expect(hideCalled).toBe(true); + expect(statusBarItem.text).toEqual(''); + expect(statusBarItem.command).toBe(undefined); }); test('Project status is shown if there is an MSBuild object', () => { const event = getWorkspaceInformationUpdated(getMSBuildWorkspaceInformation('somePath', [])); observer.post(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.contain(event.info.MsBuild?.SolutionPath); - expect(statusBarItem.command).to.equal('o.pickProjectAndStart'); + expect(showCalled).toBe(true); + expect(statusBarItem.text).toContain(event.info.MsBuild?.SolutionPath); + expect(statusBarItem.command).toEqual('o.pickProjectAndStart'); }); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/razorLoggerObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/razorLoggerObserver.test.ts index 486d6e1c5c..8426081948 100644 --- a/omnisharptest/omnisharpUnitTests/logging/razorLoggerObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/razorLoggerObserver.test.ts @@ -2,7 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * 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 { RazorLoggerObserver } from '../../../src/observers/razorLoggerObserver'; import { @@ -11,8 +11,7 @@ import { RazorDevModeActive, } from '../../../src/omnisharp/loggingEvents'; -suite('RazorLoggerObserver', () => { - suiteSetup(() => should()); +describe('RazorLoggerObserver', () => { let logOutput = ''; const observer = new RazorLoggerObserver({ ...getNullChannel(), @@ -21,25 +20,25 @@ suite('RazorLoggerObserver', () => { }, }); - setup(() => { + beforeEach(() => { logOutput = ''; }); test(`RazorPluginPathSpecified: Path is logged`, () => { const event = new RazorPluginPathSpecified('somePath'); observer.post(event); - expect(logOutput).to.contain(event.path); + expect(logOutput).toContain(event.path); }); test(`RazorPluginPathDoesNotExist: Path is logged`, () => { const event = new RazorPluginPathDoesNotExist('somePath'); observer.post(event); - expect(logOutput).to.contain(event.path); + expect(logOutput).toContain(event.path); }); test(`RazorDevModeActive: Logs dev mode active`, () => { const event = new RazorDevModeActive(); observer.post(event); - expect(logOutput).to.contain('Razor dev mode active'); + expect(logOutput).toContain('Razor dev mode active'); }); }); diff --git a/omnisharptest/omnisharpUnitTests/logging/warningMessageObserver.test.ts b/omnisharptest/omnisharpUnitTests/logging/warningMessageObserver.test.ts index 90b830bb07..73e867cc47 100644 --- a/omnisharptest/omnisharpUnitTests/logging/warningMessageObserver.test.ts +++ b/omnisharptest/omnisharpUnitTests/logging/warningMessageObserver.test.ts @@ -2,9 +2,8 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ - +import { describe, test, expect, beforeEach } from '@jest/globals'; import { WarningMessageObserver } from '../../../src/observers/warningMessageObserver'; -import { assert, expect, should } from 'chai'; import { getFakeVsCode, getMSBuildDiagnosticsMessage, @@ -16,9 +15,7 @@ import { TestScheduler } from 'rxjs/testing'; import { from as observableFrom, Subject } from 'rxjs'; import { timeout, map } from 'rxjs/operators'; -suite('WarningMessageObserver', () => { - suiteSetup(() => should()); - +describe('WarningMessageObserver', () => { let doClickOk: () => void; let doClickCancel: () => void; let signalCommandDone: () => void; @@ -55,9 +52,11 @@ suite('WarningMessageObserver', () => { return undefined; }; - setup(() => { + beforeEach(() => { assertionObservable = new Subject(); - scheduler = new TestScheduler(assert.deepEqual); + scheduler = new TestScheduler((actual, expected) => { + expect(actual).toStrictEqual(expected); + }); scheduler.maxFrames = 9000; observer = new WarningMessageObserver(vscode, () => false, scheduler); warningMessages = []; @@ -80,8 +79,8 @@ suite('WarningMessageObserver', () => { const eventList = scheduler.createHotObservable(marble, marble_event_map); eventList.subscribe((e) => observer.post(e)); scheduler.flush(); - expect(warningMessages).to.be.empty; - expect(invokedCommand).to.be.undefined; + expect(warningMessages).toHaveLength(0); + expect(invokedCommand).toBe(undefined); }); test('OmnisharpServerMsBuildProjectDiagnostics: No event is posted if warning is disabled', () => { @@ -96,8 +95,8 @@ suite('WarningMessageObserver', () => { const eventList = scheduler.createHotObservable(marble, marble_event_map); eventList.subscribe((e) => newObserver.post(e)); scheduler.flush(); - expect(warningMessages).to.be.empty; - expect(invokedCommand).to.be.undefined; + expect(warningMessages).toHaveLength(0); + expect(invokedCommand).toBe(undefined); }); [ @@ -134,7 +133,7 @@ suite('WarningMessageObserver', () => { command: 'o.showOutput', }, ].forEach((elem) => { - suite(`${elem.eventA.constructor.name}`, () => { + describe(`${elem.eventA.constructor.name}`, () => { test(`When the event is fired then a warning message is displayed`, () => { const marble = `${timeToMarble(1500)}a`; const marble_event_map = { a: elem.eventA }; @@ -142,8 +141,8 @@ suite('WarningMessageObserver', () => { eventList.subscribe((e) => observer.post(e)); scheduler.expectObservable(assertionObservable).toBe(`${timeToMarble(3000)}a`, { a: elem.assertion1 }); scheduler.flush(); - expect(warningMessages.length).to.be.equal(1); - expect(warningMessages[0]).to.be.equal(elem.expected); + expect(warningMessages.length).toEqual(1); + expect(warningMessages[0]).toEqual(elem.expected); }); test(`When events are fired rapidly, then they are debounced by 1500 ms`, () => { @@ -154,8 +153,8 @@ suite('WarningMessageObserver', () => { scheduler.expectObservable(assertionObservable).toBe(`${timeToMarble(3520)}a`, { a: elem.assertion1 }); scheduler.flush(); - expect(warningMessages.length).to.be.equal(1); - expect(warningMessages[0]).to.be.equal(elem.expected); + expect(warningMessages.length).toEqual(1); + expect(warningMessages[0]).toEqual(elem.expected); }); test(`When events are 1500 ms apart, then they are not debounced`, () => { @@ -168,8 +167,8 @@ suite('WarningMessageObserver', () => { b: elem.assertion2, }); scheduler.flush(); - expect(warningMessages.length).to.be.equal(2); - expect(warningMessages[0]).to.be.equal(elem.expected); + expect(warningMessages.length).toEqual(2); + expect(warningMessages[0]).toEqual(elem.expected); }); test(`Given a warning message, when the user clicks ok the command is executed`, async () => { @@ -179,7 +178,7 @@ suite('WarningMessageObserver', () => { scheduler.flush(); doClickOk(); await commandDone; - expect(invokedCommand).to.be.equal(elem.command); + expect(invokedCommand).toEqual(elem.command); }); test(`Given a warning message, when the user clicks cancel the command is not executed`, async () => { @@ -188,8 +187,8 @@ suite('WarningMessageObserver', () => { scheduler.expectObservable(eventList.pipe(map((e) => observer.post(e)))); scheduler.flush(); doClickCancel(); - await expect(observableFrom(commandDone).pipe(timeout(1)).toPromise()).to.be.rejected; - expect(invokedCommand).to.be.undefined; + await expect(observableFrom(commandDone).pipe(timeout(1)).toPromise()).rejects.toThrow(); + expect(invokedCommand).toBe(undefined); }); }); }); diff --git a/omnisharptest/omnisharpJestTests/omnisharp/omniSharpMonoResolver.test.ts b/omnisharptest/omnisharpUnitTests/omnisharp/omniSharpMonoResolver.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/omnisharp/omniSharpMonoResolver.test.ts rename to omnisharptest/omnisharpUnitTests/omnisharp/omniSharpMonoResolver.test.ts diff --git a/omnisharptest/omnisharpJestTests/omnisharpDownloader.test.ts b/omnisharptest/omnisharpUnitTests/omnisharpDownloader.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/omnisharpDownloader.test.ts rename to omnisharptest/omnisharpUnitTests/omnisharpDownloader.test.ts diff --git a/omnisharptest/omnisharpJestTests/omnisharpManager.test.ts b/omnisharptest/omnisharpUnitTests/omnisharpManager.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/omnisharpManager.test.ts rename to omnisharptest/omnisharpUnitTests/omnisharpManager.test.ts diff --git a/omnisharptest/omnisharpJestTests/omnisharpPackageCreator.test.ts b/omnisharptest/omnisharpUnitTests/omnisharpPackageCreator.test.ts similarity index 95% rename from omnisharptest/omnisharpJestTests/omnisharpPackageCreator.test.ts rename to omnisharptest/omnisharpUnitTests/omnisharpPackageCreator.test.ts index 7bd91875d7..df9c5e78eb 100644 --- a/omnisharptest/omnisharpJestTests/omnisharpPackageCreator.test.ts +++ b/omnisharptest/omnisharpUnitTests/omnisharpPackageCreator.test.ts @@ -56,7 +56,9 @@ describe('GetOmnisharpPackage : Output package depends on the input package and expect(resultPackage.description).toEqual(`${testPackage.description}, Version = 1.2.3`); }); - test(`Install path is calculated using the specified path and version useFramework: ${useFramework}`, () => { + test(`Install path is calculated using the specified path and version ${ + useFramework ? 'on framework' : '' + }`, () => { const testPackage = inputPackages.find( (element) => element.platformId && element.platformId == 'os-architecture' ); @@ -70,7 +72,9 @@ describe('GetOmnisharpPackage : Output package depends on the input package and expect(resultPackage.installPath).toEqual(`experimentPath/1.2.3${pathSuffix}`); }); - test(`Install test path is calculated using specified path, version and ends with OmniSharp.exe or OmniSharp.dll - Windows(x86) useFramework: ${useFramework}`, () => { + test(`Install test path is calculated using specified path, version and ends with OmniSharp.exe or OmniSharp.dll - Windows(x86) ${ + useFramework ? 'on framework' : '' + }`, () => { const testPackage = inputPackages.find((element) => element.platformId && element.platformId == 'win-x86'); const resultPackage = SetBinaryAndGetPackage( testPackage!, @@ -84,7 +88,9 @@ describe('GetOmnisharpPackage : Output package depends on the input package and ); }); - test(`Install test path is calculated using specified path, version and ends with OmniSharp.exe or OmniSharp.dll - Windows(x64) useFramework: ${useFramework}`, () => { + test(`Install test path is calculated using specified path, version and ends with OmniSharp.exe or OmniSharp.dll - Windows(x64) ${ + useFramework ? 'on framework' : '' + }`, () => { const testPackage = inputPackages.find((element) => element.platformId && element.platformId == 'win-x64'); const resultPackage = SetBinaryAndGetPackage( testPackage!, @@ -98,7 +104,9 @@ describe('GetOmnisharpPackage : Output package depends on the input package and ); }); - test(`Install test path is calculated using specified path, version and ends with correct binary - OSX useFramework: ${useFramework}`, () => { + test(`Install test path is calculated using specified path, version and ends with correct binary - OSX ${ + useFramework ? 'on framework' : '' + }`, () => { const testPackage = inputPackages.find((element) => element.platformId && element.platformId == 'osx'); const resultPackage = SetBinaryAndGetPackage( testPackage!, @@ -112,7 +120,9 @@ describe('GetOmnisharpPackage : Output package depends on the input package and ); }); - test(`Install test path is calculated using specified path, version and ends with correct binary - Linux(x86) useFramework: ${useFramework}`, () => { + test(`Install test path is calculated using specified path, version and ends with correct binary - Linux(x86) ${ + useFramework ? 'on framework' : '' + }`, () => { const testPackage = inputPackages.find( (element) => element.platformId && element.platformId == 'linux-x86' ); @@ -128,7 +138,9 @@ describe('GetOmnisharpPackage : Output package depends on the input package and ); }); - test(`Install test path is calculated using specified path, version and ends with correct binary - Linux(x64) useFramework: ${useFramework}`, () => { + test(`Install test path is calculated using specified path, version and ends with correct binary - Linux(x64) useFramework: ${ + useFramework ? 'on framework' : '' + }`, () => { const testPackage = inputPackages.find( (element) => element.platformId && element.platformId == 'linux-x64' ); @@ -145,7 +157,7 @@ describe('GetOmnisharpPackage : Output package depends on the input package and }); }); - test('Download url is calculated using server url and version (useFramework: true)', () => { + test('Download url is calculated using server url and version on framework', () => { const testPackage = inputPackages.find( (element) => element.platformId && element.platformId == 'os-architecture' ); diff --git a/omnisharptest/omnisharpJestTests/optionChangeObserver.test.ts b/omnisharptest/omnisharpUnitTests/optionChangeObserver.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/optionChangeObserver.test.ts rename to omnisharptest/omnisharpUnitTests/optionChangeObserver.test.ts diff --git a/omnisharptest/omnisharpJestTests/optionStream.test.ts b/omnisharptest/omnisharpUnitTests/optionStream.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/optionStream.test.ts rename to omnisharptest/omnisharpUnitTests/optionStream.test.ts diff --git a/omnisharptest/omnisharpJestTests/options.test.ts b/omnisharptest/omnisharpUnitTests/options.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/options.test.ts rename to omnisharptest/omnisharpUnitTests/options.test.ts diff --git a/omnisharptest/omnisharpUnitTests/packages/downloadAndInstallPackages.test.ts b/omnisharptest/omnisharpUnitTests/packages/downloadAndInstallPackages.test.ts index 2787f034e3..6468a0f6e2 100644 --- a/omnisharptest/omnisharpUnitTests/packages/downloadAndInstallPackages.test.ts +++ b/omnisharptest/omnisharpUnitTests/packages/downloadAndInstallPackages.test.ts @@ -3,12 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { describe, test, expect, beforeEach, afterEach } from '@jest/globals'; import * as path from 'path'; -import * as chaiAsPromised from 'chai-as-promised'; -import * as chai from 'chai'; import * as util from '../../../src/common'; import { CreateTmpDir, TmpAsset } from '../../../src/createTmpAsset'; -import TestZip from '../testAssets/testZip'; +import TestZip from '../../omnisharpUnitTests/testAssets/testZip'; import { downloadAndInstallPackages } from '../../../src/packageManager/downloadAndInstallPackages'; import NetworkSettings from '../../../src/networkSettings'; import { EventStream } from '../../../src/eventStream'; @@ -23,17 +22,14 @@ import { DownloadFailure, InstallationFailure, } from '../../../src/omnisharp/loggingEvents'; -import MockHttpsServer from '../testAssets/mockHttpsServer'; -import { createTestFile } from '../testAssets/testFile'; -import TestEventBus from '../testAssets/testEventBus'; +import MockHttpsServer from '../../omnisharpUnitTests/testAssets/mockHttpsServer'; +import { createTestFile } from '../../omnisharpUnitTests/testAssets/testFile'; +import TestEventBus from '../../omnisharpUnitTests/testAssets/testEventBus'; import { AbsolutePathPackage } from '../../../src/packageManager/absolutePathPackage'; import { AbsolutePath } from '../../../src/packageManager/absolutePath'; import { DownloadValidator } from '../../../src/packageManager/isValidDownload'; -chai.use(chaiAsPromised); -const expect = chai.expect; - -suite(`${downloadAndInstallPackages.name}`, () => { +describe(`${downloadAndInstallPackages.name}`, () => { let tmpInstallDir: TmpAsset; let server: MockHttpsServer; let testZip: TestZip; @@ -47,7 +43,7 @@ suite(`${downloadAndInstallPackages.name}`, () => { const packageDescription = 'Test Package'; const networkSettingsProvider = () => new NetworkSettings('', false); - setup(async () => { + beforeEach(async () => { eventStream = new EventStream(); server = await MockHttpsServer.CreateMockHttpsServer(); eventBus = new TestEventBus(eventStream); @@ -85,7 +81,7 @@ suite(`${downloadAndInstallPackages.name}`, () => { server.addRequestHandler('GET', '/notDownloadablePackage', 404); }); - suite('If the download and install succeeds', () => { + describe('If the download and install succeeds', () => { test('The expected files are installed at the specified path', async () => { await downloadAndInstallPackages( downloadablePackage, @@ -95,7 +91,7 @@ suite(`${downloadAndInstallPackages.name}`, () => { ); for (const elem of testZip.files) { const filePath = path.join(tmpDirPath, elem.path); - expect(await util.fileExists(filePath)).to.be.true; + expect(await util.fileExists(filePath)).toBe(true); } }); @@ -106,7 +102,7 @@ suite(`${downloadAndInstallPackages.name}`, () => { eventStream, downloadValidator ); - expect(await util.fileExists(path.join(tmpDirPath, 'install.Lock'))).to.be.true; + expect(await util.fileExists(path.join(tmpDirPath, 'install.Lock'))).toBe(true); }); test('Events are created in the correct order', async () => { @@ -125,7 +121,7 @@ suite(`${downloadAndInstallPackages.name}`, () => { eventStream, downloadValidator ); - expect(eventBus.getEvents()).to.be.deep.equal(eventsSequence); + expect(eventBus.getEvents()).toStrictEqual(eventsSequence); }); test('If the download validation fails for the first time and passed second time, the correct events are logged', async () => { @@ -159,11 +155,11 @@ suite(`${downloadAndInstallPackages.name}`, () => { eventStream, downloadValidator ); - expect(eventBus.getEvents()).to.be.deep.equal(eventsSequence); + expect(eventBus.getEvents()).toStrictEqual(eventsSequence); }); }); - suite('If the download and install fails', () => { + describe('If the download and install fails', () => { test('If the download succeeds but the validation fails, events are logged', async () => { const downloadValidator = () => false; const eventsSequence = [ @@ -186,7 +182,7 @@ suite(`${downloadAndInstallPackages.name}`, () => { eventStream, downloadValidator ); - expect(eventBus.getEvents()).to.be.deep.equal(eventsSequence); + expect(eventBus.getEvents()).toStrictEqual(eventsSequence); }); test('Returns false when the download fails', async () => { @@ -203,12 +199,12 @@ suite(`${downloadAndInstallPackages.name}`, () => { downloadValidator ); const obtainedEvents = eventBus.getEvents(); - expect(obtainedEvents[0]).to.be.deep.equal(eventsSequence[0]); - expect(obtainedEvents[1]).to.be.deep.equal(eventsSequence[1]); - expect(obtainedEvents[2]).to.be.deep.equal(eventsSequence[2]); + expect(obtainedEvents[0]).toStrictEqual(eventsSequence[0]); + expect(obtainedEvents[1]).toStrictEqual(eventsSequence[1]); + expect(obtainedEvents[2]).toStrictEqual(eventsSequence[2]); const installationFailureEvent = obtainedEvents[3]; - expect(installationFailureEvent.stage).to.be.equal('downloadPackage'); - expect(installationFailureEvent.error).to.not.be.null; + expect(installationFailureEvent.stage).toEqual('downloadPackage'); + expect(installationFailureEvent.error).not.toBe(null); }); test('install.Lock is not present when the download fails', async () => { @@ -218,11 +214,11 @@ suite(`${downloadAndInstallPackages.name}`, () => { eventStream, downloadValidator ); - expect(await util.fileExists(path.join(tmpDirPath, 'install.Lock'))).to.be.false; + expect(await util.fileExists(path.join(tmpDirPath, 'install.Lock'))).toBe(false); }); }); - teardown(async () => { + afterEach(async () => { if (tmpInstallDir) { tmpInstallDir.dispose(); } diff --git a/omnisharptest/omnisharpUnitTests/packages/fileDownloader.test.ts b/omnisharptest/omnisharpUnitTests/packages/fileDownloader.test.ts index b239e1ae74..852f1c0a1b 100644 --- a/omnisharptest/omnisharpUnitTests/packages/fileDownloader.test.ts +++ b/omnisharptest/omnisharpUnitTests/packages/fileDownloader.test.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as chai from 'chai'; +import { describe, test, expect, beforeEach, afterEach } from '@jest/globals'; import { EventStream } from '../../../src/eventStream'; import { DownloadFile } from '../../../src/packageManager/fileDownloader'; import NetworkSettings from '../../../src/networkSettings'; @@ -15,12 +15,10 @@ import { DownloadFallBack, DownloadFailure, } from '../../../src/omnisharp/loggingEvents'; -import MockHttpsServer from '../testAssets/mockHttpsServer'; -import TestEventBus from '../testAssets/testEventBus'; +import MockHttpsServer from '../../omnisharpUnitTests/testAssets/mockHttpsServer'; +import TestEventBus from '../../omnisharpUnitTests/testAssets/testEventBus'; -const expect = chai.expect; - -suite('FileDownloader', () => { +describe('FileDownloader', () => { const fileDescription = 'Test file'; const correctUrlPath = `/resource`; const redirectUrlPath = '/redirectResource'; @@ -50,7 +48,7 @@ suite('FileDownloader', () => { let server: MockHttpsServer; - setup(async () => { + beforeEach(async () => { server = await MockHttpsServer.CreateMockHttpsServer(); await server.start(); eventBus = new TestEventBus(eventStream); @@ -59,7 +57,7 @@ suite('FileDownloader', () => { server.addRequestHandler('GET', redirectUrlPath, 301, { location: `${server.baseUrl}${correctUrlPath}` }); }); - suite('If the response status Code is 200, the download succeeds', () => { + describe('If the response status Code is 200, the download succeeds', () => { [ { description: 'Primary url', @@ -74,7 +72,7 @@ suite('FileDownloader', () => { getEventSequence: getFallBackURLEvents, }, ].forEach((elem) => { - suite(elem.description, () => { + describe(elem.description, () => { test('File is downloaded', async () => { const buffer = await DownloadFile( fileDescription, @@ -84,7 +82,7 @@ suite('FileDownloader', () => { getURL(elem.fallBackUrlPath) ); const text = buffer.toString('utf8'); - expect(text).to.be.equal('Test content'); + expect(text).toEqual('Test content'); }); test('Events are created in the correct order', async () => { @@ -95,13 +93,13 @@ suite('FileDownloader', () => { getURL(elem.urlPath), getURL(elem.fallBackUrlPath) ); - expect(eventBus.getEvents()).to.be.deep.equal(elem.getEventSequence()); + expect(eventBus.getEvents()).toStrictEqual(elem.getEventSequence()); }); }); }); }); - suite('If the response status Code is 301, redirect occurs and the download succeeds', () => { + describe('If the response status Code is 301, redirect occurs and the download succeeds', () => { test('File is downloaded from the redirect url', async () => { const buffer = await DownloadFile( fileDescription, @@ -110,11 +108,11 @@ suite('FileDownloader', () => { getURL(redirectUrlPath) ); const text = buffer.toString('utf8'); - expect(text).to.be.equal('Test content'); + expect(text).toEqual('Test content'); }); }); - suite('If the response status code is not 301, 302 or 200 then the download fails', () => { + describe('If the response status code is not 301, 302 or 200 then the download fails', () => { test('Error is thrown', async () => { const downloadPromise = DownloadFile( fileDescription, @@ -127,7 +125,7 @@ suite('FileDownloader', () => { } catch { /* empty */ } - expect(downloadPromise).be.rejected; + expect(downloadPromise).rejects.toThrow(); }); test('Download Start and Download Failure events are created', async () => { @@ -138,12 +136,12 @@ suite('FileDownloader', () => { try { await DownloadFile(fileDescription, eventStream, networkSettingsProvider, getURL(errorUrlPath)); } catch (error) { - expect(eventBus.getEvents()).to.be.deep.equal(eventsSequence); + expect(eventBus.getEvents()).toStrictEqual(eventsSequence); } }); }); - teardown(async () => { + afterEach(async () => { await server.stop(); eventBus.dispose(); }); diff --git a/omnisharptest/omnisharpUnitTests/packages/isValidDownload.test.ts b/omnisharptest/omnisharpUnitTests/packages/isValidDownload.test.ts index d2186d873f..21430cf2c2 100644 --- a/omnisharptest/omnisharpUnitTests/packages/isValidDownload.test.ts +++ b/omnisharptest/omnisharpUnitTests/packages/isValidDownload.test.ts @@ -3,29 +3,26 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { describe, test, expect } from '@jest/globals'; import { isValidDownload } from '../../../src/packageManager/isValidDownload'; -import * as chai from 'chai'; import { EventStream } from '../../../src/eventStream'; -chai.should(); -const expect = chai.expect; - -suite(`${isValidDownload.name}`, () => { +describe(`${isValidDownload.name}`, () => { const sampleBuffer = Buffer.from('sampleBuffer'); const validIntegrity = 'eb7201b5d986919e0ac67c820886358869d8f7059193d33c902ad7fe1688e1e9'; test('Returns false for non-matching integrity', async () => { const result = await isValidDownload(sampleBuffer, 'inValidIntegrity', new EventStream()); - expect(result).to.be.false; + expect(result).toBe(false); }); test('Returns true for matching integrity', async () => { const result = await isValidDownload(sampleBuffer, validIntegrity, new EventStream()); - expect(result).to.be.true; + expect(result).toBe(true); }); test('Returns true if no integrity has been specified', async () => { const result = await isValidDownload(sampleBuffer, undefined, new EventStream()); - expect(result).to.be.true; + expect(result).toBe(true); }); }); diff --git a/omnisharptest/omnisharpUnitTests/packages/packageFilterer.test.ts b/omnisharptest/omnisharpUnitTests/packages/packageFilterer.test.ts index c576a45106..a65405ce93 100644 --- a/omnisharptest/omnisharpUnitTests/packages/packageFilterer.test.ts +++ b/omnisharptest/omnisharpUnitTests/packages/packageFilterer.test.ts @@ -2,19 +2,16 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as chai from 'chai'; +import { describe, test, expect, beforeEach, jest } from '@jest/globals'; import { PlatformInformation } from '../../../src/shared/platform'; import { getNotInstalledPackagesForPlatform } from '../../../src/packageManager/packageFilterer'; import { Package } from '../../../src/packageManager/package'; import { AbsolutePathPackage } from '../../../src/packageManager/absolutePathPackage'; +import { MockedFunction } from 'jest-mock'; +import * as fs from 'fs'; import { join } from 'path'; -const expect = chai.expect; -// There are no typings for this library. -// eslint-disable-next-line @typescript-eslint/no-var-requires -const mock = require('mock-fs'); - -suite(`${getNotInstalledPackagesForPlatform.name}`, () => { +describe(`${getNotInstalledPackagesForPlatform.name}`, () => { let absolutePathPackages: AbsolutePathPackage[]; const extensionPath = '/ExtensionPath'; const packages = [ @@ -57,34 +54,40 @@ suite(`${getNotInstalledPackagesForPlatform.name}`, () => { }, ]; - setup(async () => { + beforeEach(async () => { absolutePathPackages = packages.map((pkg) => AbsolutePathPackage.getAbsolutePathPackage(pkg, extensionPath)); const installLockPath = join(absolutePathPackages[1].installPath.value, 'install.Lock'); //mock the install lock path so the package should be filtered - mock({ - [installLockPath]: 'no content', + const statSpy = jest.spyOn(fs, 'stat') as unknown as MockedFunction< + ( + path: fs.PathLike, + callback: (err: NodeJS.ErrnoException | null, stats: fs.Stats | undefined) => void + ) => void + >; + statSpy.mockImplementation((path, callback) => { + if (installLockPath === path) { + callback(null, { isFile: () => true } as unknown as fs.Stats); + } else { + callback(null, undefined); + } }); }); test('Filters the packages based on Platform Information', async () => { const platformInfo = new PlatformInformation('win32', 'architecture2'); const filteredPackages = await getNotInstalledPackagesForPlatform(absolutePathPackages, platformInfo); - expect(filteredPackages.length).to.be.equal(1); - expect(filteredPackages[0].description).to.be.equal('win32-Architecture2 uninstalled package'); - expect(filteredPackages[0].platforms[0]).to.be.equal('win32'); - expect(filteredPackages[0].architectures[0]).to.be.equal('architecture2'); + expect(filteredPackages.length).toEqual(1); + expect(filteredPackages[0].description).toEqual('win32-Architecture2 uninstalled package'); + expect(filteredPackages[0].platforms[0]).toEqual('win32'); + expect(filteredPackages[0].architectures[0]).toEqual('architecture2'); }); test('Returns only the packages where install.Lock is not present', async () => { const platformInfo = new PlatformInformation('linux', 'architecture1'); const filteredPackages = await getNotInstalledPackagesForPlatform(absolutePathPackages, platformInfo); - expect(filteredPackages.length).to.be.equal(1); - expect(filteredPackages[0].description).to.be.equal('linux-Architecture1 uninstalled package'); - expect(filteredPackages[0].platforms[0]).to.be.equal('linux'); - expect(filteredPackages[0].architectures[0]).to.be.equal('architecture1'); - }); - - teardown(() => { - mock.restore(); + expect(filteredPackages.length).toEqual(1); + expect(filteredPackages[0].description).toEqual('linux-Architecture1 uninstalled package'); + expect(filteredPackages[0].platforms[0]).toEqual('linux'); + expect(filteredPackages[0].architectures[0]).toEqual('architecture1'); }); }); diff --git a/omnisharptest/omnisharpUnitTests/packages/zipInstaller.test.ts b/omnisharptest/omnisharpUnitTests/packages/zipInstaller.test.ts index 908e18f5f7..66be19b33c 100644 --- a/omnisharptest/omnisharpUnitTests/packages/zipInstaller.test.ts +++ b/omnisharptest/omnisharpUnitTests/packages/zipInstaller.test.ts @@ -3,23 +3,21 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { describe, test, expect, beforeEach, afterEach } from '@jest/globals'; import * as fs from 'async-file'; import * as path from 'path'; -import * as chai from 'chai'; import * as util from '../../../src/common'; import { CreateTmpDir, TmpAsset } from '../../../src/createTmpAsset'; import { InstallZip } from '../../../src/packageManager/zipInstaller'; import { EventStream } from '../../../src/eventStream'; import { PlatformInformation } from '../../../src/shared/platform'; import { BaseEvent, InstallationStart, ZipError } from '../../../src/omnisharp/loggingEvents'; -import { createTestFile } from '../testAssets/testFile'; -import TestZip from '../testAssets/testZip'; -import TestEventBus from '../testAssets/testEventBus'; +import { createTestFile } from '../../omnisharpUnitTests/testAssets/testFile'; +import TestZip from '../../omnisharpUnitTests/testAssets/testZip'; +import TestEventBus from '../../omnisharpUnitTests/testAssets/testEventBus'; import { AbsolutePath } from '../../../src/packageManager/absolutePath'; -const expect = chai.expect; - -suite('ZipInstaller', () => { +describe('ZipInstaller', () => { const binaries = [createTestFile('binary1', 'binary1.txt'), createTestFile('binary2', 'binary2.txt')]; const files = [createTestFile('file1', 'file1.txt'), createTestFile('file2', 'folder/file2.txt')]; @@ -31,7 +29,7 @@ suite('ZipInstaller', () => { let eventStream: EventStream; let eventBus: TestEventBus; - setup(async () => { + beforeEach(async () => { eventStream = new EventStream(); eventBus = new TestEventBus(eventStream); tmpInstallDir = await CreateTmpDir(true); @@ -44,14 +42,14 @@ suite('ZipInstaller', () => { await InstallZip(testZip.buffer, fileDescription, installationPath, [], eventStream); for (const elem of testZip.files) { const filePath = path.join(installationPath.value, elem.path); - expect(await util.fileExists(filePath)).to.be.true; + expect(await util.fileExists(filePath)).toBe(true); } }); test('The folder is unzipped and all the expected events are created', async () => { await InstallZip(testZip.buffer, fileDescription, installationPath, [], eventStream); const eventSequence: BaseEvent[] = [new InstallationStart(fileDescription)]; - expect(eventBus.getEvents()).to.be.deep.equal(eventSequence); + expect(eventBus.getEvents()).toStrictEqual(eventSequence); }); test('The folder is unzipped and the binaries have the expected permissions(except on Windows)', async () => { @@ -61,16 +59,17 @@ suite('ZipInstaller', () => { ); await InstallZip(testZip.buffer, fileDescription, installationPath, absoluteBinaries, eventStream); for (const binaryPath of absoluteBinaries) { - expect(await util.fileExists(binaryPath.value)).to.be.true; + expect(await util.fileExists(binaryPath.value)).toBe(true); const mode = (await fs.stat(binaryPath.value)).mode; - expect(mode & 0o7777).to.be.equal(0o755, `Expected mode for path ${binaryPath}`); + expect(mode & 0o7777).toEqual(0o755); } } }); test('Error is thrown when the buffer contains an invalid zip', async () => { - expect(InstallZip(Buffer.from('My file', 'utf8'), 'Text File', installationPath, [], eventStream)).to.be - .rejected; + expect( + InstallZip(Buffer.from('My file', 'utf8'), 'Text File', installationPath, [], eventStream) + ).rejects.toThrow(); }); test('Error event is created when the buffer contains an invalid zip', async () => { @@ -83,11 +82,11 @@ suite('ZipInstaller', () => { 'C# Extension was unable to download its dependencies. Please check your internet connection. If you use a proxy server, please visit https://aka.ms/VsCodeCsharpNetworking' ), ]; - expect(eventBus.getEvents()).to.be.deep.equal(eventSequence); + expect(eventBus.getEvents()).toStrictEqual(eventSequence); } }); - teardown(async () => { + afterEach(async () => { if (tmpInstallDir) { tmpInstallDir.dispose(); } diff --git a/omnisharptest/omnisharpJestTests/platform.test.ts b/omnisharptest/omnisharpUnitTests/platform.test.ts similarity index 100% rename from omnisharptest/omnisharpJestTests/platform.test.ts rename to omnisharptest/omnisharpUnitTests/platform.test.ts diff --git a/tasks/testTasks.ts b/tasks/testTasks.ts index 9857dbb410..cb8478ca89 100644 --- a/tasks/testTasks.ts +++ b/tasks/testTasks.ts @@ -8,7 +8,6 @@ import * as path from 'path'; import { codeExtensionPath, omnisharpFeatureTestRunnerPath, - mochaPath, rootPath, integrationTestAssetsRootPath, omnisharpTestRootPath, @@ -20,7 +19,7 @@ import { import spawnNode from './spawnNode'; import * as jest from 'jest'; import { Config } from '@jest/types'; -import { jestOmniSharpUnitTestProjectName } from '../omnisharptest/omnisharpJestTests/jest.config'; +import { jestOmniSharpUnitTestProjectName } from '../omnisharptest/omnisharpUnitTests/jest.config'; import { jestUnitTestProjectName } from '../test/unitTests/jest.config'; import { razorTestProjectName } from '../test/razorTests/jest.config'; @@ -58,23 +57,6 @@ gulp.task( ); gulp.task('omnisharptest:unit', async () => { - const result = await spawnNode([ - mochaPath, - '--ui', - 'tdd', - '-c', - 'out/omnisharptest/omnisharpUnitTests/**/*.test.js', - ]); - - if (result.code === null || result.code > 0) { - // Ensure that gulp fails when tests fail - throw new Error(`Exit code: ${result.code} Signal: ${result.signal}`); - } - - return result; -}); - -gulp.task('omnisharp:jest:test', async () => { runJestTest(jestOmniSharpUnitTestProjectName); }); @@ -108,7 +90,7 @@ gulp.task( // TODO: Enable lsp integration tests once tests for unimplemented features are disabled. gulp.task( 'omnisharptest', - gulp.series('omnisharp:jest:test', 'omnisharptest:feature', 'omnisharptest:unit', 'omnisharptest:integration:stdio') + gulp.series('omnisharptest:unit', 'omnisharptest:feature', 'omnisharptest:integration:stdio') ); gulp.task('test:unit', async () => {