Migrate clipboard api tests to playwright (only chromium)
This commit is contained in:
@@ -1,88 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2023 The xterm.js authors. All rights reserved.
|
|
||||||
* @license MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { assert } from 'chai';
|
|
||||||
import { openTerminal, launchBrowser, writeSync, getBrowserType } from '../../../out-test/api/TestUtils';
|
|
||||||
import { Browser, BrowserContext, Page } from '@playwright/test';
|
|
||||||
import { beforeEach } from 'mocha';
|
|
||||||
|
|
||||||
const APP = 'http://127.0.0.1:3001/test';
|
|
||||||
|
|
||||||
let browser: Browser;
|
|
||||||
let context: BrowserContext;
|
|
||||||
let page: Page;
|
|
||||||
const width = 800;
|
|
||||||
const height = 600;
|
|
||||||
|
|
||||||
describe('ClipboardAddon', () => {
|
|
||||||
before(async function (): Promise<any> {
|
|
||||||
browser = await launchBrowser({
|
|
||||||
// Enable clipboard access in firefox, mainly for readText
|
|
||||||
firefoxUserPrefs: {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
||||||
'dom.events.testing.asyncClipboard': true,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
||||||
'dom.events.asyncClipboard.readText': true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
context = await browser.newContext();
|
|
||||||
if (getBrowserType().name() !== 'webkit') {
|
|
||||||
// Enable clipboard access in chromium without user gesture
|
|
||||||
context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
|
||||||
}
|
|
||||||
page = await context.newPage();
|
|
||||||
await page.setViewportSize({ width, height });
|
|
||||||
await page.goto(APP);
|
|
||||||
await openTerminal(page);
|
|
||||||
await page.evaluate(`
|
|
||||||
window.clipboardAddon = new ClipboardAddon();
|
|
||||||
window.term.loadAddon(window.clipboardAddon);
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
|
|
||||||
after(() => {
|
|
||||||
browser.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
await page.evaluate(`window.term.reset()`);
|
|
||||||
});
|
|
||||||
|
|
||||||
const testDataEncoded = 'aGVsbG8gd29ybGQ=';
|
|
||||||
const testDataDecoded = 'hello world';
|
|
||||||
|
|
||||||
describe('write data', async function (): Promise<any> {
|
|
||||||
it('simple string', async () => {
|
|
||||||
await writeSync(page, `\x1b]52;c;${testDataEncoded}\x07`);
|
|
||||||
assert.deepEqual(await page.evaluate(() => window.navigator.clipboard.readText()), testDataDecoded);
|
|
||||||
});
|
|
||||||
it('invalid base64 string', async () => {
|
|
||||||
await writeSync(page, `\x1b]52;c;${testDataEncoded}invalid\x07`);
|
|
||||||
assert.deepEqual(await page.evaluate(() => window.navigator.clipboard.readText()), '');
|
|
||||||
});
|
|
||||||
it('empty string', async () => {
|
|
||||||
await writeSync(page, `\x1b]52;c;${testDataEncoded}\x07`);
|
|
||||||
await writeSync(page, `\x1b]52;c;\x07`);
|
|
||||||
assert.deepEqual(await page.evaluate(() => window.navigator.clipboard.readText()), '');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('read data', async function (): Promise<any> {
|
|
||||||
it('simple string', async () => {
|
|
||||||
await page.evaluate(`
|
|
||||||
window.data = [];
|
|
||||||
window.term.onData(e => data.push(e));
|
|
||||||
`);
|
|
||||||
await page.evaluate(() => window.navigator.clipboard.writeText('hello world'));
|
|
||||||
await writeSync(page, `\x1b]52;c;?\x07`);
|
|
||||||
assert.deepEqual(await page.evaluate('window.data'), [`\x1b]52;c;${testDataEncoded}\x07`]);
|
|
||||||
});
|
|
||||||
it('clear clipboard', async () => {
|
|
||||||
await writeSync(page, `\x1b]52;c;!\x07`);
|
|
||||||
await writeSync(page, `\x1b]52;c;?\x07`);
|
|
||||||
assert.deepEqual(await page.evaluate(() => window.navigator.clipboard.readText()), '');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2023 The xterm.js authors. All rights reserved.
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
import test from '@playwright/test';
|
||||||
|
import { deepEqual, ok, strictEqual } from 'assert';
|
||||||
|
import { ITestContext, createTestContext, launchBrowser, openTerminal, timeout } from '../../../out-test/playwright/TestUtils';
|
||||||
|
|
||||||
|
let ctx: ITestContext;
|
||||||
|
test.beforeAll(async ({ browser }, testInfo) => {
|
||||||
|
ctx = await createTestContext(browser);
|
||||||
|
await openTerminal(ctx);
|
||||||
|
});
|
||||||
|
test.afterAll(async () => {
|
||||||
|
await ctx.page.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('ClipboardAddon', () => {
|
||||||
|
|
||||||
|
test.beforeEach(async ({}, testInfo) => {
|
||||||
|
// DEBT: This test doesn't work since the migration to @playwright/test
|
||||||
|
if (ctx.browser.browserType().name() !== 'chromium') {
|
||||||
|
testInfo.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ctx.browser.browserType().name() === 'chromium') {
|
||||||
|
// Enable clipboard access in chromium without user gesture
|
||||||
|
await ctx.page.context().grantPermissions(['clipboard-read', 'clipboard-write']);
|
||||||
|
}
|
||||||
|
await ctx.page.evaluate(`
|
||||||
|
window.term.reset()
|
||||||
|
window.clipboard?.dispose();
|
||||||
|
window.clipboard = new ClipboardAddon();
|
||||||
|
window.term.loadAddon(window.clipboard);
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.beforeEach(async () => {
|
||||||
|
await ctx.proxy.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
const testDataEncoded = 'aGVsbG8gd29ybGQ=';
|
||||||
|
const testDataDecoded = 'hello world';
|
||||||
|
|
||||||
|
test.describe('write data', async function (): Promise<any> {
|
||||||
|
test('simple string', async () => {
|
||||||
|
await ctx.proxy.write(`\x1b]52;c;${testDataEncoded}\x07`);
|
||||||
|
deepEqual(await ctx.page.evaluate(() => window.navigator.clipboard.readText()), testDataDecoded);
|
||||||
|
});
|
||||||
|
test('invalid base64 string', async () => {
|
||||||
|
await ctx.proxy.write(`\x1b]52;c;${testDataEncoded}invalid\x07`);
|
||||||
|
deepEqual(await ctx.page.evaluate(() => window.navigator.clipboard.readText()), '');
|
||||||
|
});
|
||||||
|
test('empty string', async () => {
|
||||||
|
await ctx.proxy.write(`\x1b]52;c;${testDataEncoded}\x07`);
|
||||||
|
await ctx.proxy.write(`\x1b]52;c;\x07`);
|
||||||
|
deepEqual(await ctx.page.evaluate(() => window.navigator.clipboard.readText()), '');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('read data', async function (): Promise<any> {
|
||||||
|
test('simple string', async () => {
|
||||||
|
await ctx.page.evaluate(`
|
||||||
|
window.data = [];
|
||||||
|
window.term.onData(e => data.push(e));
|
||||||
|
`);
|
||||||
|
await ctx.page.evaluate(() => window.navigator.clipboard.writeText('hello world'));
|
||||||
|
await ctx.proxy.write(`\x1b]52;c;?\x07`);
|
||||||
|
deepEqual(await ctx.page.evaluate('window.data'), [`\x1b]52;c;${testDataEncoded}\x07`]);
|
||||||
|
});
|
||||||
|
test('clear clipboard', async () => {
|
||||||
|
await ctx.proxy.write(`\x1b]52;c;!\x07`);
|
||||||
|
await ctx.proxy.write(`\x1b]52;c;?\x07`);
|
||||||
|
deepEqual(await ctx.page.evaluate(() => window.navigator.clipboard.readText()), '');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { PlaywrightTestConfig } from '@playwright/test';
|
||||||
|
|
||||||
|
const config: PlaywrightTestConfig = {
|
||||||
|
testDir: '.',
|
||||||
|
timeout: 10000,
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'ChromeStable',
|
||||||
|
use: {
|
||||||
|
browserName: 'chromium',
|
||||||
|
channel: 'chrome'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'FirefoxStable',
|
||||||
|
use: {
|
||||||
|
browserName: 'firefox'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'WebKit',
|
||||||
|
use: {
|
||||||
|
browserName: 'webkit'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
reporter: 'list',
|
||||||
|
webServer: {
|
||||||
|
command: 'npm run start-server-only',
|
||||||
|
port: 3000,
|
||||||
|
timeout: 120000,
|
||||||
|
reuseExistingServer: !process.env.CI
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export default config;
|
||||||
@@ -3,21 +3,37 @@
|
|||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"target": "es2021",
|
"target": "es2021",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es2015"
|
"es2021",
|
||||||
],
|
],
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
"outDir": "../out-test",
|
"outDir": "../out-test",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"common/*": [
|
||||||
|
"../../../src/common/*"
|
||||||
|
],
|
||||||
|
"browser/*": [
|
||||||
|
"../../../src/browser/*"
|
||||||
|
]
|
||||||
|
},
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"types": [
|
"types": [
|
||||||
"../../../node_modules/@types/mocha",
|
|
||||||
"../../../node_modules/@types/node",
|
"../../../node_modules/@types/node",
|
||||||
"../../../out-test/api/TestUtils"
|
"../../../out-test/playwright/TestUtils"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./**/*",
|
"./**/*",
|
||||||
"../../../typings/xterm.d.ts"
|
"../../../typings/xterm.d.ts"
|
||||||
|
],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "../../../src/common"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "../../../src/browser"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,12 @@ while (argv.some(e => e.startsWith('--suite='))) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let configs = [
|
let configs = [
|
||||||
{ name: 'core', path: 'out-test/playwright/playwright.config.js' },
|
{ name: 'core', path: 'out-test/playwright/playwright.config.js' },
|
||||||
{ name: 'addon-canvas', path: 'addons/addon-canvas/out-test/playwright.config.js' },
|
{ name: 'addon-canvas', path: 'addons/addon-canvas/out-test/playwright.config.js' },
|
||||||
{ name: 'addon-fit', path: 'addons/addon-fit/out-test/playwright.config.js' },
|
{ name: 'addon-clipboard', path: 'addons/addon-clipboard/out-test/playwright.config.js' },
|
||||||
{ name: 'addon-search', path: 'addons/addon-search/out-test/playwright.config.js' },
|
{ name: 'addon-fit', path: 'addons/addon-fit/out-test/playwright.config.js' },
|
||||||
{ name: 'addon-webgl', path: 'addons/addon-webgl/out-test/playwright.config.js' }
|
{ name: 'addon-search', path: 'addons/addon-search/out-test/playwright.config.js' },
|
||||||
|
{ name: 'addon-webgl', path: 'addons/addon-webgl/out-test/playwright.config.js' }
|
||||||
];
|
];
|
||||||
|
|
||||||
if (suiteFilter) {
|
if (suiteFilter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user