mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
2 years ago
|
import os from 'os'
|
||
|
import path from 'path'
|
||
|
import fs from 'fs-extra'
|
||
|
import type { BrowserServer } from 'playwright-chromium'
|
||
|
import { chromium } from 'playwright-chromium'
|
||
|
|
||
|
const DIR = path.join(os.tmpdir(), 'vitest_playwright_global_setup')
|
||
|
|
||
|
let browserServer: BrowserServer | undefined
|
||
|
|
||
|
export async function setup(): Promise<void> {
|
||
|
browserServer = await chromium.launchServer({
|
||
|
headless: !process.env.VITE_DEBUG_SERVE,
|
||
|
args: process.env.CI
|
||
|
? ['--no-sandbox', '--disable-setuid-sandbox']
|
||
|
: undefined
|
||
|
})
|
||
|
|
||
|
await fs.mkdirp(DIR)
|
||
|
await fs.writeFile(path.join(DIR, 'wsEndpoint'), browserServer.wsEndpoint())
|
||
|
|
||
|
const tempDir = path.resolve(__dirname, '../examples-temp')
|
||
|
await fs.ensureDir(tempDir)
|
||
|
await fs.emptyDir(tempDir)
|
||
|
await fs
|
||
|
.copy(path.resolve(__dirname, '../examples'), tempDir, {
|
||
|
dereference: false,
|
||
|
filter(file) {
|
||
|
file = file.replace(/\\/g, '/')
|
||
|
return !file.includes('__tests__') && !file.match(/dist(\/|$)/)
|
||
|
}
|
||
|
})
|
||
|
.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
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
export async function teardown(): Promise<void> {
|
||
|
browserServer?.close()
|
||
|
if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) {
|
||
|
fs.removeSync(path.resolve(__dirname, '../examples-temp'))
|
||
|
}
|
||
|
}
|