Skip to content

Commit 5258670

Browse files
committed
refactor: use playwright-test syntax for e2e tests
1 parent 08cd2d8 commit 5258670

File tree

6 files changed

+47
-69
lines changed

6 files changed

+47
-69
lines changed

test/e2e/browser.test.ts

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
/// <reference types="jest-playwright-preset" />
1+
import { test, expect } from "@playwright/test"
22

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-
})
3+
test("should display correct browser based on userAgent", async ({ page, browserName }) => {
4+
const displayNames = {
5+
chromium: "Chrome",
6+
firefox: "Firefox",
7+
webkit: "Safari",
8+
}
9+
const userAgent = await page.evaluate("navigator.userAgent")
1410

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")
11+
if (browserName === "chromium") {
12+
expect(userAgent).toContain(displayNames[browserName])
13+
}
2214

23-
if (browserName === "chromium") {
24-
expect(userAgent).toContain(displayNames[browserName])
25-
}
15+
if (browserName === "firefox") {
16+
expect(userAgent).toContain(displayNames[browserName])
17+
}
2618

27-
if (browserName === "firefox") {
28-
expect(userAgent).toContain(displayNames[browserName])
29-
}
30-
31-
if (browserName === "webkit") {
32-
expect(userAgent).toContain(displayNames[browserName])
33-
}
34-
})
19+
if (browserName === "webkit") {
20+
expect(userAgent).toContain(displayNames[browserName])
21+
}
3522
})

test/e2e/globalSetup.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
/// <reference types="jest-playwright-preset" />
1+
import { test, expect } from "@playwright/test"
22
import { CODE_SERVER_ADDRESS, STORAGE } from "../utils/constants"
33

44
// This test is to make sure the globalSetup works as expected
55
// 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({
6+
test.describe("globalSetup", () => {
7+
// Create a new context with the saved storage state
8+
// so we don't have to logged in
9+
const storageState = JSON.parse(STORAGE) || {}
10+
const options = {
11+
contextOptions: {
1212
storageState,
13-
})
13+
},
14+
}
15+
test("should keep us logged in using the storageState", options, async ({ page }) => {
1416
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
15-
})
16-
17-
it("should keep us logged in using the storageState", async () => {
1817
// Make sure the editor actually loaded
1918
expect(await page.isVisible("div.monaco-workbench"))
2019
})

test/e2e/login.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/// <reference types="jest-playwright-preset" />
1+
import { test, expect } from "@playwright/test"
22
import { CODE_SERVER_ADDRESS, PASSWORD } from "../utils/constants"
33

4-
describe("login", () => {
5-
beforeEach(async () => {
6-
await jestPlaywright.resetBrowser()
4+
test.describe("login", () => {
5+
test.beforeEach(async ({ page }) => {
6+
// TODO@jsjoeio reset the browser
77
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
88
})
99

10-
it("should be able to login", async () => {
10+
test("should be able to login", async ({ page }) => {
1111
// Type in password
1212
await page.fill(".password", PASSWORD)
1313
// Click the submit button and login

test/e2e/loginPage.test.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
/// <reference types="jest-playwright-preset" />
2-
1+
import { test, expect } from "@playwright/test"
32
import { CODE_SERVER_ADDRESS } from "../utils/constants"
43

5-
describe("login page", () => {
6-
beforeEach(async () => {
7-
await jestPlaywright.resetContext({
8-
logger: {
9-
isEnabled: (name, severity) => name === "browser",
10-
log: (name, severity, message, args) => console.log(`${name} ${message}`),
11-
},
12-
})
4+
test.describe("login page", () => {
5+
test.beforeEach(async ({ page }) => {
6+
// TODO@jsjoeio reset context somehow
137
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
148
})
159

16-
it("should see the login page", async () => {
10+
test("should see the login page", async ({ page }) => {
1711
// It should send us to the login page
1812
expect(await page.title()).toBe("code-server login")
1913
})

test/e2e/logout.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/// <reference types="jest-playwright-preset" />
1+
import { test, expect } from "@playwright/test"
22
import { CODE_SERVER_ADDRESS, PASSWORD } from "../utils/constants"
33

4-
describe("logout", () => {
5-
beforeEach(async () => {
6-
await jestPlaywright.resetBrowser()
4+
test.describe("logout", () => {
5+
test.beforeEach(async ({ page }) => {
6+
// TODO@jsjoeio reset context
77
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
88
})
99

10-
it("should be able login and logout", async () => {
10+
test("should be able login and logout", async ({ page }) => {
1111
// Type in password
1212
await page.fill(".password", PASSWORD)
1313
// Click the submit button and login

test/e2e/openHelpAbout.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
/// <reference types="jest-playwright-preset" />
1+
import { test, expect } from "@playwright/test"
22
import { CODE_SERVER_ADDRESS, STORAGE } from "../utils/constants"
33

4-
describe("Open Help > About", () => {
5-
beforeEach(async () => {
4+
test.describe("Open Help > About", () => {
5+
test.beforeEach(async ({ page }) => {
66
// Create a new context with the saved storage state
77
// so we don't have to logged in
8+
// TODO@jsjoeio reset context and use storageState
89
const storageState = JSON.parse(STORAGE) || {}
9-
await jestPlaywright.resetContext({
10-
storageState,
11-
})
1210
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" })
1311
})
1412

15-
it("should see a 'Help' then 'About' button in the Application Menu that opens a dialog", async () => {
13+
test("should see a 'Help' then 'About' button in the Application Menu that opens a dialog", async ({ page }) => {
1614
// Make sure the editor actually loaded
1715
expect(await page.isVisible("div.monaco-workbench"))
1816

0 commit comments

Comments
 (0)