How to use the @jupyterlab/testutils.sleep function in @jupyterlab/testutils

To help you get started, we’ve selected a few @jupyterlab/testutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / tests / test-notebook / src / actions.spec.ts View on Github external
it('should render all markdown cells on an error', async () => {
        widget.activeCell.model.value.text = ERROR_INPUT;
        const cell = widget.widgets[1] as MarkdownCell;
        cell.rendered = false;
        widget.select(cell);
        const result = await NotebookActions.runAndInsert(widget, ipySession);
        // Markdown rendering is asynchronous, but the cell
        // provides no way to hook into that. Sleep here
        // to make sure it finishes.
        await sleep(100);
        expect(result).to.equal(false);
        expect(cell.rendered).to.equal(true);
        expect(widget.activeCellIndex).to.equal(2);
        await ipySession.kernel.restart();
      }).timeout(60000); // Allow for slower CI
    });
github jupyterlab / jupyterlab-data-explorer / tests / test-notebook / src / actions.spec.ts View on Github external
it('should render all markdown cells on an error', async () => {
        widget.activeCell.model.value.text = ERROR_INPUT;
        const cell = widget.widgets[1] as MarkdownCell;
        cell.rendered = false;
        widget.select(cell);
        const result = await NotebookActions.runAndInsert(widget, ipySession);
        // Markdown rendering is asynchronous, but the cell
        // provides no way to hook into that. Sleep here
        // to make sure it finishes.
        await sleep(100);
        expect(result).to.equal(false);
        expect(cell.rendered).to.equal(true);
        expect(widget.activeCellIndex).to.equal(2);
        await ipySession.kernel.restart();
      }).timeout(60000); // Allow for slower CI
    });
github jupyterlab / jupyterlab / tests / test-coreutils / src / poll.spec.ts View on Github external
it('should emit when the poll ticks after `when` rejects', async () => {
      const expected = 'when-rejected resolved';
      const ticker: IPoll.Phase[] = [];
      const promise = Promise.reject();
      poll = new Poll({
        factory: () => Promise.resolve(),
        frequency: { interval: 2000, backoff: false },
        name: '@jupyterlab/test-coreutils:Poll#ticked-2',
        when: promise
      });
      poll.ticked.connect(() => {
        ticker.push(poll.state.phase);
      });
      await promise.catch(() => undefined);
      await sleep(200); // Sleep for less than the interval.
      expect(ticker.join(' ')).to.equal(expected);
    });
github jupyterlab / jupyterlab / tests / test-docregistry / src / default.spec.ts View on Github external
it('should resolve after the reveal and context ready promises', async () => {
        const x = Object.create(null);
        const reveal = sleep(300, x);
        const contextReady = Promise.all([context.ready, x]);
        const widget = new DocumentWidget({ context, content, reveal });
        expect(widget.isRevealed).to.equal(false);

        // Our promise should resolve before the widget reveal promise.
        expect(await Promise.race([widget.revealed, reveal])).to.equal(x);
        // The context ready promise should also resolve first.
        void context.initialize(true);
        expect(
          await Promise.race([widget.revealed, contextReady])
        ).to.deep.equal([undefined, x]);
        // The widget.revealed promise should finally resolve.
        expect(await widget.revealed).to.be.undefined;
      });
    });
github jupyterlab / jupyterlab / tests / test-filebrowser / src / openfiledialog.spec.ts View on Github external
host: node,
        filter: (value: Contents.IModel) => value.type === 'notebook'
      });

      await waitForDialog();
      await framePromise();

      let counter = 0;
      let listing = node.getElementsByClassName('jp-DirListing-content')[0];
      expect(listing).to.be.ok;

      let items = listing.getElementsByTagName('li');
      counter = 0;
      // Wait for the directory listing to be populated
      while (items.length === 0 && counter < 100) {
        await sleep(10);
        items = listing.getElementsByTagName('li');
        counter++;
      }

      // Fails if there is no items shown
      expect(items.length).to.be.greaterThan(0);

      // Emulate notebook file selection
      // Get node coordinates we need to be precised as code test for hit position
      const rect = items.item(items.length - 1)!.getBoundingClientRect();

      simulate(items.item(items.length - 1)!, 'mousedown', {
        clientX: 0.5 * (rect.left + rect.right),
        clientY: 0.5 * (rect.bottom + rect.top)
      });
