-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
jestGlobalSetup.cjs
41 lines (36 loc) · 1.35 KB
/
jestGlobalSetup.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// @ts-check
const os = require('os')
const fs = require('fs-extra')
const path = require('path')
const { chromium } = require('playwright-chromium')
const DIR = path.join(os.tmpdir(), 'jest_playwright_global_setup')
module.exports = async () => {
const browserServer = await chromium.launchServer({
headless: !process.env.VITE_DEBUG_SERVE,
args: process.env.CI
? ['--no-sandbox', '--disable-setuid-sandbox']
: undefined
})
global.__BROWSER_SERVER__ = browserServer
await fs.mkdirp(DIR)
await fs.writeFile(path.join(DIR, 'wsEndpoint'), browserServer.wsEndpoint())
const tempDir = path.resolve(__dirname, '../packages/temp')
await fs.remove(tempDir)
await fs
.copy(path.resolve(__dirname, '../packages/playground'), 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
}
})
}