From bd55cb94becc5953f16945fffa9057e993d5ee59 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 30 Mar 2021 12:24:51 -0700 Subject: [PATCH] refactor: move test dir to jest e2e config --- test/e2e/browser.test.ts | 32 +++++++++++++++++++++----------- test/e2e/logout.test.ts | 6 ++---- test/e2e/openHelpAbout.test.ts | 3 +-- test/jest.e2e.config.ts | 8 ++++++++ test/utils/constants.ts | 1 - 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/test/e2e/browser.test.ts b/test/e2e/browser.test.ts index 0801c9e9..27e2f165 100644 --- a/test/e2e/browser.test.ts +++ b/test/e2e/browser.test.ts @@ -1,16 +1,26 @@ /// -beforeAll(async () => { - await page.goto("https://whatismybrowser.com/") -}) +// This test is for nothing more than to make sure +// tests are running in multiple browsers +describe("Browser gutcheck", () => { + beforeEach(async () => { + await jestPlaywright.resetBrowser() + }) -test("should display correct browser", async () => { - const browser = await page.$eval(".string-major", (el) => el.innerHTML) + test("should display correct browser", async () => { + const displayNames = { + chromium: "Chrome", + firefox: "Firefox", + webkit: "Safari", + } + const userAgent = await page.evaluate("navigator.userAgent") - const displayNames = { - chromium: "Chrome", - firefox: "Firefox", - webkit: "Safari", - } - expect(browser).toContain(displayNames[browserName]) + if (browserName === "firefox") { + expect(userAgent).toContain(displayNames[browserName]) + } + + if (browserName === "chromium") { + expect(userAgent).toContain(displayNames[browserName]) + } + }) }) diff --git a/test/e2e/logout.test.ts b/test/e2e/logout.test.ts index 74df799a..da26ece3 100644 --- a/test/e2e/logout.test.ts +++ b/test/e2e/logout.test.ts @@ -1,5 +1,5 @@ import { chromium, Page, Browser, BrowserContext } from "playwright" -import { CODE_SERVER_ADDRESS, PASSWORD, E2E_VIDEO_DIR } from "../utils/constants" +import { CODE_SERVER_ADDRESS, PASSWORD } from "../utils/constants" describe("logout", () => { let browser: Browser @@ -8,9 +8,7 @@ describe("logout", () => { beforeAll(async () => { browser = await chromium.launch() - context = await browser.newContext({ - recordVideo: { dir: E2E_VIDEO_DIR }, - }) + context = await browser.newContext() }) afterAll(async () => { diff --git a/test/e2e/openHelpAbout.test.ts b/test/e2e/openHelpAbout.test.ts index 2a6ac57b..31bad066 100644 --- a/test/e2e/openHelpAbout.test.ts +++ b/test/e2e/openHelpAbout.test.ts @@ -1,6 +1,6 @@ import { chromium, Page, Browser, BrowserContext, Cookie } from "playwright" import { hash } from "../../src/node/util" -import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE, E2E_VIDEO_DIR } from "../utils/constants" +import { CODE_SERVER_ADDRESS, PASSWORD, STORAGE } from "../utils/constants" import { createCookieIfDoesntExist } from "../utils/helpers" describe("Open Help > About", () => { @@ -45,7 +45,6 @@ describe("Open Help > About", () => { context = await browser.newContext({ storageState: { cookies: maybeUpdatedCookies }, - recordVideo: { dir: E2E_VIDEO_DIR }, }) }) diff --git a/test/jest.e2e.config.ts b/test/jest.e2e.config.ts index 6f0fa73a..dd7af6f6 100644 --- a/test/jest.e2e.config.ts +++ b/test/jest.e2e.config.ts @@ -12,6 +12,14 @@ const config: Config.InitialOptions = { // TODO enable on webkit as well // waiting on https://github.com/playwright-community/jest-playwright/issues/659 browsers: ["chromium", "firefox"], + // If there's a page error, we don't exit + // i.e. something logged in the console + exitOnPageError: false, + contextOptions: { + recordVideo: { + dir: "./test/e2e/videos", + }, + }, }, }, testPathIgnorePatterns: ["/node_modules/", "/lib/", "/out/", "test/unit"], diff --git a/test/utils/constants.ts b/test/utils/constants.ts index 9a750892..ac2250e1 100644 --- a/test/utils/constants.ts +++ b/test/utils/constants.ts @@ -1,4 +1,3 @@ export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080" export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab" export const STORAGE = process.env.STORAGE || "" -export const E2E_VIDEO_DIR = "./test/e2e/videos"