部署azure网站时运行jasmine/karma单元测试

zzoitvuj  于 2021-06-20  发布在  Kudu
关注(0)|答案(0)|浏览(341)

我一直看到在部署到azure网站时能够运行jasmine单元测试的引用,但我似乎无法让它工作,也找不到任何成功的代码。
我在大口喝。我已经配置好了所有的东西,所以在我自己的盒子里我可以运行“吞咽测试”,它成功地启动了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丢失,因为我以前没有package.json,它给了我一个关于二进制丢失的错误。一旦我把它包含在npm中安装,我就开始出现上面的错误。
我看到一些论坛帖子建议azure部署沙盒可能不允许与phantomjs之类的端口通信,所以这可能就是问题所在。如果是这样的话,有没有办法在kudu部署中实际运行jasmine单元测试?
这很长,有一些额外的调试代码,但下面是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.

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题