github jupyterlab / jupyterlab / tests / test-completer / src / widget.spec.ts View on Github external
line: position.line,
            text: 'a'
          };

          model.original = request;
          model.cursor = { start: text.length - 1, end: text.length };
          model.setOptions(['abc', 'abd', 'abe', 'abi']);

          let widget = new Completer({ model, editor: code.editor });
          Widget.attach(widget, document.body);
          MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
          simulate(document.body, 'scroll');

          // Because the scroll handling is asynchronous, this test uses a large
          // timeout (500ms) to guarantee the scroll handling has finished.
          await sleep(500);
          let top = parseInt(window.getComputedStyle(widget.node).top, 10);
          let bottom = Math.floor(coords.bottom);
          expect(top + panel.node.scrollTop).to.equal(bottom);
          widget.dispose();
          code.dispose();
          panel.dispose();
        });
      });
github jupyterlab / jupyterlab / tests / test-coreutils / src / poll.spec.ts View on Github external
// Kick off the promise listener, but void its settlement to verify that
      // the poll's internal sync of the promise and the signal is correct.
      void poll.tick.then(tock);
      await poll.stop();
      await poll.start();
      await poll.tick;
      await poll.refresh();
      await poll.tick;
      await poll.refresh();
      await poll.tick;
      await poll.refresh();
      await poll.tick;
      await poll.stop();
      await poll.start();
      await poll.tick;
      await sleep(100);
      await poll.tick;
      expect(ticker.join(' ')).to.equal(tocker.join(' '));
    });
  });
github jupyterlab / jupyterlab-data-explorer / tests / test-completer / src / widget.spec.ts View on Github external
line: position.line,
            text: 'a'
          };

          model.original = request;
          model.cursor = { start: text.length - 1, end: text.length };
          model.setOptions(['abc', 'abd', 'abe', 'abi']);

          let widget = new Completer({ model, editor: code.editor });
          Widget.attach(widget, document.body);
          MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
          simulate(document.body, 'scroll');

          // Because the scroll handling is asynchronous, this test uses a large
          // timeout (500ms) to guarantee the scroll handling has finished.
          await sleep(500);
          let top = parseInt(window.getComputedStyle(widget.node).top, 10);
          let bottom = Math.floor(coords.bottom);
          expect(top + panel.node.scrollTop).to.equal(bottom);
          widget.dispose();
          code.dispose();
          panel.dispose();
        });
      });
github jupyterlab / jupyterlab / tests / test-coreutils / src / ratelimiter.spec.ts View on Github external
it('should debounce invocations within an interval', async () => {
      const limit = 500;
      const sleeps = [200, 200, 200, 200, 600];
      const wanted = [1, 1, 1, 1, 1, 2];
      let called = 0;

      debouncer = new Debouncer(() => ++called, limit);

      const one = debouncer.invoke();
      await sleep(sleeps[0]);
      const two = debouncer.invoke();
      await sleep(sleeps[1]);
      const three = debouncer.invoke();
      await sleep(sleeps[2]);
      const four = debouncer.invoke();
      await sleep(sleeps[3]);
      const five = debouncer.invoke();
      await sleep(sleeps[4]);
      const six = debouncer.invoke();

      expect(await one).to.equal(wanted[0]);
      expect(await two).to.equal(wanted[1]);
      expect(await three).to.equal(wanted[2]);
      expect(await four).to.equal(wanted[3]);
      expect(await five).to.equal(wanted[4]);
      expect(await six).to.equal(wanted[5]);
    });
  });
github jupyterlab / jupyterlab-data-explorer / tests / test-coreutils / src / activitymonitor.spec.ts View on Github external
it('should be emitted after the signal has fired and a timeout', async () => {
        let called = false;
        const monitor = new ActivityMonitor({ signal, timeout: 100 });
        monitor.activityStopped.connect((sender, args) => {
          expect(sender).to.equal(monitor);
          expect(args.sender).to.equal(testObj);
          expect(args.args).to.equal(10);
          called = true;
        });
        signal.emit(10);
        expect(called).to.equal(false);
        await sleep(100);
        expect(called).to.equal(true);
      });
    });