Browse Source

modernize terminal

update terminal tests

lint

modernize terminal
Steven Silvester 5 years ago
parent
commit
5831c8a46b

+ 11 - 0
packages/terminal/.vscode/launch.json

@@ -0,0 +1,11 @@
+{
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "node",
+            "request": "attach",
+            "name": "Attach",
+            "port": 9229
+        }
+    ]
+}

+ 1 - 0
packages/terminal/babel.config.js

@@ -0,0 +1 @@
+module.exports = require('@jupyterlab/testutils/lib/babel.config');

+ 2 - 0
packages/terminal/jest.config.js

@@ -0,0 +1,2 @@
+const func = require('@jupyterlab/testutils/lib/jest-config-new');
+module.exports = func(__dirname);

+ 10 - 0
packages/terminal/package.json

@@ -29,9 +29,14 @@
   },
   "scripts": {
     "build": "tsc -b",
+    "build:test": "tsc --build tsconfig.test.json",
     "clean": "rimraf lib",
     "docs": "typedoc src",
     "prepublishOnly": "npm run build",
+    "test": "jest",
+    "test:cov": "jest --collect-coverage",
+    "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
+    "test:debug:watch": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
     "watch": "tsc -b --watch"
   },
   "dependencies": {
@@ -45,7 +50,12 @@
     "xterm-addon-fit": "~0.3.0"
   },
   "devDependencies": {
+    "@jupyterlab/testutils": "^2.1.0",
+    "@types/jest": "^24.0.23",
+    "canvas": "^2.6.1",
+    "jest": "^25.2.3",
     "rimraf": "~3.0.0",
+    "ts-jest": "^25.2.1",
     "typedoc": "^0.15.4",
     "typescript": "~3.7.3"
   },

+ 7 - 1
packages/terminal/src/tokens.ts

