2021-02-02 04:38:53 +07: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-13 01:55:16 +07:00
|
|
|
import { chromium } from "playwright"
|
2021-02-13 02:08:34 +07:00
|
|
|
import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
|
2021-02-13 02:41:59 +07:00
|
|
|
import * as wtfnode from "./wtfnode"
|
2021-02-02 04:38:53 +07:00
|
|
|
|
|
|
|
module.exports = async () => {
|
2021-03-10 06:33:39 +07:00
|
|
|
console.log("\n🚨 Running Global Setup for Jest End-to-End Tests")
|
2021-02-13 02:43:11 +07:00
|
|
|
console.log(" Please hang tight...")
|
2021-02-13 01:55:16 +07:00
|
|
|
const browser = await chromium.launch()
|
|
|
|
const context = await browser.newContext()
|
|
|
|
const page = await context.newPage()
|
2021-02-02 04:38:53 +07:00
|
|
|
|
2021-02-13 02:43:11 +07:00
|
|
|
if (process.env.WTF_NODE) {
|
|
|
|
wtfnode.setup()
|
|
|
|
}
|
2021-02-13 02:41:59 +07:00
|
|
|
|
2021-02-13 02:08:34 +07:00
|
|
|
await page.goto(CODE_SERVER_ADDRESS, { waitUntil: "domcontentloaded" })
|
2021-02-02 04:38:53 +07:00
|
|
|
// Type in password
|
2021-02-13 02:08:34 +07:00
|
|
|
await page.fill(".password", PASSWORD)
|
2021-02-02 04:38:53 +07:00
|
|
|
// Click the submit button and login
|
|
|
|
await page.click(".submit")
|
|
|
|
|
|
|
|
// 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 06:33:39 +07:00
|
|
|
console.log("✅ Global Setup for Jest End-to-End Tests is now complete.")
|
2021-02-02 04:38:53 +07:00
|
|
|
}
|