javascriptnode.jsnodeunit

NodeUnit enable harmony features


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.


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