#!/bin/sh
. "$(dirname "$0")/../common.sh"
if [ "$OS" = "brew" ]; then
run_install nodejs npm node ca-certificates bash coreutils gcc
else
run_install nodejs npm node ca-certificates
fi
check_cmd node --version || lang_skip "no node package for OS=$OS"
run_ebin_if npx --version
run_ebin_if npm --version
run_ebin node --version
run node -e "console.log(1+1)"
run node -e "console.log('ok')"
if [ "$OS" = "conda" ]; then
run node -e "require('fs').mkdirSync('$TEST_TMP/nodeproj', {recursive:true}); require('fs').writeFileSync('$TEST_TMP/nodeproj/index.js', 'console.log(\"hello\")')"
run node "$TEST_TMP/nodeproj/index.js" | grep -q hello
lang_ok
exit 0
elif [ "$OS" = "brew" ]; then
SHELL_CMD="bash -c"
else
SHELL_CMD="/bin/sh -c"
fi
run $SHELL_CMD "mkdir -p $TEST_TMP/nodeproj && cd $TEST_TMP/nodeproj && echo 'console.log(\"hello\");' > index.js"
run $SHELL_CMD "cd $TEST_TMP/nodeproj && node index.js"
run $SHELL_CMD "cd $TEST_TMP/nodeproj && npm init -y && npm install lodash && node -e \"require('lodash'); console.log('ok')\""
run $SHELL_CMD "mkdir -p $TEST_TMP/nodeproj2 && cd $TEST_TMP/nodeproj2 && npm init -y"
if [ -n "${ENV_ROOT:-}" ] && [ -x "$ENV_ROOT/ebin/npm" ]; then
run /bin/sh -c "cd $TEST_TMP/nodeproj2 && '$ENV_ROOT/ebin/npm' install lodash"
fi
lang_ok