カスタムレポーターを作成する
概要
提供されている 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に公開することもできます。
例
NPMパッケージの公開が初めての場合は、スコープのないパブリックパッケージの作成と公開ガイドを最初に読んでください。
`index.js`ファイルは、ファイルベースのカスタムレポーターと同じインターフェースを実装する必要があります。
index.js
module.exports = {
write: async function(results, options) {
console.log('custom reporting...');
}
};
使用方法
- 使用したいカスタムレポーターのNPMパッケージをインストールします。
npm i <nightwatch-custom-reporter>
- カスタムレポーターを使用する
nightwatch --reporter=<nightwatch-custom-reporter>