Skip to content

Commit da2267a

Browse files
authored
Merge pull request #5648 from Tyriar/slow_tests_2
Speed up all remaining unit tests below threshold (40ms?)
2 parents 1c42957 + 34e68b1 commit da2267a

5 files changed

Lines changed: 56 additions & 43 deletions

File tree

src/browser/Terminal.test.ts

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ describe('Terminal', () => {
190190
});
191191
it('should clear a buffer larger than rows', async () => {
192192
// Fill the buffer with dummy rows
193-
for (let i = 0; i < term.rows * 2; i++) {
194-
await term.writeP('test\n');
195-
}
193+
await term.writeP('test\n'.repeat(term.rows * 2));
196194

197195
const promptLine = term.buffer.lines.get(term.buffer.ybase + term.buffer.y);
198196
term.clear();
@@ -389,9 +387,7 @@ describe('Terminal', () => {
389387

390388
it('should not scroll down, when a custom keydown handler prevents the event', async () => {
391389
// Add some output to the terminal
392-
for (let i = 0; i < term.rows * 3; i++) {
393-
await term.writeP('test\r\n');
394-
}
390+
await term.writeP('test\r\n'.repeat(term.rows * 3));
395391
const startYDisp = (term.rows * 2) + 1;
396392
term.attachCustomKeyEventHandler(() => {
397393
return false;
@@ -731,70 +727,87 @@ describe('Terminal', () => {
731727
it(`${range}: 2 characters per cell`, async function (): Promise<void> {
732728
const high = String.fromCharCode(0xD800);
733729
const cell = new CellData();
730+
const values: string[] = [];
734731
for (let j = i; j <= i + 0xF; j++) {
735-
await term.writeP(high + String.fromCharCode(j));
736-
const tchar = term.buffer.lines.get(0)!.loadCell(0, cell);
737-
assert.equal(tchar.getChars(), high + String.fromCharCode(j));
732+
values.push(high + String.fromCharCode(j));
733+
}
734+
await term.writeP(values.join('\r\n'));
735+
for (let idx = 0; idx < values.length; idx++) {
736+
const expected = values[idx];
737+
const tchar = term.buffer.lines.get(idx)!.loadCell(0, cell);
738+
assert.equal(tchar.getChars(), expected);
738739
assert.equal(tchar.getChars().length, 2);
739740
assert.equal(tchar.getWidth(), 1);
740-
assert.equal(term.buffer.lines.get(0)!.loadCell(1, cell).getChars(), '');
741-
term.reset();
741+
assert.equal(term.buffer.lines.get(idx)!.loadCell(1, cell).getChars(), '');
742742
}
743743
});
744744
it(`${range}: 2 characters at last cell`, async () => {
745745
const high = String.fromCharCode(0xD800);
746746
const cell = new CellData();
747-
term.buffer.x = term.cols - 1;
747+
const values: string[] = [];
748748
for (let j = i; j <= i + 0xF; j++) {
749-
await term.writeP(high + String.fromCharCode(j));
750-
assert.equal(term.buffer.lines.get(0)!.loadCell(term.buffer.x - 1, cell).getChars(), high + String.fromCharCode(j));
751-
assert.equal(term.buffer.lines.get(0)!.loadCell(term.buffer.x - 1, cell).getChars().length, 2);
752-
assert.equal(term.buffer.lines.get(1)!.loadCell(0, cell).getChars(), '');
753-
term.reset();
749+
values.push(high + String.fromCharCode(j));
750+
}
751+
await term.writeP(values.map((value, idx) => `\x1b[${idx + 1};${term.cols}H${value}`).join(''));
752+
for (let idx = 0; idx < values.length; idx++) {
753+
const expected = values[idx];
754+
assert.equal(term.buffer.lines.get(idx)!.loadCell(term.cols - 1, cell).getChars(), expected);
755+
assert.equal(term.buffer.lines.get(idx)!.loadCell(term.cols - 1, cell).getChars().length, 2);
756+
assert.equal(term.buffer.lines.get(idx + 1)!.loadCell(0, cell).getChars(), '');
754757
}
755758
});
756759
it(`${range}: 2 characters per cell over line end with autowrap`, async function (): Promise<void> {
757760
const high = String.fromCharCode(0xD800);
758761
const cell = new CellData();
762+
term.resize(term.cols, 40);
763+
const values: string[] = [];
759764
for (let j = i; j <= i + 0xF; j++) {
760-
term.buffer.x = term.cols - 1;
761-
await term.writeP('a' + high + String.fromCharCode(j));
762-
assert.equal(term.buffer.lines.get(0)!.loadCell(term.cols - 1, cell).getChars(), 'a');
763-
assert.equal(term.buffer.lines.get(1)!.loadCell(0, cell).getChars(), high + String.fromCharCode(j));
764-
assert.equal(term.buffer.lines.get(1)!.loadCell(0, cell).getChars().length, 2);
765-
assert.equal(term.buffer.lines.get(1)!.loadCell(1, cell).getChars(), '');
766-
term.reset();
765+
values.push(high + String.fromCharCode(j));
766+
}
767+
await term.writeP(values.map((value, idx) => `\x1b[${idx * 2 + 1};${term.cols}H` + 'a' + value).join(''));
768+
for (let idx = 0; idx < values.length; idx++) {
769+
const expected = values[idx];
770+
const row = idx * 2;
771+
assert.equal(term.buffer.lines.get(row)!.loadCell(term.cols - 1, cell).getChars(), 'a');
772+
assert.equal(term.buffer.lines.get(row + 1)!.loadCell(0, cell).getChars(), expected);
773+
assert.equal(term.buffer.lines.get(row + 1)!.loadCell(0, cell).getChars().length, 2);
774+
assert.equal(term.buffer.lines.get(row + 1)!.loadCell(1, cell).getChars(), '');
767775
}
768776
});
769777
it(`${range}: 2 characters per cell over line end without autowrap`, async function (): Promise<void> {
770778
const high = String.fromCharCode(0xD800);
771779
const cell = new CellData();
780+
const values: string[] = [];
772781
for (let j = i; j <= i + 0xF; j++) {
773-
term.buffer.x = term.cols - 1;
774-
await term.writeP('\x1b[?7l'); // Disable wraparound mode
775782
const width = wcwidth((0xD800 - 0xD800) * 0x400 + j - 0xDC00 + 0x10000);
776783
if (width !== 1) {
777784
continue;
778785
}
779-
await term.writeP('a' + high + String.fromCharCode(j));
780-
// auto wraparound mode should cut off the rest of the line
781-
assert.equal(term.buffer.lines.get(0)!.loadCell(term.cols - 1, cell).getChars(), high + String.fromCharCode(j));
782-
assert.equal(term.buffer.lines.get(0)!.loadCell(term.cols - 1, cell).getChars().length, 2);
783-
assert.equal(term.buffer.lines.get(1)!.loadCell(1, cell).getChars(), '');
784-
term.reset();
786+
values.push(high + String.fromCharCode(j));
787+
}
788+
await term.writeP('\x1b[?7l' + values.map((value, idx) => `\x1b[${idx + 1};${term.cols}H` + 'a' + value).join(''));
789+
for (let idx = 0; idx < values.length; idx++) {
790+
const expected = values[idx];
791+
assert.equal(term.buffer.lines.get(idx)!.loadCell(term.cols - 1, cell).getChars(), expected);
792+
assert.equal(term.buffer.lines.get(idx)!.loadCell(term.cols - 1, cell).getChars().length, 2);
793+
assert.equal(term.buffer.lines.get(idx + 1)!.loadCell(1, cell).getChars(), '');
785794
}
786795
});
787796
it(`${range}: splitted surrogates`, async function (): Promise<void> {
788797
const high = String.fromCharCode(0xD800);
789798
const cell = new CellData();
799+
const values: string[] = [];
790800
for (let j = i; j <= i + 0xF; j++) {
791-
await term.writeP(high + String.fromCharCode(j));
792-
const tchar = term.buffer.lines.get(0)!.loadCell(0, cell);
793-
assert.equal(tchar.getChars(), high + String.fromCharCode(j));
801+
values.push(high + String.fromCharCode(j));
802+
}
803+
await term.writeP(values.join('\r\n'));
804+
for (let idx = 0; idx < values.length; idx++) {
805+
const expected = values[idx];
806+
const tchar = term.buffer.lines.get(idx)!.loadCell(0, cell);
807+
assert.equal(tchar.getChars(), expected);
794808
assert.equal(tchar.getChars().length, 2);
795809
assert.equal(tchar.getWidth(), 1);
796-
assert.equal(term.buffer.lines.get(0)!.loadCell(1, cell).getChars(), '');
797-
term.reset();
810+
assert.equal(term.buffer.lines.get(idx)!.loadCell(1, cell).getChars(), '');
798811
}
799812
});
800813
}

src/common/InputHandler.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,7 @@ describe('InputHandler', () => {
25212521
const cpr: number[][] = [];
25222522
inputHandler.registerCsiHandler({ final: 'H' }, async params => {
25232523
cup.push(params.toArray() as number[]);
2524-
await new Promise(res => setTimeout(res, 50));
2524+
await Promise.resolve();
25252525
// late call of real repositioning
25262526
return inputHandler.cursorPosition(params);
25272527
});
@@ -2536,7 +2536,7 @@ describe('InputHandler', () => {
25362536
});
25372537
it('async OSC between', async () => {
25382538
inputHandler.registerOscHandler(1000, async data => {
2539-
await new Promise(res => setTimeout(res, 50));
2539+
await Promise.resolve();
25402540
assert.deepEqual(getLines(bufferService, 2), ['hello world!', '']);
25412541
assert.equal(data, 'some data');
25422542
return true;
@@ -2546,7 +2546,7 @@ describe('InputHandler', () => {
25462546
});
25472547
it('async DCS between', async () => {
25482548
inputHandler.registerDcsHandler({ final: 'a' }, async (data, params) => {
2549-
await new Promise(res => setTimeout(res, 50));
2549+
await Promise.resolve();
25502550
assert.deepEqual(getLines(bufferService, 2), ['hello world!', '']);
25512551
assert.equal(data, 'some data');
25522552
assert.deepEqual(params.toArray(), [1, 2]);

src/common/input/WriteBuffer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('WriteBuffer', () => {
8888
it('writeSync called from action does not overflow callstack - issue #3265', () => {
8989
wb = new WriteBuffer(data => {
9090
const num = parseInt(data as string);
91-
if (num < 1000000) {
91+
if (num < 10000) {
9292
wb.writeSync('' + (num + 1));
9393
}
9494
});

src/common/parser/DcsParser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class TestHandlerAsync implements IDcsHandler {
278278
}
279279
public async unhook(success: boolean): Promise<boolean> {
280280
// simple sleep to check in tests whether ordering gets messed up
281-
await new Promise(res => setTimeout(res, 20));
281+
await Promise.resolve();
282282
this.output.push([this.msg, 'UNHOOK', success]);
283283
if (this.returnFalse) {
284284
return false;

src/common/parser/OscParser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class TestHandlerAsync implements IOscHandler {
275275
this.output.push([this.msg, this.id, 'PUT', utf32ToString(data, start, end)]);
276276
}
277277
public async end(success: boolean): Promise<boolean> {
278-
await new Promise(res => setTimeout(res, 20));
278+
await Promise.resolve();
279279
this.output.push([this.msg, this.id, 'END', success]);
280280
if (this.returnFalse) {
281281
return false;

0 commit comments

Comments
 (0)