Properly expose errors in ads and tests (#8692)

* add code to expose errors outside zone

* remove unexpect error hiding

* remove uncessary code

* fix tests

* trying to catch more errros

* revert for testing

* wip

* wip

* figured out what was going on

* wip

* fix tests

* fix tests
This commit is contained in:
Anthony Dresser
2019-12-17 12:06:36 -08:00
committed by GitHub
parent 6b5c31410d
commit ea5f9be441
29 changed files with 483 additions and 790 deletions

View File

@@ -7,6 +7,7 @@ import * as azdata from 'azdata';
import { Event, Emitter } from 'vs/base/common/event';
import { IAccountManagementService } from 'sql/platform/accounts/common/interfaces';
import { AccountProviderAddedEventParams, UpdateAccountListEventParams } from 'sql/platform/accounts/common/eventTypes';
import { coalesce } from 'vs/base/common/arrays';
/**
* View model for account dialog
@@ -57,7 +58,7 @@ export class AccountViewModel {
},
() => { /* Swallow failures at getting accounts, we'll just hide that provider */ });
});
return Promise.all(promises);
return Promise.all(promises).then(accounts => coalesce(accounts));
}, () => {
/* Swallow failures and just pretend we don't have any providers */
return [];

View File

@@ -71,14 +71,14 @@ suite('Account picker view model tests', () => {
evUpdateAccounts.assertFired(argUpdateAccounts);
});
test('Initialize - Success', done => {
test('Initialize - Success', () => {
// Setup: Create a viewmodel with event handlers
let mockAccountManagementService = getMockAccountManagementService(true, true);
let evUpdateAccounts = new EventVerifierSingle<UpdateAccountListEventParams>();
let vm = getViewModel(mockAccountManagementService.object, evUpdateAccounts);
// If: I initialize the view model
vm.initialize()
return vm.initialize()
.then(results => {
// Then:
// ... None of the events should have fired
@@ -91,20 +91,17 @@ suite('Account picker view model tests', () => {
assert.ok(Array.isArray(results));
assert.equal(results.length, 2);
assert.equal(results, accounts);
}).then(
() => done(),
err => done(err)
);
});
});
test('Initialize - Get accounts fails expects empty array', done => {
test('Initialize - Get accounts fails expects empty array', () => {
// Setup: Create a mock account management service that rejects the promise
let mockAccountManagementService = getMockAccountManagementService(true, false);
let evUpdateAccounts = new EventVerifierSingle<UpdateAccountListEventParams>();
let vm = getViewModel(mockAccountManagementService.object, evUpdateAccounts);
// If: I initialize the view model
vm.initialize()
return vm.initialize()
.then(result => {
// Then:
// ... None of the events should have fired
@@ -116,11 +113,7 @@ suite('Account picker view model tests', () => {
// ... The results should be an empty array
assert.ok(Array.isArray(result));
assert.equal(result.length, 0);
assert.equal(result, []);
}).then(
() => done(),
err => done()
);
});
});
});

View File

@@ -9,13 +9,13 @@ import AccountStore from 'sql/platform/accounts/common/accountStore';
import { EventVerifierSingle } from 'sql/base/test/common/event';
suite('Account Store Tests', () => {
test('AddOrUpdate - Uninitialized memento', done => {
test('AddOrUpdate - Uninitialized memento', () => {
// Setup: Create account store w/o initialized memento
let memento = {};
let as = new AccountStore(memento);
// If: I add an account to the store
as.addOrUpdate(account1)
return as.addOrUpdate(account1)
.then(result => {
// Then:
// ... I should have gotten back a result indicating the account was added
@@ -27,21 +27,17 @@ suite('Account Store Tests', () => {
assert.ok(Array.isArray(memento[AccountStore.MEMENTO_KEY]));
assert.equal(memento[AccountStore.MEMENTO_KEY].length, 1);
assertAccountEqual(memento[AccountStore.MEMENTO_KEY][0], account1);
})
.then(
() => done(),
e => done(e)
);
});
});
test('AddOrUpdate - Adds to accounts', done => {
test('AddOrUpdate - Adds to accounts', () => {
// Setup: Create account store with initialized memento with accounts
let memento = {};
memento[AccountStore.MEMENTO_KEY] = [];
let as = new AccountStore(memento);
// If: I add an account to the store
as.addOrUpdate(account1)
return as.addOrUpdate(account1)
.then(result => {
// Then:
// ... I should have gotten back a result indicating the account was added
@@ -53,14 +49,10 @@ suite('Account Store Tests', () => {
assert.ok(Array.isArray(memento[AccountStore.MEMENTO_KEY]));
assert.equal(memento[AccountStore.MEMENTO_KEY].length, 1);
assertAccountEqual(memento[AccountStore.MEMENTO_KEY][0], account1);
})
.then(
() => done(),
e => done(e)
);
});
});
test('AddOrUpdate - Updates account', done => {
test('AddOrUpdate - Updates account', () => {
// Setup: Create account store with initialized memento with accounts
let memento = getTestMemento();
let as = new AccountStore(memento);
@@ -71,7 +63,7 @@ suite('Account Store Tests', () => {
displayInfo: account1.displayInfo,
isStale: account1.isStale
};
as.addOrUpdate(param)
return as.addOrUpdate(param)
.then(result => {
// Then:
// ... I should have gotten back a result indicating the account was updated
@@ -84,20 +76,16 @@ suite('Account Store Tests', () => {
assert.equal(memento[AccountStore.MEMENTO_KEY].length, 2);
assertAccountEqual(memento[AccountStore.MEMENTO_KEY][0], account1);
assertAccountEqual(memento[AccountStore.MEMENTO_KEY][1], param);
})
.then(
() => done(),
e => done(e)
);
});
});
test('GetAccountsByProvider - Uninitialized memento', done => {
test('GetAccountsByProvider - Uninitialized memento', () => {
// Setup: Create account store w/o initialized memento
let memento = {};
let as = new AccountStore(memento);
// If: I get accounts by provider
as.getAccountsByProvider('azure')
return as.getAccountsByProvider('azure')
.then(result => {
// Then:
// ... I should get back an empty array
@@ -106,77 +94,61 @@ suite('Account Store Tests', () => {
// ... Memento should not have been written
assert.equal(Object.keys(memento).length, 0);
})
.then(
() => done(),
e => done(e)
);
});
});
test('GetAccountsByProvider - No accounts', done => {
test('GetAccountsByProvider - No accounts', () => {
// Setup: Create account store with initialized memento with accounts
let memento = {};
memento[AccountStore.MEMENTO_KEY] = [];
let as = new AccountStore(memento);
// If: I get accounts when there aren't any accounts
as.getAccountsByProvider('azure')
return as.getAccountsByProvider('azure')
.then(result => {
// Then: I should get back an empty array
assert.ok(Array.isArray(result));
assert.equal(result.length, 0);
})
.then(
() => done(),
e => done(e)
);
});
});
test('GetAccountsByProvider - Accounts, but no accounts for provider', done => {
test('GetAccountsByProvider - Accounts, but no accounts for provider', () => {
// Setup: Create account store with initialized memento with accounts
let memento = getTestMemento();
let as = new AccountStore(memento);
// If: I get accounts by provider that doesn't have accounts
as.getAccountsByProvider('cloudycloud')
return as.getAccountsByProvider('cloudycloud')
.then(result => {
// Then: I should get back an empty array
assert.ok(Array.isArray(result));
assert.equal(result.length, 0);
})
.then(
() => done(),
e => done(e)
);
});
});
test('GetAccountsByProvider - Accounts for provider', done => {
test('GetAccountsByProvider - Accounts for provider', () => {
// Setup: Create account store with initialized memento with accounts
let memento = getTestMemento();
let as = new AccountStore(memento);
// If: I get accounts by provider that has accounts
as.getAccountsByProvider('azure')
return as.getAccountsByProvider('azure')
.then(result => {
// Then: I should get the accounts
assert.ok(Array.isArray(result));
assert.equal(result.length, 2);
assertAccountEqual(result[0], memento[AccountStore.MEMENTO_KEY][0]);
assertAccountEqual(result[1], memento[AccountStore.MEMENTO_KEY][1]);
})
.then(
() => done(),
e => done(e)
);
});
});
test('GetAllAccounts - Uninitialized memento', done => {
test('GetAllAccounts - Uninitialized memento', () => {
// Setup: Create account store w/o initialized memento
let memento = {};
let as = new AccountStore(memento);
// If: I get accounts
as.getAllAccounts()
return as.getAllAccounts()
.then(result => {
// Then:
// ... I should get back an empty array
@@ -185,59 +157,47 @@ suite('Account Store Tests', () => {
// ... Memento should not have been written
assert.equal(Object.keys(memento).length, 0);
})
.then(
() => done(),
e => done(e)
);
});
});
test('GetAllAccounts - No accounts', done => {
test('GetAllAccounts - No accounts', () => {
// Setup: Create account store with initialized memento with accounts
let memento = {};
memento[AccountStore.MEMENTO_KEY] = [];
let as = new AccountStore(memento);
// If: I get accounts when there aren't any accounts
as.getAllAccounts()
return as.getAllAccounts()
.then(result => {
// Then: I should get back an empty array
assert.ok(Array.isArray(result));
assert.equal(result.length, 0);
})
.then(
() => done(),
e => done(e)
);
});
});
test('GetAllAccounts - Accounts', done => {
test('GetAllAccounts - Accounts', () => {
// Setup: Create account store with initialized memento with accounts
let memento = getTestMemento();
let as = new AccountStore(memento);
// If: I get accounts
as.getAllAccounts()
return as.getAllAccounts()
.then(result => {
// Then: I should get the accounts
assert.ok(Array.isArray(result));
assert.equal(result.length, 2);
assertAccountEqual(result[0], memento[AccountStore.MEMENTO_KEY][0]);
assertAccountEqual(result[1], memento[AccountStore.MEMENTO_KEY][1]);
})
.then(
() => done(),
e => done(e)
);
});
});
test('Remove - Uninitialized menento', done => {
test('Remove - Uninitialized menento', () => {
// Setup: Create account store w/o initialized memento
let memento = {};
let as = new AccountStore(memento);
// If: I remove an account when there's an uninitialized memento
as.remove(account1.key)
return as.remove(account1.key)
.then(result => {
// Then:
// ... I should get back false (no account removed)
@@ -246,21 +206,17 @@ suite('Account Store Tests', () => {
// ... The memento should have been initialized
assert.ok(Array.isArray(memento[AccountStore.MEMENTO_KEY]));
assert.equal(memento[AccountStore.MEMENTO_KEY].length, 0);
})
.then(
() => done(),
e => done(e)
);
});
});
test('Remove - Account does not exist', done => {
test('Remove - Account does not exist', () => {
// Setup: Create account store with initialized memento with accounts
let memento = {};
memento[AccountStore.MEMENTO_KEY] = [];
let as = new AccountStore(memento);
// If: I remove an account that doesn't exist
as.remove({ providerId: 'cloudyCloud', accountId: 'testyTest' })
return as.remove({ providerId: 'cloudyCloud', accountId: 'testyTest' })
.then(result => {
// Then:
// ... I should get back false (no account removed)
@@ -269,20 +225,16 @@ suite('Account Store Tests', () => {
// ... The memento should still be empty
assert.ok(Array.isArray(memento[AccountStore.MEMENTO_KEY]));
assert.equal(memento[AccountStore.MEMENTO_KEY].length, 0);
})
.then(
() => done(),
e => done(e)
);
});
});
test('Remove - Account exists', done => {
test('Remove - Account exists', () => {
// Setup: Create account store with initialized memento with accounts
let memento = getTestMemento();
let as = new AccountStore(memento);
// If: I remove an account that does exist
as.remove(account1.key)
return as.remove(account1.key)
.then(result => {
// Then:
// ... I should get back true (account removed)
@@ -292,14 +244,10 @@ suite('Account Store Tests', () => {
assert.ok(Array.isArray(memento[AccountStore.MEMENTO_KEY]));
assert.equal(memento[AccountStore.MEMENTO_KEY].length, 1);
assertAccountEqual(memento[AccountStore.MEMENTO_KEY][0], account2);
})
.then(
() => done(),
e => done(e)
);
});
});
test('Update - Uninitialized menento', done => {
test('Update - Uninitialized menento', () => {
// Setup:
// ... Create account store w/o initialized memento
let memento = {};
@@ -309,7 +257,7 @@ suite('Account Store Tests', () => {
let updateCallback = new EventVerifierSingle<azdata.Account>();
// If: I update an account
as.update(account1.key, updateCallback.eventHandler)
return as.update(account1.key, updateCallback.eventHandler)
.then(result => {
// Then:
// ... I should get back false (account did not change)
@@ -321,14 +269,10 @@ suite('Account Store Tests', () => {
// ... The callback shouldn't have been called
updateCallback.assertNotFired();
})
.then(
() => done(),
e => done(e)
);
});
});
test('Update - Account does not exist', done => {
test('Update - Account does not exist', () => {
// Setup: Create account store with initialized memento with accounts
let memento = {};
memento[AccountStore.MEMENTO_KEY] = [];
@@ -338,7 +282,7 @@ suite('Account Store Tests', () => {
let updateCallback = new EventVerifierSingle<azdata.Account>();
// If: I update an account that doesn't exist
as.update({ accountId: 'testyTest', providerId: 'cloudyCloud' }, updateCallback.eventHandler)
return as.update({ accountId: 'testyTest', providerId: 'cloudyCloud' }, updateCallback.eventHandler)
.then(result => {
// Then:
// ... I should get back false (account did not change)
@@ -350,14 +294,10 @@ suite('Account Store Tests', () => {
// ... The callback shouldn't have been called
updateCallback.assertNotFired();
})
.then(
() => done(),
e => done(e)
);
});
});
test('Update - Account exists', done => {
test('Update - Account exists', () => {
// Setup: Create account store with initialized memento with accounts
let memento = getTestMemento();
let as = new AccountStore(memento);
@@ -369,7 +309,7 @@ suite('Account Store Tests', () => {
};
// If: I update an account that exists
as.update(account1.key, updateCallback)
return as.update(account1.key, updateCallback)
.then(result => {
// Then:
// ... I should get back true (account did change)
@@ -384,11 +324,7 @@ suite('Account Store Tests', () => {
// ... Account 2 should have stayed the same
assertAccountEqual(memento[AccountStore.MEMENTO_KEY][1], account2);
})
.then(
() => done(),
e => done(e)
);
});
});
// TODO: Test to make sure operations occur sequentially

View File

@@ -91,7 +91,7 @@ suite('Account Management Dialog ViewModel Tests', () => {
evUpdateAccounts.assertFired(argUpdateAccounts);
});
test('Initialize - Success', done => {
test('Initialize - Success', () => {
// Setup: Create a viewmodel with event handlers
let mockAccountManagementService = getMockAccountManagementService(true, true);
let evAddProvider = new EventVerifierSingle<AccountProviderAddedEventParams>();
@@ -100,7 +100,7 @@ suite('Account Management Dialog ViewModel Tests', () => {
let vm = getViewModel(mockAccountManagementService.object, evAddProvider, evRemoveProvider, evUpdateAccounts);
// If: I initialize the view model
vm.initialize()
return vm.initialize()
.then(results => {
// Then:
// ... None of the events should have fired
@@ -115,13 +115,10 @@ suite('Account Management Dialog ViewModel Tests', () => {
assert.equal(results.length, 1);
assert.equal(results[0].addedProvider, providers[0]);
assert.equal(results[0].initialAccounts, accounts);
}).then(
() => done(),
err => done(err)
);
});
});
test('Initialize - Get providers fails', done => {
test('Initialize - Get providers fails', () => {
// Setup: Create a mock account management service that rejects looking up providers
let mockAccountManagementService = getMockAccountManagementService(false, true);
let evAddProvider = new EventVerifierSingle<AccountProviderAddedEventParams>();
@@ -130,7 +127,7 @@ suite('Account Management Dialog ViewModel Tests', () => {
let vm = getViewModel(mockAccountManagementService.object, evAddProvider, evRemoveProvider, evUpdateAccounts);
// If: I initialize the view model
vm.initialize()
return vm.initialize()
.then(results => {
// Then
// ... None of the events should have fired
@@ -143,14 +140,10 @@ suite('Account Management Dialog ViewModel Tests', () => {
// ... The results that were returned should be an empty array
assert.ok(Array.isArray(results));
assert.equal(results.length, 0);
})
.then(
() => done(),
err => done(err)
);
});
});
test('Initialize - Get accounts fails', done => {
test.skip('Initialize - Get accounts fails', () => { // @anthonydresser I don't understand this test, it says get accounts fails, but then assumes there will be accounts in the results...
// Setup: Create a mock account management service that rejects the promise
let mockAccountManagementService = getMockAccountManagementService(true, false);
let evAddProvider = new EventVerifierSingle<AccountProviderAddedEventParams>();
@@ -159,7 +152,7 @@ suite('Account Management Dialog ViewModel Tests', () => {
let vm = getViewModel(mockAccountManagementService.object, evAddProvider, evRemoveProvider, evUpdateAccounts);
// If: I initialize the view model
vm.initialize()
return vm.initialize()
.then(result => {
// Then:
// ... None of the events should have fired
@@ -174,10 +167,7 @@ suite('Account Management Dialog ViewModel Tests', () => {
assert.equal(result.length, 1);
assert.equal(result[0].addedProvider, providers[0]);
assert.equal(result[0].initialAccounts, accounts);
}).then(
() => done(),
err => done()
);
});
});
});