]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Fix some tests and docs, little code fix up.
authorOleksandr Andriienko <oandriie@redhat.com>
Fri, 30 Jun 2017 10:56:37 +0000 (13:56 +0300)
committerParis Kasidiaris <pariskasidiaris@gmail.com>
Sun, 16 Jul 2017 00:47:15 +0000 (03:47 +0300)
Fix some tests and docs. Add ability to run one test file with help gulp task.

Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
gulpfile.js
package.json
src/Buffer.ts
src/SelectionManager.test.ts
src/SelectionModel.test.ts
src/Viewport.test.ts
src/Viewport.ts
src/xterm.js

index 9b0a6de73f25a775eba3602677e134a504b472ee..ef4e46099858a36e60b12b3ebb5678973c1b3960 100644 (file)
@@ -14,7 +14,7 @@ const sorcery = require('sorcery');
 const source = require('vinyl-source-stream');
 const sourcemaps = require('gulp-sourcemaps');
 const ts = require('gulp-typescript');
-
+const util = require('gulp-util');
 
 let buildDir = process.env.BUILD_DIR || 'build';
 let tsProject = ts.createProject('tsconfig.json');
@@ -121,13 +121,26 @@ gulp.task('mocha', ['instrument-test'], function () {
       .pipe(istanbul.writeReports());
 });
 
+/**
+ * Run single test file by file name(without file extension). Example of the command:
+ * gulp mocha-test --test InputHandler.test
+ */
+gulp.task('mocha-test', ['instrument-test'], function () {
+  let testName = util.env.test;
+  util.log("Run test by Name: " + testName);
+  return gulp.src([`${outDir}/${testName}.js`, `${outDir}/**/${testName}.js`], {read: false})
+         .pipe(mocha())
+         .once('error', () => process.exit(1))
+         .pipe(istanbul.writeReports());
+});
+
 /**
  * Use `sorcery` to resolve the source map chain and point back to the TypeScript files.
  * (Without this task the source maps produced for the JavaScript bundle points into the
  * compiled JavaScript files in ${outDir}/).
  */
 gulp.task('sorcery', ['browserify'], function () {
-  var chain = sorcery.loadSync(`${buildDir}/xterm.js`);
+  let chain = sorcery.loadSync(`${buildDir}/xterm.js`);
   chain.apply();
   chain.writeSync();
 });
index b23f4a2c50039dd4869e0793dc99f5243dc066a3..065925b3a3fca6f5963ac67c00176bcf42d2a668 100644 (file)
@@ -62,7 +62,8 @@
     "tslint": "^4.0.2",
     "typescript": "~2.2.0",
     "vinyl-buffer": "^1.0.0",
