link up errors in tests to promises

This commit is contained in:
Joao Moreno 2016-12-01 08:34:46 +01:00
parent c751c0cdaf
commit 7423b776ea

View file

@ -9,6 +9,7 @@ import * as sinon from 'sinon';
import * as assert from 'assert';
import * as fs from 'fs';
import { assign } from 'vs/base/common/objects';
import { TPromise } from 'vs/base/common/winjs.base';
import { generateUuid } from 'vs/base/common/uuid';
import { IExtensionsWorkbenchService, ExtensionState } from 'vs/workbench/parts/extensions/common/extensions';
import { ExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/node/extensionsWorkbenchService';
@ -70,7 +71,7 @@ suite('ExtensionsWorkbenchService Test', () => {
(<ExtensionsWorkbenchService>testObject).dispose();
});
test('test gallery extension', (done) => {
test('test gallery extension', () => {
const expected = aGalleryExtension('expectedName', {
displayName: 'expectedDisplayName',
version: '1.5',
@ -92,9 +93,11 @@ suite('ExtensionsWorkbenchService Test', () => {
iconFallback: 'expectedIconFallback',
license: 'expectedLicense'
});
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(expected));
testObject.queryGallery().done(pagedResponse => {
return testObject.queryGallery().then(pagedResponse => {
assert.equal(1, pagedResponse.firstPage.length);
const actual = pagedResponse.firstPage[0];
@ -116,7 +119,6 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.equal(100, actual.ratingCount);
assert.equal(false, actual.outdated);
assert.deepEqual(['pub.1', 'pub.2'], actual.dependencies);
done();
});
});
@ -194,7 +196,7 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.deepEqual([], actual.dependencies);
});
test('test installed extensions get syncs with gallery', (done) => {
test('test installed extensions get syncs with gallery', () => {
const local1 = aLocalExtension('local1', {
publisher: 'localPublisher1',
version: '1.1.0',
@ -244,7 +246,7 @@ suite('ExtensionsWorkbenchService Test', () => {
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery1));
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
listenAfter(testObject.onChange)(() => {
return eventToPromise(testObject.onChange).then(() => {
const actuals = testObject.local;
assert.equal(2, actuals.length);
@ -284,16 +286,15 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.equal(null, actual.ratingCount);
assert.equal(false, actual.outdated);
assert.deepEqual([], actual.dependencies);
done();
});
});
test('test extension state computation', (done) => {
test('test extension state computation', () => {
const gallery = aGalleryExtension('gallery1');
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
testObject.queryGallery().done(page => {
return testObject.queryGallery().then(page => {
const extension = page.firstPage[0];
assert.equal(ExtensionState.Uninstalled, extension.state);
@ -323,7 +324,6 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.equal(ExtensionState.Uninstalled, actual.state);
assert.equal(0, testObject.local.length);
done();
});
});
@ -348,26 +348,25 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.ok(!testObject.canInstall(target));
});
test('test canInstall returns true for extensions with gallery', (done) => {
test('test canInstall returns true for extensions with gallery', () => {
const local = aLocalExtension('a', { version: '1.0.1' }, { type: LocalExtensionType.System });
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension(local.manifest.name, { id: local.id })));
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
const target = testObject.local[0];
listenAfter(testObject.onChange)(() => {
return eventToPromise(testObject.onChange).then(() => {
assert.ok(testObject.canInstall(target));
done();
});
});
test('test onchange event is triggered while installing', (done) => {
test('test onchange event is triggered while installing', () => {
const gallery = aGalleryExtension('gallery1');
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
const target = sinon.spy();
testObject.queryGallery().done(page => {
return testObject.queryGallery().then(page => {
const extension = page.firstPage[0];
assert.equal(ExtensionState.Uninstalled, extension.state);
@ -379,17 +378,16 @@ suite('ExtensionsWorkbenchService Test', () => {
didInstallEvent.fire({ id: gallery.id, gallery, local: aLocalExtension(gallery.name, gallery, gallery) });
assert.ok(target.calledOnce);
done();
});
});
test('test onchange event is triggered when installation is finished', (done) => {
test('test onchange event is triggered when installation is finished', () => {
const gallery = aGalleryExtension('gallery1');
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(gallery));
const target = sinon.spy();
testObject.queryGallery().done(page => {
return testObject.queryGallery().then(page => {
const extension = page.firstPage[0];
assert.equal(ExtensionState.Uninstalled, extension.state);
@ -400,7 +398,6 @@ suite('ExtensionsWorkbenchService Test', () => {
installEvent.fire({ id: gallery.id, gallery });
assert.ok(target.calledOnce);
done();
});
});
@ -431,26 +428,25 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.ok(target.calledOnce);
});
test('test extension dependencies when empty', (done) => {
test('test extension dependencies when empty', () => {
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a')));
testObject.queryGallery().done(page => {
testObject.loadDependencies(page.firstPage[0]).done(dependencies => {
return testObject.queryGallery().then(page => {
return testObject.loadDependencies(page.firstPage[0]).then(dependencies => {
assert.equal(null, dependencies);
done();
});
});
});
test('test one level extension dependencies without cycle', (done) => {
test('test one level extension dependencies without cycle', () => {
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', {}, { dependencies: ['pub.b', 'pub.c', 'pub.d'] })));
instantiationService.stubPromise(IExtensionGalleryService, 'getAllDependencies', [aGalleryExtension('b'), aGalleryExtension('c'), aGalleryExtension('d')]);
testObject.queryGallery().done(page => {
return testObject.queryGallery().then(page => {
const extension = page.firstPage[0];
testObject.loadDependencies(extension).done(actual => {
return testObject.loadDependencies(extension).then(actual => {
assert.ok(actual.hasDependencies);
assert.equal(extension, actual.extension);
assert.equal(null, actual.dependent);
@ -478,19 +474,18 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.equal('pub.d', actual.identifier);
assert.equal(dependent, actual.dependent);
assert.equal(0, actual.dependencies.length);
done();
});
});
});
test('test one level extension dependencies with cycle', (done) => {
test('test one level extension dependencies with cycle', () => {
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', {}, { dependencies: ['pub.b', 'pub.a'] })));
instantiationService.stubPromise(IExtensionGalleryService, 'getAllDependencies', [aGalleryExtension('b'), aGalleryExtension('a')]);
testObject.queryGallery().done(page => {
return testObject.queryGallery().then(page => {
const extension = page.firstPage[0];
testObject.loadDependencies(extension).done(actual => {
return testObject.loadDependencies(extension).then(actual => {
assert.ok(actual.hasDependencies);
assert.equal(extension, actual.extension);
assert.equal(null, actual.dependent);
@ -511,20 +506,18 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.equal('pub.a', actual.identifier);
assert.equal(dependent, actual.dependent);
assert.equal(0, actual.dependencies.length);
done();
});
});
});
test('test one level extension dependencies with missing dependencies', (done) => {
test('test one level extension dependencies with missing dependencies', () => {
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', {}, { dependencies: ['pub.b', 'pub.a'] })));
instantiationService.stubPromise(IExtensionGalleryService, 'getAllDependencies', [aGalleryExtension('a')]);
testObject.queryGallery().done(page => {
return testObject.queryGallery().then(page => {
const extension = page.firstPage[0];
testObject.loadDependencies(extension).done(actual => {
return testObject.loadDependencies(extension).then(actual => {
assert.ok(actual.hasDependencies);
assert.equal(extension, actual.extension);
assert.equal(null, actual.dependent);
@ -545,22 +538,20 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.equal('pub.a', actual.identifier);
assert.equal(dependent, actual.dependent);
assert.equal(0, actual.dependencies.length);
done();
});
});
});
test('test one level extension dependencies with in built dependencies', (done) => {
test('test one level extension dependencies with in built dependencies', () => {
const local = aLocalExtension('inbuilt', {}, { type: LocalExtensionType.System });
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a', {}, { dependencies: ['pub.inbuilt', 'pub.a'] })));
instantiationService.stubPromise(IExtensionGalleryService, 'getAllDependencies', [aGalleryExtension('a')]);
testObject.queryGallery().done(page => {
return testObject.queryGallery().then(page => {
const extension = page.firstPage[0];
testObject.loadDependencies(extension).done(actual => {
return testObject.loadDependencies(extension).then(actual => {
assert.ok(actual.hasDependencies);
assert.equal(extension, actual.extension);
assert.equal(null, actual.dependent);
@ -582,13 +573,11 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.equal('pub.a', actual.identifier);
assert.equal(dependent, actual.dependent);
assert.equal(0, actual.dependencies.length);
done();
});
});
});
test('test more than one level of extension dependencies', (done) => {
test('test more than one level of extension dependencies', () => {
const local = aLocalExtension('c', { extensionDependencies: ['pub.d'] }, { type: LocalExtensionType.System });
instantiationService.stubPromise(IExtensionManagementService, 'getInstalled', [local]);
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
@ -598,9 +587,9 @@ suite('ExtensionsWorkbenchService Test', () => {
aGalleryExtension('d', {}, { dependencies: ['pub.f', 'pub.c'] }),
aGalleryExtension('e')]);
testObject.queryGallery().done(page => {
return testObject.queryGallery().then(page => {
const extension = page.firstPage[0];
testObject.loadDependencies(extension).done(a => {
return testObject.loadDependencies(extension).then(a => {
assert.ok(a.hasDependencies);
assert.equal(extension, a.extension);
assert.equal(null, a.dependent);
@ -677,25 +666,21 @@ suite('ExtensionsWorkbenchService Test', () => {
assert.equal('pub.c', c.identifier);
assert.equal(d, c.dependent);
assert.equal(0, c.dependencies.length);
done();
});
});
});
test('test disabled flags are false for uninstalled extension', (done) => {
test('test disabled flags are false for uninstalled extension', () => {
instantiationService.get(IExtensionEnablementService).setEnablement('pub.b', false);
instantiationService.get(IExtensionEnablementService).setEnablement('pub.c', false, true);
testObject = instantiationService.createInstance(ExtensionsWorkbenchService);
instantiationService.stubPromise(IExtensionGalleryService, 'query', aPage(aGalleryExtension('a')));
testObject.queryGallery().done(pagedResponse => {
return testObject.queryGallery().then(pagedResponse => {
const actual = pagedResponse.firstPage[0];
assert.ok(!actual.disabledForWorkspace);
assert.ok(!actual.disabledGlobally);
done();
});
});
test('test disabled flags are false for installed enabled extension', () => {
@ -845,15 +830,14 @@ suite('ExtensionsWorkbenchService Test', () => {
return { firstPage: objects, total: objects.length, pageSize: objects.length, getPage: () => null };
}
function listenAfter(event: Event<any>, count: number = 1): Event<any> {
let counter = 0;
const emitter = new Emitter<any>();
event(() => {
if (++counter === count) {
emitter.fire();
emitter.dispose();
}
function eventToPromise(event: Event<any>, count: number = 1): TPromise<void> {
return new TPromise<void>(c => {
let counter = 0;
event(() => {
if (++counter === count) {
c(null);
}
});
});
return emitter.event;
}
});