forked from xtermjs/xterm.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request xtermjs#5079 from Tyriar/more_playwright
Migrate more API tests to playwright
- Loading branch information
Showing
17 changed files
with
969 additions
and
797 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
/** | ||
* Copyright (c) 2019 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import WebSocket = require('ws'); | ||
|
||
import test from '@playwright/test'; | ||
import { ITestContext, createTestContext, openTerminal, pollFor, timeout } from '../../../out-test/playwright/TestUtils'; | ||
|
||
let ctx: ITestContext; | ||
test.beforeAll(async ({ browser }) => { | ||
ctx = await createTestContext(browser); | ||
await openTerminal(ctx); | ||
}); | ||
test.afterAll(async () => await ctx.page.close()); | ||
|
||
test.describe('Search Tests', () => { | ||
|
||
test.beforeEach(async () => { | ||
await ctx.proxy.reset(); | ||
}); | ||
|
||
test('string', async function(): Promise<any> { | ||
const port = 8080; | ||
const server = new WebSocket.Server({ port }); | ||
server.on('connection', socket => socket.send('foo')); | ||
await ctx.page.evaluate(`window.term.loadAddon(new window.AttachAddon(new WebSocket('ws://localhost:${port}')))`); | ||
await pollFor(ctx.page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foo'); | ||
server.close(); | ||
}); | ||
|
||
test('utf8', async function(): Promise<any> { | ||
const port = 8080; | ||
const server = new WebSocket.Server({ port }); | ||
const data = new Uint8Array([102, 111, 111]); | ||
server.on('connection', socket => socket.send(data)); | ||
await ctx.page.evaluate(`window.term.loadAddon(new window.AttachAddon(new WebSocket('ws://localhost:${port}')))`); | ||
await pollFor(ctx.page, `window.term.buffer.active.getLine(0).translateToString(true)`, 'foo'); | ||
server.close(); | ||
}); | ||
}); |
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,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; |
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
This file was deleted.
Oops, something went wrong.
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,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()), ''); | ||
}); | ||
}); | ||
}); |
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,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; |
Oops, something went wrong.