config.ts 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
import {
  ChromiumEnv,
  FirefoxEnv,
  WebKitEnv,
  test,
  setConfig,
  PlaywrightOptions,
  Config,
  globalSetup,
} from "@playwright/test"
11
import * as argon2 from "argon2"
12 13 14
import path from "path"
import { PASSWORD } from "./utils/constants"
import * as wtfnode from "./utils/wtfnode"
J
Joe Previte 已提交
15

16 17
// Playwright doesn't like that ../src/node/util has an enum in it
// so I had to copy hash in separately
18 19
const hash = async (str: string): Promise<string> => {
  return await argon2.hash(str)
20 21 22 23 24
}

const cookieToStore = {
  sameSite: "Lax" as const,
  name: "key",
25
  value: "",
26 27 28 29 30 31 32 33
  domain: "localhost",
  path: "/",
  expires: -1,
  httpOnly: false,
  secure: false,
}

globalSetup(async () => {
34
  console.log("\n🚨 Running globalSetup for playwright end-to-end tests")
35 36 37 38 39 40
  console.log("👋 Please hang tight...")

  if (process.env.WTF_NODE) {
    wtfnode.setup()
  }

41 42
  cookieToStore.value = await hash(PASSWORD)

43 44 45 46 47 48 49
  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)
50
  console.log("✅ globalSetup is now complete.")
J
Joe Previte 已提交
51 52
})

53 54
const config: Config = {
  testDir: path.join(__dirname, "e2e"), // Search for tests in this directory.
55
  timeout: 60000, // Each test is given 60 seconds.
J
Joe Previte 已提交
56
  retries: 3, // Retry failing tests 2 times
57
  workers: 1,
J
Joe Previte 已提交
58 59 60
}

if (process.env.CI) {
61 62
  // In CI, retry failing tests 2 times
  // in the event of flakiness
J
Joe Previte 已提交
63
  config.retries = 2
64 65 66 67
}

setConfig(config)

J
Joe Previte 已提交
68 69
const options: PlaywrightOptions = {
  headless: true, // Run tests in headless browsers.
70
  video: "on",
J
Joe Previte 已提交
71 72 73 74 75 76
}

// 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" })