From 8403e9841d22c41a3ca3042b89d356399039df27 Mon Sep 17 00:00:00 2001 From: Jiayin Pei Date: Thu, 20 Feb 2020 09:58:39 +0800 Subject: [PATCH 1/2] fix UT --- src/credential/credentialController.ts | 4 +- .../credentialController.test.ts | 89 ++++++++++--------- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/credential/credentialController.ts b/src/credential/credentialController.ts index 188125da..66f5d236 100644 --- a/src/credential/credentialController.ts +++ b/src/credential/credentialController.ts @@ -145,7 +145,7 @@ export class CredentialController { let opened = await vscode.env.openExternal(vscode.Uri.parse(signUrl)); if (!opened) { // User decline to open external URL to sign in - throw new DocsError(`Sign-in with AAD Failed: Please Allow Code to open `, ErrorCode.AADSignInExternalUrlDeclined); + throw new DocsError(`Sign-in with AAD Failed: Please Allow to open external URL to Sign-In`, ErrorCode.AADSignInExternalUrlDeclined); } try { @@ -180,7 +180,7 @@ export class CredentialController { let opened = await vscode.env.openExternal(vscode.Uri.parse(signUrl)); if (!opened) { // User decline to open external URL to sign in - throw new DocsError(`Sign-in with GitHub Failed: Please Allow Code to open `, ErrorCode.GitHubSignInExternalUrlDeclined); + throw new DocsError(`Sign-in with GitHub Failed: Please Allow to open external URL to Sign-In`, ErrorCode.GitHubSignInExternalUrlDeclined); } try { diff --git a/test/componentTests/credentialController.test.ts b/test/componentTests/credentialController.test.ts index 26e9731f..8ea24bd6 100644 --- a/test/componentTests/credentialController.test.ts +++ b/test/componentTests/credentialController.test.ts @@ -1,15 +1,18 @@ import * as vscode from 'vscode'; -import { CredentialExpired, CredentialReset, EnvironmentChanged, BaseEvent, CredentialRetrieveFromLocalCredentialManager, UserSignedOut, UserSignInProgress, UserSigningIn, UserSignInSucceeded, UserSignInFailed } from '../../src/common/loggingEvents'; +import * as assert from 'assert'; +import { CredentialExpired, CredentialReset, EnvironmentChanged, BaseEvent, CredentialRetrieveFromLocalCredentialManager, UserSignInProgress, UserSignInSucceeded, UserSignInFailed, UserSignInTriggered, UserSignOutSucceeded, UserSignOutTriggered } from '../../src/common/loggingEvents'; import { EventStream } from '../../src/common/eventStream'; import { CredentialController, Credential } from '../../src/credential/credentialController'; import { KeyChain } from '../../src/credential/keyChain'; import { EnvironmentController } from '../../src/common/environmentController'; import { SinonSandbox, createSandbox, SinonStub } from 'sinon'; -import { expect } from 'chai'; import TestEventBus from '../utils/testEventBus'; import { UserInfo, uriHandler } from '../../src/shared'; import { getFakeEnvironmentController } from '../utils/faker'; import extensionConfig from '../../src/config'; +import { DocsError } from '../../src/error/docsError'; +import { ErrorCode } from '../../src/error/errorCode'; +import { TimeOutError } from '../../src/error/timeOutError'; const fakedAADCallbackURL = { authority: 'ceapex.docs-build', @@ -110,9 +113,9 @@ describe('CredentialController', () => { } function AssertCredentialReset(credential: Credential) { - expect(isResetAADInfoCalled).to.be.true; - expect(isResetUserInfoCalled).to.be.true; - expect(credential).to.deep.equal({ + assert.equal(isResetAADInfoCalled, true); + assert.equal(isResetUserInfoCalled, true); + assert.deepStrictEqual(credential, { signInStatus: 'SignedOut', aadInfo: undefined, userInfo: undefined @@ -135,7 +138,7 @@ describe('CredentialController', () => { it(`CredentialController Initialize should be Called`, () => { credentialController.eventHandler(event); - expect(isCredentialControllerInitializeCalled).to.be.true; + assert.equal(isCredentialControllerInitializeCalled, true); }); }); }); @@ -146,7 +149,7 @@ describe('CredentialController', () => { let credential = credentialController.credential; AssertCredentialReset(credential); - expect(testEventBus.getEvents()).to.deep.equal([new CredentialReset()]); + assert.deepStrictEqual(testEventBus.getEvents(), [new CredentialReset()]); }); describe(`Initialize`, () => { @@ -169,8 +172,8 @@ describe('CredentialController', () => { userToken: 'fake-token' } }; - expect(credential).to.deep.equal(expectedCredential); - expect(testEventBus.getEvents()).to.deep.equal([new CredentialRetrieveFromLocalCredentialManager(expectedCredential)]); + assert.deepStrictEqual(credential, expectedCredential); + assert.deepStrictEqual(testEventBus.getEvents(), [new CredentialRetrieveFromLocalCredentialManager(expectedCredential)]); }); it(`Should be 'SignedOut' status if the user info can not be retrieved from keyChain`, async () => { @@ -183,7 +186,7 @@ describe('CredentialController', () => { // Assert let credential = credentialController.credential; AssertCredentialReset(credential); - expect(testEventBus.getEvents()).to.deep.equal([new CredentialReset()]); + assert.deepStrictEqual(testEventBus.getEvents(), [new CredentialReset()]); }); }); @@ -209,7 +212,7 @@ describe('CredentialController', () => { ); // act - await credentialController.signIn(); + await credentialController.signIn('fakedCorrelationId'); // Assert let credential = credentialController.credential; @@ -224,17 +227,17 @@ describe('CredentialController', () => { aadInfo: 'aad-code', userInfo: expectedUserInfo }; - expect(credential).to.deep.equal(expectedCredential); - expect(isSetAADInfoCalled).to.be.true; - expect(setAADInfo).to.equal('aad-code'); - expect(isSetUserInfoCalled).to.be.true; - expect(setUserInfo).to.deep.equal(expectedUserInfo); - expect(testEventBus.getEvents()).to.deep.equal([ + assert.deepStrictEqual(credential, expectedCredential); + assert.equal(isSetAADInfoCalled, true); + assert.equal(setAADInfo, 'aad-code'); + assert.equal(isSetUserInfoCalled, true); + assert.deepStrictEqual(setUserInfo, expectedUserInfo); + assert.deepStrictEqual(testEventBus.getEvents(), [ new CredentialReset(), - new UserSigningIn(), + new UserSignInTriggered('fakedCorrelationId'), new UserSignInProgress(`Sign-in to docs build with AAD...`, 'Sign-in'), new UserSignInProgress(`Sign-in to docs build with GitHub account...`, 'Sign-in'), - new UserSignInSucceeded(expectedCredential) + new UserSignInSucceeded('fakedCorrelationId', expectedCredential) ]); }); @@ -243,17 +246,17 @@ describe('CredentialController', () => { stubOpenExternal = sinon.stub(vscode.env, 'openExternal').resolves(false); // Act - await credentialController.signIn(); + await credentialController.signIn('fakedCorrelationId'); // Assert let credential = credentialController.credential; AssertCredentialReset(credential); - expect(testEventBus.getEvents()).to.deep.equal([ + assert.deepStrictEqual(testEventBus.getEvents(), [ new CredentialReset(), - new UserSigningIn(), + new UserSignInTriggered('fakedCorrelationId'), new UserSignInProgress(`Sign-in to docs build with AAD...`, 'Sign-in'), - new UserSignInFailed(`Sign-in with AAD Failed`), - new CredentialReset() + new CredentialReset(), + new UserSignInFailed('fakedCorrelationId', new DocsError(`Sign-in with AAD Failed: Please Allow to open external URL to Sign-In`, ErrorCode.AADSignInExternalUrlDeclined)), ]); }); @@ -274,18 +277,18 @@ describe('CredentialController', () => { ); // Act - await credentialController.signIn(); + await credentialController.signIn('fakedCorrelationId'); // Assert let credential = credentialController.credential; AssertCredentialReset(credential); - expect(testEventBus.getEvents()).to.deep.equal([ + assert.deepStrictEqual(testEventBus.getEvents(), [ new CredentialReset(), - new UserSigningIn(), + new UserSignInTriggered('fakedCorrelationId'), new UserSignInProgress(`Sign-in to docs build with AAD...`, 'Sign-in'), new UserSignInProgress(`Sign-in to docs build with GitHub account...`, 'Sign-in'), - new UserSignInFailed(`Sign-in with GitHub Failed`), - new CredentialReset() + new CredentialReset(), + new UserSignInFailed('fakedCorrelationId', new DocsError(`Sign-in with GitHub Failed: Please Allow to open external URL to Sign-In`, ErrorCode.GitHubSignInExternalUrlDeclined)), ]); }); @@ -298,17 +301,17 @@ describe('CredentialController', () => { stubOpenExternal = sinon.stub(vscode.env, 'openExternal').resolves(true); // Act - await credentialController.signIn(); + await credentialController.signIn('fakedCorrelationId'); // Assert let credential = credentialController.credential; AssertCredentialReset(credential); - expect(testEventBus.getEvents()).to.deep.equal([ + assert.deepStrictEqual(testEventBus.getEvents(), [ new CredentialReset(), - new UserSigningIn(), + new UserSignInTriggered('fakedCorrelationId'), new UserSignInProgress(`Sign-in to docs build with AAD...`, 'Sign-in'), - new UserSignInFailed(`Sign-in with AAD Failed: Timeout`), - new CredentialReset() + new CredentialReset(), + new UserSignInFailed('fakedCorrelationId', new DocsError(`Sign-in with AAD Failed: Time out`, ErrorCode.AADSignInTimeOut, new TimeOutError('Time out'))), ]); }); @@ -332,18 +335,18 @@ describe('CredentialController', () => { ); // Act - await credentialController.signIn(); + await credentialController.signIn('fakedCorrelationId'); // Assert let credential = credentialController.credential; AssertCredentialReset(credential); - expect(testEventBus.getEvents()).to.deep.equal([ + assert.deepStrictEqual(testEventBus.getEvents(), [ new CredentialReset(), - new UserSigningIn(), + new UserSignInTriggered('fakedCorrelationId'), new UserSignInProgress(`Sign-in to docs build with AAD...`, 'Sign-in'), new UserSignInProgress(`Sign-in to docs build with GitHub account...`, 'Sign-in'), - new UserSignInFailed(`Sign-in with GitHub Failed: Timeout`), - new CredentialReset() + new CredentialReset(), + new UserSignInFailed('fakedCorrelationId', new DocsError(`Sign-in with GitHub Failed: Time out`, ErrorCode.GitHubSignInTimeOut, new TimeOutError('Time out'))), ]); }); }); @@ -354,11 +357,15 @@ describe('CredentialController', () => { credentialController.initialize(); // Act - Sign-out - credentialController.signOut(); + credentialController.signOut('fakedCorrelationId'); // Assert let credential = credentialController.credential; AssertCredentialReset(credential); - expect(testEventBus.getEvents()).to.deep.equal([new CredentialReset(), new UserSignedOut()]); + assert.deepStrictEqual(testEventBus.getEvents(), [ + new UserSignOutTriggered('fakedCorrelationId'), + new CredentialReset(), + new UserSignOutSucceeded('fakedCorrelationId') + ]); }); }); \ No newline at end of file From ec330e0684a0b58cdf978b6932997bbb3c46f592 Mon Sep 17 00:00:00 2001 From: Jiayin Pei Date: Thu, 20 Feb 2020 10:06:06 +0800 Subject: [PATCH 2/2] use Nodejs assert instead of chai since it cannot handle error equality --- package.json | 6 -- test/componentTests/index.ts | 3 - test/unitTests/credential/keychain.test.ts | 18 ++-- .../dependency/fileDownloader.test.ts | 31 ++++--- .../observers/buildStatusBarObserver.test.ts | 18 ++-- .../observers/docsLoggerObserver.test.ts | 82 +++++++++---------- .../docsOutputChannelObserver.test.ts | 4 +- .../observers/signStatusBarObserver.test.ts | 50 +++++------ .../observers/telemetryObserver.test.ts | 48 +++++------ 9 files changed, 124 insertions(+), 136 deletions(-) diff --git a/package.json b/package.json index fa369057..6d5efb3b 100644 --- a/package.json +++ b/package.json @@ -118,9 +118,6 @@ "lint": "tslint --project tsconfig.json -e src/*.d.ts -t verbose" }, "devDependencies": { - "@types/chai": "^4.2.7", - "@types/chai-as-promised": "^7.1.2", - "@types/chai-subset": "^1.3.3", "@types/glob": "^7.1.1", "@types/gulp": "^4.0.6", "@types/mocha": "^5.2.7", @@ -129,9 +126,6 @@ "@types/sinon": "^7.5.1", "@types/vscode": "^1.40.0", "async-child-process": "^1.1.1", - "chai": "^4.2.0", - "chai-as-promised": "^7.1.1", - "chai-subset": "^1.6.0", "codecov": "^3.6.1", "get-port": "^5.1.0", "gulp": "^4.0.2", diff --git a/test/componentTests/index.ts b/test/componentTests/index.ts index 7657b25c..ddbe4589 100644 --- a/test/componentTests/index.ts +++ b/test/componentTests/index.ts @@ -1,10 +1,7 @@ -import { use } from 'chai'; import * as path from 'path'; import * as Mocha from 'mocha'; import * as glob from 'glob'; -use(require('chai-subset')); - export async function run(): Promise { const nyc = process.env.COVERAGE ? setupCoverage() : undefined; const mocha = new Mocha({ diff --git a/test/unitTests/credential/keychain.test.ts b/test/unitTests/credential/keychain.test.ts index 1729f368..0739f3e1 100644 --- a/test/unitTests/credential/keychain.test.ts +++ b/test/unitTests/credential/keychain.test.ts @@ -1,5 +1,5 @@ +import * as assert from 'assert'; import { KeyChain, Keytar } from '../../../src/credential/keyChain'; -import { expect } from 'chai'; import { UserInfo } from '../../../src/shared'; import { getFakeEnvironmentController, setEnvToPROD, setEnvToPPE } from '../../utils/faker'; import { EnvironmentController } from '../../../src/common/environmentController'; @@ -36,14 +36,14 @@ describe('KeyChain', () => { setEnvToPROD(environmentController); await keyChain.setAADInfo('fake-aad'); let aadInfo = await keyChain.getAADInfo(); - expect(aadInfo).to.equal('fake-aad'); + assert.equal(aadInfo, 'fake-aad'); // Mock PPE environment setEnvToPPE(environmentController); // Test aadInfo = await keyChain.getAADInfo(); - expect(aadInfo).to.be.undefined; + assert.equal(aadInfo, undefined); }); it('setUserInfo gets tokens set by setToken with the same environment', async () => { @@ -56,24 +56,24 @@ describe('KeyChain', () => { }; await keyChain.setUserInfo(expectedUserInfo); let userInfo = await keyChain.getUserInfo(); - expect(userInfo).to.deep.equal(expectedUserInfo); + assert.deepStrictEqual(userInfo, expectedUserInfo); // Mock PPE environment setEnvToPPE(environmentController); // Test userInfo = await keyChain.getUserInfo(); - expect(userInfo).to.be.undefined; + assert.equal(userInfo, undefined); }); it('getAADInfo no longer returns removed tokens', async () => { await keyChain.setAADInfo('fake-aad'); let aadInfo = await keyChain.getAADInfo(); - expect(aadInfo).to.equal('fake-aad'); + assert.equal(aadInfo, 'fake-aad'); await keyChain.resetAADInfo(); aadInfo = await keyChain.getAADInfo(); - expect(aadInfo).to.be.undefined; + assert.equal(aadInfo, undefined); }); it('setUserInfo no longer returns removed tokens', async () => { @@ -85,10 +85,10 @@ describe('KeyChain', () => { }; await keyChain.setUserInfo(expectedUserInfo); let userInfo = await keyChain.getUserInfo(); - expect(userInfo).to.deep.equal(expectedUserInfo); + assert.deepStrictEqual(userInfo, expectedUserInfo); await keyChain.resetUserInfo(); userInfo = await keyChain.getUserInfo(); - expect(userInfo).to.be.undefined; + assert.equal(userInfo, undefined); }); }); \ No newline at end of file diff --git a/test/unitTests/dependency/fileDownloader.test.ts b/test/unitTests/dependency/fileDownloader.test.ts index fae6ff83..dd8a9bdc 100644 --- a/test/unitTests/dependency/fileDownloader.test.ts +++ b/test/unitTests/dependency/fileDownloader.test.ts @@ -1,13 +1,10 @@ -import { MockHttpsServer } from "../../utils/MockHttpsServer"; +import * as assert from 'assert'; +import { MockHttpsServer } from "../../utils/mockHttpsServer"; import { downloadFile } from "../../../src/dependency/fileDownloader"; -import { EventStream } from "../../../src/common/EventStream"; -import TestEventBus from "../../utils/TestEventBus"; -import * as chai from "chai"; +import { EventStream } from "../../../src/common/eventStream"; +import TestEventBus from "../../utils/testEventBus"; import { DownloadStarted, DownloadSizeObtained, DownloadProgress, DownloadValidating, DownloadIntegrityCheckFailed } from "../../../src/common/loggingEvents"; -chai.use(require('chai-as-promised')); -const expect = chai.expect; - describe(`fileDownloader`, () => { const downloadDescription = 'Test FileDownloader'; const correctUrlPath = '/resource'; @@ -56,8 +53,8 @@ describe(`fileDownloader`, () => { let buffer = await downloadFile(downloadDescription, getUrl(elem.urlPath), eventStream, correctResourceIntegrity, false); let text = buffer.toString(); - expect(text).to.equal(correctResourceContent, 'File is downloaded'); - expect(eventBus.getEvents()).to.deep.equal([ + assert.equal(text, correctResourceContent, 'File is downloaded'); + assert.deepStrictEqual(eventBus.getEvents(), [ new DownloadStarted(downloadDescription), new DownloadSizeObtained(12), new DownloadProgress(100), @@ -71,9 +68,9 @@ describe(`fileDownloader`, () => { await downloadFile(downloadDescription, getUrl(elem.urlPath), eventStream, errorResourceIntegrity, false); } catch (err) { errorThrown = true; - expect(err).to.has.property('message').that.equal('Failed integrity check.'); + assert.deepStrictEqual(err, new Error('Failed integrity check.')); - expect(eventBus.getEvents()).to.deep.equal([ + assert.deepStrictEqual(eventBus.getEvents(), [ new DownloadStarted(downloadDescription), new DownloadSizeObtained(12), new DownloadProgress(100), @@ -81,15 +78,15 @@ describe(`fileDownloader`, () => { new DownloadIntegrityCheckFailed(), ], 'Events are created in the correct order'); } - expect(errorThrown).to.equal(true, 'Error is thrown'); + assert.equal(errorThrown, true, 'Error is thrown'); }); it(`Download succeeds if no integrity provided`, async () => { let buffer = await downloadFile(downloadDescription, getUrl(elem.urlPath), eventStream, undefined, false); let text = buffer.toString(); - expect(text).to.equal(correctResourceContent, 'File is downloaded'); - expect(eventBus.getEvents()).to.deep.equal([ + assert.equal(text, correctResourceContent, 'File is downloaded'); + assert.deepStrictEqual(eventBus.getEvents(), [ new DownloadStarted(downloadDescription), new DownloadSizeObtained(12), new DownloadProgress(100), @@ -106,13 +103,13 @@ describe(`fileDownloader`, () => { await downloadFile(downloadDescription, errorUrl, eventStream, undefined, false); } catch (err) { errorThrown = true; - expect(err).to.has.property('message').that.equal(`Failed to download from ${errorUrl}. Error code '404'`); + assert.deepStrictEqual(err, new Error(`Failed to download from ${errorUrl}. Error code '404'`)); - expect(eventBus.getEvents()).to.deep.equal([ + assert.deepStrictEqual(eventBus.getEvents(), [ new DownloadStarted(downloadDescription) ], 'Events are created in the correct order'); } - expect(errorThrown).to.equal(true, 'Error is thrown'); + assert.equal(errorThrown, true, 'Error is thrown'); }); function getUrl(path: string) { diff --git a/test/unitTests/observers/buildStatusBarObserver.test.ts b/test/unitTests/observers/buildStatusBarObserver.test.ts index c79a95c4..2a223c06 100644 --- a/test/unitTests/observers/buildStatusBarObserver.test.ts +++ b/test/unitTests/observers/buildStatusBarObserver.test.ts @@ -1,4 +1,4 @@ -import { expect } from 'chai'; +import * as assert from 'assert'; import { StatusBarItem } from 'vscode'; import { BuildStatusBarObserver } from '../../../src/observers/buildStatusBarObserver'; import { BuildInstantAllocated, BuildInstantReleased } from '../../../src/common/loggingEvents'; @@ -25,18 +25,18 @@ describe('BuildStatusBarObserver', () => { it(`BuildInstantAllocated: Status bar is shown with '$(sync~spin)' text`, () => { let event = new BuildInstantAllocated(); observer.eventHandler(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`$(sync~spin)`); - expect(statusBarItem.command).to.be.undefined; - expect(statusBarItem.tooltip).to.equal('Building the current workspace folder'); + assert.equal(showCalled, true); + assert.equal(statusBarItem.text, `$(sync~spin)`); + assert.equal(statusBarItem.command, undefined); + assert.equal(statusBarItem.tooltip, 'Building the current workspace folder'); }); it(`BuildInstantReleased: Status bar is shown with '$(sync)' text`, () => { let event = new BuildInstantReleased(); observer.eventHandler(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`$(sync)`); - expect(statusBarItem.command).to.be.undefined; - expect(statusBarItem.tooltip).to.equal('Ready to Build'); + assert.equal(showCalled, true); + assert.equal(statusBarItem.text, `$(sync)`); + assert.equal(statusBarItem.command, undefined); + assert.equal(statusBarItem.tooltip, 'Ready to Build'); }); }); \ No newline at end of file diff --git a/test/unitTests/observers/docsLoggerObserver.test.ts b/test/unitTests/observers/docsLoggerObserver.test.ts index 833e17fc..a613fb51 100644 --- a/test/unitTests/observers/docsLoggerObserver.test.ts +++ b/test/unitTests/observers/docsLoggerObserver.test.ts @@ -1,4 +1,4 @@ -import { expect } from 'chai'; +import * as assert from 'assert'; import { OutputChannel } from 'vscode'; import { UserSignInSucceeded, CredentialRetrieveFromLocalCredentialManager, UserSignInProgress, RepositoryInfoRetrieved, BuildInstantAllocated, BuildProgress, APICallStarted, APICallFailed, DependencyInstallStarted, DependencyInstallFinished, PackageInstallStarted, PackageInstallSucceeded, PackageInstallFailed, DownloadStarted, DownloadSizeObtained, DownloadProgress, DownloadValidating, DownloadIntegrityCheckFailed, ZipFileInstalling, PlatformInfoRetrieved, UserSignInFailed, UserSignOutSucceeded, UserSignOutFailed, BuildStarted, BuildSucceeded, BuildCanceled, BuildFailed, DocfxRestoreCompleted, DocfxBuildCompleted } from '../../../src/common/loggingEvents'; import { DocsLoggerObserver } from '../../../src/observers/docsLoggerObserver'; @@ -41,7 +41,7 @@ describe('DocsLoggerObserver', () => { + ` - GitHub Account: Faked User\n` + ` - User email : fake@microsoft.com\n` + `\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it('UserSignInFailed', () => { @@ -49,7 +49,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Failed to sign-in to Docs Build: Faked error msg\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); }); @@ -70,7 +70,7 @@ describe('DocsLoggerObserver', () => { + ` - GitHub Account: Faked User\n` + ` - User email : fake@microsoft.com\n` + `\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); describe('UserSignOutCompleted', () => { @@ -79,7 +79,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Successfully sign-out from Docs Build!\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`UserSignOutFailed`, () => { @@ -87,7 +87,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Failed to sign-out from Docs Build: Faked error msg\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); }); @@ -96,7 +96,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `[Faked Tag] Faked process msg\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); // Build @@ -108,7 +108,7 @@ describe('DocsLoggerObserver', () => { let expectedOutput = `Repository Information of current workspace folder:\n` + ` Local Repository URL: https://faked.repository\n` + `\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`Different original repository url with local repository url`, () => { @@ -118,7 +118,7 @@ describe('DocsLoggerObserver', () => { let expectedOutput = `Repository Information of current workspace folder:\n` + ` Local Repository URL: https://faked.local.repository(original: https://faked.original.repository)\n` + `\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); }); @@ -128,7 +128,7 @@ describe('DocsLoggerObserver', () => { let expectedOutput = `\n---------------------------\n` + `Preparing build context...\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`BuildStarted`, () => { @@ -136,7 +136,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Start to build workspace folder 'FakedWorkspaceFolderName'\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); describe('BuildCompleted', () => { @@ -145,7 +145,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Report generated, please view them in 'PROBLEMS' tab\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it('BuildCanceled', () => { @@ -153,7 +153,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Build has been canceled\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it('BuildFailed', () => { @@ -161,7 +161,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Build failed: Faked error msg\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); }); @@ -170,7 +170,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `faked msg\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); describe('DocfxRestoreCompleted', () => { @@ -179,7 +179,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Restore Finished, start to run 'docfx build'...\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`Docfx Restore failed`, () => { @@ -187,7 +187,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Error: Running 'docfx restore' failed with exit code: 1\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`Docfx Restore canceled`, () => { @@ -195,7 +195,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `'docfx restore' command has been canceled, skip running 'docfx build'\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); }); @@ -205,7 +205,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Build Finished, Generating report...\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`Docfx Build failed`, () => { @@ -213,7 +213,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Error: Running 'docfx build' failed with exit code: 1\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`Docfx Build canceled`, () => { @@ -221,7 +221,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `'docfx build' command has been canceled\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); }); @@ -231,7 +231,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `[OPBuildAPIClient.FakedAPIName] Calling API 'https://faked.api'...\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`APICallFailed`, () => { @@ -239,7 +239,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `[OPBuildAPIClient.FakedAPIName] Call API 'https://faked.api' failed: Faked msg\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); // Runtime Dependency @@ -248,7 +248,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Installing runtime dependencies...\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`DependencyInstallFinished`, () => { @@ -256,7 +256,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Runtime dependencies installation finished!\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`PackageInstallStarted`, () => { @@ -264,7 +264,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Installing package 'Faked package description'...\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`PackageInstallSucceeded`, () => { @@ -272,7 +272,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Package 'Faked package description' installed!\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); describe('PackageInstallFailed', () => { @@ -281,7 +281,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Failed to install package 'Faked package description': Faked error msg. Retrying..\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`Will not Retry`, () => { @@ -289,7 +289,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Failed to install package 'Faked package description': Faked error msg. Some features may not work as expected. Please restart Visual Studio Code to re-trigger the download.\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); }); @@ -299,8 +299,8 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Downloading package '${event.pkgDescription}' `; - expect(loggerText).to.equal(expectedOutput); - expect(observer.downloadProgressDotValue).to.equal(0); + assert.equal(loggerText, expectedOutput); + assert.equal(observer.downloadProgressDotValue, 0); }); it(`DownloadSizeObtained`, () => { @@ -308,7 +308,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `(2 KB)`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); describe('DownloadProgress', () => { @@ -317,7 +317,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = ` Done!\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it('5%', () => { @@ -326,8 +326,8 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `.`; - expect(loggerText).to.equal(expectedOutput); - expect(observer.downloadProgressDotValue).to.equal(1); + assert.equal(loggerText, expectedOutput); + assert.equal(observer.downloadProgressDotValue, 1); }); it('6%', () => { @@ -336,8 +336,8 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `..`; - expect(loggerText).to.equal(expectedOutput); - expect(observer.downloadProgressDotValue).to.equal(2); + assert.equal(loggerText, expectedOutput); + assert.equal(observer.downloadProgressDotValue, 2); }); }); @@ -346,7 +346,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Validating download...\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`DownloadIntegrityCheckFailed`, () => { @@ -354,7 +354,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Package download failed integrity check.\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`ZipFileInstalling`, () => { @@ -362,7 +362,7 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Installing zip file...\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); it(`PlatformInfoRetrieved`, () => { @@ -370,6 +370,6 @@ describe('DocsLoggerObserver', () => { observer.eventHandler(event); let expectedOutput = `Platform: faked-platform, faked-arch\n\n`; - expect(loggerText).to.equal(expectedOutput); + assert.equal(loggerText, expectedOutput); }); }); \ No newline at end of file diff --git a/test/unitTests/observers/docsOutputChannelObserver.test.ts b/test/unitTests/observers/docsOutputChannelObserver.test.ts index 1fd354a1..48bea2ba 100644 --- a/test/unitTests/observers/docsOutputChannelObserver.test.ts +++ b/test/unitTests/observers/docsOutputChannelObserver.test.ts @@ -1,4 +1,4 @@ -import { expect } from 'chai'; +import * as assert from 'assert'; import { OutputChannel } from 'vscode'; import { BaseEvent, DependencyInstallStarted, BuildInstantAllocated, UserSignInTriggered } from '../../../src/common/loggingEvents'; import { DocsOutputChannelObserver } from '../../../src/observers/docsOutputChannelObserver'; @@ -23,7 +23,7 @@ describe('DocsOutputChannelObserver', () => { ].forEach((event: BaseEvent) => { it(`${event.constructor.name}: Channel is shown and focused `, () => { observer.eventHandler(event); - expect(showCalled).to.be.true; + assert.equal(showCalled, true); }); }); }); \ No newline at end of file diff --git a/test/unitTests/observers/signStatusBarObserver.test.ts b/test/unitTests/observers/signStatusBarObserver.test.ts index d1475444..d30fcb03 100644 --- a/test/unitTests/observers/signStatusBarObserver.test.ts +++ b/test/unitTests/observers/signStatusBarObserver.test.ts @@ -1,4 +1,4 @@ -import { expect } from 'chai'; +import * as assert from 'assert'; import { SignStatusBarObserver } from '../../../src/observers/signStatusBarObserver'; import { StatusBarItem } from 'vscode'; import { CredentialInitializing, UserSignInSucceeded, CredentialRetrieveFromLocalCredentialManager, CredentialReset, UserSignInTriggered } from '../../../src/common/loggingEvents'; @@ -30,19 +30,19 @@ describe('SignStatusBarObserver', () => { it(`Initialization: Status bar is shown with 'Initializing' text`, () => { let event = new CredentialInitializing(); observer.eventHandler(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`Docs: Initializing`); - expect(statusBarItem.command).to.be.undefined; - expect(statusBarItem.tooltip).to.be.undefined; + assert.equal(showCalled, true); + assert.equal(statusBarItem.text, `Docs: Initializing`); + assert.equal(statusBarItem.command, undefined); + assert.equal(statusBarItem.tooltip, undefined); }); it(`User Signing in: Status bar is shown with 'Signing In' text`, () => { let event = new UserSignInTriggered('FakedCorrelationId'); observer.eventHandler(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`Docs: Signing-in`); - expect(statusBarItem.command).to.be.undefined; - expect(statusBarItem.tooltip).to.be.undefined; + assert.equal(showCalled, true); + assert.equal(statusBarItem.text, `Docs: Signing-in`); + assert.equal(statusBarItem.command, undefined); + assert.equal(statusBarItem.tooltip, undefined); }); it(`User Signed In: Status bar is shown with user info`, () => { @@ -57,10 +57,10 @@ describe('SignStatusBarObserver', () => { }, }); observer.eventHandler(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`Docs: $(mark-github) Fake User(fake@microsoft.com)`); - expect(statusBarItem.command).to.equal('docs.validationQuickPick'); - expect(statusBarItem.tooltip).to.be.undefined; + assert.equal(showCalled, true); + assert.equal(statusBarItem.text, `Docs: $(mark-github) Fake User(fake@microsoft.com)`); + assert.equal(statusBarItem.command, 'docs.validationQuickPick'); + assert.equal(statusBarItem.tooltip, undefined); }); it(`Fetch From Local Credential Manager: Status bar is shown with user info`, () => { @@ -75,19 +75,19 @@ describe('SignStatusBarObserver', () => { }, }); observer.eventHandler(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`Docs: $(mark-github) Fake User(fake@microsoft.com)`); - expect(statusBarItem.command).to.equal('docs.validationQuickPick'); - expect(statusBarItem.tooltip).to.be.undefined; + assert.equal(showCalled, true); + assert.equal(statusBarItem.text, `Docs: $(mark-github) Fake User(fake@microsoft.com)`); + assert.equal(statusBarItem.command, 'docs.validationQuickPick'); + assert.equal(statusBarItem.tooltip, undefined); }); it(`Reset User Info: Status bar is shown with 'Sign-in to Docs' text`, () => { let event = new CredentialReset(); observer.eventHandler(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`Docs: Sign-in to Docs`); - expect(statusBarItem.command).to.equal('docs.signIn'); - expect(statusBarItem.tooltip).to.be.undefined; + assert.equal(showCalled, true); + assert.equal(statusBarItem.text, `Docs: Sign-in to Docs`); + assert.equal(statusBarItem.command, 'docs.signIn'); + assert.equal(statusBarItem.tooltip, undefined); }); it(`PPE Environment: Status bar is shown with 'Docs(Sandbox):'`, () => { @@ -97,9 +97,9 @@ describe('SignStatusBarObserver', () => { // Test let event = new CredentialInitializing(); observer.eventHandler(event); - expect(showCalled).to.be.true; - expect(statusBarItem.text).to.equal(`Docs(Sandbox): Initializing`); - expect(statusBarItem.command).to.be.undefined; - expect(statusBarItem.tooltip).to.be.undefined; + assert.equal(showCalled, true); + assert.equal(statusBarItem.text, `Docs(Sandbox): Initializing`); + assert.equal(statusBarItem.command, undefined); + assert.equal(statusBarItem.tooltip, undefined); }); }); \ No newline at end of file diff --git a/test/unitTests/observers/telemetryObserver.test.ts b/test/unitTests/observers/telemetryObserver.test.ts index 802f2cf1..0095bd3a 100644 --- a/test/unitTests/observers/telemetryObserver.test.ts +++ b/test/unitTests/observers/telemetryObserver.test.ts @@ -1,4 +1,4 @@ -import { expect } from 'chai'; +import * as assert from 'assert'; import { UserSignInTriggered, UserSignInSucceeded, UserSignInFailed, UserSignOutTriggered, UserSignOutSucceeded, UserSignOutFailed, BuildCanceled, BuildFailed, BuildTriggered, BuildSucceeded, } from '../../../src/common/loggingEvents'; import { TelemetryObserver } from '../../../src/observers/telemetryObserver'; import TelemetryReporter from 'vscode-extension-telemetry'; @@ -40,8 +40,8 @@ describe('TelemetryObserver', () => { it(`UserSignInTriggered: 'SignIn.Triggered' event should be sent`, () => { let event = new UserSignInTriggered('fakedCorrelationId'); observer.eventHandler(event); - expect(sentEventName).to.equal('SignIn.Triggered'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'SignIn.Triggered'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'fakedCorrelationId' }); }); @@ -59,8 +59,8 @@ describe('TelemetryObserver', () => { } }); observer.eventHandler(event); - expect(sentEventName).to.equal('SignIn.Completed'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'SignIn.Completed'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'fakedCorrelationId', result: 'Succeeded', signInType: "GitHub", @@ -73,8 +73,8 @@ describe('TelemetryObserver', () => { it('UserSignInFailed', () => { let event = new UserSignInFailed('fakedCorrelationId', new DocsError('Faked error message', ErrorCode.AADSignInFailed)); observer.eventHandler(event); - expect(sentEventName).to.equal('SignIn.Completed'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'SignIn.Completed'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'fakedCorrelationId', result: 'Failed', signInType: undefined, @@ -88,8 +88,8 @@ describe('TelemetryObserver', () => { it(`UserSignOutTriggered: 'SignOut.Triggered' event should be sent`, () => { let event = new UserSignOutTriggered('fakedCorrelationId'); observer.eventHandler(event); - expect(sentEventName).to.equal('SignOut.Triggered'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'SignOut.Triggered'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'fakedCorrelationId' }); }); @@ -98,8 +98,8 @@ describe('TelemetryObserver', () => { it('UserSignOutSucceeded', () => { let event = new UserSignOutSucceeded('fakedCorrelationId'); observer.eventHandler(event); - expect(sentEventName).to.equal('SignOut.Completed'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'SignOut.Completed'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'fakedCorrelationId', result: 'Succeeded', }); @@ -108,8 +108,8 @@ describe('TelemetryObserver', () => { it('UserSignOutFailed', () => { let event = new UserSignOutFailed('fakedCorrelationId', new Error('Faked error message')); observer.eventHandler(event); - expect(sentEventName).to.equal('SignOut.Completed'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'SignOut.Completed'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'fakedCorrelationId', result: 'Failed', }); @@ -119,8 +119,8 @@ describe('TelemetryObserver', () => { it(`BuildTriggered: 'Build.Triggered' event should be sent`, () => { let event = new BuildTriggered('fakedCorrelationId'); observer.eventHandler(event); - expect(sentEventName).to.equal('Build.Triggered'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'Build.Triggered'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'fakedCorrelationId' }); }); @@ -145,8 +145,8 @@ describe('TelemetryObserver', () => { }); observer.eventHandler(event); - expect(sentEventName).to.equal('Build.Completed'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'Build.Completed'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'FakedCorrelationId', result: 'Succeeded', errorCode: undefined, @@ -156,7 +156,7 @@ describe('TelemetryObserver', () => { originalRepositoryUrl: 'https://faked.original-repository.com', localRepositoryBranch: 'master' }); - expect(sentEventMeasurements).to.deep.equal({ + assert.deepStrictEqual(sentEventMeasurements, { totalTimeInSeconds: 10, restoreTimeInSeconds: 4, buildTimeInSeconds: 5 @@ -177,8 +177,8 @@ describe('TelemetryObserver', () => { new DocsError('Faked error msg', ErrorCode.GenerateReportFailed)); observer.eventHandler(event); - expect(sentEventName).to.equal('Build.Completed'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'Build.Completed'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'FakedCorrelationId', result: 'Failed', errorCode: 'GenerateReportFailed', @@ -188,7 +188,7 @@ describe('TelemetryObserver', () => { originalRepositoryUrl: 'https://faked.original-repository.com', localRepositoryBranch: 'master' }); - expect(sentEventMeasurements).to.deep.equal({ + assert.deepStrictEqual(sentEventMeasurements, { totalTimeInSeconds: 10, restoreTimeInSeconds: undefined, buildTimeInSeconds: undefined @@ -208,8 +208,8 @@ describe('TelemetryObserver', () => { 10); observer.eventHandler(event); - expect(sentEventName).to.equal('Build.Completed'); - expect(sentEventProperties).to.deep.equal({ + assert.equal(sentEventName, 'Build.Completed'); + assert.deepStrictEqual(sentEventProperties, { correlationId: 'FakedCorrelationId', result: 'Canceled', errorCode: undefined, @@ -219,7 +219,7 @@ describe('TelemetryObserver', () => { originalRepositoryUrl: 'https://faked.original-repository.com', localRepositoryBranch: 'master' }); - expect(sentEventMeasurements).to.deep.equal({ + assert.deepStrictEqual(sentEventMeasurements, { totalTimeInSeconds: 10, restoreTimeInSeconds: undefined, buildTimeInSeconds: undefined