@theia/playwright 1.43.1 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/lib/index.d.ts +1 -0
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +1 -0
  4. package/lib/index.js.map +1 -1
  5. package/lib/tests/theia-app.test.js +7 -7
  6. package/lib/tests/theia-app.test.js.map +1 -1
  7. package/lib/tests/theia-explorer-view.test.js +40 -23
  8. package/lib/tests/theia-explorer-view.test.js.map +1 -1
  9. package/lib/tests/theia-main-menu.test.js +33 -14
  10. package/lib/tests/theia-main-menu.test.js.map +1 -1
  11. package/lib/tests/theia-output-view.test.js +13 -11
  12. package/lib/tests/theia-output-view.test.js.map +1 -1
  13. package/lib/tests/theia-preference-view.test.js +14 -12
  14. package/lib/tests/theia-preference-view.test.js.map +1 -1
  15. package/lib/tests/theia-problems-view.test.js +12 -10
  16. package/lib/tests/theia-problems-view.test.js.map +1 -1
  17. package/lib/tests/theia-quick-command.test.js +13 -11
  18. package/lib/tests/theia-quick-command.test.js.map +1 -1
  19. package/lib/tests/theia-sample-app.test.js +11 -7
  20. package/lib/tests/theia-sample-app.test.js.map +1 -1
  21. package/lib/tests/theia-status-bar.test.js +11 -8
  22. package/lib/tests/theia-status-bar.test.js.map +1 -1
  23. package/lib/tests/theia-terminal-view.test.js +11 -9
  24. package/lib/tests/theia-terminal-view.test.js.map +1 -1
  25. package/lib/tests/theia-text-editor.test.js +21 -19
  26. package/lib/tests/theia-text-editor.test.js.map +1 -1
  27. package/lib/tests/theia-toolbar.test.js +10 -8
  28. package/lib/tests/theia-toolbar.test.js.map +1 -1
  29. package/lib/tests/theia-workspace.test.js +34 -12
  30. package/lib/tests/theia-workspace.test.js.map +1 -1
  31. package/lib/theia-app-loader.d.ts +20 -0
  32. package/lib/theia-app-loader.d.ts.map +1 -0
  33. package/lib/theia-app-loader.js +130 -0
  34. package/lib/theia-app-loader.js.map +1 -0
  35. package/lib/theia-app.d.ts +11 -11
  36. package/lib/theia-app.d.ts.map +1 -1
  37. package/lib/theia-app.js +21 -33
  38. package/lib/theia-app.js.map +1 -1
  39. package/lib/theia-explorer-view.d.ts.map +1 -1
  40. package/lib/theia-explorer-view.js +1 -0
  41. package/lib/theia-explorer-view.js.map +1 -1
  42. package/lib/theia-preference-view.d.ts +8 -0
  43. package/lib/theia-preference-view.d.ts.map +1 -1
  44. package/lib/theia-preference-view.js +8 -0
  45. package/lib/theia-preference-view.js.map +1 -1
  46. package/package.json +6 -4
  47. package/src/index.ts +1 -0
  48. package/src/tests/theia-app.test.ts +7 -8
  49. package/src/tests/theia-explorer-view.test.ts +30 -8
  50. package/src/tests/theia-main-menu.test.ts +31 -8
  51. package/src/tests/theia-output-view.test.ts +10 -10
  52. package/src/tests/theia-preference-view.test.ts +10 -6
  53. package/src/tests/theia-problems-view.test.ts +10 -6
  54. package/src/tests/theia-quick-command.test.ts +11 -7
  55. package/src/tests/theia-sample-app.test.ts +11 -6
  56. package/src/tests/theia-status-bar.test.ts +11 -6
  57. package/src/tests/theia-terminal-view.test.ts +8 -4
  58. package/src/tests/theia-text-editor.test.ts +11 -7
  59. package/src/tests/theia-toolbar.test.ts +8 -4
  60. package/src/tests/theia-workspace.test.ts +38 -12
  61. package/src/theia-app-loader.ts +167 -0
  62. package/src/theia-app.ts +26 -29
  63. package/src/theia-explorer-view.ts +1 -0
  64. package/src/theia-preference-view.ts +8 -0
  65. package/lib/tests/fixtures/theia-fixture.d.ts +0 -4
  66. package/lib/tests/fixtures/theia-fixture.d.ts.map +0 -1
  67. package/lib/tests/fixtures/theia-fixture.js +0 -24
  68. package/lib/tests/fixtures/theia-fixture.js.map +0 -1
  69. package/src/tests/fixtures/theia-fixture.ts +0 -25
