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

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// Playwright doesn't like that ../src/node/util has an enum in it
// so I had to copy hash in separately
const hash = (str: string): string => {
  return crypto.createHash("sha256").update(str).digest("hex")
}

const cookieToStore = {
  sameSite: "Lax" as const,
  name: "key",
  value: hash(PASSWORD),
  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 41 42 43 44 45 46 47
  console.log("👋 Please hang tight...")

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

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

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

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

setConfig(config)

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

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