Browse Source

Merge pull request #9997 from jtpio/fix-apputils

Fix js-apputils session context tests
Steven Silvester 4 years ago
parent
commit
9ecbde22ff
1 changed files with 29 additions and 19 deletions
  1. 29 19
      packages/apputils/test/sessioncontext.spec.ts

+ 29 - 19
packages/apputils/test/sessioncontext.spec.ts

@@ -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);
       }
@@ -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', () => {
@@ -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', () => {