|
1 |
| -import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright" |
2 |
| -import { hash } from "../../src/node/util" |
3 |
| -import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE, E2E_VIDEO_DIR } from "../utils/constants" |
4 |
| -import { createCookieIfDoesntExist } from "../utils/helpers" |
| 1 | +/// <reference types="jest-playwright-preset" /> |
| 2 | +import { CODE_SERVER_ADDRESS, STORAGE } from "../utils/constants" |
5 | 3 |
|
6 | 4 | describe("Open Help > About", () => {
|
7 |
| - let browser: Browser |
8 |
| - let page: Page |
9 |
| - let context: BrowserContext |
10 |
| - |
11 |
| - beforeAll(async () => { |
12 |
| - browser = await chromium.launch() |
| 5 | + beforeEach(async () => { |
13 | 6 | // Create a new context with the saved storage state
|
| 7 | + // so we don't have to logged in |
14 | 8 | const storageState = JSON.parse(STORAGE) || {}
|
15 |
| - |
16 |
| - const cookieToStore = { |
17 |
| - sameSite: "Lax" as const, |
18 |
| - name: "key", |
19 |
| - value: hash(PASSWORD), |
20 |
| - domain: "localhost", |
21 |
| - path: "/", |
22 |
| - expires: -1, |
23 |
| - httpOnly: false, |
24 |
| - secure: false, |
25 |
| - } |
26 |
| - |
27 |
| - // For some odd reason, the login method used in globalSetup.ts doesn't always work |
28 |
| - // I don't know if it's on playwright clearing our cookies by accident |
29 |
| - // or if it's our cookies disappearing. |
30 |
| - // This means we need an additional check to make sure we're logged in. |
31 |
| - // We do this by manually adding the cookie to the browser environment |
32 |
| - // if it's not there at the time the test starts |
33 |
| - const cookies: Cookie[] = storageState.cookies || [] |
34 |
| - // If the cookie exists in cookies then |
35 |
| - // this will return the cookies with no changes |
36 |
| - // otherwise if it doesn't exist, it will create it |
37 |
| - // hence the name maybeUpdatedCookies |
38 |
| - // |
39 |
| - // TODO(@jsjoeio) |
40 |
| - // The playwright storage thing sometimes works and sometimes doesn't. We should investigate this further |
41 |
| - // at some point. |
42 |
| - // See discussion: https://github.com/cdr/code-server/pull/2648#discussion_r575434946 |
43 |
| - |
44 |
| - const maybeUpdatedCookies = createCookieIfDoesntExist(cookies, cookieToStore) |
45 |
| - |
46 |
| - context = await browser.newContext({ |
47 |
| - storageState: { cookies: maybeUpdatedCookies }, |
48 |
| - recordVideo: { dir: E2E_VIDEO_DIR }, |
| 9 | + await jestPlaywright.resetContext({ |
| 10 | + storageState, |
49 | 11 | })
|
50 |
| - }) |
51 |
| - |
52 |
| - afterAll(async () => { |
53 |
| - // Remove password from local storage |
54 |
| - await context.clearCookies() |
55 |
| - |
56 |
| - await context.close() |
57 |
| - await browser.close() |
58 |
| - }) |
59 |
| - |
60 |
| - beforeEach(async () => { |
61 |
| - page = await context.newPage() |
| 12 | + await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) |
62 | 13 | })
|
63 | 14 |
|
64 | 15 | it("should see a 'Help' then 'About' button in the Application Menu that opens a dialog", async () => {
|
65 |
| - // waitUntil: "domcontentloaded" |
66 |
| - // In case the page takes a long time to load |
67 |
| - await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" }) |
68 |
| - |
69 | 16 | // Make sure the editor actually loaded
|
70 | 17 | expect(await page.isVisible("div.monaco-workbench"))
|
71 | 18 |
|
|
0 commit comments