Commit e2275685 authored by Hunter Loftis's avatar Hunter Loftis

test and implementation for error on failure to parse package.json

parent d020d2a2
......@@ -31,26 +31,7 @@ trap build_failed ERR
####### Determine current state
head "Reading application state"
info "package.json..."
iojs_engine=$(read_json "$build_dir/package.json" ".engines.iojs")
node_engine=$(read_json "$build_dir/package.json" ".engines.node")
npm_engine=$(read_json "$build_dir/package.json" ".engines.npm")
info "build directory..."
start_method=$(get_start_method "$build_dir")
modules_source=$(get_modules_source "$build_dir")
info "cache directory..."
npm_previous=$(file_contents "$cache_dir/node/npm-version")
node_previous=$(file_contents "$cache_dir/node/node-version")
modules_cached=$(get_modules_cached "$cache_dir")
info "environment variables..."
export_env_dir $env_dir
export NPM_CONFIG_PRODUCTION=${NPM_CONFIG_PRODUCTION:-true}
export NODE_MODULES_CACHE=${NODE_MODULES_CACHE:-true}
read_current_state
show_current_state
if [ "$iojs_engine" == "" ]; then
......
......@@ -24,7 +24,7 @@ testBadJson() {
assertCaptured "We're sorry this build is failing"
assertNotCaptured "build directory..."
assertNotCaptured "Installing binaries"
assertCapturedError 1 ""
assertCapturedError 1 "Unable to parse"
}
testIoJs() {
......@@ -206,6 +206,7 @@ testProcfileAbsentNpmStartPresent() {
testProcfileAbsentNpmStartAbsent() {
compile "procfile-absent-npm-start-absent"
assertCaptured "Start mechanism: none"
assertCaptured "None found"
assertNotCaptured "new Procfile"
assertCapturedSuccess
}
......
......@@ -53,6 +53,39 @@ get_modules_cached() {
fi
}
# Sets:
# iojs_engine
# node_engine
# npm_engine
# start_method
# modules_source
# npm_previous
# node_previous
# modules_cached
# environment variables (from ENV_DIR)
read_current_state() {
info "package.json..."
assert_json "$build_dir/package.json"
iojs_engine=$(read_json "$build_dir/package.json" ".engines.iojs")
node_engine=$(read_json "$build_dir/package.json" ".engines.node")
npm_engine=$(read_json "$build_dir/package.json" ".engines.npm")
info "build directory..."
start_method=$(get_start_method "$build_dir")
modules_source=$(get_modules_source "$build_dir")
info "cache directory..."
npm_previous=$(file_contents "$cache_dir/node/npm-version")
node_previous=$(file_contents "$cache_dir/node/node-version")
modules_cached=$(get_modules_cached "$cache_dir")
info "environment variables..."
export_env_dir $env_dir
export NPM_CONFIG_PRODUCTION=${NPM_CONFIG_PRODUCTION:-true}
export NODE_MODULES_CACHE=${NODE_MODULES_CACHE:-true}
}
show_current_state() {
echo ""
if [ "$iojs_engine" == "" ]; then
......@@ -172,6 +205,8 @@ ensure_procfile() {
elif [ "$start_method" == "server.js" ]; then
info "No Procfile; Adding 'web: node server.js' to new Procfile"
echo "web: node server.js" > $build_dir/Procfile
else
info "None found"
fi
}
......
error() {
echo " ! $*" >&2
exit 1
echo ""
return 1
}
head() {
......@@ -27,6 +28,15 @@ achievement() {
echo ""
}
assert_json() {
local file=$1
if test -f $file; then
if ! cat $file | $bp_dir/vendor/jq '.' > /dev/null; then
error "Unable to parse $file as JSON"
fi
fi
}
file_contents() {
if test -f $1; then
echo "$(cat $1)"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment