session.spec.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { expect } from 'chai';
  4. import { ClientSession, IClientSession } from '@jupyterlab/apputils';
  5. import { createClientSession } from '@jupyterlab/testutils';
  6. import { DebugSession } from '../../lib/session';
  7. describe('DebugSession', () => {
  8. let client: IClientSession;
  9. beforeEach(async () => {
  10. client = await createClientSession({
  11. kernelPreference: {
  12. name: 'xpython'
  13. }
  14. });
  15. await (client as ClientSession).initialize();
  16. await client.kernel.ready;
  17. });
  18. afterEach(async () => {
  19. await client.shutdown();
  20. });
  21. describe('#isDisposed', () => {
  22. it('should return whether the object is disposed', () => {
  23. const debugSession = new DebugSession({ client });
  24. expect(debugSession.isDisposed).to.equal(false);
  25. debugSession.dispose();
  26. expect(debugSession.isDisposed).to.equal(true);
  27. });
  28. });
  29. describe('#eventMessage', () => {
  30. it('should be emitted when sending debug messages', async () => {
  31. const debugSession = new DebugSession({ client });
  32. let events: string[] = [];
  33. debugSession.eventMessage.connect((sender, event) => {
  34. events.push(event.event);
  35. });
  36. await debugSession.start();
  37. await debugSession.stop();
  38. expect(events).to.deep.equal(['output', 'initialized', 'process']);
  39. });
  40. });
  41. describe('#sendRequest', () => {
  42. let debugSession: DebugSession;
  43. beforeEach(async () => {
  44. debugSession = new DebugSession({ client });
  45. await debugSession.start();
  46. });
  47. afterEach(async () => {
  48. await debugSession.stop();
  49. debugSession.dispose();
  50. });
  51. it('should send debug messages to the kernel', async () => {
  52. const code = 'i=0\ni+=1\ni+=1';
  53. const reply = await debugSession.sendRequest('updateCell', {
  54. cellId: 0,
  55. nextId: 1,
  56. code
  57. });
  58. console.log(reply);
  59. expect(reply.body.sourcePath).to.contain('.py');
  60. });
  61. it('should handle replies with success false', async () => {
  62. const reply = await debugSession.sendRequest('evaluate', {
  63. expression: 'a'
  64. });
  65. const { success, message } = reply;
  66. console.log(reply);
  67. expect(success).to.be.false;
  68. expect(message).to.contain('Unable to find thread for evaluation');
  69. });
  70. });
  71. });