Question

I'm new to nodejs, and am not sure how I can enable harmony features in nodeunit?

I know I can enable them in node by using the --harmony flag, but nodeunit does not have this flag. I'm looking specifically to make let work.

Was it helpful?

Solution

This might not work for all cases, but we can add the --harmony flag in the nodeunit startup script:

batch:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --harmony "%~dp0\..\nodeunit\bin\nodeunit" %*
) ELSE (
  node --harmony "%~dp0\..\nodeunit\bin\nodeunit" %*
)

sh:

#!/bin/sh
basedir=`dirname "$0"`

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node" --harmony "$basedir/../nodeunit/bin/nodeunit" "$@"
  ret=$?
else 
  node --harmony "$basedir/../nodeunit/bin/nodeunit" "$@"
  ret=$?
fi
exit $ret

OTHER TIPS

On Linux, if you have nodeunit installed globally (npm install -g nodeunit), this works just fine:

node --harmony `which nodeunit` /path/to/tests

On a Mac with the default install locations, a quick one liner:

node --harmony /usr/local/bin/nodeunit /path/to/your/testFile.js 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top