-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Copyright (c) 2019 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import * as puppeteer from 'puppeteer'; | ||
import { assert } from 'chai'; | ||
import { ITerminalOptions } from 'xterm'; | ||
|
||
const APP = 'http://127.0.0.1:3000/test'; | ||
|
||
let browser: puppeteer.Browser; | ||
let page: puppeteer.Page; | ||
const width = 1024; | ||
const height = 768; | ||
|
||
describe('FitAddon', () => { | ||
before(async function(): Promise<any> { | ||
this.timeout(20000); | ||
browser = await puppeteer.launch({ | ||
headless: process.argv.indexOf('--headless') !== -1, | ||
slowMo: 80, | ||
args: [`--window-size=${width},${height}`, `--no-sandbox`] | ||
}); | ||
page = (await browser.pages())[0]; | ||
await page.setViewport({ width, height }); | ||
}); | ||
|
||
after(async () => { | ||
await browser.close(); | ||
}); | ||
|
||
beforeEach(async function(): Promise<any> { | ||
this.timeout(20000); | ||
await page.goto(APP); | ||
}); | ||
|
||
describe('proposeDimensions', () => { | ||
it('no terminal', async function(): Promise<any> { | ||
await page.evaluate(`window.fit = new FitAddon();`); | ||
assert.equal(await page.evaluate(`window.fit.proposeDimensions()`), undefined); | ||
}); | ||
|
||
it('default', async function(): Promise<any> { | ||
await openTerminal(); | ||
await loadFit(); | ||
assert.deepEqual(await page.evaluate(`window.fit.proposeDimensions()`), { | ||
cols: 87, | ||
rows: 26 | ||
}); | ||
}); | ||
|
||
it('width', async function(): Promise<any> { | ||
await openTerminal(); | ||
await loadFit(1008); | ||
assert.deepEqual(await page.evaluate(`window.fit.proposeDimensions()`), { | ||
cols: 110, | ||
rows: 26 | ||
}); | ||
}); | ||
|
||
it('small', async function(): Promise<any> { | ||
await openTerminal(); | ||
await loadFit(1, 1); | ||
assert.deepEqual(await page.evaluate(`window.fit.proposeDimensions()`), { | ||
cols: 2, | ||
rows: 1 | ||
}); | ||
}); | ||
}); | ||
|
||
describe('fit', () => { | ||
it('default', async function(): Promise<any> { | ||
await openTerminal(); | ||
await loadFit(); | ||
await page.evaluate(`window.fit.fit()`); | ||
assert.equal(await page.evaluate(`window.term.cols`), 87); | ||
assert.equal(await page.evaluate(`window.term.rows`), 26); | ||
}); | ||
|
||
it('width', async function(): Promise<any> { | ||
await openTerminal(); | ||
await loadFit(1008); | ||
await page.evaluate(`window.fit.fit()`); | ||
assert.equal(await page.evaluate(`window.term.cols`), 110); | ||
assert.equal(await page.evaluate(`window.term.rows`), 26); | ||
}); | ||
|
||
it('small', async function(): Promise<any> { | ||
await openTerminal(); | ||
await loadFit(1, 1); | ||
await page.evaluate(`window.fit.fit()`); | ||
assert.equal(await page.evaluate(`window.term.cols`), 2); | ||
assert.equal(await page.evaluate(`window.term.rows`), 1); | ||
}); | ||
}); | ||
}); | ||
|
||
async function loadFit(width: number = 800, height: number = 450): Promise<void> { | ||
await page.evaluate(` | ||
window.fit = new FitAddon(); | ||
window.term.loadAddon(window.fit); | ||
document.querySelector('#terminal-container').style.width='${width}px'; | ||
document.querySelector('#terminal-container').style.height='${height}px'; | ||
`); | ||
} | ||
|
||
async function openTerminal(options: ITerminalOptions = {}): Promise<void> { | ||
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`); | ||
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`); | ||
if (options.rendererType === 'dom') { | ||
await page.waitForSelector('.xterm-rows'); | ||
} else { | ||
await page.waitForSelector('.xterm-text-layer'); | ||
} | ||
} |