@@ -106,6 +106,11 @@ export namespace ITerminal {
      * This setting has no effect on macOS, where Cmd+V is available.
      */
     pasteWithCtrlV: boolean;
+
+    /**
+     * Whether to auto-fit the terminal to its host element size.
+     */
+    autoFit?: boolean;
   }
 
   /**
@@ -121,7 +126,8 @@ export namespace ITerminal {
     cursorBlink: true,
     initialCommand: '',
     screenReaderMode: false, // False by default, can cause scrollbar mouse interaction issues.
-    pasteWithCtrlV: true
+    pasteWithCtrlV: true,
+    autoFit: true
   };
 
   /**

+ 3 - 1
packages/terminal/src/widget.ts

@@ -320,7 +320,9 @@ export class Terminal extends Widget implements ITerminal.ITerminal {
    * Resize the terminal based on computed geometry.
    */
   private _resizeTerminal() {
-    this._fitAddon.fit();
+    if (this._options.autoFit) {
+      this._fitAddon.fit();
+    }
     if (this._offsetWidth === -1) {
       this._offsetWidth = this.node.offsetWidth;
     }

+ 47 - 32
tests/test-terminal/src/terminal.spec.ts → packages/terminal/test/terminal.spec.ts

@@ -1,7 +1,6 @@
 // Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
 
-import { expect } from 'chai';
+import 'jest';
 
 import { Terminal as TerminalNS, TerminalManager } from '@jupyterlab/services';
 
@@ -9,9 +8,23 @@ import { Message, MessageLoop } from '@lumino/messaging';
 
 import { Widget } from '@lumino/widgets';
 
-import { Terminal } from '@jupyterlab/terminal';
+import { Terminal } from '../src';
 
-import { framePromise, testEmission } from '@jupyterlab/testutils';
+import {
+  framePromise,
+  testEmission,
+  JupyterServer
+} from '@jupyterlab/testutils';
+
+const server = new JupyterServer();
+
+beforeAll(async () => {
+  await server.start();
+});
+
+afterAll(async () => {
+  await server.shutdown();
+});
 
 class LogTerminal extends Terminal {
   methods: string[] = [];
@@ -51,14 +64,15 @@ describe('terminal/index', () => {
   describe('Terminal', () => {
     let widget: LogTerminal;
     let session: TerminalNS.ITerminalConnection;
-    const manager = new TerminalManager();
+    let manager: TerminalManager;
 
-    before(async () => {
+    beforeAll(async () => {
+      manager = new TerminalManager();
       session = await manager.startNew();
     });
 
     beforeEach(() => {
-      widget = new LogTerminal(session);
+      widget = new LogTerminal(session, { autoFit: false });
       Widget.attach(widget, document.body);
       return framePromise();
     });
@@ -69,13 +83,13 @@ describe('terminal/index', () => {
 
     describe('#constructor()', () => {
       it('should create a terminal widget', () => {
-        expect(widget).to.be.an.instanceof(Terminal);
+        expect(widget).toBeInstanceOf(Terminal);
       });
     });
 
     describe('#session', () => {
       it('should be the constructor value', () => {
-        expect(widget.session).to.equal(session);
+        expect(widget.session).toBe(session);
       });
 
       it('should set the title when ready', async () => {
@@ -84,47 +98,47 @@ describe('terminal/index', () => {
             find: (_, status) => status === 'connected'
           });
         }
-        expect(widget.title.label).to.contain(session.name);
+        expect(widget.title.label).toContain(session.name);
       });
     });
 
     describe('#fontSize', () => {
       it('should be 13 by default', () => {
-        expect(widget.getOption('fontSize')).to.equal(13);
+        expect(widget.getOption('fontSize')).toBe(13);
       });
 
       it('should trigger an update request', async () => {
         widget.setOption('fontSize', 14);
-        expect(widget.getOption('fontSize')).to.equal(14);
+        expect(widget.getOption('fontSize')).toBe(14);
         await framePromise();
-        expect(widget.methods).to.contain('onUpdateRequest');
+        expect(widget.methods).toContain('onUpdateRequest');
       });
     });
 
     describe('#scrollback', () => {
       it('should be 1000 by default', () => {
-        expect(widget.getOption('scrollback')).to.equal(1000);
+        expect(widget.getOption('scrollback')).toBe(1000);
       });
     });
 
     describe('#theme', () => {
       it('should be set to inherit by default', () => {
-        expect(widget.getOption('theme')).to.equal('inherit');
+        expect(widget.getOption('theme')).toBe('inherit');
       });
 
       it('should be light if we change it', () => {
         widget.setOption('theme', 'light');
-        expect(widget.getOption('theme')).to.equal('light');
+        expect(widget.getOption('theme')).toBe('light');
       });
     });
 
     describe('#dispose()', () => {
       it('should dispose of the resources used by the widget', () => {
-        expect(widget.isDisposed).to.equal(false);
+        expect(widget.isDisposed).toBe(false);
         widget.dispose();
-        expect(widget.isDisposed).to.equal(true);
+        expect(widget.isDisposed).toBe(true);
         widget.dispose();
-        expect(widget.isDisposed).to.equal(true);
+        expect(widget.isDisposed).toBe(true);
       });
     });
 
@@ -137,7 +151,7 @@ describe('terminal/index', () => {
     describe('#processMessage()', () => {
       it('should handle fit requests', () => {
         widget.processMessage(Widget.Msg.FitRequest);
-        expect(widget.methods).to.contain('onFitRequest');
+        expect(widget.methods).toContain('onFitRequest');
       });
     });
 
@@ -146,7 +160,7 @@ describe('terminal/index', () => {
         Widget.detach(widget);
         Widget.attach(widget, document.body);
         await framePromise();
-        expect(widget.methods).to.contain('onUpdateRequest');
+        expect(widget.methods).toContain('onUpdateRequest');
       });
     });
 
@@ -159,7 +173,7 @@ describe('terminal/index', () => {
         widget.methods = [];
         widget.show();
         await framePromise();
-        expect(widget.methods).to.contain('onUpdateRequest');
+        expect(widget.methods).toContain('onUpdateRequest');
       });
     });
 
@@ -167,27 +181,28 @@ describe('terminal/index', () => {
       it('should trigger an update request', async () => {
         const msg = Widget.ResizeMessage.UnknownSize;
         MessageLoop.sendMessage(widget, msg);
-        expect(widget.methods).to.contain('onResize');
+        expect(widget.methods).toContain('onResize');
         await framePromise();
-        expect(widget.methods).to.contain('onUpdateRequest');
+        expect(widget.methods).toContain('onUpdateRequest');
       });
     });
 
     describe('#onUpdateRequest()', () => {
-      it('should set the style of the terminal', () => {
+      it('should attach the terminal', () => {
         Widget.detach(widget);
         Widget.attach(widget, document.body);
         MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
-        expect(widget.methods).to.contain('onUpdateRequest');
-        const style = window.getComputedStyle(widget.node);
-        expect(style.backgroundColor).to.equal('rgba(0, 0, 0, 0)');
+        expect(widget.methods).toContain('onUpdateRequest');
+        expect(widget.node.firstElementChild!.classList).toContain(
+          'jp-Terminal-body'
+        );
       });
     });
 
     describe('#onFitRequest', () => {
       it('should send a resize request', () => {
         MessageLoop.sendMessage(widget, Widget.Msg.FitRequest);
-        expect(widget.methods).to.contain('onResize');
+        expect(widget.methods).toContain('onResize');
       });
     });
 
@@ -195,10 +210,10 @@ describe('terminal/index', () => {
       it('should focus the terminal element', () => {
         Widget.detach(widget);
         Widget.attach(widget, document.body);
-        expect(widget.node.contains(document.activeElement)).to.equal(false);
+        expect(widget.node.contains(document.activeElement)).toBe(false);
         MessageLoop.sendMessage(widget, Widget.Msg.ActivateRequest);
-        expect(widget.methods).to.contain('onActivateRequest');
-        expect(widget.node.contains(document.activeElement)).to.equal(true);
+        expect(widget.methods).toContain('onActivateRequest');
+        expect(widget.node.contains(document.activeElement)).toBe(true);
       });
     });
   });

+ 21 - 0
packages/terminal/tsconfig.test.json

@@ -0,0 +1,21 @@
+{
+  "extends": "../../tsconfigbase.test",
+  "include": ["src/*", "test/*"],
+  "references": [
+    {
+      "path": "../apputils"
+    },
+    {
+      "path": "../services"
+    },
+    {
+      "path": "../../testutils"
+    },
+    {
+      "path": "../apputils"
+    },
+    {
+      "path": "../services"
+    }
+  ]
+}

+ 2 - 1
tests/modernize.js

@@ -88,11 +88,12 @@ console.debug('.');
 console.debug('------------------------------------');
 utils.run('jlpm jest-codemods --force', { cwd: testSrc });
 
-// Move the test files to `/packages/{name}/test`
+// Move the test config files to `/packages/{name}`
 utils.run(`git mv ${testSrc}/src ${pkgPath}/${name}/test`);
 ['tsconfig.test.json', 'babel.config.js', 'jest.config.js'].forEach(fname => {
   utils.run(`mv ${testSrc}/${fname} ${pkgPath}/${name}`);
 });
+utils.run(`git add ${pkgPath}/${name}`);
 
 // Add a vscode launch file and force it to commit.
 utils.run(`mkdir -p ${pkgPath}/${name}/.vscode`);

+ 0 - 1
tests/test-terminal/karma-cov.conf.js

@@ -1 +0,0 @@
-module.exports = require('../karma-cov.conf');

+ 0 - 1
tests/test-terminal/karma.conf.js

@@ -1 +0,0 @@
-module.exports = require('../karma.conf');

+ 0 - 36
tests/test-terminal/package.json

@@ -1,36 +0,0 @@
-{
-  "name": "@jupyterlab/test-terminal",
-  "version": "2.1.0",
-  "private": true,
-  "scripts": {
-    "build": "tsc -b",
-    "clean": "rimraf build && rimraf coverage",
-    "coverage": "python run-test.py --browsers=ChromeHeadless karma-cov.conf.js",
-    "test": "jlpm run test:firefox-headless",
-    "test:chrome": "python run-test.py --browsers=Chrome karma.conf.js",
-    "test:chrome-headless": "python run-test.py --browsers=ChromeHeadless karma.conf.js",
-    "test:debug": "python run-test.py  --browsers=Chrome --singleRun=false --debug=true --browserNoActivityTimeout=10000000 karma.conf.js",
-    "test:firefox": "python run-test.py --browsers=Firefox karma.conf.js",
-    "test:firefox-headless": "python run-test.py --browsers=FirefoxHeadless karma.conf.js",
-    "test:ie": "python run-test.py  --browsers=IE karma.conf.js",
-    "watch": "tsc -b --watch",
-    "watch:src": "tsc -p src --watch"
-  },
-  "dependencies": {
-    "@jupyterlab/services": "^5.1.0",
-    "@jupyterlab/terminal": "^2.1.0",
-    "@jupyterlab/testutils": "^2.1.0",
-    "@lumino/messaging": "^1.3.3",
-    "@lumino/widgets": "^1.11.1",
-    "chai": "^4.2.0"
-  },
-  "devDependencies": {
-    "@types/chai": "^4.2.7",
-    "@types/mocha": "^7.0.2",
-    "karma": "^4.4.1",
-    "karma-chrome-launcher": "~3.1.0",
-    "puppeteer": "~2.0.0",
-    "rimraf": "~3.0.0",
-    "typescript": "~3.7.3"
-  }
-}

+ 0 - 8
tests/test-terminal/run-test.py

@@ -1,8 +0,0 @@
-# Copyright (c) Jupyter Development Team.
-# Distributed under the terms of the Modified BSD License.
-
-import os.path as osp
-from jupyterlab.tests.test_app import run_karma
-
-if __name__ == '__main__':
-    run_karma(osp.dirname(osp.realpath(__file__)))

+ 0 - 22
tests/test-terminal/tsconfig.json

@@ -1,22 +0,0 @@
-{
-  "extends": "../../tsconfigbase",
-  "compilerOptions": {
-    "outDir": "build",
-    "types": ["mocha"],
-    "composite": false,
-    "rootDir": "src",
-    "skipLibCheck": true
-  },
-  "include": ["src/*"],
-  "references": [
-    {
-      "path": "../../packages/services"
-    },
-    {
-      "path": "../../packages/terminal"
-    },
-    {
-      "path": "../../testutils"
-    }
-  ]
-}