Running node.js tests when deploying to Azure Websites

By default, Windows Azure Websites does not run your unit tests when you push a new deployment. However, it’s quite straight forward to set this up.

If you haven’t already done so, install Azure Command-Line tools for Mac and Linux (they work just fine on Windows too).

> npm install -g azure-cli

Now navigate to your node app, and run a command which will create a custom deployment script for you:

> azure site deploymentscript --node

This will add the following files to your directory:

deploy.cmd
iisnode.yml
web.config

The deploy.cmd file is executed every time you push your repository up to Azure. You can customise this to include some testing, here is a snippet with NPM TEST added (in bold).

...
IF NOT DEFINED KUDU_SYNC_COMMAND (
 :: Install kudu sync
 echo Installing Kudu Sync
 call npm install kudusync -g --silent
 IF !ERRORLEVEL! NEQ 0 goto error
:: Locally just running "kuduSync" would also work
 SET KUDU_SYNC_COMMAND=node "%appdata%\npm\node_modules\kuduSync\bin\kuduSync"
)
npm test :: THIS LINE HAS BEEN ADDED TO RUN THE TESTS
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------
...

You’ll need to add these files to your repository (assuming you’re using git) and push the changes up.

> git add .
> git commit -am "adding custom deployment script"
> git push azure master

Your tests will now run, and the deployment will fail if the tests fail! The error message can be viewed by expanding the detail of the deployment.

Untitled

About these ads