core.test.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import * as playwright from 'playwright';
  2. import { assert } from 'chai';
  3. const APP = 'http://127.0.0.1:8080/dist/core.html';
  4. let browser: playwright.Browser;
  5. let page: playwright.Page;
  6. type BrowserType = "chromium" | "firefox" | "webkit"
  7. const browserType: BrowserType = process.env.BROWSER as BrowserType || "chromium"
  8. before(async function () {
  9. this.timeout(5 * 1000);
  10. console.log(`Starting browser: ${browserType}`)
  11. browser = await playwright[browserType].launch({
  12. headless: process.argv.includes('--headless'),
  13. });
  14. });
  15. after(async function () {
  16. this.timeout(5 * 1000);
  17. await browser.close();
  18. });
  19. beforeEach(async function () {
  20. this.timeout(5 * 1000)
  21. page = await browser.newPage({
  22. viewport: {
  23. width: 800,
  24. height: 600
  25. }
  26. });
  27. });
  28. afterEach(async () => {
  29. await page.close();
  30. });
  31. describe('Basic loading', function (): void {
  32. this.timeout(20000);
  33. it('should fail because page has an error', async () => {
  34. const pageErrors: any[] = [];
  35. page.on('pageerror', (e) => {
  36. console.log(e);
  37. pageErrors.push(e);
  38. });
  39. page.on('pageerror', (e) => {
  40. console.log(e);
  41. pageErrors.push(e);
  42. });
  43. await page.goto(APP);
  44. this.timeout(20000);
  45. for (const e of pageErrors) {
  46. throw e;
  47. }
  48. });
  49. });
  50. describe('API Integration Tests', function (): void {
  51. this.timeout(20000);
  52. beforeEach(async () => {
  53. await page.goto(APP);
  54. });
  55. it('Default initialization should be error-less', async function (): Promise<any> {
  56. assert.equal(await page.evaluate(`monaco.editor.DefaultEndOfLine[1]`), 'LF');
  57. });
  58. it('Focus and Type', async function (): Promise<any> {
  59. await page.evaluate(`
  60. (function () {
  61. instance.focus();
  62. instance.trigger('keyboard', 'cursorHome');
  63. instance.trigger('keyboard', 'type', {
  64. text: 'a'
  65. });
  66. })()
  67. `);
  68. assert.equal(await page.evaluate(`instance.getModel().getLineContent(1)`), 'afrom banana import *');
  69. });
  70. it('Type and Undo', async function (): Promise<any> {
  71. await page.evaluate(`
  72. (function () {
  73. instance.focus();
  74. instance.trigger('keyboard', 'cursorHome');
  75. instance.trigger('keyboard', 'type', {
  76. text: 'a'
  77. });
  78. instance.getModel().undo();
  79. })()
  80. `);
  81. assert.equal(await page.evaluate(`instance.getModel().getLineContent(1)`), 'from banana import *');
  82. });
  83. it('Multi Cursor', async function (): Promise<any> {
  84. await page.evaluate(`
  85. (function () {
  86. instance.focus();
  87. instance.trigger('keyboard', 'editor.action.insertCursorBelow');
  88. instance.trigger('keyboard', 'editor.action.insertCursorBelow');
  89. instance.trigger('keyboard', 'editor.action.insertCursorBelow');
  90. instance.trigger('keyboard', 'editor.action.insertCursorBelow');
  91. instance.trigger('keyboard', 'editor.action.insertCursorBelow');
  92. instance.trigger('keyboard', 'type', {
  93. text: '# '
  94. });
  95. instance.focus();
  96. })()
  97. `);
  98. await page.waitForTimeout(1000);
  99. assert.deepEqual(await page.evaluate(`
  100. [
  101. instance.getModel().getLineContent(1),
  102. instance.getModel().getLineContent(2),
  103. instance.getModel().getLineContent(3),
  104. instance.getModel().getLineContent(4),
  105. instance.getModel().getLineContent(5),
  106. instance.getModel().getLineContent(6),
  107. instance.getModel().getLineContent(7),
  108. ]
  109. `), [
  110. '# from banana import *',
  111. '# ',
  112. '# class Monkey:',
  113. '# # Bananas the monkey can eat.',
  114. '# capacity = 10',
  115. '# def eat(self, N):',
  116. '\t\t\'\'\'Make the monkey eat N bananas!\'\'\''
  117. ]);
  118. });
  119. });