1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-27 04:35:25 +00:00
code-server-2/test/utils/globalSetup.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Cookie } from "playwright"
import { hash } from "../../src/node/util"
import { PASSWORD, workspaceDir } from "./constants"
import { clean } from "./helpers"
import * as wtfnode from "./wtfnode"
2021-02-01 21:38:53 +00:00
/**
* Perform workspace cleanup and authenticate. This should be set up to run
* before our tests execute.
*/
export default async function () {
console.log("\n🚨 Running Global Setup for Playwright End-to-End Tests")
console.log(" Please hang tight...")
// Cleanup workspaces from previous tests.
await clean(workspaceDir)
if (process.env.WTF_NODE) {
wtfnode.setup()
}
// 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,
name: "key",
path: "/",
sameSite: "Lax",
secure: false,
value: await hash(PASSWORD),
},
]
2021-02-01 21:38:53 +00:00
// Save storage state and store as an env variable
// More info: https://playwright.dev/docs/auth/#reuse-authentication-state
process.env.STORAGE = JSON.stringify({ cookies })
console.log("✅ Global Setup for Playwright End-to-End Tests is now complete.")
2021-02-01 21:38:53 +00:00
}