Fix rest of notebook unhandled promises (#16933)

* Fix rest of notebook unhandled promises

* add rule

* fix some tests
This commit is contained in:
Charles Gagnon
2021-08-30 14:14:48 -07:00
committed by GitHub
parent 26e08fdf9e
commit 76e01fee60
21 changed files with 79 additions and 53 deletions

View File

@@ -146,7 +146,7 @@ describe('BookPinManagerTests', function () {
should(isNotebookPinnedBeforeChange).be.false('Notebook should NOT be pinned');
// mock pin book item from viewlet
bookPinManager.pinNotebook(books[0].bookItems[1]);
await bookPinManager.pinNotebook(books[0].bookItems[1]);
let isNotebookPinnedAfterChange = isBookItemPinned(notebookUri);
should(isNotebookPinnedAfterChange).be.true('Notebook should be pinned');
@@ -158,7 +158,7 @@ describe('BookPinManagerTests', function () {
should(isNotebookPinned).be.true('Notebook should be pinned');
bookPinManager.unpinNotebook(books[0].bookItems[0]);
await bookPinManager.unpinNotebook(books[0].bookItems[0]);
let isNotebookPinnedAfterChange = isBookItemPinned(notebookUri);
should(isNotebookPinnedAfterChange).be.false('Notebook should not be pinned after notebook is unpinned');

View File

@@ -31,7 +31,7 @@ describe('Github Remote Book', function () {
it('Verify GitHub Remote Book is created by controller', async function (): Promise<void> {
let releaseURL = vscode.Uri.parse('https://api.github.com/repos/microsoft/test/releases/v1');
let asset : IAsset = {
let asset: IAsset = {
name: 'CU-1.0-EN.zip',
book: 'CU',
version: '1.0',
@@ -41,7 +41,13 @@ describe('Github Remote Book', function () {
browserDownloadUrl: vscode.Uri.parse('https://github.com/microsoft/test/releases/download/v1/CU-1.0-EN.zip'),
};
let remoteLocation = loc.onGitHub;
controller.setRemoteBook(releaseURL, remoteLocation, asset);
nock('https://github.com')
.persist()
.get('/microsoft/test/releases/download/v1/CU-1.0-EN.zip')
.replyWithFile(200, __filename);
// Aren't returning an actual zip so just stub this out since we don't care about actually testing that functionality currently
sinon.stub(GitHubRemoteBook.prototype, 'extractFiles').resolves();
await controller.setRemoteBook(releaseURL, remoteLocation, asset);
should(controller.model.remoteBook).not.null();
should(controller.model.remoteBook instanceof GitHubRemoteBook).be.true();
let book = model.remoteBook as GitHubRemoteBook;
@@ -50,7 +56,7 @@ describe('Github Remote Book', function () {
it('Verify set local path is called when creating a GitHub Remote Book', async function (): Promise<void> {
let releaseURL = vscode.Uri.parse('https://api.github.com/repos/microsoft/test/releases/v1');
let asset : IAsset = {
let asset: IAsset = {
name: 'CU-1.0-EN.zip',
book: 'CU',
version: '1.0',
@@ -60,16 +66,22 @@ describe('Github Remote Book', function () {
browserDownloadUrl: vscode.Uri.parse('https://github.com/microsoft/test/releases/download/v1/CU-1.0-EN.zip'),
};
let remoteLocation = loc.onGitHub;
nock('https://github.com')
.persist()
.get('/microsoft/test/releases/download/v1/CU-1.0-EN.zip')
.replyWithFile(200, __filename);
// Aren't returning an actual zip so just stub this out since we don't care about actually testing that functionality currently
const createCopySpy = sinon.spy(GitHubRemoteBook.prototype, 'createLocalCopy');
sinon.stub(GitHubRemoteBook.prototype, 'extractFiles').resolves();
const setPathSpy = sinon.spy(RemoteBook.prototype, 'setLocalPath');
controller.setRemoteBook(releaseURL, remoteLocation, asset);
should(createCopySpy.calledOnce).be.true();
should(setPathSpy.calledOnce).be.true();
await controller.setRemoteBook(releaseURL, remoteLocation, asset);
should(createCopySpy.calledOnce).be.true('createLocalCopy not called');
should(setPathSpy.calledOnce).be.true('setLocalPath not called');
});
it('Should download contents from Github', async function (): Promise<void> {
let releaseURL = vscode.Uri.parse('https://api.github.com/repos/microsoft/test/releases/v1');
let asset : IAsset = {
let asset: IAsset = {
name: 'CU-1.0-EN.zip',
book: 'CU',
version: '1.0',
@@ -79,18 +91,19 @@ describe('Github Remote Book', function () {
browserDownloadUrl: vscode.Uri.parse('https://github.com/microsoft/test/releases/download/v1/CU-1.0-EN.zip'),
};
let remoteLocation = loc.onGitHub;
controller.setRemoteBook(releaseURL, remoteLocation, asset);
const setExtractSpy = sinon.spy(GitHubRemoteBook.prototype, 'extractFiles');
nock('https://github.com')
.persist()
.get('/microsoft/test/releases/download/v1/CU-1.0-EN.zip')
.replyWithFile(200, __filename);
await controller.setRemoteBook(releaseURL, remoteLocation, asset);
model.remoteBook.localPath = vscode.Uri.file(os.tmpdir());
let setPathStub = sinon.stub(GitHubRemoteBook.prototype, 'setLocalPath');
setPathStub.callsFake(function() {
setPathStub.callsFake(function () {
console.log(`Downloading book in ${model.remoteBook.localPath}`);
});
const setExtractSpy = sinon.spy(GitHubRemoteBook.prototype, 'extractFiles');
nock('https://github.com')
.persist()
.get('/microsoft/test/releases/download/v1/CU-1.0-EN.zip')
.replyWithFile(200, __filename);
await model.remoteBook.createLocalCopy();
should(setExtractSpy.calledOnceWith(vscode.Uri.file(model.remoteBook.localPath.fsPath)));
await fs.promises.stat(model.remoteBook.localPath.fsPath);
@@ -98,18 +111,18 @@ describe('Github Remote Book', function () {
it('Should reject if unexpected error', async function (): Promise<void> {
nock('https://github.com')
.persist()
.get('/microsoft/test/releases/download/v1/CU-1.0-EN.zip')
.replyWithError(new Error('Unexpected Error'));
.persist()
.get('/microsoft/test/releases/download/v1/CU-1.0-EN.zip')
.replyWithError(new Error('Unexpected Error'));
await should(model.remoteBook.createLocalCopy()).be.rejected();
});
it('Should reject if response status code is not 200', async function (): Promise<void> {
nock('https://github.com')
.persist()
.get('/microsoft/test/releases/download/v1/CU-1.0-EN.zip')
.reply(404);
const createLocalCopy = model.remoteBook.createLocalCopy();
.persist()
.get('/microsoft/test/releases/download/v1/CU-1.0-EN.zip')
.reply(404);
const createLocalCopy = model.remoteBook.createLocalCopy();
await should(createLocalCopy).be.rejected();
});
});

View File

@@ -82,7 +82,7 @@ describe('notebookUtils Tests', function (): void {
should(azdata.nb.notebookDocuments.find(doc => doc.fileName === notebookUri.fsPath)).not.be.undefined();
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
} finally {
tryDeleteFile(notebookPath);
await tryDeleteFile(notebookPath);
}
});

View File

@@ -55,7 +55,7 @@ describe('Manage Packages', () => {
await should(model.installPackages([])).rejected();
await should(model.uninstallPackages([])).rejected();
should.equal(await model.getLocations(), undefined, 'Get Locations should be undefined before provider is set');
should(model.getPackageOverview('package')).rejected();
await should(model.getPackageOverview('package')).rejected();
// Change provider and then retest functions which throw without valid provider
model.changeProvider(provider.providerId);
@@ -63,7 +63,7 @@ describe('Manage Packages', () => {
await should(model.installPackages([])).resolved();
await should(model.uninstallPackages([])).resolved();
should.deepEqual(await model.getLocations(), await provider.getLocations(), 'Get Locations should be valid after provider is set');
should(model.getPackageOverview('p1')).resolved();
await should(model.getPackageOverview('p1')).resolved();
model.changeLocation('location1');
});

View File

@@ -78,7 +78,7 @@ describe('Jupyter Controller', function () {
await controller.activate();
should(controller.notebookProvider.standardKernels).deepEqual([], 'Notebook provider standard kernels should return empty array');
should(controller.notebookProvider.providerId).equal('jupyter', 'Notebook provider should be jupyter');
should(controller.notebookProvider.getNotebookManager(undefined)).be.rejected();
await should(controller.notebookProvider.getNotebookManager(undefined)).be.rejected();
should(controller.notebookProvider.notebookManagerCount).equal(0);
controller.notebookProvider.handleNotebookClosed(undefined);
});

View File

@@ -146,7 +146,7 @@ describe('Jupyter Future', function (): void {
})
});
should(handler).not.be.undefined();
verifyRelayMessage('shell', handler, () => msg);
await verifyRelayMessage('shell', handler, () => msg);
});
@@ -162,7 +162,7 @@ describe('Jupyter Future', function (): void {
})
});
should(handler).not.be.undefined();
verifyRelayMessage('stdin', handler, () => msg);
await verifyRelayMessage('stdin', handler, () => msg);
});
it('should relay IOPub message', async function (): Promise<void> {
@@ -177,11 +177,11 @@ describe('Jupyter Future', function (): void {
})
});
should(handler).not.be.undefined();
verifyRelayMessage('iopub', handler, () => msg);
await verifyRelayMessage('iopub', handler, () => msg);
});
function verifyRelayMessage(channel: nb.Channel | KernelMessage.Channel, handler: (msg: KernelMessage.IMessage) => void | PromiseLike<void>, getMessage: () => nb.IMessage): void {
handler({
async function verifyRelayMessage(channel: nb.Channel | KernelMessage.Channel, handler: (msg: KernelMessage.IMessage) => void | PromiseLike<void>, getMessage: () => nb.IMessage): Promise<void> {
await handler({
channel: <any>channel,
content: { value: 'test' },
metadata: { value: 'test' },

View File

@@ -65,7 +65,7 @@ describe('Jupyter Session Manager', function (): void {
sessionManager.ready.then(() => {
should(sessionManager.isReady).be.true();
done();
});
}).catch(err => done(err));
});
it('should passthrough the ready calls', function (done): void {
@@ -75,7 +75,7 @@ describe('Jupyter Session Manager', function (): void {
// When I wait on the ready method before completing
sessionManager.setJupyterSessionManager(mockJupyterManager.object);
sessionManager.ready.then(() => done());
sessionManager.ready.then(() => done()).catch(err => done(err));
// Then session manager should eventually resolve
deferred.resolve();