2018-09-30 23:02:10 +00:00
|
|
|
const isWindows = /^win/.test(process.platform)
|
2017-06-22 13:52:13 +00:00
|
|
|
const childProcess = require('child_process')
|
2018-01-31 07:35:10 +00:00
|
|
|
const rimraf = require('rimraf')
|
|
|
|
const mkdirp = require('mkdirp')
|
2018-09-04 09:21:00 +00:00
|
|
|
|
2018-09-30 23:02:10 +00:00
|
|
|
export async function pretest (task) {
|
|
|
|
// Create node_modules/next for the use of test apps
|
2018-01-31 07:35:10 +00:00
|
|
|
rimraf.sync('test/node_modules/next')
|
|
|
|
mkdirp.sync('test/node_modules')
|
|
|
|
|
2018-09-30 23:02:10 +00:00
|
|
|
if (isWindows) {
|
|
|
|
const symlinkCommand = 'mklink /D "next" "..\\..\\packages\\next"'
|
|
|
|
childProcess.execSync(symlinkCommand, { cwd: 'test/node_modules' })
|
|
|
|
}
|
2017-06-22 13:52:13 +00:00
|
|
|
|
2018-09-30 23:02:10 +00:00
|
|
|
// 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.
|
2018-01-31 07:35:10 +00:00
|
|
|
// Start chromedriver
|
2017-06-22 13:52:13 +00:00
|
|
|
const processName = isWindows ? 'chromedriver.cmd' : 'chromedriver'
|
2017-06-26 17:51:52 +00:00
|
|
|
childProcess.spawn(processName, { stdio: 'inherit' })
|
2018-01-31 07:35:10 +00:00
|
|
|
|
2017-06-22 13:52:13 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|