Skip to content

Commit 366154f

Browse files
authored
Fixed shell tests (#634)
1 parent cc87d58 commit 366154f

File tree

4 files changed

+173
-22
lines changed

4 files changed

+173
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
# This workflow will build the TypeAgent TypeScript code
5+
6+
name: build-ts
7+
8+
on:
9+
# Manual approval of forked environments is required
10+
pull_request_target:
11+
branches:
12+
- main
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
16+
cancel-in-progress: true
17+
18+
permissions:
19+
pull-requests: read
20+
contents: read
21+
id-token: write
22+
23+
env:
24+
NODE_OPTIONS: --max_old_space_size=8192
25+
26+
jobs:
27+
build_ts:
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
32+
version: [18, 20, 22]
33+
34+
runs-on: ${{ matrix.os }}
35+
environment: development-forks
36+
steps:
37+
- if: runner.os == 'Linux'
38+
run: |
39+
sudo apt install libsecret-1-0
40+
- name: Setup Git LF
41+
run: |
42+
git config --global core.autocrlf false
43+
- uses: actions/checkout@v4
44+
- uses: dorny/paths-filter@v3
45+
id: filter
46+
with:
47+
filters: |
48+
ts:
49+
- "ts/**"
50+
- ".github/workflows/build-ts.yml"
51+
- uses: pnpm/action-setup@v4
52+
if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.ts == 'true' }}
53+
name: Install pnpm
54+
with:
55+
package_json_file: ts/package.json
56+
- uses: actions/setup-node@v4
57+
if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.ts == 'true' }}
58+
with:
59+
node-version: ${{ matrix.version }}
60+
cache: "pnpm"
61+
cache-dependency-path: ts/pnpm-lock.yaml
62+
- name: Install dependencies
63+
if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.ts == 'true' }}
64+
working-directory: ts
65+
run: |
66+
pnpm install --frozen-lockfile --strict-peer-dependencies
67+
- name: Install Playwright Browsers
68+
if: ${{ runner.os == 'windows' && matrix.version == '22' }}
69+
run: pnpm exec playwright install --with-deps
70+
working-directory: ts/packages/shell
71+
- name: Build
72+
if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.ts == 'true' }}
73+
working-directory: ts
74+
run: |
75+
npm run build
76+
- name: Test
77+
if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.ts == 'true' }}
78+
working-directory: ts
79+
run: |
80+
npm run test:local
81+
- name: Lint
82+
if: ${{ github.event_name != 'pull_request' || steps.filter.outputs.ts == 'true' }}
83+
working-directory: ts
84+
run: |
85+
npm run lint
86+
- name: Login to Azure
87+
if: ${{ github.event_name != 'merge_group' }}
88+
uses: azure/[email protected]
89+
with:
90+
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_5B0D2D6BA40F4710B45721D2112356DD }}
91+
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_39BB903136F14B6EAD8F53A8AB78E3AA }}
92+
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_F36C1F2C4B2C49CA8DD5C52FAB98FA30 }}
93+
- name: Get Keys
94+
if: ${{ github.event_name != 'merge_group' }}
95+
run: |
96+
node tools/scripts/getKeys.mjs --vault build-pipeline-kv
97+
working-directory: ts
98+
- name: Test CLI - smoke
99+
if: ${{ github.event_name != 'merge_group' }}
100+
run: |
101+
npm run start:dev 'prompt' 'why is the sky blue'
102+
working-directory: ts/packages/cli
103+
continue-on-error: true
104+
- name: Shell Tests - smoke (windows)
105+
if: ${{ github.event_name != 'merge_group' && runner.os == 'windows' && matrix.version == '22' }}
106+
timeout-minutes: 60
107+
run: |
108+
npx playwright test simple.spec.ts
109+
rm ../../.env
110+
- name: Shell Tests - smoke (linux)
111+
if: ${{ github.event_name != 'merge_group' && runner.os == 'Linux' && matrix.version == '22' }}
112+
timeout-minutes: 60
113+
run: |
114+
Xvfb :99 -screen 0 1600x1200x24 & export DISPLAY=:99
115+
npx playwright test simple.spec.ts
116+
rm ../../.env
117+
working-directory: ts/packages/shell
118+
continue-on-error: true
119+
- name: Live Tests
120+
if: ${{ github.event_name != 'merge_group' && runner.os == 'linux' && matrix.version == '22' }}
121+
timeout-minutes: 60
122+
run: |
123+
npm run test:live
124+
working-directory: ts
125+
continue-on-error: true

.github/workflows/shell-tests.yml

+15-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ permissions:
1414

1515
env:
1616
NODE_OPTIONS: --max_old_space_size=8192
17-
DEBUG: pw:browser*
17+
# DEBUG: pw:browser* # PlayWright debug messages
18+
# ELECTRON_ENABLE_LOGGING: true # Electron debug messages
19+
# DEBUG: typeagent:* # TypeAgent debug messages
1820

1921
# run only one of these at a time
2022
concurrency:
@@ -26,60 +28,66 @@ jobs:
2628
strategy:
2729
fail-fast: false
2830
matrix:
29-
#os: ["ubuntu-latest", "windows-latest", "macos-latest"]
30-
os: ["windows-latest", "ubuntu-latest"]
31+
os: ["windows-latest"]
3132
version: [20]
3233

