Add unit tests for TerminalRecorder
This commit is contained in:
parent
7c0e20ca4c
commit
7a6944d2d0
4 changed files with 57 additions and 16 deletions
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/terminalProcess';
|
||||
import { IPtyHostProcessReplayEvent, ReplayEntry } from 'vs/platform/terminal/common/terminalProcess';
|
||||
|
||||
const MAX_RECORDER_DATA_SIZE = 1024 * 1024; // 1MB
|
||||
|
||||
|
@ -13,8 +13,6 @@ interface RecorderEntry {
|
|||
data: string[];
|
||||
}
|
||||
|
||||
export interface ReplayEntry { cols: number; rows: number; data: string; }
|
||||
|
||||
export interface IRemoteTerminalProcessReplayEvent {
|
||||
events: ReplayEntry[];
|
||||
}
|
||||
|
@ -24,17 +22,8 @@ export class TerminalRecorder {
|
|||
private _entries: RecorderEntry[];
|
||||
private _totalDataLength: number = 0;
|
||||
|
||||
constructor(initialDimensions?: { cols: number, rows: number }) {
|
||||
if (initialDimensions) {
|
||||
this._entries = [{
|
||||
cols: initialDimensions.cols,
|
||||
rows: initialDimensions.rows,
|
||||
data: []
|
||||
}];
|
||||
} else {
|
||||
this._entries = [];
|
||||
}
|
||||
this._totalDataLength = 0;
|
||||
constructor(cols: number, rows: number) {
|
||||
this._entries = [{ cols, rows, data: [] }];
|
||||
}
|
||||
|
||||
public recordResize(cols: number, rows: number): void {
|
||||
|
|
|
@ -270,7 +270,7 @@ export class PersistentTerminalProcess extends Disposable {
|
|||
private readonly _logService: ILogService
|
||||
) {
|
||||
super();
|
||||
this._recorder = new TerminalRecorder({ cols, rows });
|
||||
this._recorder = new TerminalRecorder(cols, rows);
|
||||
this._orphanQuestionBarrier = null;
|
||||
this._orphanQuestionReplyTime = 0;
|
||||
this._disconnectRunner1 = this._register(new RunOnceScheduler(() => {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { TerminalRecorder } from 'vs/platform/terminal/common/terminalRecorder';
|
||||
import { ReplayEntry } from 'vs/platform/terminal/common/terminalProcess';
|
||||
|
||||
function eventsEqual(recorder: TerminalRecorder, expected: ReplayEntry[]) {
|
||||
const actual = recorder.generateReplayEvent().events;
|
||||
for (let i = 0; i < expected.length; i++) {
|
||||
assert.deepStrictEqual(actual[i], expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
suite('TerminalRecorder', () => {
|
||||
test('should record dimensions', () => {
|
||||
const recorder = new TerminalRecorder(1, 2);
|
||||
eventsEqual(recorder, [
|
||||
{ cols: 1, rows: 2, data: '' }
|
||||
]);
|
||||
recorder.recordData('a');
|
||||
recorder.recordResize(3, 4);
|
||||
eventsEqual(recorder, [
|
||||
{ cols: 1, rows: 2, data: 'a' },
|
||||
{ cols: 3, rows: 4, data: '' }
|
||||
]);
|
||||
});
|
||||
test('should ignore resize events without data', () => {
|
||||
const recorder = new TerminalRecorder(1, 2);
|
||||
eventsEqual(recorder, [
|
||||
{ cols: 1, rows: 2, data: '' }
|
||||
]);
|
||||
recorder.recordResize(3, 4);
|
||||
eventsEqual(recorder, [
|
||||
{ cols: 3, rows: 4, data: '' }
|
||||
]);
|
||||
});
|
||||
test('should record data and combine it into the previous resize event', () => {
|
||||
const recorder = new TerminalRecorder(1, 2);
|
||||
recorder.recordData('a');
|
||||
recorder.recordData('b');
|
||||
recorder.recordResize(3, 4);
|
||||
recorder.recordData('c');
|
||||
recorder.recordData('d');
|
||||
eventsEqual(recorder, [
|
||||
{ cols: 1, rows: 2, data: 'ab' },
|
||||
{ cols: 3, rows: 4, data: 'cd' }
|
||||
]);
|
||||
});
|
||||
});
|
|
@ -662,7 +662,7 @@ class SeamlessRelaunchDataFilter extends Disposable {
|
|||
}
|
||||
|
||||
private _createRecorder(process: ITerminalChildProcess): [TerminalRecorder, IDisposable] {
|
||||
const recorder = new TerminalRecorder();
|
||||
const recorder = new TerminalRecorder(0, 0);
|
||||
const disposable = process.onProcessData(e => recorder.recordData(typeof e === 'string' ? e : e.data));
|
||||
return [recorder, disposable];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue