How to use @jupyterlab/testutils - 10 common examples

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-services / src / kernel / ikernel.spec.ts View on Github external
it('should fail if the kernel is dead', async () => {
      const tester = new KernelTester();
      const kernel = await tester.start();

      // Create a promise that resolves when the kernel's status changes to dead
      const dead = testEmission(kernel.statusChanged, {
        find: () => kernel.status === 'dead'
      });
      tester.sendStatus(UUID.uuid4(), 'dead');
      await dead;
      await expectFailure(kernel.interrupt(), 'Kernel is dead');
      tester.dispose();
    });
  });
github jupyterlab / jupyterlab / tests / test-docmanager / src / savehandler.spec.ts View on Github external
it('should continue to save', async () => {
        let called = 0;
        // Lower the duration multiplier.
        (handler as any)._multiplier = 1;
        let promise = testEmission(context.fileChanged, {
          test: () => {
            if (called === 0) {
              context.model.fromString('bar');
              called++;
            }
            return called === 1;
          }
        });
        context.model.fromString('foo');
        expect(handler.isActive).to.equal(false);
        handler.saveInterval = 1;
        handler.start();
        return promise;
      });
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-console / src / foreign.spec.ts View on Github external
// If the message was not injected but otherwise would have been, emit
      // a rejected signal. This should only happen if `enabled` is `false`.
      const session = (msg.parent_header as KernelMessage.IHeader).session;
      const msgType = msg.header.msg_type;
      if (
        session !== this.session.kernel.clientId &&
        relevantTypes.has(msgType)
      ) {
        this.rejected.emit(msg);
      }
    }
    return injected;
  }
}

const rendermime = defaultRenderMime();

const relevantTypes = [
  'execute_input',
  'execute_result',
  'display_data',
  'stream',
  'error',
  'clear_output'
].reduce((acc, val) => {
  acc.add(val);
  return acc;
}, new Set());

describe('@jupyterlab/console', () => {
  describe('ForeignHandler', () => {
    let local: Session.ISession;
github jupyterlab / jupyterlab-data-explorer / tests / test-console / src / foreign.spec.ts View on Github external
// If the message was not injected but otherwise would have been, emit
      // a rejected signal. This should only happen if `enabled` is `false`.
      const session = (msg.parent_header as KernelMessage.IHeader).session;
      const msgType = msg.header.msg_type;
      if (
        session !== this.session.kernel.clientId &&
        relevantTypes.has(msgType)
      ) {
        this.rejected.emit(msg);
      }
    }
    return injected;
  }
}

const rendermime = defaultRenderMime();

const relevantTypes = [
  'execute_input',
  'execute_result',
  'display_data',
  'stream',
  'error',
  'clear_output'
].reduce((acc, val) => {
  acc.add(val);
  return acc;
}, new Set());

describe('@jupyterlab/console', () => {
  describe('ForeignHandler', () => {
    let local: Session.ISession;
github jupyterlab / jupyterlab / tests / test-apputils / src / clientsession.spec.ts View on Github external
it('should present a dialog if there is no distinct kernel to start', async () => {
        // Remove the kernel preference before initializing.
        session.kernelPreference = {};

        const accept = acceptDialog();

        await session.initialize();
        await accept;
        expect(session.kernel.name).to.equal(manager.specs.default);
      });
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)
      });