我需要在我的覆盖率测试报告中启用livereload



我一直在尝试为我的覆盖率报告启用livereload。我生成此报告的工具是因果报应覆盖率,我在以下文件夹中生成此报告:test/coverage/html/report

 -test
 |
 |-- coverage
     |
     |-- report-html
         |
         |-- index.html

当生成报告时,我使用grunt contrib连接并使用以下方法提供生成的报告:

 var COVERAGE_BASE = './test/coverage/report-html',
   ...
   ...
   ...
   connect: {
      server: {
        options: {
          port: 9000,
          base: '.',
          open: false
        }
      },
      dist:{
        options: {
          keepalive: true,
          port: 9000,
          base: './dist',
          open: false
        }
      },
      coverage: {
        options: {
          keepalive: true,
          port: 9001,
          base: COVERAGE_BASE ,
          open: false
        }
      }
    }

当我执行任务grunt coverage时,我的配置是

COVERAGE_TASKS = ['shell:test','open:coverage', 'connect:coverage','watch'];
grunt.registerTask('coverage', COVERAGE_TASKS);

我的想法是"拦截"index.html并将脚本注入到livereload

<script src="//localhost:35729/livereload.js"></script>

在提供连接包并处理它以添加此脚本之前,是否存在拦截index.html的方法?

这可能会有所帮助:你可以添加中间软件,可以用来拦截请求到你的连接服务器,如下所示:

grunt.initConfig({
  connect: {
    server: {
      options: {
        middleware: [
          function myMiddleware(req, res, next) {
            
            // DO YOUR THING HERE!!!!
            res.end('Hello, world!');
          }
        ],
      },
    },
  },
});

最新更新