Karma 没有在 Jenkins CI 中运行,找不到模块 'karma-jasmine'
Posted
技术标签:
【中文标题】Karma 没有在 Jenkins CI 中运行,找不到模块 \'karma-jasmine\'【英文标题】:Karma not running in Jenkins CI, Cannot find module 'karma-jasmine'Karma 没有在 Jenkins CI 中运行,找不到模块 'karma-jasmine' 【发布时间】:2018-03-19 07:25:29 【问题描述】:我正在 Jenkins CI 中设置具有自动测试功能的 Angular 4 SPA。 SPA 是由 Maven 管理的更大项目的一部分,因此构建也是由 Maven 管理的。到目前为止,我已经:
-
在 Jenkins 上安装了 NodeJS 插件,使用从 nodejs.org 安装,版本为 8.6.0
已配置“要安装的全局 npm 包”=“karma-cli phantomjs-prebuilt jasmine-core karma-jasmine karma-phantomjs-launcher karma-junit-reporter karma-coverage”
在 pom.xml 中添加了“maven-karma-plugin”,browsers=PhantomJS / singleRun=true /reporters=dots,junit
在 Jenkins 作业配置中启用“将节点和 npm bin/ 文件夹提供到 PATH”
构建过程开始时很好,但最终我得到:
[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 install:
$ /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”包目前不在列表中的原因是我在某处读到应该使用 karma-cli 代替 karma。但是,添加“karma”包不会改变任何东西。)
知道为什么会弹出“找不到模块'karma-jasmine'”吗?在(2)中你会看到 karma-jasmine 包被列出来了,我在服务器上找到了它,但仍然没有被 NodeJS 插件找到。
谢谢,西蒙
【问题讨论】:
【参考方案1】:我设法通过在构建过程中运行“npm install”来使其工作,然后在本地 npm 包上运行所有内容。
此处描述了整个设置:https://funneltravel.wordpress.com/2017/10/16/running-karma-with-maven-on-jenkins-ci/
【讨论】:
以上是关于Karma 没有在 Jenkins CI 中运行,找不到模块 'karma-jasmine'的主要内容,如果未能解决你的问题,请参考以下文章
使用 Jenkins 从 Karma.js 获得百分比覆盖率
设置Jenkins使用Karma和Eslint进行单元测试和Lint检查
grunt karma 覆盖在 jenkins 上失败,但在 windows/unix 上有效
[karma-server]:TypeError:无法读取未定义的属性“范围”-CI 环境中的 Angular 单元测试