2021-04-14 00:15:07 +00:00
|
|
|
import {
|
|
|
|
ChromiumEnv,
|
|
|
|
FirefoxEnv,
|
|
|
|
WebKitEnv,
|
|
|
|
test,
|
|
|
|
setConfig,
|
|
|
|
PlaywrightOptions,
|
|
|
|
Config,
|
|
|
|
globalSetup,
|
|
|
|
} from "@playwright/test"
|
2021-06-02 20:31:50 +00:00
|
|
|
import * as argon2 from "argon2"
|
2021-04-14 00:15:07 +00:00
|
|
|
import path from "path"
|
|
|
|
import { PASSWORD } from "./utils/constants"
|
|
|
|
import * as wtfnode from "./utils/wtfnode"
|
2021-04-13 18:58:09 +00:00
|
|
|
|
2021-04-14 00:15:07 +00:00
|
|
|
// Playwright doesn't like that ../src/node/util has an enum in it
|
|
|
|
// so I had to copy hash in separately
|
2021-06-02 20:31:50 +00:00
|
|
|
const hash = async (str: string): Promise<string> => {
|
|
|
|
return await argon2.hash(str)
|
2021-04-14 00:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const cookieToStore = {
|
|
|
|
sameSite: "Lax" as const,
|
|
|
|
name: "key",
|
2021-06-02 20:31:50 +00:00
|
|
|
value: "",
|
2021-04-14 00:15:07 +00:00
|
|
|
domain: "localhost",
|
|
|
|
path: "/",
|
|
|
|
expires: -1,
|
|
|
|
httpOnly: false,
|
|
|
|
secure: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
globalSetup(async () => {
|
2021-04-14 21:45:30 +00:00
|
|
|
console.log("\n🚨 Running globalSetup for playwright end-to-end tests")
|
2021-04-14 00:15:07 +00:00
|
|
|
console.log("👋 Please hang tight...")
|
|
|
|
|
|
|
|
if (process.env.WTF_NODE) {
|
|
|
|
wtfnode.setup()
|
|
|
|
}
|
|
|
|
|
2021-06-02 20:31:50 +00:00
|
|
|
cookieToStore.value = await hash(PASSWORD)
|
|
|
|
|
2021-04-14 00:15:07 +00:00
|
|
|
const storage = {
|
|
|
|
cookies: [cookieToStore],
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2021-04-14 21:45:30 +00:00
|
|
|
console.log("✅ globalSetup is now complete.")
|
2021-04-13 18:58:09 +00:00
|
|
|
})
|
|
|
|
|
2021-04-14 00:15:07 +00:00
|
|
|
const config: Config = {
|
|
|
|
testDir: path.join(__dirname, "e2e"), // Search for tests in this directory.
|
2021-04-15 23:34:36 +00:00
|
|
|
timeout: 60000, // Each test is given 60 seconds.
|
2021-04-14 19:03:47 +00:00
|
|
|
retries: 3, // Retry failing tests 2 times
|
2021-04-29 23:27:19 +00:00
|
|
|
workers: 1,
|
2021-04-14 19:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.CI) {
|
2021-04-14 21:45:30 +00:00
|
|
|
// In CI, retry failing tests 2 times
|
|
|
|
// in the event of flakiness
|
2021-04-14 19:03:47 +00:00
|
|
|
config.retries = 2
|
2021-04-14 00:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setConfig(config)
|
|
|
|
|
2021-04-13 18:58:09 +00:00
|
|
|
const options: PlaywrightOptions = {
|
|
|
|
headless: true, // Run tests in headless browsers.
|
2021-04-16 21:12:10 +00:00
|
|
|
video: "on",
|
2021-04-13 18:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run tests in three browsers.
|
|
|
|
test.runWith(new ChromiumEnv(options), { tag: "chromium" })
|
|
|
|
test.runWith(new FirefoxEnv(options), { tag: "firefox" })
|
|
|
|
test.runWith(new WebKitEnv(options), { tag: "webkit" })
|