From 92b7c1e9a84fac8d8eb89513e029b49dbfbafaae Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 13 Apr 2021 17:31:56 -0700 Subject: [PATCH] refactor: test-e2e.sh script --- ci/dev/test-e2e.sh | 16 +++------------- test/e2e/loginPage.test.ts | 14 +++++++++----- test/e2e/logout.test.ts | 13 ++++++++----- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/ci/dev/test-e2e.sh b/ci/dev/test-e2e.sh index 62a6fcf4..aaf3906b 100755 --- a/ci/dev/test-e2e.sh +++ b/ci/dev/test-e2e.sh @@ -3,19 +3,9 @@ set -euo pipefail main() { cd "$(dirname "$0")/../.." - # We must keep jest in a sub-directory. See ../../test/package.json for more - # information. We must also run it from the root otherwise coverage will not - # include our source files. - if [[ -z ${PASSWORD-} ]] || [[ -z ${CODE_SERVER_ADDRESS-} ]]; then - echo "The end-to-end testing suites rely on your local environment" - echo -e "\n" - echo "Please set the following environment variables locally:" - echo " \$PASSWORD" - echo " \$CODE_SERVER_ADDRESS" - echo -e "\n" - exit 1 - fi - CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" --config ./test/jest.e2e.config.ts --runInBand + cd test + # TODO@jsjoeio remove the test-match + PASSWORD=e45432jklfdsab CODE_SERVER_ADDRESS=http://localhost:8080 yarn folio --config=config.ts --test-match login.test.ts --reporter=list } main "$@" diff --git a/test/e2e/loginPage.test.ts b/test/e2e/loginPage.test.ts index e6f03d3e..3cf1d9cf 100644 --- a/test/e2e/loginPage.test.ts +++ b/test/e2e/loginPage.test.ts @@ -2,12 +2,16 @@ import { test, expect } from "@playwright/test" import { CODE_SERVER_ADDRESS } from "../utils/constants" test.describe("login page", () => { - test.beforeEach(async ({ page }) => { - // TODO@jsjoeio reset context somehow - await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) - }) + // Reset the browser so no cookies are persisted + // by emptying the storageState + const options = { + contextOptions: { + storageState: {}, + }, + } - test("should see the login page", async ({ page }) => { + test("should see the login page", options, async ({ page }) => { + await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) // It should send us to the login page expect(await page.title()).toBe("code-server login") }) diff --git a/test/e2e/logout.test.ts b/test/e2e/logout.test.ts index f3acf08e..e3ef887a 100644 --- a/test/e2e/logout.test.ts +++ b/test/e2e/logout.test.ts @@ -2,12 +2,15 @@ import { test, expect } from "@playwright/test" import { CODE_SERVER_ADDRESS, PASSWORD } from "../utils/constants" test.describe("logout", () => { - test.beforeEach(async ({ page }) => { - // TODO@jsjoeio reset context + // Reset the browser so no cookies are persisted + // by emptying the storageState + const options = { + contextOptions: { + storageState: {}, + }, + } + test("should be able login and logout", options, async ({ page }) => { await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "networkidle" }) - }) - - test("should be able login and logout", async ({ page }) => { // Type in password await page.fill(".password", PASSWORD) // Click the submit button and login