|
| 1 | +// ***************************************************************************** |
| 2 | +// Copyright (C) 2023 Toro Cloud Pty Ltd 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 | +import { test } from '@playwright/test'; |
| 17 | +import { TheiaApp } from '../theia-app'; |
| 18 | +import { TheiaAppLoader } from '../theia-app-loader'; |
| 19 | +import { TheiaExplorerView } from '../theia-explorer-view'; |
| 20 | +import { TheiaTextEditor } from '../theia-text-editor'; |
| 21 | +import { TheiaWelcomeView } from '../theia-welcome-view'; |
| 22 | +import { TheiaWorkspace } from '../theia-workspace'; |
| 23 | + |
| 24 | +test.describe('Theia Application Shell', () => { |
| 25 | + test.describe.configure({ |
| 26 | + timeout: 120000 |
| 27 | + }); |
| 28 | + |
| 29 | + let app: TheiaApp; |
| 30 | + |
| 31 | + test.beforeAll(async ({ playwright, browser }) => { |
| 32 | + const ws = new TheiaWorkspace(['src/tests/resources/sample-files1']); |
| 33 | + app = await TheiaAppLoader.load({ playwright, browser }, ws); |
| 34 | + |
| 35 | + // The welcome view must be closed because the memory leak only occurs when there are |
| 36 | + // no tabs left open. |
| 37 | + const welcomeView = new TheiaWelcomeView(app); |
| 38 | + |
| 39 | + if (await welcomeView.isTabVisible()) { |
| 40 | + await welcomeView.close(); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + test.afterAll(async () => { |
| 45 | + await app.page.close(); |
| 46 | + }); |
| 47 | + |
| 48 | + /** |
| 49 | + * The aim of this test is to detect memory leaks when opening and closing editors many times. |
| 50 | + * Remove the skip and run the test, check the logs for any memory leak warnings. |
| 51 | + * It should take less than 2min to run, if it takes longer than that, just increase the timeout. |
| 52 | + */ |
| 53 | + test.skip('should open and close a text editor many times', async () => { |
| 54 | + for (let i = 0; i < 200; i++) { |
| 55 | + const explorer = await app.openView(TheiaExplorerView); |
| 56 | + |
| 57 | + const fileStatNode = await explorer.getFileStatNodeByLabel('sample.txt'); |
| 58 | + const contextMenu = await fileStatNode.openContextMenu(); |
| 59 | + await contextMenu.clickMenuItem('Open'); |
| 60 | + |
| 61 | + const textEditor = new TheiaTextEditor('sample.txt', app); |
| 62 | + await textEditor.waitForVisible(); |
| 63 | + |
| 64 | + await textEditor.close(); |
| 65 | + } |
| 66 | + }); |
| 67 | +}); |
0 commit comments