-    "vinyl-source-stream": "^1.1.0"
+    "vinyl-source-stream": "^1.1.0",
+    "gulp-util": "^3.0.8"
   },
   "scripts": {
     "prestart": "npm run build",
index e36ff99e6d573ee5b31aed88a1e3fb93e44f1013..a3e45d25c67366683abff69e12210e5e83413896 100644 (file)
@@ -9,7 +9,7 @@ import { CircularList } from './utils/CircularList';
  * This class represents a terminal buffer (an internal state of the terminal)/
  */
 export class Buffer {
-  public lines: CircularList<any>;
+  public lines: CircularList<string>;
 
   /**
    * Create a new Buffer.
@@ -29,7 +29,7 @@ export class Buffer {
     public scrollTop: number = 0,
     public tabs: any = {},
   ) {
-    this.lines = new CircularList(this.terminal.scrollback);
+    this.lines = new CircularList<string>(this.terminal.scrollback);
     this.scrollBottom = this.terminal.rows - 1;
   }
 }
index e09a6e3d553b2a119596c1f017ee454d385a1ec8..12784e02b0782e844fcb9a1b7dd00981bd517e1e 100644 (file)
@@ -8,6 +8,7 @@ import { CharMeasure } from './utils/CharMeasure';
 import { CircularList } from './utils/CircularList';
 import { SelectionManager } from './SelectionManager';
 import { SelectionModel } from './SelectionModel';
+import {BufferSet} from './BufferSet';
 
 class TestSelectionManager extends SelectionManager {
   constructor(
@@ -40,13 +41,31 @@ describe('SelectionManager', () => {
   let rowContainer: HTMLElement;
   let selectionManager: TestSelectionManager;
 
+<<<<<<< HEAD
   beforeEach(() => {
     dom = new jsdom.JSDOM('');
     window = dom.window;
-    document = window.document;
-    buffer = new CircularList<any>(100);
+    document = window.document
     terminal = <any>{ cols: 80, rows: 2 };
+    terminal.scrollback = 100;
+    terminal.buffers = new BufferSet(terminal);
+    terminal.buffer = terminal.buffers.active;
     selectionManager = new TestSelectionManager(terminal, buffer, rowContainer, null);
+=======
+  beforeEach(done => {
+    jsdom.env('', (err, w) => {
+      window = w;
+      document = window.document;
+      buffer = new CircularList<any>(100);
+      terminal = <any>{ cols: 80, rows: 2 };
+      terminal.scrollback = 10;
+      terminal.buffers = new BufferSet(terminal);
+      terminal.buffer = terminal.buffers.active;
+
+      selectionManager = new TestSelectionManager(terminal, buffer, rowContainer, null);
+      done();
+    });
+>>>>>>> Fix some tests and docs, little code fix up.
   });
 
   function stringToRow(text: string): [number, string, number][] {
index ab22b77cc50bb9fb6ccbf8a25df0528dc82de1a4..6da3874bd40ed0e3ade296f0bdf3079bc1add443 100644 (file)
@@ -4,6 +4,7 @@
 import { assert } from 'chai';
 import { ITerminal } from './Interfaces';
 import { SelectionModel } from './SelectionModel';
+import {BufferSet} from './BufferSet';
 
 class TestSelectionModel extends SelectionModel {
   constructor(
@@ -22,6 +23,10 @@ describe('SelectionManager', () => {
 
   beforeEach(() => {
     terminal = <any>{ cols: 80, rows: 2, ybase: 0 };
+    terminal.scrollback = 10;
+    terminal.buffers = new BufferSet(terminal);
+    terminal.buffer = terminal.buffers.active;
+
     model = new TestSelectionModel(terminal);
   });
 
index 193e7969fd6732e2e4c51c7fbdb2999825375a4a..6d09ea86a2b9d102b109ead0bc7746ff50f9f0d8 100644 (file)
@@ -1,10 +1,10 @@
 import { assert } from 'chai';
 import { Viewport } from './Viewport';
+import {BufferSet} from './BufferSet';
 
 describe('Viewport', () => {
   let terminal;
   let viewportElement;
-  let selectionContainer;
   let charMeasure;
   let viewport;
   let scrollAreaElement;
@@ -13,7 +13,6 @@ describe('Viewport', () => {
 
   beforeEach(() => {
     terminal = {
-      lines: [],
       rows: 0,
       ydisp: 0,
       on: () => {},
@@ -26,8 +25,11 @@ describe('Viewport', () => {
         style: {
           height: 0
         }
-      }
+      },
+      scrollback: 10
     };
+    terminal.buffers = new BufferSet(terminal);
+    terminal.buffer = terminal.buffers.active;
     viewportElement = {
       addEventListener: () => {},
       style: {
@@ -60,14 +62,14 @@ describe('Viewport', () => {
       }, 0);
     });
     it('should set the height of the viewport when the line-height changed', () => {
-      terminal.lines.push('');
-      terminal.lines.push('');
+      terminal.buffer.lines.push('');
+      terminal.buffer.lines.push('');
       terminal.rows = 1;
       viewport.refresh();
       assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
-      charMeasure.height = 20;
+      charMeasure.height = 2 * CHARACTER_HEIGHT;
       viewport.refresh();
-      assert.equal(viewportElement.style.height, 20 + 'px');
+      assert.equal(viewportElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
     });
   });
 
@@ -75,13 +77,13 @@ describe('Viewport', () => {
     it('should sync the scroll area', done => {
       // Allow CharMeasure to be initialized
       setTimeout(() => {
-        terminal.lines.push('');
+        terminal.buffer.lines.push('');
         terminal.rows = 1;
         assert.equal(scrollAreaElement.style.height, 0 * CHARACTER_HEIGHT + 'px');
         viewport.syncScrollArea();
         assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
         assert.equal(scrollAreaElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
-        terminal.lines.push('');
+        terminal.buffer.lines.push('');
         viewport.syncScrollArea();
         assert.equal(viewportElement.style.height, 1 * CHARACTER_HEIGHT + 'px');
         assert.equal(scrollAreaElement.style.height, 2 * CHARACTER_HEIGHT + 'px');
index 81ecca1b9af2cc69a57d6939f1c417946373b803..fe276935bb7b507f67f115598c038e53c12b398a 100644 (file)
@@ -20,7 +20,7 @@ export class Viewport {
    * @param terminal The terminal this viewport belongs to.
    * @param viewportElement The DOM element acting as the viewport.
    * @param scrollArea The DOM element acting as the scroll area.
-   * @param charMeasureElement A DOM element used to measure the character size of. the terminal.
+   * @param charMeasure A DOM element used to measure the character size of. the terminal.
    */
   constructor(
     private terminal: ITerminal,
@@ -43,8 +43,6 @@ export class Viewport {
   /**
    * Refreshes row height, setting line-height, viewport height and scroll area height if
    * necessary.
-   * @param charSize A character size measurement bounding rect object, if it doesn't exist it will
-   *   be created.
    */
   private refresh(): void {
     if (this.charMeasure.height > 0) {
index 6460ca9042945d2b96d706f51fc9334dc45c5842..a0cd9fd223be038c58de7fe75c656fed16fcccbf 100644 (file)
@@ -415,7 +415,7 @@ Terminal.prototype.setOption = function(key, value) {
       }
 
       if (this.options[key] !== value) {
-        if (this.buffer.length > value) {
+        if (this.buffer.lines.length > value) {
           const amountToTrim = this.buffer.lines.length - value;
           const needsRefresh = (this.buffer.ydisp - amountToTrim < 0);
           this.buffer.lines.trimStart(amountToTrim);
@@ -498,7 +498,7 @@ Terminal.prototype.blur = function() {
  */
 Terminal.bindBlur = function (term) {
   on(term.textarea, 'blur', function (ev) {
-    term.refresh(term.y, term.y);
+    term.refresh(term.buffer.y, term.buffer.y);
     if (term.sendFocus) {
       term.send(C0.ESC + '[O');
     }