UNPKG

vitest-e2e

Version:
44 lines (41 loc) 1.67 kB
import { workspaceRoot } from './chunk-JXTCPVDR.js'; import fs from 'fs-extra'; import os from 'node:os'; import path from 'node:path'; import { chromium } from 'playwright-chromium'; var DIR = path.join(os.tmpdir(), "vitest_playwright_global_setup"); var browserServer; async function setup() { process.env.NODE_ENV = process.env.VITE_TEST_BUILD ? "production" : "development"; browserServer = await chromium.launchServer({ headless: !process.env.VITE_DEBUG_SERVE, args: process.env.CI ? ["--no-sandbox", "--disable-setuid-sandbox"] : void 0 }); await fs.mkdirp(DIR); await fs.writeFile(path.join(DIR, "wsEndpoint"), browserServer.wsEndpoint()); const tempDir = path.resolve(workspaceRoot, "./playground-temp"); await fs.ensureDir(tempDir); await fs.emptyDir(tempDir); await fs.copy(path.resolve(workspaceRoot, "./playground"), tempDir, { dereference: false, filter(file) { file = file.replace(/\\/g, "/"); return !file.includes("__tests__") && !/dist(\/|$)/.test(file); } }).catch(async (error) => { if (error.code === "EPERM" && error.syscall === "symlink") { throw new Error( "Could not create symlinks. On Windows, consider activating Developer Mode to allow non-admin users to create symlinks by following the instructions at https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development." ); } else { throw error; } }); } async function teardown() { await browserServer?.close(); if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) { fs.removeSync(path.resolve(workspaceRoot, "./playground-temp")); } } export { setup, teardown };