forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskfile.js
35 lines (30 loc) · 1.2 KB
/
taskfile.js
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
const isWindows = /^win/.test(process.platform)
const childProcess = require('child_process')
const rimraf = require('rimraf')
const mkdirp = require('mkdirp')
export async function pretest (task) {
// Create node_modules/next for the use of test apps
rimraf.sync('test/node_modules/next')
mkdirp.sync('test/node_modules')
if (isWindows) {
const symlinkCommand = 'mklink /D "next" "..\\..\\packages\\next"'
childProcess.execSync(symlinkCommand, { cwd: 'test/node_modules' })
}
// We run following task inside a NPM script chain and it runs chromedriver
// inside a child process tree.
// Even though we kill this task's process, chromedriver exists throughout
// the lifetime of the original npm script.
// Start chromedriver
const processName = isWindows ? 'chromedriver.cmd' : 'chromedriver'
childProcess.spawn(processName, { stdio: 'inherit' })
// We need to do this, otherwise this task's process will keep waiting.
setTimeout(() => process.exit(0), 2000)
}
export async function posttest (task) {
try {
const cmd = isWindows ? 'taskkill /im chromedriver* /t /f' : 'pkill chromedriver'
childProcess.execSync(cmd, { stdio: 'ignore' })
} catch (err) {
// Do nothing
}
}