Commit 8d2b627a authored by Hunter Loftis's avatar Hunter Loftis

test and implementation to detect common missing dependencies

parent bfb75db6
......@@ -19,6 +19,9 @@ mkdir -p "$BUILD_DIR/.heroku/node/"
cd $BUILD_DIR
export PATH="$BUILD_DIR/.heroku/node/bin":$PATH
LOG_FILE='/tmp/node-build-log.txt'
echo "" > "$LOG_FILE"
### Load dependencies
source $BP_DIR/lib/output.sh
......@@ -33,7 +36,8 @@ source $BP_DIR/lib/dependencies.sh
handle_failure() {
header "Build failed"
failure_message | indent
warn_untracked_dependencies "$LOG_FILE"
failure_message | output "$LOG_FILE"
}
trap 'handle_failure' ERR
......@@ -57,8 +61,8 @@ create_env() {
}
header "Creating runtime environment"
create_env # can't indent the whole thing because piping causes subshells; no exporting possible
list_node_config | indent
create_env # can't pipe the whole thing because piping causes subshells, preventing exports
list_node_config | output "$LOG_FILE"
install_bins() {
local node_engine=$(read_json "$BUILD_DIR/package.json" ".engines.node")
......@@ -86,7 +90,7 @@ install_bins() {
}
header "Installing binaries"
install_bins | indent
install_bins | output "$LOG_FILE"
restore_cache() {
local cache_status="$(get_cache_status)"
......@@ -106,7 +110,7 @@ restore_cache() {
}
header "Restoring cache"
restore_cache | indent
restore_cache | output "$LOG_FILE"
build_dependencies() {
if $PREBUILD; then
......@@ -118,11 +122,11 @@ build_dependencies() {
}
header "Building dependencies"
build_dependencies | indent
build_dependencies | output "$LOG_FILE"
cache_build() {
local cache_directories=$(get_cache_directories)
echo "Clearing previous node cache"
clear_cache
if [ "$cache_directories" == "" ]; then
......@@ -136,7 +140,7 @@ cache_build() {
}
header "Caching build"
cache_build | indent
cache_build | output "$LOG_FILE"
summarize_build() {
cd $BUILD_DIR
......@@ -144,4 +148,4 @@ summarize_build() {
}
header "Build succeeded!"
summarize_build | indent
summarize_build | output "$LOG_FILE"
......@@ -67,3 +67,14 @@ warn_old_npm() {
warning "This version of npm ($npm_version) has several known issues - consider upgrading to the latest release ($latest_npm)" "https://devcenter.heroku.com/articles/nodejs-support#specifying-an-npm-version"
fi
}
warn_untracked_dependencies() {
local log_file="$1"
if grep -qi 'gulp: not found' "$log_file"; then
warning "gulp may not be tracked in package.json" "https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies"
elif grep -qi 'grunt: not found' "$log_file"; then
warning "grunt may not be tracked in package.json" "https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies"
elif grep -qi 'bower: not found' "$log_file"; then
warning "bower may not be tracked in package.json" "https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies"
fi
}
......@@ -5,11 +5,13 @@ info() {
# sed -l basically makes sed replace and buffer through stdin to stdout
# so you get updates while the command runs and dont wait for the end
# e.g. npm install | indent
indent() {
c='s/^/ /'
output() {
local logfile="$1"
local c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
Darwin) tee -a "$logfile" | sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) tee -a "$logfile" | sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
esac
}
......
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
{
"name": "node-buildpack-test-app",
"version": "1.0.0",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"dependencies": {
},
"engines": {
"node": "4.1.1"
},
"scripts": {
"postinstall": "grunt build"
}
}
#!/usr/bin/env bash
# See README.md for info on running these tests.
testUntrackedDependencies() {
compile "missing-grunt"
assertCaptured "grunt may not be tracked in package.json"
assertCapturedError
}
testBadJson() {
compile "bad-json"
assertCaptured "Build failed"
assertCaptured "We're sorry this build is failing"
assertNotCaptured "Installing binaries"
assertCapturedError 1 "Unable to parse"
}
testBuildWithUserCacheDirectoriesCamel() {
cache=$(mktmpdir)
......@@ -151,14 +165,6 @@ testDetectWithoutPackageJson() {
assertCapturedError 1 ""
}
testBadJson() {
compile "bad-json"
assertCaptured "Build failed"
assertCaptured "We're sorry this build is failing"
assertNotCaptured "Installing binaries"
assertCapturedError 1 "Unable to parse"
}
testIoJs() {
compile "iojs"
assertCaptured "engines.iojs (package.json): 1.0."
......
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