Add test for corrupt install error message
This commit is contained in:
parent
b85ec95975
commit
e3e05aa797
1 changed files with 40 additions and 16 deletions
|
@ -3,7 +3,7 @@ var tape = require('tape')
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
var childProcess = require('child_process')
|
var childProcess = require('child_process')
|
||||||
|
|
||||||
tape('fails for unsupported platforms', function (t) {
|
tape('install fails for unsupported platforms', function (t) {
|
||||||
install({npm_config_platform: 'android'}, function (code, stderr) {
|
install({npm_config_platform: 'android'}, function (code, stderr) {
|
||||||
t.notEqual(stderr.indexOf('Electron builds are not available on platform: android'), -1, 'has error message')
|
t.notEqual(stderr.indexOf('Electron builds are not available on platform: android'), -1, 'has error message')
|
||||||
t.notEqual(code, 0, 'exited with error')
|
t.notEqual(code, 0, 'exited with error')
|
||||||
|
@ -11,7 +11,7 @@ tape('fails for unsupported platforms', function (t) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
tape('fails for unknown architectures', function (t) {
|
tape('install fails for unsupported architectures', function (t) {
|
||||||
install({
|
install({
|
||||||
npm_config_arch: 'midcentury',
|
npm_config_arch: 'midcentury',
|
||||||
npm_config_platform: 'win32',
|
npm_config_platform: 'win32',
|
||||||
|
@ -25,8 +25,16 @@ tape('fails for unknown architectures', function (t) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
var install = function (env, callback) {
|
tape('require fails for corrupted installs', function (t) {
|
||||||
removeVersionFile()
|
cli(function (code, stderr) {
|
||||||
|
t.notEqual(stderr.indexOf('Electron failed to install correctly'), -1, 'has error message')
|
||||||
|
t.notEqual(code, 0, 'exited with error')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function install (env, callback) {
|
||||||
|
var restoreFile = removeFile(path.join(__dirname, '..', 'dist', 'version'))
|
||||||
|
|
||||||
var installPath = path.join(__dirname, '..', 'install.js')
|
var installPath = path.join(__dirname, '..', 'install.js')
|
||||||
var installProcess = childProcess.fork(installPath, {
|
var installProcess = childProcess.fork(installPath, {
|
||||||
|
@ -40,23 +48,39 @@ var install = function (env, callback) {
|
||||||
})
|
})
|
||||||
|
|
||||||
installProcess.on('close', function (code) {
|
installProcess.on('close', function (code) {
|
||||||
restoreVersionFile()
|
restoreFile()
|
||||||
callback(code, stderr)
|
callback(code, stderr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var versionPath = path.join(__dirname, '..', 'dist', 'version')
|
function cli (callback) {
|
||||||
var versionContents = null
|
var restoreFile = removeFile(path.join(__dirname, '..', 'path.txt'))
|
||||||
function removeVersionFile () {
|
|
||||||
if (fs.existsSync(versionPath)) {
|
var cliPath = path.join(__dirname, '..', 'cli.js')
|
||||||
versionContents = fs.readFileSync(versionPath)
|
var cliProcess = childProcess.fork(cliPath, {
|
||||||
fs.unlinkSync(versionPath)
|
silent: true
|
||||||
}
|
})
|
||||||
|
|
||||||
|
var stderr = ''
|
||||||
|
cliProcess.stderr.on('data', function (data) {
|
||||||
|
stderr += data
|
||||||
|
})
|
||||||
|
|
||||||
|
cliProcess.on('close', function (code) {
|
||||||
|
restoreFile()
|
||||||
|
callback(code, stderr)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreVersionFile () {
|
function removeFile (filePath) {
|
||||||
if (versionContents != null) {
|
var contents = null
|
||||||
fs.writeFileSync(versionPath, versionContents)
|
if (fs.existsSync(filePath)) {
|
||||||
versionContents = null
|
contents = fs.readFileSync(filePath)
|
||||||
|
fs.unlinkSync(filePath)
|
||||||
|
}
|
||||||
|
return function restoreFile () {
|
||||||
|
if (contents != null) {
|
||||||
|
fs.writeFileSync(filePath, contents)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue