Steven Silvester пре 8 година
родитељ
комит
16618ce751

+ 82 - 71
test/src/apputils/clientsession.spec.ts

@@ -54,7 +54,7 @@ describe('@jupyterlab/apputils', () => {
     describe('#terminated', () => {
 
       it('should be emitted when the session is terminated', (done) => {
-        session.initialize().then(() => {
+        session.ready.then(() => {
           session.terminated.connect((sender, args) => {
             expect(sender).to.be(session);
             expect(args).to.be(undefined);
@@ -74,7 +74,7 @@ describe('@jupyterlab/apputils', () => {
           expect(args).to.be.ok();
           done();
         });
-        session.initialize().catch(done);
+        session.ready.catch(done);
       });
 
     });
@@ -87,7 +87,7 @@ describe('@jupyterlab/apputils', () => {
           expect(typeof args).to.be('string');
           done();
         });
-        session.initialize().catch(done);
+        session.ready.catch(done);
       });
 
     });
@@ -99,7 +99,7 @@ describe('@jupyterlab/apputils', () => {
           expect(sender).to.be(session);
           done();
         });
-        session.initialize().catch(done);
+        session.ready.catch(done);
       });
 
     });
@@ -139,7 +139,7 @@ describe('@jupyterlab/apputils', () => {
 
       it('should be the current kernel of the the session', () => {
         expect(session.kernel).to.be(null);
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           expect(session.kernel).to.be.ok();
         });
       });
@@ -211,11 +211,78 @@ describe('@jupyterlab/apputils', () => {
 
     });
 
+    describe('#isReady', () => {
+
+      it('should be false until ready', () => {
+        expect(session.isReady).to.be(false);
+        return session.ready.then(() => {
+          expect(session.isReady).to.be(true);
+        });
+      });
+
+    });
+
+    describe('#ready', () => {
+
+      it('should start the default kernel', () => {
+        return session.ready.then(() => {
+          expect(session.kernel.name).to.be(manager.specs.default);
+        });
+      });
+
+      it('should connect to an existing session on the path', () => {
+        let other: Session.ISession;
+        return manager.startNew({ path: session.path }).then(o => {
+          other = o;
+          return session.ready;
+        }).then(() => {
+          expect(session.kernel.id).to.be(other.kernel.id);
+          return other.dispose();
+        });
+      });
+
+      it('should connect to an existing kernel', () => {
+        let other: Session.ISession;
+        return manager.startNew({ path: uuid() }).then(o => {
+          other = o;
+          session.kernelPreference = { id: other.kernel.id };
+          return session.ready;
+        }).then(() => {
+          expect(session.kernel.id).to.be(other.kernel.id);
+          return other.dispose();
+        });
+      });
+
+      it('should present a dialog if there is no distinct kernel to start', () => {
+        session.kernelPreference = {};
+        acceptDialog();
+        return session.ready.then(() => {
+          expect(session.kernel.name).to.be(manager.specs.default);
+        });
+      });
+
+      it('should be a no-op if if the shouldStart kernelPreference is false', () => {
+        session.kernelPreference = { shouldStart: false };
+        return session.ready.then(() => {
+          expect(session.kernel).to.not.be.ok();
+        });
+      });
+
+
+      it('should be a no-op if if the canStart kernelPreference is false', () => {
+        session.kernelPreference = { canStart: false };
+        return session.ready.then(() => {
+          expect(session.kernel).to.not.be.ok();
+        });
+      });
+
+    });
+
     describe('#kernelDisplayName', () => {
 
       it('should be the display name of the current kernel', () => {
         expect(session.kernelDisplayName).to.be('No Kernel!');
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           expect(session.kernelDisplayName).to.not.be('No Kernel!');
         });
       });
@@ -249,7 +316,7 @@ describe('@jupyterlab/apputils', () => {
       it('should change the current kernel', () => {
         let id = '';
         let name = '';
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           name = session.kernel.name;
           id = session.kernel.id;
           return session.changeKernel({ name });
@@ -271,7 +338,7 @@ describe('@jupyterlab/apputils', () => {
     describe('#selectKernel()', () => {
 
       it('should select a kernel for the session', () => {
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           let { id, name } = session.kernel;
           acceptDialog();
           return session.selectKernel().then(() => {
@@ -282,7 +349,7 @@ describe('@jupyterlab/apputils', () => {
       });
 
       it('should keep the existing kernel', () => {
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           let { id, name } = session.kernel;
           dismissDialog();
           return session.selectKernel().then(() => {
@@ -297,7 +364,7 @@ describe('@jupyterlab/apputils', () => {
     describe('#shutdown', () => {
 
       it('should kill the kernel and shut down the session', () => {
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           return session.shutdown();
         }).then(() => {
           expect(session.kernel).to.be(null);
@@ -310,7 +377,7 @@ describe('@jupyterlab/apputils', () => {
 
       it('should restart if the user accepts the dialog', () => {
         let called = false;
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           acceptDialog();
           session.statusChanged.connect((sender, args) => {
             if (args === 'restarting') {
@@ -325,7 +392,7 @@ describe('@jupyterlab/apputils', () => {
 
       it('should not restart if the user rejects the dialog', () => {
         let called = false;
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           dismissDialog();
           session.statusChanged.connect((sender, args) => {
             if (args === 'restarting') {
@@ -339,7 +406,7 @@ describe('@jupyterlab/apputils', () => {
       });
 
       it('should start the same kernel as the previously started kernel', () => {
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           return session.shutdown();
         }).then(() => {
           return session.restart();
@@ -386,67 +453,11 @@ describe('@jupyterlab/apputils', () => {
 
     });
 
-    describe('#initialize()', () => {
-
-      it('should start the default kernel', () => {
-        return session.initialize().then(() => {
-          expect(session.kernel.name).to.be(manager.specs.default);
-        });
-      });
-
-      it('should connect to an existing session on the path', () => {
-        let other: Session.ISession;
-        return manager.startNew({ path: session.path }).then(o => {
-          other = o;
-          return session.initialize();
-        }).then(() => {
-          expect(session.kernel.id).to.be(other.kernel.id);
-          return other.dispose();
-        });
-      });
-
-      it('should connect to an existing kernel', () => {
-        let other: Session.ISession;
-        return manager.startNew({ path: uuid() }).then(o => {
-          other = o;
-          session.kernelPreference = { id: other.kernel.id };
-          return session.initialize();
-        }).then(() => {
-          expect(session.kernel.id).to.be(other.kernel.id);
-          return other.dispose();
-        });
-      });
-
-      it('should present a dialog if there is no distinct kernel to start', () => {
-        session.kernelPreference = {};
-        acceptDialog();
-        return session.initialize().then(() => {
-          expect(session.kernel.name).to.be(manager.specs.default);
-        });
-      });
-
-      it('should be a no-op if if the shouldStart kernelPreference is false', () => {
-        session.kernelPreference = { shouldStart: false };
-        return session.initialize().then(() => {
-          expect(session.kernel).to.not.be.ok();
-        });
-      });
-
-
-      it('should be a no-op if if the canStart kernelPreference is false', () => {
-        session.kernelPreference = { canStart: false };
-        return session.initialize().then(() => {
-          expect(session.kernel).to.not.be.ok();
-        });
-      });
-
-    });
-
     describe('.restartKernel()', () => {
 
       it('should restart if the user accepts the dialog', () => {
         let called = false;
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           acceptDialog();
           session.statusChanged.connect((sender, args) => {
             if (args === 'restarting') {
@@ -461,7 +472,7 @@ describe('@jupyterlab/apputils', () => {
 
       it('should not restart if the user rejects the dialog', () => {
         let called = false;
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           dismissDialog();
           session.statusChanged.connect((sender, args) => {
             if (args === 'restarting') {

+ 2 - 2
test/src/apputils/toolbar.spec.ts

@@ -178,7 +178,7 @@ describe('@jupyterlab/apputils', () => {
 
       it('should display the `\'display_name\'` of the kernel', () => {
         let item = Toolbar.createKernelNameItem(session);
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           expect(item.node.textContent).to.be(session.kernelDisplayName);
         });
       });
@@ -193,7 +193,7 @@ describe('@jupyterlab/apputils', () => {
     describe('.createKernelStatusItem()', () => {
 
       beforeEach(() => {
-        return session.initialize().then(() => {
+        return session.ready.then(() => {
           return session.kernel.ready;
         });
       });

+ 1 - 1
test/src/cells/widget.spec.ts

@@ -392,7 +392,7 @@ describe('cells/widget', () => {
       beforeEach(() => {
         return createClientSession().then(s => {
           session = s;
-          return s.initialize();
+          return s.ready;
         }).then(() => {
           return session.kernel.ready;
         });

+ 1 - 1
test/src/completer/handler.spec.ts

@@ -89,7 +89,7 @@ describe('@jupyterlab/completer', () => {
   before(() => {
     return createClientSession().then(s => {
       session = s;
-      return s.initialize();
+      return s.ready;
     });
   });
 

+ 1 - 1
test/src/console/foreign.spec.ts

@@ -112,7 +112,7 @@ describe('@jupyterlab/console', () => {
         return createClientSession({ path: local.path });
       }).then(s => {
         session = s;
-        return s.initialize();
+        return s.ready;
       });
     });
 

+ 7 - 7
test/src/console/widget.spec.ts

@@ -105,7 +105,7 @@ describe('console/widget', () => {
       it('should reflect the contents of the widget', () => {
         let force = true;
         Widget.attach(widget, document.body);
-        return (widget.session as ClientSession).initialize().then(() => {
+        return widget.session.ready.then(() => {
           return widget.execute(force);
         }).then(() => {
           expect(widget.cells.length).to.be(1);
@@ -123,7 +123,7 @@ describe('console/widget', () => {
         let force = true;
         Widget.attach(widget, document.body);
         widget.executed.connect((sender, time) => { called = time; });
-        return (widget.session as ClientSession).initialize().then(() => {
+        return widget.session.ready.then(() => {
           return widget.execute(force);
         }).then(() => {
           expect(called).to.be.a(Date);
@@ -146,7 +146,7 @@ describe('console/widget', () => {
         let old = widget.prompt;
         expect(old).to.be.a(CodeCellWidget);
 
-        return (widget.session as ClientSession).initialize().then(() => {
+        return widget.session.ready.then(() => {
           return widget.execute(force);
         }).then(() => {
           expect(widget.prompt).to.be.a(CodeCellWidget);
@@ -191,7 +191,7 @@ describe('console/widget', () => {
       it('should clear all of the content cells except the banner', () => {
         let force = true;
         Widget.attach(widget, document.body);
-        return (widget.session as ClientSession).initialize().then(() => {
+        return widget.session.ready.then(() => {
           return widget.execute(force);
         }).then(() => {
           expect(widget.cells.length).to.be.greaterThan(0);
@@ -228,7 +228,7 @@ describe('console/widget', () => {
         let force = true;
         Widget.attach(widget, document.body);
         expect(widget.cells.length).to.be(0);
-        return (widget.session as ClientSession).initialize().then(() => {
+        return widget.session.ready.then(() => {
           return widget.execute(force);
         }).then(() => {
           expect(widget.cells.length).to.be.greaterThan(0);
@@ -241,7 +241,7 @@ describe('console/widget', () => {
         Widget.attach(widget, document.body);
         widget.prompt.model.value.text = 'for x in range(5):';
         expect(widget.cells.length).to.be(0);
-        return (widget.session as ClientSession).initialize().then(() => {
+        return widget.session.ready.then(() => {
           return widget.execute(force, timeout);
         }).then(() => {
           expect(widget.cells.length).to.be(0);
@@ -311,7 +311,7 @@ describe('console/widget', () => {
         expect(old).to.be.a(CodeCellWidget);
         widget.methods = [];
 
-        return (widget.session as ClientSession).initialize().then(() => {
+        return widget.session.ready.then(() => {
           return widget.execute(force);
         }).then(() => {
           expect(widget.prompt).to.be.a(CodeCellWidget);

+ 1 - 1
test/src/docmanager/savehandler.spec.ts

@@ -20,7 +20,7 @@ import {
 } from '@jupyterlab/docmanager';
 
 import {
-  acceptDialog, dismissDialog
+  acceptDialog, waitForDialog
 } from '../utils';
 
 

+ 4 - 4
test/src/notebook/actions.spec.ts

@@ -467,7 +467,7 @@ describe('@jupyterlab/notebook', () => {
     describe('#run()', () => {
 
       beforeEach(() => {
-        return session.initialize();
+        return session.ready;
       });
 
       it('should run the selected cells', function (done) {
@@ -557,7 +557,7 @@ describe('@jupyterlab/notebook', () => {
     describe('#runAndAdvance()', () => {
 
       beforeEach(() => {
-        return session.initialize();
+        return session;
       });
 
       it('should run the selected cells ', (done) => {
@@ -655,7 +655,7 @@ describe('@jupyterlab/notebook', () => {
     describe('#runAndInsert()', () => {
 
       beforeEach(() => {
-        return session.initialize();
+        return session.ready;
       });
 
       it('should run the selected cells ', (done) => {
@@ -743,7 +743,7 @@ describe('@jupyterlab/notebook', () => {
         // Make sure all cells have valid code.
         widget.widgets[2].model.value.text = 'a = 1';
 
-        return session.initialize();
+        return session.ready;
       });
 
       it('should run all of the cells in the notebok', (done) => {

+ 1 - 1
test/src/outputarea/widget.spec.ts

@@ -180,7 +180,7 @@ describe('outputarea/widget', () => {
       beforeEach(() => {
         return createClientSession().then(s => {
           session = s;
-          return session.initialize();
+          return session.ready;
         });
       });