storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/mint/run/core/minio-js/minioreporter.js (about) 1 /* 2 * Minio Reporter for JSON formatted logging, (C) 2017 Minio, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 var mocha = require('mocha'); 18 module.exports = minioreporter; 19 20 function minioreporter(runner) { 21 mocha.reporters.Base.call(this, runner); 22 var self = this; 23 24 runner.on('pass', function (test) { 25 GenerateJsonEntry(test) 26 }); 27 28 runner.on('fail', function (test, err) { 29 GenerateJsonEntry(test, err) 30 }); 31 32 } 33 34 /** 35 * Convert test result into a JSON object and print on the console. 36 * 37 * @api private 38 * @param test, err 39 */ 40 41 function GenerateJsonEntry (test, err) { 42 var res = test.title.split("_") 43 var jsonEntry = {}; 44 45 jsonEntry.name = "minio-js" 46 47 if (res.length > 0 && res[0].length) { 48 jsonEntry.function = res[0] 49 } 50 51 if (res.length > 1 && res[1].length) { 52 jsonEntry.args = res[1] 53 } 54 55 jsonEntry.duration = test.duration 56 57 if (res.length > 2 && res[2].length) { 58 jsonEntry.alert = res[2] 59 } 60 61 if (err != null ) { 62 jsonEntry.status = "FAIL" 63 jsonEntry.error = err.stack.replace(/\n/g, " ").replace(/ +(?= )/g,'') 64 } else { 65 jsonEntry.status = "PASS" 66 } 67 68 process.stdout.write(JSON.stringify(jsonEntry) + "\n") 69 }