|
1 |
| -import { ChromiumEnv, FirefoxEnv, WebKitEnv, test, setConfig, PlaywrightOptions } from "@playwright/test" |
| 1 | +import { |
| 2 | + ChromiumEnv, |
| 3 | + FirefoxEnv, |
| 4 | + WebKitEnv, |
| 5 | + test, |
| 6 | + setConfig, |
| 7 | + PlaywrightOptions, |
| 8 | + Config, |
| 9 | + globalSetup, |
| 10 | +} from "@playwright/test" |
| 11 | +import * as crypto from "crypto" |
| 12 | +import path from "path" |
| 13 | +import { PASSWORD } from "./utils/constants" |
| 14 | +import * as wtfnode from "./utils/wtfnode" |
2 | 15 |
|
3 |
| -setConfig({ |
4 |
| - testDir: "e2e", // Search for tests in this directory. |
5 |
| - timeout: 30000, // Each test is given 30 seconds. |
| 16 | +// Playwright doesn't like that ../src/node/util has an enum in it |
| 17 | +// so I had to copy hash in separately |
| 18 | +const hash = (str: string): string => { |
| 19 | + return crypto.createHash("sha256").update(str).digest("hex") |
| 20 | +} |
| 21 | + |
| 22 | +const cookieToStore = { |
| 23 | + sameSite: "Lax" as const, |
| 24 | + name: "key", |
| 25 | + value: hash(PASSWORD), |
| 26 | + domain: "localhost", |
| 27 | + path: "/", |
| 28 | + expires: -1, |
| 29 | + httpOnly: false, |
| 30 | + secure: false, |
| 31 | +} |
| 32 | + |
| 33 | +globalSetup(async () => { |
| 34 | + console.log("\n🚨 Running Global Setup for Jest End-to-End Tests") |
| 35 | + console.log("👋 Please hang tight...") |
| 36 | + |
| 37 | + if (process.env.WTF_NODE) { |
| 38 | + wtfnode.setup() |
| 39 | + } |
| 40 | + |
| 41 | + const storage = { |
| 42 | + cookies: [cookieToStore], |
| 43 | + } |
| 44 | + |
| 45 | + // Save storage state and store as an env variable |
| 46 | + // More info: https://playwright.dev/docs/auth?_highlight=authe#reuse-authentication-state |
| 47 | + process.env.STORAGE = JSON.stringify(storage) |
| 48 | + console.log("✅ Global Setup for Jest End-to-End Tests is now complete.") |
6 | 49 | })
|
7 | 50 |
|
| 51 | +const config: Config = { |
| 52 | + testDir: path.join(__dirname, "e2e"), // Search for tests in this directory. |
| 53 | + timeout: 30000, // Each test is given 30 seconds. |
| 54 | +} |
| 55 | + |
| 56 | +if (process.env.CI) { |
| 57 | + config.retries = 2 // Retry failing tests 2 times |
| 58 | +} |
| 59 | + |
| 60 | +setConfig(config) |
| 61 | + |
8 | 62 | const options: PlaywrightOptions = {
|
9 | 63 | headless: true, // Run tests in headless browsers.
|
10 | 64 | video: "retain-on-failure",
|
|
0 commit comments