Skip to content

Commit

Permalink
Merge pull request #9997 from jtpio/fix-apputils
Browse files Browse the repository at this point in the history
Fix js-apputils session context tests
  • Loading branch information
blink1073 committed Mar 24, 2021
2 parents 60336e5 + 7559aec commit 9ecbde2
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions packages/apputils/test/sessioncontext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ describe('@jupyterlab/apputils', () => {
afterEach(async () => {
Dialog.flush();
try {
await sessionContext.shutdown();
if (sessionContext.session) {
await sessionContext.shutdown();
}
} catch (error) {
console.warn('Session shutdown failed.', error);
}
Expand Down Expand Up @@ -296,6 +298,32 @@ describe('@jupyterlab/apputils', () => {
expect(result).toBe(false);
expect(sessionContext.session?.kernel).toBeFalsy();
});

it('should handle an error during startup', async () => {
// Give it a mock manager that errors on connectTo
const mockManager = new SessionManager({ kernelManager });

sessionContext = new SessionContext({
path,
sessionManager: mockManager,
specsManager,
kernelPreference: { name: specsManager.specs?.default }
});

(mockManager as any).running = () => {
return [{ path }];
};
(mockManager as any).connectTo = () => {
throw new Error('mock error');
};

let caught = false;
const promise = sessionContext.initialize().catch(() => {
caught = true;
});
await Promise.all([promise, acceptDialog()]);
expect(caught).toBe(true);
});
});

describe('#kernelDisplayName', () => {
Expand Down Expand Up @@ -442,24 +470,6 @@ describe('@jupyterlab/apputils', () => {
// could be either, just make sure it isn't the original kernel.
expect([results[0], results[1]]).toContain(lastKernel);
});

it('should handle an error during kernel change', async () => {
await sessionContext.initialize();
await sessionContext.session?.kernel?.info;
let status = 'idle';
sessionContext.statusChanged.connect(() => {
status = sessionContext.kernelDisplayStatus;
});
let caught = false;
const promise = sessionContext
.changeKernel({ name: 'does-not-exist' })
.catch(() => {
caught = true;
});
await Promise.all([promise, acceptDialog()]);
expect(caught).toBe(true);
expect(status).toBe('unknown');
});
});

describe('#shutdown', () => {
Expand Down

0 comments on commit 9ecbde2

Please sign in to comment.