Running Jasmine / Karma Unit Tests on Azure Website Deployment

I keep seeing links to the ability to run Jasmine unit tests when deploying to an Azure website, but I can't seem to get it to work and can't find any successful code.

I am using gulp. I've got everything set up like this on my own pitch. I can run "gulp test" and it successfully runs Karma, which then runs the tests through PhantomJS. But when deploying, I see the following in the log:

[23:55:39] Starting 'test'...
[23:55:40] Starting Karma server...
[32mINFO [karma]: [39mKarma v0.12.28 server started at http://localhost:9876/
[32mINFO [launcher]: [39mStarting browser PhantomJS
[33mWARN [launcher]: [39mPhantomJS have not captured in 60000 ms, killing.
[32mINFO [launcher]: [39mTrying to start PhantomJS again (1/2).
[33mWARN [launcher]: [39mPhantomJS have not captured in 60000 ms, killing.
[32mINFO [launcher]: [39mTrying to start PhantomJS again (2/2).
[33mWARN [launcher]: [39mPhantomJS have not captured in 60000 ms, killing.
Failed exitCode=8, command="C:\DWASFiles\Sites\#1twctoolkittestclient\AppData\npm\gulp.cmd" test

      

I am running a test with the following in deploy.cmd:

Here is the test.js gulp task:

var gulp = require('gulp');
var karma = require('gulp-karma');

var testFiles = [
    'path to each file.js',
    ....   
];

gulp.task('test', function() {
    // Be sure to return the stream
    return gulp.src(testFiles)
        .pipe(karma({
            configFile: 'Assistant/Tests/karma.conf.js',
            action: 'run'
        }))
        .on('error', function(err) {
            // Make sure failed tests cause gulp to exit non-zero
            throw err;
        });
});

      

Here is karma.conf.js:

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '/',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [

    ],

    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  });
};

      

And I'm pretty sure the problem isn't that PhantomJS is missing, because I didn't have the package.json package before and it was giving me an error regarding missing binary. As soon as I enabled it to install npm I started getting the above error.

I've seen some forum posts suggesting that the Azure Sandbox might not allow communication with ports like PhantomJS, so this might be the problem. If so, is it possible at all to run Jasmine benchmarks as part of a Kudu deployment?

It's long and has some extra code to debug, but here's deploy.cmd:

@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off

:: ----------------------
:: KUDU Deployment Script
:: Version: 0.1.11
:: ----------------------

:: Prerequisites
:: -------------

echo Running deployment script
:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
  echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
  goto error
)

:: Setup
:: -----

setlocal enabledelayedexpansion

SET ARTIFACTS=%~dp0%..\artifacts

IF NOT DEFINED DEPLOYMENT_SOURCE (
  SET DEPLOYMENT_SOURCE=%~dp0%.
)

IF NOT DEFINED DEPLOYMENT_TARGET (
  SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)

IF NOT DEFINED NEXT_MANIFEST_PATH (
  SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest

  IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
    SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
  )
)

IF NOT DEFINED KUDU_SYNC_CMD (
  :: 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_CMD=%appdata%\npm\kuduSync.cmd
)
IF NOT DEFINED DEPLOYMENT_TEMP (
  SET DEPLOYMENT_TEMP=%temp%\___deployTemp%random%
  SET CLEAN_LOCAL_DEPLOYMENT_TEMP=true
)

IF DEFINED CLEAN_LOCAL_DEPLOYMENT_TEMP (
  IF EXIST "%DEPLOYMENT_TEMP%" rd /s /q "%DEPLOYMENT_TEMP%"
  mkdir "%DEPLOYMENT_TEMP%"
)

IF NOT DEFINED MSBUILD_PATH (
  SET MSBUILD_PATH=%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
)

IF NOT DEFINED GULP_CMD (
  :: Install gulp
  echo %time% Installing Gulp
  call npm --registry "http://registry.npmjs.org/" install gulp -g --silent
  call npm install gulp --save-dev
  echo %time% Gulp install complete
  IF !ERRORLEVEL! NEQ 0 goto error

  :: Locally just running "gulp" would also work
  SET GULP_CMD=%appdata%\npm\gulp.cmd

)


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------

echo Handling .NET Web Application deployment.

:: 1. Restore NuGet packages
IF /I "TWCRSA.sln" NEQ "" (
  echo %time% Restoring NuGet
  call :ExecuteCmd nuget restore "%DEPLOYMENT_SOURCE%\TWCRSA.sln"
  IF !ERRORLEVEL! NEQ 0 goto error  
)

:: Update NPM packages
Echo %time% NPM Install
pushd %DEPLOYMENT_SOURCE%\AssistantClient
call :ExecuteCmd npm install
popd
Echo %time% NPM Install complete

:: 1.1 Gulp Build
IF EXIST "%DEPLOYMENT_SOURCE%\AssistantClient\gulpfile.js" (
  pushd "%DEPLOYMENT_SOURCE%\AssistantClient"
  echo %time% Executing "%GULP_CMD%" build
  call :ExecuteCmd "%GULP_CMD%" build
  IF !ERRORLEVEL! NEQ 0 goto error
  popd
)

:: 1.2 Gulp Test
IF EXIST "%DEPLOYMENT_SOURCE%\AssistantClient\gulpfile.js" (
  pushd "%DEPLOYMENT_SOURCE%\AssistantClient"
  echo %time% Executing "%GULP_CMD%" test
  call :ExecuteCmd "%GULP_CMD%" test
  IF !ERRORLEVEL! NEQ 0 goto error
  popd
)


:: 2. Build to the temporary path
echo %time% Building
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
  call :ExecuteCmd "%MSBUILD_PATH%" "%DEPLOYMENT_SOURCE%\AssistantClient\AssistantClient.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="%DEPLOYMENT_TEMP%";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release /p:SolutionDir="%DEPLOYMENT_SOURCE%\.\\" %SCM_BUILD_ARGS%
) ELSE (
  call :ExecuteCmd "%MSBUILD_PATH%" "%DEPLOYMENT_SOURCE%\AssistantClient\AssistantClient.csproj" /nologo /verbosity:m /t:Build /p:AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release /p:SolutionDir="%DEPLOYMENT_SOURCE%\.\\" %SCM_BUILD_ARGS%
)

IF !ERRORLEVEL! NEQ 0 goto error



:: 3. KuduSync
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
  echo %time% Kudu Sync
  call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
  IF !ERRORLEVEL! NEQ 0 goto error
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Post deployment stub
IF DEFINED POST_DEPLOYMENT_ACTION call "%POST_DEPLOYMENT_ACTION%"
IF !ERRORLEVEL! NEQ 0 goto error

goto end

:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%

:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul

:exitSetErrorLevel
exit /b 1

:exitFromFunction
()

:end
endlocal
echo Finished successfully.

      

+3


source to share





All Articles