Karma没有在Jenkins CI中运行,找不到模块'karma-jasmine'

时间:2017-10-07 18:12:26

标签: jenkins karma-jasmine

我正在Jenkins CI中设置一个带有自动测试功能的Angular 4 SPA。 SPA是Maven管理的大型项目的一部分,因此构建也是Maven管理的。到目前为止,我已经:

  1. 使用版本8.6.0的nodejs.org安装在Jenkins上安装NodeJS插件
  2. 配置“全球npm包安装”=“karma-cli phantomjs-prebuilt jasmine-core karma-jasmine karma-phantomjs-launcher karma-junit-reporter karma-coverage”
  3. 在pom.xml中添加了“maven-karma-plugin”,浏览器= PhantomJS / singleRun = true / reporter = dots,junit
  4. 在Jenkins作业配置上启用“向PATH提供节点&npm bin /文件夹”
  5. 构建过程启动得很好,但最终我得到了:

    [INFO] --- maven-karma-plugin:1.6:start (default) @ webclient ---
    [INFO] Executing Karma Test Suite ...
    /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/bin/karma start /var/lib/jenkins/workspace/funnel_build/webclient/karma.conf.js --browsers PhantomJS --reporters dots,junit --single-run
    07 10 2017 17:07:52.801:ERROR [config]: Error in config file! 
     { Error: Cannot find module 'karma-jasmine' 
        at Function.Module._resolveFilename (module.js:527:15) 
        at Function.Module._load (module.js:476:23) 
        at Module.require (module.js:568:17) 
        at require (internal/module.js:11:18) 
        at module.exports (/var/lib/jenkins/workspace/funnel_build/webclient/karma.conf.js:9:7) 
        at Object.parseConfig (/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/lib/node_modules/karma/lib/config.js:410:5)
    

    构建日志开头的npm安装:

    $ /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/bin/npm install -g karma-cli phantomjs-prebuilt jasmine-core karma-jasmine karma-phantomjs-launcher karma-junit-reporter karma-coverage
    /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/bin/karma -> /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/lib/node_modules/karma-cli/bin/karma
    /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/bin/phantomjs -> /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/lib/node_modules/phantomjs-prebuilt/bin/phantomjs
    
    > phantomjs-prebuilt@2.1.15 install /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/lib/node_modules/phantomjs-prebuilt
    > node install.js
    
    Considering PhantomJS found at /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/bin/phantomjs
    Looks like an `npm install -g`
    Could not link global install, skipping...
    Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
    Verified checksum of previously downloaded file
    Extracting tar contents (via spawned process)
    Removing /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/lib/node_modules/phantomjs-prebuilt/lib/phantom
    Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1507388835905/phantomjs-2.1.1-linux-x86_64 -> /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/lib/node_modules/phantomjs-prebuilt/lib/phantom
    Writing location.js file
    Done. Phantomjs binary available at /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/Node.js_8.6.0/lib/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
    npm WARN karma-jasmine@1.1.0 requires a peer of karma@* but none was installed.
    npm WARN karma-junit-reporter@1.2.0 requires a peer of karma@>=0.9 but none was installed.
    npm WARN karma-phantomjs-launcher@1.0.4 requires a peer of karma@>=0.9 but none was installed.
    
    + karma-phantomjs-launcher@1.0.4
    + karma-coverage@1.1.1
    + karma-jasmine@1.1.0
    + karma-cli@1.0.1
    + karma-junit-reporter@1.2.0
    + jasmine-core@2.8.0
    + phantomjs-prebuilt@2.1.15
    updated 7 packages in 10.553s
    

    (包裹'业力'目前不在列表中的原因是我在某处读到应该用karma-cli来代替业力。但是,添加'业力'包不会改变任何东西。)< / p>

    任何想法为什么会出现“无法找到模块'karma-jasmine'”?在(2)中你会看到列出了karma-jasmine包,我在服务器上找到它,但是仍然没有找到NodeJS插件。

    谢谢,西蒙

1 个答案:

答案 0 :(得分:0)

我设法通过在构建过程中运行“npm install”来运行它,然后在本地npm包上运行所有内容。

此处描述了整个设置:https://funneltravel.wordpress.com/2017/10/16/running-karma-with-maven-on-jenkins-ci/