Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM renderer playwright tests #4768

Merged
merged 15 commits into from
Sep 8, 2023
3 changes: 2 additions & 1 deletion addons/xterm-addon-webgl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"build": "../../node_modules/.bin/tsc -p .",
"prepackage": "npm run build",
"package": "../../node_modules/.bin/webpack",
"prepublishOnly": "npm run package"
"prepublishOnly": "npm run package",
"start": "node ../../demo/start"
},
"peerDependencies": {
"xterm": "^5.0.0"
Expand Down
1,163 changes: 0 additions & 1,163 deletions addons/xterm-addon-webgl/test/WebglRenderer.api.ts

This file was deleted.

44 changes: 44 additions & 0 deletions addons/xterm-addon-webgl/test/WebglRenderer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/

import test from '@playwright/test';
import { strictEqual } from 'assert';
import { injectSharedRendererTests } from '../../../out-test/playwright/SharedRendererTests';
import { ITestContext, createTestContext, openTerminal } from '../../../out-test/playwright/TestUtils';
import { platform } from 'os';

let ctx: ITestContext;
const ctxWrapper: { value: ITestContext } = { value: undefined } as any;
test.beforeAll(async ({ browser }) => {
ctx = await createTestContext(browser);
await openTerminal(ctx);
ctxWrapper.value = ctx;
await ctx.page.evaluate(`
window.addon = new WebglAddon(true);
window.term.loadAddon(window.addon);
`);
});
test.afterAll(async () => await ctx.page.close());

test.describe('WebGL Renderer Integration Tests', async () => {
// HACK: webgl2 is often not supported in headless firefox on Linux
// https://github.com/microsoft/playwright/issues/11566
if (platform() === 'linux') {
test.skip(({ browserName }) => browserName === 'firefox');
}

test('dispose removes renderer canvases', async function(): Promise<void> {
strictEqual(await ctx.page.evaluate(`document.querySelectorAll('.xterm canvas').length`), 2);
await ctx.page.evaluate(`addon.dispose()`);
strictEqual(await ctx.page.evaluate(`document.querySelectorAll('.xterm canvas').length`), 0);
// Re-create webgl addon to avoid side effects impacting other tests
await ctx.page.evaluate(`
window.addon = new WebglAddon(true);
window.term.loadAddon(window.addon);
`);
});

injectSharedRendererTests(ctxWrapper);
});
35 changes: 35 additions & 0 deletions addons/xterm-addon-webgl/test/playwright.config.ts
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: 'Chrome Stable',
use: {
browserName: 'chromium',
channel: 'chrome'
}
},
{
name: 'Firefox Stable',
use: {
browserName: 'firefox'
}
},
{
name: 'WebKit',
use: {
browserName: 'webkit'
}
}
],
reporter: 'list',
webServer: {
command: 'npm start',
port: 3000,
timeout: 120000,
reuseExistingServer: !process.env.CI
}
};
export default config;
5 changes: 3 additions & 2 deletions addons/xterm-addon-webgl/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
},
"strict": true,
"types": [
"../../../node_modules/@types/mocha",
"../../../node_modules/@types/node",
"../../../out-test/api/TestUtils"
"../../../node_modules/@lunapaint/png-codec",
"../../../out-test/playwright/TestUtils",
"../../../out-test/playwright/SharedRendererTests"
]
},
"include": [
Expand Down
34 changes: 34 additions & 0 deletions bin/test_playwright.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/

// @ts-check

const cp = require('child_process');
const path = require('path');

const configs = [
{ name: 'core', path: 'out-test/playwright/playwright.config.js' },
{ name: 'xterm-addon-webgl', path: 'addons/xterm-addon-webgl/out-test/playwright.config.js' }
];

function npmBinScript(script) {
return path.resolve(__dirname, `../node_modules/.bin/` + (process.platform === 'win32' ?
`${script}.cmd` : script));
}

for (const config of configs) {
const command = npmBinScript('playwright');
const args = ['test', '-c', config.path, ...process.argv.slice(2)];
console.log(`Running suite \x1b[1;34m${config.name}...\x1b[0m`);
console.log(`\n\x1b[32m${command}\x1b[0m`, args);
const run = cp.spawnSync(command, args, {
cwd: path.resolve(__dirname, '..'),
stdio: 'inherit'
}
);
if (run.status) {
process.exit(run.status);
}
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"test-api-chromium": "node ./bin/test_api.js --browser=chromium --timeout=20000",
"test-api-firefox": "node ./bin/test_api.js --browser=firefox --timeout=20000",
"test-api-webkit": "node ./bin/test_api.js --browser=webkit --timeout=20000",
"test-playwright": "playwright test -c ./out-test/playwright/playwright.config.js --workers 4",
"test-playwright-chromium": "playwright test -c ./out-test/playwright/playwright.config.js --workers 4 --project='Chrome Stable'",
"test-playwright-firefox": "playwright test -c ./out-test/playwright/playwright.config.js --workers 4 --project='Firefox Stable'",
"test-playwright-webkit": "playwright test -c ./out-test/playwright/playwright.config.js --workers 4 --project='WebKit'",
"test-playwright-debug": "playwright test -c ./out-test/playwright/playwright.config.js --headed --workers 1 --timeout 30000",
"test-playwright": "node ./bin/test_playwright.js --workers 4",
"test-playwright-chromium": "node ./bin/test_playwright.js --workers 4 \"--project=Chrome Stable\"",
"test-playwright-firefox": "node ./bin/test_playwright.js --workers 4 \"--project=Firefox Stable\"",
"test-playwright-webkit": "node ./bin/test_playwright.js --workers 4 \"--project=WebKit\"",
"test-playwright-debug": "node ./bin/test_playwright.js --headed --workers 1 --timeout 30000",
"test-unit": "node ./bin/test.js",
"test-unit-coverage": "node ./bin/test.js --coverage",
"test-unit-dev": "cross-env NODE_PATH='./out' mocha",
Expand All @@ -59,6 +59,7 @@
"vtfeatures": "node bin/extract_vtfeatures.js src/**/*.ts src/*.ts"
},
"devDependencies": {
"@lunapaint/png-codec": "^0.2.0",
"@playwright/test": "^1.37.1",
"@types/chai": "^4.2.22",
"@types/debug": "^4.1.7",
Expand Down
22 changes: 22 additions & 0 deletions test/playwright/Renderer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/

import { test } from '@playwright/test';
import { ITestContext, createTestContext, openTerminal } from './TestUtils';
import { injectSharedRendererTests } from './SharedRendererTests';

let ctx: ITestContext;
const ctxWrapper: { value: ITestContext } = { value: undefined } as any;
test.beforeAll(async ({ browser }) => {
ctx = await createTestContext(browser);
ctxWrapper.value = ctx;
await openTerminal(ctx);
});
test.afterAll(async () => await ctx.page.close());

test.describe('DOM Renderer Integration Tests', () => {
injectSharedRendererTests(ctxWrapper);
});

Loading