2016-12-27 19:37:01 +00:00
|
|
|
var fs = require('fs')
|
|
|
|
var tape = require('tape')
|
|
|
|
var path = require('path')
|
|
|
|
var childProcess = require('child_process')
|
|
|
|
|
|
|
|
tape('fails for unsupported platforms', function (t) {
|
|
|
|
install({npm_config_platform: 'android'}, function (code, stderr) {
|
|
|
|
t.notEqual(stderr.indexOf('Electron builds are not available on platform: android'), -1, 'has error message')
|
2016-12-27 21:20:51 +00:00
|
|
|
t.notEqual(code, 0, 'exited with error')
|
2016-12-27 19:37:01 +00:00
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
tape('fails for unknown architectures', function (t) {
|
|
|
|
install({
|
|
|
|
npm_config_arch: 'midcentury',
|
|
|
|
npm_config_platform: 'win32',
|
|
|
|
HOME: process.env.HOME,
|
|
|
|
USERPROFILE: process.env.USERPROFILE
|
|
|
|
}, function (code, stderr) {
|
|
|
|
t.notEqual(stderr.indexOf('Failed to find Electron'), -1, 'has error message')
|
|
|
|
t.notEqual(stderr.indexOf('win32-midcentury'), -1, 'has error message')
|
2016-12-27 21:20:51 +00:00
|
|
|
t.notEqual(code, 0, 'exited with error')
|
2016-12-27 19:37:01 +00:00
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
var install = function (env, callback) {
|
|
|
|
removeVersionFile()
|
|
|
|
|
|
|
|
var installPath = path.join(__dirname, '..', 'install.js')
|
|
|
|
var installProcess = childProcess.fork(installPath, {
|
|
|
|
silent: true,
|
|
|
|
env: env
|
|
|
|
})
|
|
|
|
|
|
|
|
var stderr = ''
|
|
|
|
installProcess.stderr.on('data', function (data) {
|
|
|
|
stderr += data
|
|
|
|
})
|
|
|
|
|
|
|
|
installProcess.on('close', function (code) {
|
|
|
|
restoreVersionFile()
|
|
|
|
callback(code, stderr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var versionPath = path.join(__dirname, '..', 'dist', 'version')
|
|
|
|
var versionContents = null
|
|
|
|
function removeVersionFile () {
|
|
|
|
if (fs.existsSync(versionPath)) {
|
|
|
|
versionContents = fs.readFileSync(versionPath)
|
|
|
|
fs.unlinkSync(versionPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreVersionFile () {
|
|
|
|
if (versionContents != null) {
|
|
|
|
fs.writeFileSync(versionPath, versionContents)
|
|
|
|
versionContents = null
|
|
|
|
}
|
|
|
|
}
|