2021-02-01 21:38:53 +00: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
|
2021-02-12 18:55:16 +00:00
|
|
|
import { chromium } from "playwright"
|
2021-04-01 21:52:46 +00:00
|
|
|
import { hash } from "../../src/node/util"
|
2021-04-05 22:18:13 +00:00
|
|
|
import { PASSWORD } from "./constants"
|
2021-02-12 19:41:59 +00:00
|
|
|
import * as wtfnode from "./wtfnode"
|
2021-02-01 21:38:53 +00:00
|
|
|
|
2021-04-01 21:52:46 +00:00
|
|
|
const cookieToStore = {
|
|
|
|
sameSite: "Lax" as const,
|
|
|
|
name: "key",
|
|
|
|
value: hash(PASSWORD),
|
|
|
|
domain: "localhost",
|
|
|
|
path: "/",
|
|
|
|
expires: -1,
|
|
|
|
httpOnly: false,
|
|
|
|
secure: false,
|
|
|
|
}
|
|
|
|
|
2021-02-01 21:38:53 +00:00
|
|
|
module.exports = async () => {
|
2021-03-09 23:33:39 +00:00
|
|
|
console.log("\n🚨 Running Global Setup for Jest End-to-End Tests")
|
2021-02-12 19:43:11 +00:00
|
|
|
console.log(" Please hang tight...")
|
2021-02-12 18:55:16 +00:00
|
|
|
const browser = await chromium.launch()
|
2021-04-01 21:52:46 +00:00
|
|
|
const page = await browser.newPage()
|
|
|
|
const storage = await page.context().storageState()
|
2021-02-01 21:38:53 +00:00
|
|
|
|
2021-02-12 19:43:11 +00:00
|
|
|
if (process.env.WTF_NODE) {
|
|
|
|
wtfnode.setup()
|
|
|
|
}
|
2021-02-12 19:41:59 +00:00
|
|
|
|
2021-04-01 21:52:46 +00:00
|
|
|
storage.cookies = [cookieToStore]
|
2021-02-01 21:38:53 +00:00
|
|
|
|
|
|
|
// Save storage state and store as an env variable
|
|
|
|
// More info: https://playwright.dev/docs/auth?_highlight=authe#reuse-authentication-state
|
|
|
|
process.env.STORAGE = JSON.stringify(storage)
|
|
|
|
await page.close()
|
|
|
|
await browser.close()
|
2021-04-01 21:52:46 +00:00
|
|
|
|
2021-03-09 23:33:39 +00:00
|
|
|
console.log("✅ Global Setup for Jest End-to-End Tests is now complete.")
|
2021-02-01 21:38:53 +00:00
|
|
|
}
|