Skip to content

Commit d421ec9

Browse files
committed
playwright: make all tests executable in electron
* Use unified AppLoader for both electron and browser tests * Introduce environment variable USE_ELECTRON to run playwright tests in electron * Add ui-tests-electron target to package.json * Adjust workflow to use the new ui-tests-ci target (only one worker + both electron and browser tests) * Merge electron playwright tests into the existing tests Contributed on behalf of STMicroelectronics Signed-off-by: Olaf Lessenich <[email protected]>
1 parent cfd7de0 commit d421ec9

21 files changed

+332
-209
lines changed

.github/workflows/playwright.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ jobs:
4343
NODE_OPTIONS: --max_old_space_size=4096
4444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://github.com/microsoft/vscode-ripgrep/issues/9
4545

46+
- name: Build Electron
47+
shell: bash
48+
run: |
49+
yarn --skip-integrity-check --network-timeout 100000
50+
yarn electron build
51+
env:
52+
NODE_OPTIONS: --max_old_space_size=4096
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # https://github.com/microsoft/vscode-ripgrep/issues/9
54+
4655
- name: Build Playwright
4756
shell: bash
4857
run: |
@@ -51,4 +60,4 @@ jobs:
5160
- name: Test (playwright)
5261
uses: GabrielBB/xvfb-action@v1
5362
with:
54-
run: yarn test:playwright
63+
run: yarn --cwd examples/playwright ui-tests-ci

examples/playwright/configs/playwright.ci.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import baseConfig from './playwright.config';
2020
const ciConfig: PlaywrightTestConfig = {
2121
...baseConfig,
2222
workers: 1,
23-
retries: 1
23+
retries: 1,
24+
reporter: [['list'], ['allure-playwright'], ['github']]
2425
};
2526

2627
export default ciConfig;

