部署Azure网站时运行Jasmine / Karma单元测试

时间:2014-12-05 02:29:20

标签: unit-testing azure azure-web-sites karma-jasmine kudu

我一直看到在部署到Azure网站时能够运行Jasmine单元测试的参考,但我似乎无法使其工作,并且无法找到任何成功的代码。

我正在使用gulp。我已将所有配置都配置在我自己的盒子上,我可以运行" gulp test"它成功启动了Karma,然后通过PhantomJS运行测试。但是当我部署时,我在日志中看到以下内容:

[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

我在deploy.cmd中使用以下代码运行测试:

这是test.js gulp任务:

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;
        });
});

这是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
  });
};

而且我很确定问题不是PhantomJS丢失,因为我之前没有将它包含在内。它会给我一个关于二进制丢失的错误。一旦我将其包含在npm中进行安装,我就开始收到上述错误。

我已经看到一些论坛帖子暗示Azure部署沙箱可能不允许与PhantomJS等端口进行通信,所以可能这就是问题所在。如果是这样,有没有办法实际运行Jasmine单元测试作为Kudu部署的一部分?

这很长,有一些额外的调试代码,但这里是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.

0 个答案:

没有答案