瀏覽代碼

Add simple DebugSession

Jeremy Tuloup 5 年之前
父節點
當前提交
87f4ff5f1d
共有 4 個文件被更改,包括 113 次插入9 次删除
  1. 61 0
      src/session.ts
  2. 1 2
      src/tokens.ts
  3. 21 7
      tests/jest.config.js
  4. 30 0
      tests/src/session.spec.ts

+ 61 - 0
src/session.ts

@@ -0,0 +1,61 @@
+import { IClientSession } from '@jupyterlab/apputils';
+
+import { CodeEditor } from '@jupyterlab/codeeditor';
+
+import { ISignal, Signal } from '@phosphor/signaling';
+
+import { IDebugger } from './tokens';
+
+export class DebugSession implements IDebugger.ISession {
+  /**
+   * Instantiate a new debug session
+   *
+   * @param options - The debug session instantiation options.
+   */
+  constructor(options: DebugSession.IOptions) {
+    this.client = options.client;
+  }
+
+  /**
+   * Dispose the debug session.
+   */
+  dispose(): void {
+    if (this.isDisposed) {
+      return;
+    }
+    this._isDisposed = true;
+    this._disposed.emit();
+  }
+
+  /**
+   * A signal emitted when the debug session is disposed.
+   */
+  get disposed(): ISignal<this, void> {
+    return this._disposed;
+  }
+
+  /**
+   * Whether the debug session is disposed.
+   */
+  get isDisposed(): boolean {
+    return this._isDisposed;
+  }
+
+  client: IClientSession;
+  editors: CodeEditor.IEditor[];
+
+  private _disposed = new Signal<this, void>(this);
+  private _isDisposed: boolean = false;
+}
+
+/**
+ * A namespace for `DebugSession` statics.
+ */
+export namespace DebugSession {
+  export interface IOptions {
+    /**
+     * The client session used by the debug session.
+     */
+    client: IClientSession;
+  }
+}

+ 1 - 2
src/tokens.ts

@@ -18,8 +18,7 @@ import { Debugger } from './debugger';
 /**
  * An interface describing an application's visual debugger.
  */
-export interface IDebugger
-  extends IWidgetTracker<MainAreaWidget<Debugger>> {}
+export interface IDebugger extends IWidgetTracker<MainAreaWidget<Debugger>> {}
 
 /**
  * A namespace for visual debugger types.

+ 21 - 7
tests/jest.config.js

@@ -1,13 +1,27 @@
-module.exports = {
-  preset: "ts-jest/presets/js-with-babel",
-  moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
-  transformIgnorePatterns: ["/node_modules/(?!(@jupyterlab/.*)/)"],
+const func = require('@jupyterlab/testutils/lib/jest-config');
+const upstream = func('@jupyterlab/debugger', __dirname);
+
+let local = {
+  preset: 'ts-jest/presets/js-with-babel',
+  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
+  transformIgnorePatterns: ['/node_modules/(?!(@jupyterlab/.*)/)'],
   globals: {
-    "ts-jest": {
-      tsConfig: "./tsconfig.json"
+    'ts-jest': {
+      tsConfig: './tsconfig.json'
     }
   },
   transform: {
-    "\\.(ts|tsx)?$": "ts-jest"
+    '\\.(ts|tsx)?$': 'ts-jest'
   }
 };
+
+[
+  'moduleNameMapper',
+  'setupFilesAfterEnv',
+  'setupFiles',
+  'moduleFileExtensions'
+].forEach(option => {
+  local[option] = upstream[option];
+});
+
+module.exports = local;

+ 30 - 0
tests/src/session.spec.ts

@@ -0,0 +1,30 @@
+import { expect } from 'chai';
+
+import { ClientSession, IClientSession } from '@jupyterlab/apputils';
+
+import { createClientSession } from '@jupyterlab/testutils';
+
+import { DebugSession } from '../../lib/session';
+
+describe('DebugSession', () => {
+  let client: IClientSession;
+
+  beforeEach(async () => {
+    client = await createClientSession();
+    await (client as ClientSession).initialize();
+    await client.kernel.ready;
+  });
+
+  afterEach(async () => {
+    await client.shutdown();
+  });
+
+  describe('#isDisposed', () => {
+    it('should return whether the object is disposed', () => {
+      const debugSession = new DebugSession({ client });
+      expect(debugSession.isDisposed).to.equal(false);
+      debugSession.dispose();
+      expect(debugSession.isDisposed).to.equal(true);
+    });
+  });
+});