Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 52fe28a

Browse files
committed
feat: add test to visit go home in app menu
1 parent fb7b96d commit 52fe28a

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

‎.github/workflows/ci.yaml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
test:
2525
needs: linux-amd64
2626
runs-on: ubuntu-latest
27+
env:
28+
PASSWORD: e45432jklfdsab
29+
CODE_SERVER_ADDRESS: http://localhost:8080
2730
steps:
2831
- uses: actions/checkout@v1
2932
- name: Download release packages
@@ -37,7 +40,7 @@ jobs:
3740
- uses: microsoft/playwright-github-action@v1
3841
- name: Install dependencies and run tests
3942
run: |
40-
node ./release-packages/code-server*-linux-amd64 &
43+
node ./release-packages/code-server*-linux-amd64 --home $CODE_SERVER_ADDRESS/healthz &
4144
yarn --frozen-lockfile
4245
yarn test
4346
pkill node

‎ci/dev/test.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ main() {
99
# information. We must also run it from the root otherwise coverage will not
1010
# include our source files.
1111
cd "$OLDPWD"
12-
./test/node_modules/.bin/jest "$@"
12+
# We use the same environment variables set in ci.yml in the test job
13+
PASSWORD=e45432jklfdsab CODE_SERVER_ADDRESS=http://localhost:8080 ./test/node_modules/.bin/jest "$@"
1314
}
1415

1516
main "$@"

‎test/goHome.test.ts‎

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import { chromium, Page, Browser, BrowserContext } from "playwright"
22

3-
// NOTE: this is hard-coded and passed as an environment variable
4-
// See the test job in ci.yml
5-
const PASSWORD = "e45432jklfdsab"
6-
73
describe("login", () => {
84
let browser: Browser
95
let page: Page
106
let context: BrowserContext
117

128
beforeAll(async () => {
13-
browser = await chromium.launch({headless: false})
9+
browser = await chromium.launch()
1410
context = await browser.newContext()
1511
})
1612

1713
afterAll(async () => {
1814
await browser.close()
15+
await context.close()
1916
})
2017

2118
beforeEach(async () => {
@@ -29,22 +26,40 @@ describe("login", () => {
2926
})
3027

3128
it("should see a 'Go Home' button in the Application Menu that goes to coder.com", async () => {
32-
await page.goto("http://localhost:8080")
29+
const GO_HOME_URL = `${process.env.CODE_SERVER_ADDRESS}/healthz`
30+
let requestedGoHomeUrl = false
31+
page.on("request", (request) => {
32+
// This ensures that we did make a request to the GO_HOME_URL
33+
// Most reliable way to test button
34+
// because we don't care if the request has a response
35+
// only that it was made
36+
if (request.url() === GO_HOME_URL) {
37+
requestedGoHomeUrl = true
38+
}
39+
})
40+
// waitUntil: "networkidle"
41+
// In case the page takes a long time to load
42+
await page.goto(process.env.CODE_SERVER_ADDRESS || "http://localhost:8080", { waitUntil: "networkidle" })
3343
// Type in password
34-
await page.fill(".password", PASSWORD)
44+
await page.fill(".password", process.env.PASSWORD||"password")
3545
// Click the submit button and login
3646
await page.click(".submit")
37-
// Click the Applicaiton menu
47+
// Click the Application menu
3848
await page.click(".menubar-menu-button[title='Application Menu']")
3949
// See the Go Home button
40-
const goHomeButton = ".home-bar[aria-label='Home'] li"
50+
const goHomeButton = "a.action-menu-item span[aria-label='Go Home']"
4151
expect(await page.isVisible(goHomeButton))
42-
// Hover over element without clicking
43-
await page.hover(goHomeButton)
44-
// Click the top left corner of the element
45-
await page.click(goHomeButton)
46-
// Note: we have to click on <li> in the Go Home button for it to work
47-
// Land on coder.com
48-
// expect(await page.url()).toBe("https://coder.com/")
52+
// Click it and navigate to coder.com
53+
// NOTE: ran into issues of it failing intermittently
54+
// without having button: "middle"
55+
await page.click(goHomeButton, { button: "middle" })
56+
57+
// If there are unsaved changes it will show a dialog
58+
// asking if you're sure you want to leave
59+
page.on("dialog", (dialog) => dialog.accept())
60+
61+
// We make sure to wait on a request to the GO_HOME_URL
62+
await page.waitForRequest(GO_HOME_URL)
63+
expect(requestedGoHomeUrl).toBeTruthy()
4964
})
5065
})

‎test/login.test.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { chromium, Page, Browser, BrowserContext } from "playwright"
22

3-
// NOTE: this is hard-coded and passed as an environment variable
4-
// See the test job in ci.yml
5-
const PASSWORD = "e45432jklfdsab"
6-
73
describe("login", () => {
84
let browser: Browser
95
let page: Page
@@ -29,9 +25,9 @@ describe("login", () => {
2925
})
3026

3127
it("should be able to login with the password from config.yml", async () => {
32-
await page.goto("http://localhost:8080")
28+
await page.goto(process.env.CODE_SERVER_ADDRESS||"http://localhost:8080")
3329
// Type in password
34-
await page.fill(".password", PASSWORD)
30+
await page.fill(".password", process.env.PASSWORD||"password")
3531
// Click the submit button and login
3632
await page.click(".submit")
3733
// See the editor

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /