Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/test/utils/globalSetup.ts

39 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-02-01 22:38:53 +01:00
// This setup runs before our e2e tests
// so that it authenticates us into code-server
// ensuring that we're logged in before we run any tests
import { chromium } from "playwright"
import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
import * as wtfnode from "./wtfnode"
2021-02-01 22:38:53 +01:00
module.exports = async () => {
2021-03-10 00:33:39 +01:00
console.log("\n🚨 Running Global Setup for Jest End-to-End Tests")
console.log(" Please hang tight...")
const browser = await chromium.launch()
const context = await browser.newContext()
const page = await context.newPage()
2021-02-01 22:38:53 +01:00
if (process.env.WTF_NODE) {
wtfnode.setup()
}
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" })
2021-02-01 22:38:53 +01:00
// Type in password
await page.fill(".password", PASSWORD)
2021-02-01 22:38:53 +01:00
// Click the submit button and login
await page.click(".submit")
// After logging in, we store a cookie in localStorage
// we need to wait a bit to make sure that happens
// before we grab the storage and save it
await page.waitForTimeout(1000)
2021-02-01 22:38:53 +01:00
// Save storage state and store as an env variable
// More info: https://playwright.dev/docs/auth?_highlight=authe#reuse-authentication-state
const storage = await context.storageState()
process.env.STORAGE = JSON.stringify(storage)
await page.close()
await browser.close()
await context.close()
2021-03-10 00:33:39 +01:00
console.log("✅ Global Setup for Jest End-to-End Tests is now complete.")
2021-02-01 22:38:53 +01:00
}