examples/playwright/configs/playwright.config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { PlaywrightTestConfig } from '@playwright/test';
1919
const config: PlaywrightTestConfig = {
2020
testDir: '../lib/tests',
2121
testMatch: ['**/*.js'],
22-
workers: 2,
22+
workers: 1,
2323
// Timeout for each test in milliseconds.
2424
timeout: 60 * 1000,
2525
use: {
@@ -32,7 +32,13 @@ const config: PlaywrightTestConfig = {
3232
reporter: [
3333
['list'],
3434
['allure-playwright']
35-
]
35+
],
36+
// Reuse Theia backend on port 3000 or start instance before executing the tests
37+
webServer: {
38+
command: 'yarn theia:start',
39+
port: 3000,
40+
reuseExistingServer: true
41+
}
3642
};
3743

3844
export default config;

examples/playwright/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"lint:fix": "eslint -c ./.eslintrc.js --ext .ts ./src --fix",
2121
"playwright:install": "playwright install chromium",
2222
"ui-tests": "yarn build && playwright test --config=./configs/playwright.config.ts",
23-
"ui-tests-ci": "yarn build && playwright test --config=./configs/playwright.ci.config.ts",
23+
"ui-tests-electron": "yarn build && USE_ELECTRON=true playwright test --config=./configs/playwright.config.ts",
24+
"ui-tests-ci": "yarn build && playwright test --config=./configs/playwright.ci.config.ts && USE_ELECTRON=true playwright test --config=./configs/playwright.ci.config.ts ",
2425
"ui-tests-headful": "yarn build && playwright test --config=./configs/playwright.headful.config.ts",
2526
"ui-tests-report-generate": "allure generate ./allure-results --clean -o allure-results/allure-report",
2627
"ui-tests-report": "yarn ui-tests-report-generate && allure open allure-results/allure-report"

examples/playwright/playwright.config.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

examples/playwright/src/tests/theia-app.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,33 @@
1616

1717
import { expect, test } from '@playwright/test';
1818
import { TheiaAppLoader } from '../theia-app-loader';
19+
import { TheiaApp } from '../theia-app';
1920

2021
test.describe('Theia Application', () => {
22+
let app: TheiaApp;
23+
24+
test.afterAll(async () => {
25+
await app.page.close();
26+
});
2127

2228
test('should load and should show main content panel', async ({ playwright, browser }) => {
23-
const app = await TheiaAppLoader.load({ playwright, browser });
29+
let args;
30+
if (process.env.USE_ELECTRON === 'true') {
31+
args = {
32+
playwright: playwright,
33+
browser: browser,
34+
useElectron: {
35+
electronAppPath: '../electron',
36+
pluginsPath: '../../plugins'
37+
}
38+
};
39+
} else {
40+
args = {
41+
playwright: playwright,
42+
browser: browser
43+
};
44+
}
45+
app = await TheiaAppLoader.load(args);
2446
expect(await app.isMainContentPanelVisible()).toBe(true);
2547
});
2648

examples/playwright/src/tests/theia-electron-app.test.ts

Lines changed: 0 additions & 127 deletions
This file was deleted.

examples/playwright/src/tests/theia-explorer-view.test.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { expect, test } from '@playwright/test';
1818
import { TheiaAppLoader } from '../theia-app-loader';
1919
import { TheiaApp } from '../theia-app';
20+
import { PreferenceIds, TheiaPreferenceView } from '../theia-preference-view';
2021
import { DOT_FILES_FILTER, TheiaExplorerView } from '../theia-explorer-view';
2122
import { TheiaWorkspace } from '../theia-workspace';
2223

@@ -26,10 +27,36 @@ test.describe('Theia Explorer View', () => {
2627

2728
let app: TheiaApp;
2829
let explorer: TheiaExplorerView;
30+
let isElectron: boolean;
2931

3032
test.beforeAll(async ({ playwright, browser }) => {
33+
isElectron = process.env.USE_ELECTRON === 'true';
3134
const ws = new TheiaWorkspace(['src/tests/resources/sample-files1']);
32-
app = await TheiaAppLoader.load({ playwright, browser }, ws);
35+
let args;
36+
if (isElectron) {
37+
args = {
38+
playwright: playwright,
39+
browser: browser,
40+
useElectron: {
41+
electronAppPath: '../electron',
42+
pluginsPath: '../../plugins'
43+
}
44+
};
45+
} else {
46+
args = {
47+
playwright: playwright,
48+
browser: browser
49+
};
50+
}
51+
app = await TheiaAppLoader.load(args, ws);
52+
53+
if (isElectron) {
54+
// set trash preference to off
55+
const preferenceView = await app.openPreferences(TheiaPreferenceView);
56+
await preferenceView.setBooleanPreferenceById(PreferenceIds.Files.EnableTrash, false);
57+
await preferenceView.close();
58+
}
59+
3360
explorer = await app.openView(TheiaExplorerView);
3461
await explorer.waitForVisibleFileNodes();
3562
});
@@ -137,7 +164,9 @@ test.describe('Theia Explorer View', () => {
137164
const menuItems = await menu.visibleMenuItems();
138165
expect(menuItems).toContain('Open');
139166
expect(menuItems).toContain('Delete');
140-
expect(menuItems).toContain('Download');
167+
if (!isElectron) {
168+
expect(menuItems).toContain('Download');
169+
}
141170

142171
await menu.close();
143172
expect(await menu.isOpen()).toBe(false);
@@ -192,4 +221,11 @@ test.describe('Theia Explorer View', () => {
192221
expect(updatedFileStatElements.length).toBe(fileStatElements.length - 1);
193222
});
194223

224+
test('open "sample.txt" via the context menu', async () => {
225+
expect(await explorer.existsFileNode('sample.txt')).toBe(true);
226+
await explorer.clickContextMenuItem('sample.txt', ['Open']);
227+
const span = await app.page.waitForSelector('span:has-text("content line 2")');
228+
expect(await span.isVisible()).toBe(true);
229+
});
230+
195231
});

0 commit comments

Comments
 (0)