From ad0f12e664a318391573215cf9921790da1a2167 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 5 Apr 2021 15:18:13 -0700 Subject: [PATCH] refactor: check for editor consistently in tests --- .eslintrc.yaml | 4 +++- test/e2e/globalSetup.test.ts | 9 ++------- test/e2e/login.test.ts | 12 +++--------- test/e2e/logout.test.ts | 12 +++--------- test/e2e/openHelpAbout.test.ts | 4 ---- test/package.json | 10 ++++------ test/utils/globalSetup.ts | 2 +- 7 files changed, 16 insertions(+), 37 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index f520fd9f..9b4f5744 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -15,10 +15,12 @@ extends: - plugin:import/recommended - plugin:import/typescript - plugin:prettier/recommended - - prettier # Removes eslint rules that conflict with prettier. # Recommended by jest-playwright # https://github.com/playwright-community/jest-playwright#globals - plugin:jest-playwright/recommended + # Prettier should always be last + # Removes eslint rules that conflict with prettier. + - prettier rules: # Sometimes you need to add args to implement a function signature even diff --git a/test/e2e/globalSetup.test.ts b/test/e2e/globalSetup.test.ts index 18be48b7..3608fff4 100644 --- a/test/e2e/globalSetup.test.ts +++ b/test/e2e/globalSetup.test.ts @@ -10,17 +10,12 @@ describe("globalSetup", () => { const storageState = JSON.parse(STORAGE) || {} await jestPlaywright.resetContext({ storageState, - logger: { - isEnabled: (name, severity) => name === "browser", - log: (name, severity, message, args) => console.log(`${name} ${message}`), - }, }) await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) }) it("should keep us logged in using the storageState", async () => { - // See the editor - const codeServerEditor = await page.isVisible(".monaco-workbench") - expect(codeServerEditor).toBeTruthy() + // Make sure the editor actually loaded + expect(await page.isVisible("div.monaco-workbench")) }) }) diff --git a/test/e2e/login.test.ts b/test/e2e/login.test.ts index bf274932..41983855 100644 --- a/test/e2e/login.test.ts +++ b/test/e2e/login.test.ts @@ -3,12 +3,7 @@ import { CODE_SERVER_ADDRESS, PASSWORD } from "../utils/constants" describe("login", () => { beforeEach(async () => { - await jestPlaywright.resetBrowser({ - logger: { - isEnabled: (name, severity) => name === "browser", - log: (name, severity, message, args) => console.log(`${name} ${message}`), - }, - }) + await jestPlaywright.resetBrowser() await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) }) @@ -18,8 +13,7 @@ describe("login", () => { // Click the submit button and login await page.click(".submit") await page.waitForLoadState("networkidle") - // See the editor - const codeServerEditor = await page.isVisible(".monaco-workbench") - expect(codeServerEditor).toBeTruthy() + // Make sure the editor actually loaded + expect(await page.isVisible("div.monaco-workbench")) }) }) diff --git a/test/e2e/logout.test.ts b/test/e2e/logout.test.ts index b88c0963..bb5c2003 100644 --- a/test/e2e/logout.test.ts +++ b/test/e2e/logout.test.ts @@ -3,12 +3,7 @@ import { CODE_SERVER_ADDRESS, PASSWORD } from "../utils/constants" describe("logout", () => { beforeEach(async () => { - await jestPlaywright.resetBrowser({ - logger: { - isEnabled: (name, severity) => name === "browser", - log: (name, severity, message, args) => console.log(`${name} ${message}`), - }, - }) + await jestPlaywright.resetBrowser() await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) }) @@ -18,9 +13,8 @@ describe("logout", () => { // Click the submit button and login await page.click(".submit") await page.waitForLoadState("networkidle") - // See the editor - const codeServerEditor = await page.isVisible(".monaco-workbench") - expect(codeServerEditor).toBeTruthy() + // Make sure the editor actually loaded + expect(await page.isVisible("div.monaco-workbench")) // Click the Application menu await page.click("[aria-label='Application Menu']") diff --git a/test/e2e/openHelpAbout.test.ts b/test/e2e/openHelpAbout.test.ts index 38ac4e21..18fe407b 100644 --- a/test/e2e/openHelpAbout.test.ts +++ b/test/e2e/openHelpAbout.test.ts @@ -8,10 +8,6 @@ describe("Open Help > About", () => { const storageState = JSON.parse(STORAGE) || {} await jestPlaywright.resetContext({ storageState, - logger: { - isEnabled: (name, severity) => name === "browser", - log: (name, severity, message, args) => console.log(`${name} ${message}`), - }, }) await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) }) diff --git a/test/package.json b/test/package.json index 73da131a..a24fae4b 100644 --- a/test/package.json +++ b/test/package.json @@ -7,16 +7,14 @@ "@types/node-fetch": "^2.5.8", "@types/supertest": "^2.0.10", "jest": "^26.6.3", + "jest-playwright-preset": "^1.5.1", "jsdom": "^16.4.0", "node-fetch": "^2.6.1", "playwright": "^1.8.0", - "supertest": "^6.1.1", - "ts-jest": "^26.4.4" - }, - "dependencies": { - "jest-playwright-preset": "^1.5.1", "playwright-chromium": "^1.10.0", "playwright-firefox": "^1.10.0", - "playwright-webkit": "^1.10.0" + "playwright-webkit": "^1.10.0", + "supertest": "^6.1.1", + "ts-jest": "^26.4.4" } } diff --git a/test/utils/globalSetup.ts b/test/utils/globalSetup.ts index 44adfaa8..836cc600 100644 --- a/test/utils/globalSetup.ts +++ b/test/utils/globalSetup.ts @@ -2,8 +2,8 @@ // so that it authenticates us into code-server // ensuring that we're logged in before we run any tests import { chromium } from "playwright" -import { PASSWORD } from "./constants" import { hash } from "../../src/node/util" +import { PASSWORD } from "./constants" import * as wtfnode from "./wtfnode" const cookieToStore = {