From 973038c2d67778c9a3335dadbb8f2ad90e4d6e41 Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Fri, 30 Jun 2017 13:56:37 +0300 Subject: [PATCH] Fix some tests and docs, little code fix up. Fix some tests and docs. Add ability to run one test file with help gulp task. Signed-off-by: Oleksandr Andriienko --- gulpfile.js | 17 +++++++++++++++-- package.json | 3 ++- src/Buffer.ts | 4 ++-- src/SelectionManager.test.ts | 5 +++++ src/SelectionModel.test.ts | 5 +++++ src/Viewport.test.ts | 20 +++++++++++--------- src/Viewport.ts | 4 +--- src/xterm.js | 4 ++-- 8 files changed, 43 insertions(+), 19 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 1f92e53751..fcd90a51db 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -10,7 +10,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'); @@ -87,13 +87,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(); }); diff --git a/package.json b/package.json index 6dda754861..19946eb5e3 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,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", diff --git a/src/Buffer.ts b/src/Buffer.ts index e36ff99e6d..a3e45d25c6 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -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; + public lines: CircularList; /** * 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(this.terminal.scrollback); this.scrollBottom = this.terminal.rows - 1; } } diff --git a/src/SelectionManager.test.ts b/src/SelectionManager.test.ts index 426f589ec8..d8793062c9 100644 --- a/src/SelectionManager.test.ts +++ b/src/SelectionManager.test.ts @@ -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( @@ -45,6 +46,10 @@ describe('SelectionManager', () => { document = window.document; buffer = new CircularList(100); terminal = { 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(); }); diff --git a/src/SelectionModel.test.ts b/src/SelectionModel.test.ts index ab22b77cc5..6da3874bd4 100644 --- a/src/SelectionModel.test.ts +++ b/src/SelectionModel.test.ts @@ -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 = { cols: 80, rows: 2, ybase: 0 }; + terminal.scrollback = 10; + terminal.buffers = new BufferSet(terminal); + terminal.buffer = terminal.buffers.active; + model = new TestSelectionModel(terminal); }); diff --git a/src/Viewport.test.ts b/src/Viewport.test.ts index 193e7969fd..6d09ea86a2 100644 --- a/src/Viewport.test.ts +++ b/src/Viewport.test.ts @@ -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'); diff --git a/src/Viewport.ts b/src/Viewport.ts index 1aee8be6f7..1d71929271 100644 --- a/src/Viewport.ts +++ b/src/Viewport.ts @@ -19,7 +19,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, @@ -42,8 +42,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) { diff --git a/src/xterm.js b/src/xterm.js index fa20619319..28c2d15743 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -405,7 +405,7 @@ Terminal.prototype.setOption = function(key, value) { switch (key) { case 'scrollback': 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); @@ -488,7 +488,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'); }