Angular学习笔记74:使用 Phantomjs 模拟浏览器进行Jenkins 持续构建测试

22 篇文章 0 订阅

在 Jenkins + SonarQube 中,使用 ng test --code-coverage --watch=false只是来获取覆盖率,关于 Bugs 、Code Smells、Duplications 可以使用 Sonar-Scanner 来获取,所以使用 Phantomjs 模拟浏览器从而获取覆盖率。

安装PhantomJS

1. 下载PhantomJS

下载PhantomJS Windows 版本

下载PhantomJS MacOS 版本

下载PhantomJS Linux 64位 版本

2. 配置 Phantomjs

解压下载后的压缩包,将其添加到环境变量中。

  • 执行vi .zshrc在其中添加
# phantomjs
export PHANTOMJS_HOME=/Users/wjy/Documents/phantomjs/phantomjs-2.1
export PATH=$PATH:$PHANTOMJS_HOME/bin
  • 执行source .zshrc

  • 验证安装

phantomjs --version

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JKGYudFS-1571731737356)(evernotecid://621D2FF6-4E72-4E02-9043-55F31F42819B/appyinxiangcom/22553815/ENResource/p250)]

3. 在项目中安装 karma-phantomjs-launcher

在项目中执行命令:

npm install --save-dev karma-phantomjs-launcher

4. 修改 karma 配置文件

修改 karma.conf.js 配置文件

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-phantomjs-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, 'coverage'), reports: ['html', 'lcovonly'],
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    singleRun: false,
    browsers: ['PhantomJS'],
    phantomjsLauncher: {
      exitOnResourceError: true
    }
  });
};

5. 重新执行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值