Skip to content

Commit 15d791a

Browse files
authored
Merge pull request #3016 from cdr/jsjoeio/refactor-e2e
dev(testing): add jest-playwright and reduce flakiness of e2e tests
2 parents 4ff7338 + ad0f12e commit 15d791a

21 files changed

+735
-266
lines changed

.eslintrc.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ extends:
1515
- plugin:import/recommended
1616
- plugin:import/typescript
1717
- plugin:prettier/recommended
18-
- prettier # Removes eslint rules that conflict with prettier.
18+
# Recommended by jest-playwright
19+
# https://github.com/playwright-community/jest-playwright#globals
20+
- plugin:jest-playwright/recommended
21+
# Prettier should always be last
22+
# Removes eslint rules that conflict with prettier.
23+
- prettier
1924

2025
rules:
2126
# Sometimes you need to add args to implement a function signature even

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- uses: microsoft/playwright-github-action@v1
6464
- name: Install dependencies and run end-to-end tests
6565
run: |
66-
./release-packages/code-server*-linux-amd64/bin/code-server &
66+
./release-packages/code-server*-linux-amd64/bin/code-server --log trace &
6767
yarn --frozen-lockfile
6868
yarn test:e2e
6969
- name: Upload test artifacts

ci/dev/test-e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ main() {
1515
echo -e "\n"
1616
exit 1
1717
fi
18-
CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" --config ./test/jest.e2e.config.ts
18+
CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" --config ./test/jest.e2e.config.ts --runInBand
1919
}
2020

2121
main "$@"

ci/steps/test-e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
main() {
55
cd "$(dirname "$0")/../.."
66

7-
"./release-packages/code-server*-linux-amd64/bin/code-server" --home "$CODE_SERVER_ADDRESS"/healthz &
7+
"./release-packages/code-server*-linux-amd64/bin/code-server" &
88
yarn --frozen-lockfile
99
yarn test:e2e
1010
}

lib/vscode/src/vs/platform/extensionManagement/node/extensionDownloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class ExtensionsDownloader extends Disposable {
7676
private async cleanUp(): Promise<void> {
7777
try {
7878
if (!(await this.fileService.exists(this.extensionsDownloadDir))) {
79-
this.logService.trace('Extension VSIX downlads cache dir does not exist');
79+
this.logService.trace('Extension VSIX downloads cache dir does not exist');
8080
return;
8181
}
8282
const folderStat = await this.fileService.resolve(this.extensionsDownloadDir, { resolveMetadata: true });

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"eslint-config-prettier": "^8.1.0",
6262
"eslint-import-resolver-alias": "^1.1.2",
6363
"eslint-plugin-import": "^2.18.2",
64+
"eslint-plugin-jest-playwright": "^0.2.1",
6465
"eslint-plugin-prettier": "^3.1.0",
6566
"istanbul-badges-readme": "^1.2.0",
6667
"leaked-handles": "^5.2.0",

test/e2e/browser.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// <reference types="jest-playwright-preset" />
2+
3+
// This test is for nothing more than to make sure
4+
// tests are running in multiple browsers
5+
describe("Browser gutcheck", () => {
6+
beforeEach(async () => {
7+
await jestPlaywright.resetBrowser({
8+
logger: {
9+
isEnabled: (name) => name === "browser",
10+
log: (name, severity, message, args) => console.log(`${name} ${message}`),
11+
},
12+
})
13+
})
14+
15+
test("should display correct browser based on userAgent", async () => {
16+
const displayNames = {
17+
chromium: "Chrome",
18+
firefox: "Firefox",
19+
webkit: "Safari",
20+
}
21+
const userAgent = await page.evaluate("navigator.userAgent")
22+
23+
if (browserName === "chromium") {
24+
expect(userAgent).toContain(displayNames[browserName])
25+
}
26+
27+
if (browserName === "firefox") {
28+
expect(userAgent).toContain(displayNames[browserName])
29+
}
30+
31+
if (browserName === "webkit") {
32+
expect(userAgent).toContain(displayNames[browserName])
33+
}
34+
})
35+
})

test/e2e/e2e.test.ts

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

test/e2e/globalSetup.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference types="jest-playwright-preset" />
2+
import { CODE_SERVER_ADDRESS, STORAGE } from "../utils/constants"
3+
4+
// This test is to make sure the globalSetup works as expected
5+
// meaning globalSetup ran and stored the storageState in STORAGE
6+
describe("globalSetup", () => {
7+
beforeEach(async () => {
8+
// Create a new context with the saved storage state
9+
// so we don't have to logged in
10+
const storageState = JSON.parse(STORAGE) || {}
11+
await jestPlaywright.resetContext({
12+
storageState,
13+
})
14+
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
15+
})
16+
17+
it("should keep us logged in using the storageState", async () => {
18+
// Make sure the editor actually loaded
19+
expect(await page.isVisible("div.monaco-workbench"))
20+
})
21+
})

test/e2e/login.test.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
1-
import { chromium, Page, Browser, BrowserContext } from "playwright"
1+
/// <reference types="jest-playwright-preset" />
22
import { CODE_SERVER_ADDRESS, PASSWORD } from "../utils/constants"
33

44
describe("login", () => {
5-
let browser: Browser
6-
let page: Page
7-
let context: BrowserContext
8-
9-
beforeAll(async () => {
10-
browser = await chromium.launch()
11-
context = await browser.newContext()
12-
})
13-
14-
afterAll(async () => {
15-
await browser.close()
16-
})
17-
185
beforeEach(async () => {
19-
page = await context.newPage()
20-
})
21-
22-
afterEach(async () => {
23-
await page.close()
24-
// Remove password from local storage
25-
await context.clearCookies()
6+
await jestPlaywright.resetBrowser()
7+
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
268
})
279

2810
it("should be able to login", async () => {
29-
await page.goto(CODE_SERVER_ADDRESS)
3011
// Type in password
3112
await page.fill(".password", PASSWORD)
3213
// Click the submit button and login
3314
await page.click(".submit")
34-
// See the editor
35-
const codeServerEditor = await page.isVisible(".monaco-workbench")
36-
expect(codeServerEditor).toBeTruthy()
15+
await page.waitForLoadState("networkidle")
16+
// Make sure the editor actually loaded
17+
expect(await page.isVisible("div.monaco-workbench"))
3718
})
3819
})

0 commit comments

Comments
 (0)