start_jupyter_server.spec.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. const fetch = require('node-fetch');
  4. import { JupyterServer } from '../src';
  5. import { PageConfig, URLExt } from '@jupyterlab/coreutils';
  6. describe('JupyterServer', () => {
  7. it('should start the server', async () => {
  8. jest.setTimeout(20000);
  9. const server = new JupyterServer();
  10. const url = await server.start();
  11. await fetch(URLExt.join(url, 'api'));
  12. await server.shutdown();
  13. });
  14. it('should accept options', async () => {
  15. jest.setTimeout(20000);
  16. const pageConfig = { foo: 'bar', fizz: 'buzz' };
  17. const configData = {
  18. FakeTrait: { fake_prop: 1 },
  19. OtherTrait: { other_prop: 'hello' },
  20. KernelManager: {
  21. shutdown_wait_time: 1.11
  22. }
  23. };
  24. const additionalKernelSpecs = {
  25. foo: {
  26. argv: ['python', '-m', 'ipykernel_launcher', '-f', '{connection_file}'],
  27. display_name: 'Test Python',
  28. language: 'python'
  29. }
  30. };
  31. const server = new JupyterServer();
  32. const url = await server.start({
  33. pageConfig,
  34. configData,
  35. additionalKernelSpecs
  36. });
  37. await fetch(URLExt.join(url, 'api'));
  38. expect(PageConfig.getOption('foo')).toEqual('bar');
  39. expect(PageConfig.getOption('fizz')).toEqual('buzz');
  40. expect(PageConfig.getOption('__configData')).toContain('FakeTrait');
  41. expect(PageConfig.getOption('__configData')).toContain('OtherTrait');
  42. expect(PageConfig.getOption('__configData')).toContain('1.11');
  43. expect(PageConfig.getOption('__kernelSpec_foo')).toContain('Test Python');
  44. await expect(server.shutdown()).resolves.not.toThrow();
  45. });
  46. });