使用Selify+伊斯坦布尔的Java代码覆盖率 [英] javascript code coverage using Selenium + istanbul

查看:22
本文介绍了使用Selify+伊斯坦布尔的Java代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人能帮我讲解如何在运行Selify测试用例的同时使用伊斯坦布尔获得JavaScript代码覆盖率?

我已通过this链接,但无法获取。在我的案例中,我该如何使用它?我的测试在调用远程服务器的本地浏览器中运行。 Selify测试用例是用Java编写的。

推荐答案

https://github.com/alex028502/istanbulseleniumexample

我也很难理解,所以我和webpack一起做了上面的例子。

module.exports = {
  devtool: 'source-map',
  mode: 'none',
  module: {
    rules: [
      // { test: /.js$/, loader: 'babel-loader', exclude: /node_modules/ },
      {
        resolve: {
          extensions: ['.js'],
        },
        use: {
          loader: 'istanbul-instrumenter-loader',
          options: {esModules: true},
        },
        enforce: 'post',
        exclude: /node_modules/,
      },
      {
        test: /.coffee$/,
        use: [
          {loader: 'coffee-loader'},
        ],
      },
    ],
  },
  entry: './src/index.js',
  output: {
    path: __dirname + '/public/',
    filename: 'index.js',
  },
};

然后,如果您在浏览器中运行插入指令的代码,则可以像这样下载它

coverage_info = _driver.execute_script('return JSON.stringify(window.__coverage__);')
# each report needs a unique name
# but we don't care for this example which report corresponds
# to which test
timestamp = datetime.datetime.timestamp(datetime.datetime.now())
file = open("nyc_output/coverage%s.json" % timestamp, 'w')
file.write(coverage_info)
file.close()

然后生成这样的报告

node_modules/.bin/nyc report -t nyc_output

如果您没有使用webpack,则只需使用粘贴的示例中的命令行检测您的代码,它将创建一个包含检测的代码的新文件夹。

# from https://medium.com/@the1mills/front-end-javascript-test-coverage-with-istanbul-selenium-4b2be44e3e98
mkdir public-coverage
cp -a public/. public-coverage/   # copy all files over
istanbul instrument public  
    --output public-coverage 
    --embed-source true

您提到的链接中我可以不使用的部分是伊斯坦布尔中间件

这篇关于使用Selify+伊斯坦布尔的Java代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