1

カバレッジ レポートの livereload を有効にしようとしています。このレポートを生成するための私のツールはkarma-coverageで、このレポートを次のフォルダーに生成します: test/coverage/html-report

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

レポートが生成されたら、grunt-contrib-connectを使用し、次を使用して生成されたレポートを提供します。

 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 をインターセプトし、このスクリプトを追加するために処理する方法はありますか?

4

1 に答える 1

0

これが役立つかもしれません: 次のように、接続サーバーへのリクエストをインターセプトするために使用できるミドルウェアを追加できます。

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

于 2016-05-06T13:54:01.883 に答える