Development With Har

Filter by response code:


#!/usr/bin/node
module.paths.push('/usr/lib/node_modules');
const fs = require('fs');
var data = {};
var params = process.argv[2];
function read(config={}){
  fs.readFile(params,'utf8',function(err,data){
    if(err) throw err;
    data = JSON.parse(data).log.entries;
    if(config.by.length>0){
      if(config.by[0]=='status'){
        data = data.filter(function(v){return v.response.status==config.by[1]}).map(function(v){return v.request.url});
      }
    };
    if(config.save){
      save()
    }else{
      console.log(data)
    }
  })
};
function save(){
  fs.writeFile(params.replace(/(\.har)$/,"-output$1"),JSON.stringify(data),function(err){if(err) throw err})
};
read({
  save:false,
  by:['status',404]
})

Tidak ada komentar:

Posting Komentar