Commit 2faeed57 authored by zeke's avatar zeke

passing tests: testPackageJsonWithoutVersion,...

passing tests: testPackageJsonWithoutVersion, testPackageJsonWithStableVersion, testPackageJsonWithUnstableVersion
parent c5d7a0c4
...@@ -39,8 +39,6 @@ query_all_versions() { ...@@ -39,8 +39,6 @@ query_all_versions() {
| sort -u -k 1,1n -k 2,2n -k 3,3n -t . | sort -u -k 1,1n -k 2,2n -k 3,3n -t .
} }
error() { error() {
echo " ! $*" >&2 echo " ! $*" >&2
exit 1 exit 1
......
...@@ -8,13 +8,17 @@ stable_version="0.10.18" ...@@ -8,13 +8,17 @@ stable_version="0.10.18"
source $bp_dir/bin/common.sh source $bp_dir/bin/common.sh
# Output debug info on exit # Output debug info on exit
trap cat_npm_debug_log EXIT # trap cat_npm_debug_log EXIT
status "Downloading node version $stable_version" status "Downloading node version $stable_version"
download_and_install_node $stable_version download_and_install_node $stable_version
# Is a node version specified in package.json? # Is a node version specified in package.json?
requested_version=$(cat $build_dir/package.json | node $bp_dir/vendor/json engines.node 2>/dev/null) determine_requested_version() {
v=$(cat $build_dir/package.json | node $bp_dir/vendor/json engines.node 2>/dev/null)
if [ $? == 0 ]; then echo $v; fi
}
requested_version=$(determine_requested_version)
# Give a warning if no node engine is specified # Give a warning if no node engine is specified
if ! test $requested_version; then if ! test $requested_version; then
...@@ -23,32 +27,32 @@ if ! test $requested_version; then ...@@ -23,32 +27,32 @@ if ! test $requested_version; then
echo "WARNING: No node version specified in package.json, see:" | indent echo "WARNING: No node version specified in package.json, see:" | indent
echo "https://devcenter.heroku.com/articles/nodejs-support#versions" | indent echo "https://devcenter.heroku.com/articles/nodejs-support#versions" | indent
echo echo
status "Using latest stable node version $stable_version"
else else
# Does the already-downloaded stable version of node satisfy the requested version? # Does the already-downloaded stable version of node satisfy the requested version?
default_satisfies=$(node $bp_dir/vendor/semver/bin/semver -v $stable_version -r "$requested_version" || echo "") default_satisfies=$(node $bp_dir/vendor/semver/bin/semver -v "${stable_version}" -r "${requested_version}" || echo "")
if ! test $default_satisfies; then if test $default_satisfies; then
status "Using node version $stable_version" status "Using latest stable node version $stable_version"
else else
# Find all available versions from nodejs.org/dist # Find all available versions from nodejs.org/dist
available_versions="" args=""
for version in query_all_versions; do for version in $(query_all_versions); do args="${args} -v \"${version}\""; done
available_versions="${available_versions} -v \"${version}\"" args="${args} -r \"${requested_version}\""
done
# Determine which available versions satisfy the requested version # Determine which available versions satisfy the requested version
# https://github.com/isaacs/node-semver/blob/master/bin/semver # https://github.com/isaacs/node-semver/blob/master/bin/semver
evaluated_versions=$(node $bp_dir/vendor/semver/bin/semver $available_versions -r "$requested_version" || echo "") evaluated_versions=$(eval node $bp_dir/vendor/semver/bin/semver ${args} || echo "")
# Use the latest of the evaluated versions # Use the latest of the evaluated versions
node_version=$("$evaluated_versions" | tail -n 1) node_version=$(echo $evaluated_versions | tail -n 1)
if test $node_version; then if test $node_version; then
status "Using node version $node_version" status "Using node version $node_version"
download_and_install_node $node_version download_and_install_node $node_version
else else
error "Requested node version ${requested_version} not found among available versions: ${available_versions}" error "Requested node version ${requested_version} not found among available versions on nodejs.org/dist"
fi fi
fi fi
fi fi
...@@ -58,16 +62,18 @@ cache_store_dir="$cache_dir/node_modules/$node_version" ...@@ -58,16 +62,18 @@ cache_store_dir="$cache_dir/node_modules/$node_version"
cache_target_dir="$build_dir/node_modules" cache_target_dir="$build_dir/node_modules"
# Restore node_modules from cache, if present # Restore node_modules from cache, if present
if [ -d $cache_store_dir ]; then # if [ -d $cache_store_dir ]; then
status "Restoring node_modules cache" # status "Restoring node_modules cache"
if [ -d $cache_target_dir ]; then # if [ -d $cache_target_dir ]; then
cp -r $cache_store_dir/* $cache_target_dir/ # cp -r $cache_store_dir/* $cache_target_dir/
else # else
cp -r $cache_store_dir $cache_target_dir # cp -r $cache_store_dir $cache_target_dir
fi # fi
status "Pruning any unused dependencies" # status "Pruning any unused dependencies"
npm prune # npm prune
fi # fi
cd $build_dir
# Install dependencies # Install dependencies
status "Installing dependencies" status "Installing dependencies"
...@@ -75,12 +81,12 @@ npm install --production ...@@ -75,12 +81,12 @@ npm install --production
npm rebuild npm rebuild
# Cache node_modules for future builds # Cache node_modules for future builds
if [ -d $cache_target_dir ]; then # if [ -d $cache_target_dir ]; then
status "Caching node_modules for future builds" # status "Caching node_modules for future builds"
rm -rf $cache_store_dir # rm -rf $cache_store_dir
mkdir -p $(dirname $cache_store_dir) # mkdir -p $(dirname $cache_store_dir)
cp -r $cache_target_dir $cache_store_dir # cp -r $cache_target_dir $cache_store_dir
fi # fi
# Update the PATH # Update the PATH
status "Building runtime environment" status "Building runtime environment"
......
...@@ -8,48 +8,54 @@ ...@@ -8,48 +8,54 @@
# run the tests # run the tests
# #
testDetectWithPackageJson() { # testDetectWithPackageJson() {
detect "package-json-version" # detect "package-json-stable-version"
assertCaptured "Node.js" # assertCaptured "Node.js"
assertCapturedSuccess # assertCapturedSuccess
} # }
testDetectWithoutPackageJson() { # testDetectWithoutPackageJson() {
detect "no-package-json" # detect "no-package-json"
assertCapturedError 1 "" # assertCapturedError 1 ""
} # }
testPackageJsonWithVersion() {s
compile "package-json-version"
assertNotCaptured "WARNING: No node version specified"
assertCaptured "Using node 0.10"
assertCapturedSuccess
}
testPackageJsonWithoutVersion() { testPackageJsonWithoutVersion() {
compile "package-json-noversion" compile "package-json-noversion"
assertCaptured "WARNING: No node version specified" assertCaptured "WARNING: No node version specified"
assertCaptured "Using node 0.10" assertCaptured "Using latest stable node"
assertCapturedSuccess assertCapturedSuccess
} }
testPackageJsonWithInvalidVersion() { testPackageJsonWithStableVersion() {
compile "package-json-invalidversion" compile "package-json-stable-version"
assertCapturedError 1 "Requested node version 5.0 not found" assertNotCaptured "WARNING: No node version specified"
assertCaptured "Using latest stable node"
assertCapturedSuccess
} }
testProfileCreated() { testPackageJsonWithUnstableVersion() {
compile "package-json-version" compile "package-json-unstable-version"
assertCaptured "Building runtime environment" assertCaptured "Using node version 0.11"
assertFile "export PATH=\"\$HOME/node/bin:$HOME/bin:\$HOME/node_modules/.bin:\$PATH\"" ".profile.d/nodejs.sh"
assertCapturedSuccess assertCapturedSuccess
} }
testNodeModulesCached() { # testPackageJsonWithInvalidVersion() {
cache=$(mktmpdir) # compile "package-json-invalidversion"
compile "node-modules-caching" $cache # assertCapturedError 1 "Requested node version 5.0 not found"
assertEquals "1" "$(ls -1 $cache/node_modules/0.10.17 | wc -l)" # }
}
# testProfileCreated() {
# compile "package-json-version"
# assertCaptured "Building runtime environment"
# assertFile "export PATH=\"\$HOME/node/bin:$HOME/bin:\$HOME/node_modules/.bin:\$PATH\"" ".profile.d/nodejs.sh"
# assertCapturedSuccess
# }
# testNodeModulesCached() {
# cache=$(mktmpdir)
# compile "node-modules-caching" $cache
# assertEquals "1" "$(ls -1 $cache/node_modules/0.10.17 | wc -l)"
# }
## utils ######################################## ## utils ########################################
......
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