概要

提供されている results オブジェクトを使用して、独自のレポートを生成できます。これは、少なくとも2つの主要な方法で行うことができます。

別ファイルとして

ステップ1. ファイルを作成する

カスタムレポーターを別々のファイル(例: `custom_reporter.js`)に定義します。コールバックまたはPromiseを使用して、レポートが完了したことを通知します。

custom_reporter.js
module.exports = {
  write : function(results, options, done) {
    console.log('custom reporting...');
    
done(); } };
custom_reporter.js
module.exports = {
  write: async function(results, options) {
    
console.log('custom reporting...');
} };

ステップ2. レポーターを実行する

カスタムレポーターへの正しいパスを指定して、次のコマンドを実行します。

nightwatch --reporter=junit --reporter=/path/to/custom_reporter.js

複数のレポート(組み込みのHTMLレポートとcustom_reporter)を生成するには、次のコマンドを実行します - v2.2以降

nightwatch --reporter=/path/to/custom_reporter.js --reporter=html

NPMパッケージとして

カスタムレポーターはNPMに公開することもできます。

  ├── / 
  |   ├── src/
  |   |    ├── my_custom_reporter_lib.js
  |   |    └── my_other_custom_reporter_lib.js
  |   └── test/
  |        ├── test_for_my_custom_reporter_lib.js
  |        └── test_for_my_other_custom_reporter_lib.js
  ├── index.js
  ├── LICENSE.md
  ├── package.json
  └── README.md

NPMパッケージの公開が初めての場合は、スコープのないパブリックパッケージの作成と公開ガイドを最初に読んでください。

`index.js`ファイルは、ファイルベースのカスタムレポーターと同じインターフェースを実装する必要があります。

index.js
module.exports = {
  write: async function(results, options) {
    
console.log('custom reporting...');
} };

使用方法

  1. 使用したいカスタムレポーターのNPMパッケージをインストールします。
npm i <nightwatch-custom-reporter>
  1. カスタムレポーターを使用する
nightwatch --reporter=<nightwatch-custom-reporter>