Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use assert #56

Merged
merged 3 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions test/componentTests/index.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const nyc = process.env.COVERAGE ? setupCoverage() : undefined;
const mocha = new Mocha({
Expand Down
18 changes: 9 additions & 9 deletions test/unitTests/credential/keychain.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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);
});
});
31 changes: 14 additions & 17 deletions test/unitTests/dependency/fileDownloader.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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),
Expand All @@ -71,25 +68,25 @@ 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),
new DownloadValidating(),
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),
Expand All @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions test/unitTests/observers/buildStatusBarObserver.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
});
});
Loading