2020-12-28 23:43:35 +03:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
2022-01-15 11:35:39 +03:00
|
|
|
import * as playwright from '@playwright/test';
|
2020-12-28 23:43:35 +03:00
|
|
|
import { assert } from 'chai';
|
|
|
|
|
|
|
|
const PORT = 8563;
|
2024-08-20 15:00:18 +03:00
|
|
|
const TIMEOUT = 20 * 1000;
|
2020-12-28 23:43:35 +03:00
|
|
|
|
|
|
|
const APP = `http://127.0.0.1:${PORT}/dist/core.html`;
|
|
|
|
|
|
|
|
let browser: playwright.Browser;
|
|
|
|
let page: playwright.Page;
|
|
|
|
|
|
|
|
type BrowserType = 'chromium' | 'firefox' | 'webkit';
|
|
|
|
|
|
|
|
const browserType: BrowserType = process.env.BROWSER as BrowserType || 'chromium';
|
|
|
|
|
|
|
|
before(async function () {
|
2024-08-20 15:00:18 +03:00
|
|
|
this.timeout(TIMEOUT);
|
2020-12-28 23:43:35 +03:00
|
|
|
console.log(`Starting browser: ${browserType}`);
|
|
|
|
browser = await playwright[browserType].launch({
|
|
|
|
headless: process.argv.includes('--headless'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after(async function () {
|
2024-08-20 15:00:18 +03:00
|
|
|
this.timeout(TIMEOUT);
|
2020-12-28 23:43:35 +03:00
|
|
|
await browser.close();
|
|
|
|
});
|
|
|
|
|
2023-11-15 17:37:38 +03:00
|
|
|
const pageErrors: any[] = [];
|
2020-12-28 23:43:35 +03:00
|
|
|
beforeEach(async function () {
|
2024-08-20 15:00:18 +03:00
|
|
|
this.timeout(TIMEOUT);
|
2020-12-28 23:43:35 +03:00
|
|
|
page = await browser.newPage({
|
|
|
|
viewport: {
|
|
|
|
width: 800,
|
|
|
|
height: 600
|
|
|
|
}
|
|
|
|
});
|
2023-11-15 17:37:38 +03:00
|
|
|
|
|
|
|
pageErrors.length = 0;
|
|
|
|
page.on('pageerror', (e) => {
|
|
|
|
console.log(e);
|
|
|
|
pageErrors.push(e);
|
|
|
|
});
|
|
|
|
page.on('pageerror', (e) => {
|
|
|
|
console.log(e);
|
|
|
|
pageErrors.push(e);
|
|
|
|
});
|
2020-12-28 23:43:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await page.close();
|
2023-11-15 17:37:38 +03:00
|
|
|
for (const e of pageErrors) {
|
|
|
|
throw e;
|
|
|
|
}
|
2020-12-28 23:43:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('API Integration Tests', function (): void {
|
2024-08-20 15:00:18 +03:00
|
|
|
this.timeout(TIMEOUT);
|
2020-12-28 23:43:35 +03:00
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
await page.goto(APP);
|
|
|
|
});
|
|
|
|
|
2021-01-28 16:48:41 +03:00
|
|
|
it('`monaco` is not exposed as global', async function (): Promise<any> {
|
2021-03-29 22:48:46 +03:00
|
|
|
assert.strictEqual(await page.evaluate(`typeof monaco`), 'undefined');
|
2020-12-28 23:43:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Focus and Type', async function (): Promise<any> {
|
|
|
|
await page.evaluate(`
|
|
|
|
(function () {
|
|
|
|
instance.focus();
|
|
|
|
instance.trigger('keyboard', 'cursorHome');
|
|
|
|
instance.trigger('keyboard', 'type', {
|
|
|
|
text: 'a'
|
|
|
|
});
|
|
|
|
})()
|
|
|
|
`);
|
2021-03-29 22:48:46 +03:00
|
|
|
assert.strictEqual(await page.evaluate(`instance.getModel().getLineContent(1)`), 'afrom banana import *');
|
2020-12-28 23:43:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Type and Undo', async function (): Promise<any> {
|
|
|
|
await page.evaluate(`
|
|
|
|
(function () {
|
|
|
|
instance.focus();
|
|
|
|
instance.trigger('keyboard', 'cursorHome');
|
|
|
|
instance.trigger('keyboard', 'type', {
|
|
|
|
text: 'a'
|
|
|
|
});
|
|
|
|
instance.getModel().undo();
|
|
|
|
})()
|
|
|
|
`);
|
2021-03-29 22:48:46 +03:00
|
|
|
assert.strictEqual(await page.evaluate(`instance.getModel().getLineContent(1)`), 'from banana import *');
|
2020-12-28 23:43:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Multi Cursor', async function (): Promise<any> {
|
|
|
|
await page.evaluate(`
|
|
|
|
(function () {
|
|
|
|
instance.focus();
|
|
|
|
instance.trigger('keyboard', 'editor.action.insertCursorBelow');
|
|
|
|
instance.trigger('keyboard', 'editor.action.insertCursorBelow');
|
|
|
|
instance.trigger('keyboard', 'editor.action.insertCursorBelow');
|
|
|
|
instance.trigger('keyboard', 'editor.action.insertCursorBelow');
|
|
|
|
instance.trigger('keyboard', 'editor.action.insertCursorBelow');
|
|
|
|
instance.trigger('keyboard', 'type', {
|
|
|
|
text: '# '
|
|
|
|
});
|
|
|
|
instance.focus();
|
|
|
|
})()
|
|
|
|
`);
|
|
|
|
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
|
2021-03-30 19:05:06 +03:00
|
|
|
assert.deepStrictEqual(await page.evaluate(`
|
2020-12-28 23:43:35 +03:00
|
|
|
[
|
|
|
|
instance.getModel().getLineContent(1),
|
|
|
|
instance.getModel().getLineContent(2),
|
|
|
|
instance.getModel().getLineContent(3),
|
|
|
|
instance.getModel().getLineContent(4),
|
|
|
|
instance.getModel().getLineContent(5),
|
|
|
|
instance.getModel().getLineContent(6),
|
|
|
|
instance.getModel().getLineContent(7),
|
|
|
|
]
|
|
|
|
`), [
|
|
|
|
'# from banana import *',
|
|
|
|
'# ',
|
|
|
|
'# class Monkey:',
|
|
|
|
'# # Bananas the monkey can eat.',
|
|
|
|
'# capacity = 10',
|
|
|
|
'# def eat(self, N):',
|
|
|
|
'\t\t\'\'\'Make the monkey eat N bananas!\'\'\''
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|