2021-02-13 02:55:16 +08:00
|
|
|
import { chromium } from "playwright"
|
2021-04-02 05:52:46 +08:00
|
|
|
import { hash } from "../../src/node/util"
|
2021-06-23 05:34:11 +08:00
|
|
|
import { PASSWORD, workspaceDir } from "./constants"
|
|
|
|
import { clean } from "./helpers"
|
2021-02-13 03:41:59 +08:00
|
|
|
import * as wtfnode from "./wtfnode"
|
2021-02-02 05:38:53 +08:00
|
|
|
|
2021-06-23 05:34:11 +08:00
|
|
|
/**
|
|
|
|
* Perform workspace cleanup and authenticate. This should be set up to run
|
|
|
|
* before our tests execute.
|
|
|
|
*/
|
2021-06-10 21:09:38 +08:00
|
|
|
export default async function () {
|
|
|
|
console.log("\n🚨 Running Global Setup for Playwright End-to-End Tests")
|
|
|
|
console.log(" Please hang tight...")
|
|
|
|
|
2021-06-23 05:34:11 +08:00
|
|
|
// Cleanup workspaces from previous tests.
|
|
|
|
await clean(workspaceDir)
|
|
|
|
|
2021-06-10 21:09:38 +08:00
|
|
|
const cookieToStore = {
|
|
|
|
sameSite: "Lax" as const,
|
|
|
|
name: "key",
|
|
|
|
value: await hash(PASSWORD),
|
|
|
|
domain: "localhost",
|
|
|
|
path: "/",
|
|
|
|
expires: -1,
|
|
|
|
httpOnly: false,
|
|
|
|
secure: false,
|
|
|
|
}
|
2021-04-02 05:52:46 +08:00
|
|
|
|
2021-02-13 02:55:16 +08:00
|
|
|
const browser = await chromium.launch()
|
2021-04-02 05:52:46 +08:00
|
|
|
const page = await browser.newPage()
|
|
|
|
const storage = await page.context().storageState()
|
2021-02-02 05:38:53 +08:00
|
|
|
|
2021-02-13 03:43:11 +08:00
|
|
|
if (process.env.WTF_NODE) {
|
|
|
|
wtfnode.setup()
|
|
|
|
}
|
2021-02-13 03:41:59 +08:00
|
|
|
|
2021-04-02 05:52:46 +08:00
|
|
|
storage.cookies = [cookieToStore]
|
2021-02-02 05:38:53 +08:00
|
|
|
|
|
|
|
// Save storage state and store as an env variable
|
2021-06-10 21:09:38 +08:00
|
|
|
// More info: https://playwright.dev/docs/auth/#reuse-authentication-state
|
2021-02-02 05:38:53 +08:00
|
|
|
process.env.STORAGE = JSON.stringify(storage)
|
|
|
|
await browser.close()
|
2021-04-02 05:52:46 +08:00
|
|
|
|
2021-06-10 21:09:38 +08:00
|
|
|
console.log("✅ Global Setup for Playwright End-to-End Tests is now complete.")
|
2021-02-02 05:38:53 +08:00
|
|
|
}
|