@@ -0,0 +1,167 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Page, PlaywrightWorkerArgs, _electron as electron } from '@playwright/test';
18
+ import * as path from 'path';
19
+ import * as fs from 'fs';
20
+ import { TheiaApp } from './theia-app';
21
+ import { TheiaWorkspace } from './theia-workspace';
22
+ import { OSUtil } from './util';
23
+
24
+ export interface TheiaAppFactory<T extends TheiaApp> {
25
+ new(page: Page, initialWorkspace?: TheiaWorkspace, isElectron?: boolean): T;
26
+ }
27
+
28
+ // TODO this is just a sketch, we need a proper way to configure tests and pass this configuration to the `TheiaAppLoader`:
29
+ export interface TheiaPlaywrightTestConfig {
30
+ useElectron?: {
31
+ /** Path to the Theia Electron app package (absolute or relative to this package). */
32
+ electronAppPath?: string,
33
+ /** Path to the folder containing the plugins to load (absolute or relative to this package). */
34
+ pluginsPath?: string,
35
+ // eslint-disable-next-line max-len
36
+ /** Electron launch options as [specified by Playwright](https://github.com/microsoft/playwright/blob/396487fc4c19bf27554eac9beea9db135e96cfb4/packages/playwright-core/types/types.d.ts#L14182). */
37
+ launchOptions?: object,
38
+ }
39
+ }
40
+
41
+ function theiaAppFactory<T extends TheiaApp>(factory?: TheiaAppFactory<T>): TheiaAppFactory<T> {
42
+ return (factory ?? TheiaApp) as TheiaAppFactory<T>;
43
+ }
44
+
45
+ function initializeWorkspace(initialWorkspace?: TheiaWorkspace): TheiaWorkspace {
46
+ const workspace = initialWorkspace ? initialWorkspace : new TheiaWorkspace();
47
+ workspace.initialize();
48
+ return workspace;
49
+ }
50
+
51
+ namespace TheiaBrowserAppLoader {
52
+
53
+ export async function load<T extends TheiaApp>(
54
+ page: Page,
55
+ initialWorkspace?: TheiaWorkspace,
56
+ factory?: TheiaAppFactory<T>
57
+ ): Promise<T> {
58
+ const workspace = initializeWorkspace(initialWorkspace);
59
+ return createAndLoad<T>(page, workspace, factory);
60
+ }
61
+
62
+ async function createAndLoad<T extends TheiaApp>(
63
+ page: Page,
64
+ workspace: TheiaWorkspace,
65
+ factory?: TheiaAppFactory<T>
66
+ ): Promise<T> {
67
+ const appFactory = theiaAppFactory<T>(factory);
68
+ const app = new appFactory(page, workspace, false);
69
+ await loadOrReload(app, '/#' + app.workspace.urlEncodedPath);
70
+ await app.waitForShellAndInitialized();
71
+ return app;
72
+ }
73
+
74
+ async function loadOrReload(app: TheiaApp, url: string): Promise<void> {
75
+ if (app.page.url() === url) {
76
+ await app.page.reload();
77
+ } else {
78
+ const wasLoadedAlready = await app.isShellVisible();
79
+ await app.page.goto(url);
80
+ if (wasLoadedAlready) {
81
+ // Theia doesn't refresh on URL change only
82
+ // So we need to reload if the app was already loaded before
83
+ await app.page.reload();
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ namespace TheiaElectronAppLoader {
90
+
91
+ export async function load<T extends TheiaApp>(
92
+ args: TheiaPlaywrightTestConfig & PlaywrightWorkerArgs,
93
+ initialWorkspace?: TheiaWorkspace,
94
+ factory?: TheiaAppFactory<T>,
95
+ ): Promise<T> {
96
+ const workspace = initializeWorkspace(initialWorkspace);
97
+ const electronConfig = args.useElectron ?? {
98
+ electronAppPath: '../electron',
99
+ pluginsPath: '../../plugins'
100
+ };
101
+ if (electronConfig === undefined || electronConfig.launchOptions === undefined && electronConfig.electronAppPath === undefined) {
102
+ throw Error('The Theia Playwright configuration must either specify `useElectron.electronAppPath` or `useElectron.launchOptions`');
103
+ }
104
+ const appPath = electronConfig.electronAppPath!;
105
+ const pluginsPath = electronConfig.pluginsPath;
106
+ const launchOptions = electronConfig.launchOptions ?? {
107
+ additionalArgs: ['--no-cluster'],
108
+ electronAppPath: appPath,
109
+ pluginsPath: pluginsPath
110
+ };
111
+ const playwrightOptions = toPlaywrightOptions(launchOptions, workspace);
112
+ console.log(`Launching Electron with options: ${JSON.stringify(playwrightOptions)}`);
113
+ const electronApp = await electron.launch(playwrightOptions);
114
+ const page = await electronApp.firstWindow();
115
+
116
+ const appFactory = theiaAppFactory<T>(factory);
117
+ const app = new appFactory(page, workspace, true);
118
+ await app.waitForShellAndInitialized();
119
+ return app;
120
+ }
121
+
122
+ export function toPlaywrightOptions(
123
+ electronLaunchOptions: { additionalArgs: string[], electronAppPath: string, pluginsPath?: string } | object,
124
+ workspace?: TheiaWorkspace
125
+ ): { executablePath: string, args: string[] } | object {
126
+ if ('additionalArgs' in electronLaunchOptions && 'electronAppPath' in electronLaunchOptions) {
127
+ const executablePath = path.normalize(path.join(electronLaunchOptions.electronAppPath, 'node_modules/.bin/electron')) + (OSUtil.isWindows ? '.cmd' : '');
128
+ if (!fs.existsSync(executablePath)) {
129
+ const errorMsg = `executablePath: ${executablePath} does not exist`;
130
+ console.log(errorMsg);
131
+ throw new Error(errorMsg);
132
+ }
133
+ const args = [
134
+ electronLaunchOptions.electronAppPath,
135
+ ...electronLaunchOptions.additionalArgs,
136
+ `--app-project-path=${electronLaunchOptions.electronAppPath}`
137
+ ];
138
+ if (electronLaunchOptions.pluginsPath) {
139
+ args.push(`--plugins=local-dir:${electronLaunchOptions.pluginsPath}`);
140
+ }
141
+ if (workspace) {
142
+ args.push(workspace.path);
143
+ }
144
+
145
+ return { executablePath: executablePath, args: args };
146
+ }
147
+ return electronLaunchOptions;
148
+ }
149
+ }
150
+
151
+ export namespace TheiaAppLoader {
152
+
153
+ export async function load<T extends TheiaApp>(
154
+ args: TheiaPlaywrightTestConfig & PlaywrightWorkerArgs,
155
+ initialWorkspace?: TheiaWorkspace,
156
+ factory?: TheiaAppFactory<T>,
157
+ ): Promise<T> {
158
+ if (process.env.USE_ELECTRON === 'true') {
159
+ // disable native elements and early window to avoid issues with the electron app
160
+ process.env.THEIA_ELECTRON_DISABLE_NATIVE_ELEMENTS = '1';
161
+ process.env.THEIA_ELECTRON_NO_EARLY_WINDOW = '1';
162
+ return TheiaElectronAppLoader.load(args, initialWorkspace, factory);
163
+ }
164
+ const page = await args.browser.newPage();
165
+ return TheiaBrowserAppLoader.load(page, initialWorkspace, factory);
166
+ }
167
+ }
package/src/theia-app.ts CHANGED
@@ -37,47 +37,44 @@ export const DefaultTheiaAppData: TheiaAppData = {
37
37
 
38
38
  export class TheiaApp {
39
39
 
40
- readonly statusBar = new TheiaStatusBar(this);
41
- readonly quickCommandPalette = new TheiaQuickCommandPalette(this);
42
- readonly menuBar = new TheiaMenuBar(this);
43
- public workspace: TheiaWorkspace;
40
+ statusBar: TheiaStatusBar;
41
+ quickCommandPalette: TheiaQuickCommandPalette;
42
+ menuBar: TheiaMenuBar;
43
+
44
+ protected appData = DefaultTheiaAppData;
45
+
46
+ public constructor(
47
+ public page: Page,
48
+ public workspace: TheiaWorkspace,
49
+ public isElectron: boolean,
50
+ ) {
51
+ this.statusBar = this.createStatusBar();
52
+ this.quickCommandPalette = this.createQuickCommandPalette();
53
+ this.menuBar = this.createMenuBar();
54
+ }
55
+
56
+ protected createStatusBar(): TheiaStatusBar {
57
+ return new TheiaStatusBar(this);
58
+ }
44
59
 
45
- static async load(page: Page, initialWorkspace?: TheiaWorkspace): Promise<TheiaApp> {
46
- return this.loadApp(page, TheiaApp, initialWorkspace);
60
+ protected createQuickCommandPalette(): TheiaQuickCommandPalette {
61
+ return new TheiaQuickCommandPalette(this);
47
62
  }
48
63
 
49
- static async loadApp<T extends TheiaApp>(page: Page, appFactory: { new(page: Page, initialWorkspace?: TheiaWorkspace): T }, initialWorkspace?: TheiaWorkspace): Promise<T> {
50
- const app = new appFactory(page, initialWorkspace);
51
- await app.load();
52
- return app;
64
+ protected createMenuBar(): TheiaMenuBar {
65
+ return new TheiaMenuBar(this);
53
66
  }
54
67
 
55
- public constructor(public page: Page, initialWorkspace?: TheiaWorkspace, protected appData = DefaultTheiaAppData) {
56
- this.workspace = initialWorkspace ? initialWorkspace : new TheiaWorkspace();
57
- this.workspace.initialize();
68
+ async isShellVisible(): Promise<boolean> {
69
+ return this.page.isVisible(this.appData.shellSelector);
58
70
  }
59
71
 
60
- protected async load(): Promise<void> {
61
- await this.loadOrReload(this.page, '/#' + this.workspace.urlEncodedPath);
72
+ async waitForShellAndInitialized(): Promise<void> {
62
73
  await this.page.waitForSelector(this.appData.loadingSelector, { state: 'detached' });
63
74
  await this.page.waitForSelector(this.appData.shellSelector);
64
75
  await this.waitForInitialized();
65
76
  }
66
77
 
67
- protected async loadOrReload(page: Page, url: string): Promise<void> {
68
- if (page.url() === url) {
69
- await page.reload();
70
- } else {
71
- const wasLoadedAlready = await page.isVisible(this.appData.shellSelector);
72
- await page.goto(url);
73
- if (wasLoadedAlready) {
74
- // Theia doesn't refresh on URL change only
75
- // So we need to reload if the app was already loaded before
76
- await page.reload();
77
- }
78
- }
79
- }
80
-
81
78
  async isMainContentPanelVisible(): Promise<boolean> {
82
79
  const contentPanel = await this.page.$('#theia-main-content-panel');
83
80
  return !!contentPanel && contentPanel.isVisible();
@@ -182,6 +182,7 @@ export class TheiaExplorerView extends TheiaView {
182
182
  console.debug('Waiting for clicked tree node to be selected: ' + filePath);
183
183
  }
184
184
  }
185
+ await this.page.waitForSelector(this.treeNodeSelector(filePath) + '.theia-mod-selected');
185
186
  }
186
187
 
187
188
  async isTreeNodeSelected(filePath: string): Promise<boolean> {
@@ -33,6 +33,9 @@ export const PreferenceIds = {
33
33
  },
34
34
  DiffEditor: {
35
35
  MaxComputationTime: 'diffEditor.maxComputationTime'
36
+ },
37
+ Files: {
38
+ EnableTrash: 'files.enableTrash'
36
39
  }
37
40
  };
38
41
 
@@ -59,6 +62,11 @@ export const DefaultPreferences = {
59
62
  },
60
63
  DiffEditor: {
61
64
  MaxComputationTime: '5000'
65
+ },
66
+ Files: {
67
+ EnableTrash: {
68
+ Enabled: true
69
+ }
62
70
  }
63
71
  };
64
72
 
@@ -1,4 +0,0 @@
1
- import test, { Page } from '@playwright/test';
2
- export declare let page: Page;
3
- export default test;
4
- //# sourceMappingURL=theia-fixture.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"theia-fixture.d.ts","sourceRoot":"","sources":["../../../src/tests/fixtures/theia-fixture.ts"],"names":[],"mappings":"AAgBA,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE9C,eAAO,IAAI,IAAI,EAAE,IAAI,CAAC;AAMtB,eAAe,IAAI,CAAC"}
@@ -1,24 +0,0 @@
1
- "use strict";
2
- // *****************************************************************************
3
- // Copyright (C) 2021 logi.cals GmbH, EclipseSource and others.
4
- //
5
- // This program and the accompanying materials are made available under the
6
- // terms of the Eclipse Public License v. 2.0 which is available at
7
- // http://www.eclipse.org/legal/epl-2.0.
8
- //
9
- // This Source Code may also be made available under the following Secondary
10
- // Licenses when the conditions for such availability set forth in the Eclipse
11
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
- // with the GNU Classpath Exception which is available at
13
- // https://www.gnu.org/software/classpath/license.html.
14
- //
15
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
- // *****************************************************************************
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.page = void 0;
19
- const test_1 = require("@playwright/test");
20
- test_1.default.beforeAll(async ({ browser }) => {
21
- exports.page = await browser.newPage();
22
- });
23
- exports.default = test_1.default;
24
- //# sourceMappingURL=theia-fixture.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"theia-fixture.js","sourceRoot":"","sources":["../../../src/tests/fixtures/theia-fixture.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+DAA+D;AAC/D,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,2CAA8C;AAI9C,cAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IACjC,YAAI,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;AACnC,CAAC,CAAC,CAAC;AAEH,kBAAe,cAAI,CAAC"}
@@ -1,25 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 logi.cals GmbH, EclipseSource and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import test, { Page } from '@playwright/test';
18
-
19
- export let page: Page;
20
-
21
- test.beforeAll(async ({ browser }) => {
22
- page = await browser.newPage();
23
- });
24
-
25
- export default test;