3334
runs-on: ${{ matrix.os }}
34-
continue-on-error: true
3535
steps:
3636
- if: runner.os == 'Linux'
37-
# https://github.com/microsoft/playwright/issues/34251 - sysctl command
3837
run: |
3938
sudo apt install libsecret-1-0
40-
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
4139
4240
- name: Setup Git LF
4341
run: |
4442
git config --global core.autocrlf false
43+
4544
- uses: actions/checkout@v4
45+
4646
- uses: dorny/paths-filter@v3
4747
id: filter
4848
with:
4949
filters: |
5050
ts:
5151
- "ts/**"
5252
- ".github/workflows/build-ts.yml"
53+
5354
- uses: pnpm/action-setup@v4
5455
name: Install pnpm
5556
with:
5657
package_json_file: ts/package.json
58+
5759
- uses: actions/setup-node@v4
5860
with:
5961
node-version: ${{ matrix.version }}
6062
cache: "pnpm"
6163
cache-dependency-path: ts/pnpm-lock.yaml
64+
6265
- name: Install dependencies (pnpm)
6366
working-directory: ts
6467
run: |
6568
pnpm install --frozen-lockfile --strict-peer-dependencies
69+
6670
- name: Install Playwright Browsers
6771
run: pnpm exec playwright install --with-deps
6872
working-directory: ts/packages/shell
73+
6974
- name: Build repo
7075
working-directory: ts
7176
run: |
7277
npm run build
78+
7379
- name: Login to Azure
7480
uses: azure/[email protected]
7581
with:
7682
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_5B0D2D6BA40F4710B45721D2112356DD }}
7783
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_39BB903136F14B6EAD8F53A8AB78E3AA }}
7884
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_F36C1F2C4B2C49CA8DD5C52FAB98FA30 }}
85+
7986
- name: Get Keys
8087
run: |
8188
node tools/scripts/getKeys.mjs --vault build-pipeline-kv
8289
working-directory: ts
90+
8391
- name: Test CLI - verify .env & endpoint connectivity
8492
run: |
8593
npm run start:dev 'prompt' 'why is the sky blue'
@@ -105,8 +113,7 @@ jobs:
105113
rm ../../.env
106114
working-directory: ts/packages/shell
107115
continue-on-error: true
108-
109-
116+
110117
- uses: actions/upload-artifact@v4
111118
if: ${{ !cancelled() }}
112119
with:

ts/packages/shell/test/simple.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test("simple", { tag: "@smoke" }, async ({}, testInfo) => {
2323
console.log(`Running test '${testInfo.title}`);
2424

2525
const app: ElectronApplication = await electron.launch({
26-
args: [getAppPath(), "--no-sandbox"],
26+
args: [getAppPath()],
2727
});
2828
const mainWindow: Page = await app.firstWindow();
2929
await mainWindow.bringToFront();

ts/packages/shell/test/testHelper.ts

+32-13
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ export async function startShell(): Promise<Page> {
6363
return mainWindow;
6464
} catch (e) {
6565
console.warn(
66-
`Unable to start electrom application (${process.env["INSTANCE_NAME"]}). Attempt ${retryAttempt} of ${maxRetries}`,
66+
`Unable to start electrom application (${process.env["INSTANCE_NAME"]}). Attempt ${retryAttempt} of ${maxRetries}. Error: ${e}`,
6767
);
6868
retryAttempt++;
6969

7070
if (runningApplications.get(process.env["INSTANCE_NAME"])) {
71+
console.log(`Closing instance ${process.env["INSTANCE_NAME"]}`);
7172
await runningApplications
7273
.get(process.env["INSTANCE_NAME"]!)!
7374
.close();
@@ -83,21 +84,39 @@ export async function startShell(): Promise<Page> {
8384
}
8485

8586
async function getMainWindow(app: ElectronApplication): Promise<Page> {
86-
const window: Page = await app.firstWindow();
87-
await window.waitForLoadState("domcontentloaded");
87+
let attempts = 0;
88+
do {
89+
let windows: Page[] = await app.windows();
8890

89-
// is this the correct window?
90-
if ((await window.title()).length > 0) {
91-
return window;
92-
}
91+
// if we change the # of windows beyond 2 we'll have to update this function to correctly disambiguate which window is the correct one
92+
if (windows.length > 2) {
93+
console.log(`Found ${app.windows.length} windows. Expected 2`);
94+
throw "Please update this logic to select the correct main window. (testHelper.ts->getMainWindow())";
95+
}
9396

94-
// if we change the # of windows beyond 2 we'll have to update this function to correctly disambiguate which window is the correct one
95-
if (app.windows.length > 2) {
96-
throw "Please update this logic to select the correct main window. (testHelper.ts->getMainWindow())";
97-
}
97+
// wait for each window to load and return the one we are interested in
98+
for (let i = 0; i < windows.length; i++) {
99+
try {
100+
if (windows[i] !== undefined) {
101+
await windows[i].waitForLoadState("domcontentloaded");
102+
103+
// is this the correct window?
104+
const title = await windows[i].title();
105+
if (title.length > 0) {
106+
console.log(`Found window ${title}`);
107+
return windows[i];
108+
}
109+
}
110+
} catch (e) {
111+
console.log(e);
112+
}
113+
}
114+
115+
console.log("waiting...");
116+
await new Promise((resolve) => setTimeout(resolve, 1000));
117+
} while (++attempts < 30);
98118

99-
// since there are only two windows we know that if the first one isn't the right one we can just return the second one
100-
return app.windows[app.windows.length - 1];
119+
throw "Unable to find window...timeout";
101120
}
102121

103122
/**

0 commit comments

Comments
 (0)