2021-06-24 00:41:36 +02:00
|
|
|
import { Cookie } from "playwright"
|
2021-12-02 01:21:52 +01:00
|
|
|
import { CookieKeys } from "../../src/common/http"
|
2021-04-01 23:52:46 +02:00
|
|
|
import { hash } from "../../src/node/util"
|
2021-06-22 23:34:11 +02:00
|
|
|
import { PASSWORD, workspaceDir } from "./constants"
|
|
|
|
import { clean } from "./helpers"
|
2021-02-12 20:41:59 +01:00
|
|
|
import * as wtfnode from "./wtfnode"
|
2021-02-01 22:38:53 +01:00
|
|
|
|
2021-06-22 23:34:11 +02:00
|
|
|
/**
|
2021-12-17 20:06:52 +01:00
|
|
|
* Perform workspace cleanup and authenticate. This should be ran before e2e
|
|
|
|
* tests execute.
|
2021-06-22 23:34:11 +02:00
|
|
|
*/
|
2021-06-10 15:09:38 +02:00
|
|
|
export default async function () {
|
|
|
|
console.log("\n🚨 Running Global Setup for Playwright End-to-End Tests")
|
|
|
|
console.log(" Please hang tight...")
|
|
|
|
|
2021-06-22 23:34:11 +02:00
|
|
|
// Cleanup workspaces from previous tests.
|
|
|
|
await clean(workspaceDir)
|
|
|
|
|
2021-02-12 20:43:11 +01:00
|
|
|
if (process.env.WTF_NODE) {
|
|
|
|
wtfnode.setup()
|
|
|
|
}
|
2021-02-12 20:41:59 +01:00
|
|
|
|
2021-06-24 00:41:36 +02:00
|
|
|
// TODO: Replace this with a call to code-server to get the cookie. To avoid
|
|
|
|
// too much overhead we can do an http POST request and avoid spawning a
|
|
|
|
// browser for it.
|
|
|
|
const cookies: Cookie[] = [
|
|
|
|
{
|
|
|
|
domain: "localhost",
|
|
|
|
expires: -1,
|
|
|
|
httpOnly: false,
|
2021-12-02 01:21:52 +01:00
|
|
|
name: CookieKeys.Session,
|
2021-06-24 00:41:36 +02:00
|
|
|
path: "/",
|
|
|
|
sameSite: "Lax",
|
|
|
|
secure: false,
|
|
|
|
value: await hash(PASSWORD),
|
|
|
|
},
|
|
|
|
]
|
2021-02-01 22:38:53 +01:00
|
|
|
|
|
|
|
// Save storage state and store as an env variable
|
2021-06-10 15:09:38 +02:00
|
|
|
// More info: https://playwright.dev/docs/auth/#reuse-authentication-state
|
2021-06-24 00:41:36 +02:00
|
|
|
process.env.STORAGE = JSON.stringify({ cookies })
|
2021-04-01 23:52:46 +02:00
|
|
|
|
2021-06-10 15:09:38 +02:00
|
|
|
console.log("✅ Global Setup for Playwright End-to-End Tests is now complete.")
|
2021-02-01 22:38:53 +01:00
|
|
|
}
|