Name: js-handler/node_modules/nodeunit/node_modules/tap/lib/tap-cov-html.js 
1:
var fs = require('fs'),
2:
    path = require('path'),
3:
    asyncMap = require("slide").asyncMap,
4:
    util = require('util');
5:
 
6:
var CovHtml = module.exports = function(cov_stats, cov_dir, cb) {
7:
  var index = [];
8:
 
9:
  asyncMap(
10:
    Object.keys(cov_stats),
11:
    function(f, cb) {
12:
      var st = cov_stats[f],
13:
          missing_lines = st.missing.map(function(l) {
14:
            return l.number;
15:
          }),
16:
          out = '<!doctype html>\n<html lang="en">\n<head>\n  ' +
17:
                '<meta charset="utf-8">\n  <title>' +
18:
 
19:
      f + ' (' + st.loc + ')</title>\n' +
20:
      '<style type="text/css">\n' +
21:
      'li {\n' +
22:
      '  font-family: monospace;\n' +
23:
      '  white-space: pre;\n' +
24:
      '}\n' +
25:
      '</style>\n' +
26:
      '</head>\n<body>\n' +
27:
      '<h1>' + f + ' (' + st.loc + ')' + '</h1>' +
28:
      '<h2>Run: ' + (st.missing.length ? st.loc - st.missing.length : st.loc) + ', Missing: ' +
29:
      st.missing.length + ', Percentage: ' + st.percentage + '</h2>' +
30:
      '<h2>Source:</h2>\n' +
31:
      '<ol>\n' +
32:
      st.lines.map(function(line) {
33:
        var number = line.number,
34:
            color = (missing_lines.indexOf(number) !== -1) ? '#fcc' : '#cfc';
35:
        return '<li id="L' + line.number + '" style="background-color: ' + color +
36:
               ';">' + line.source.replace(/</g, "<") + '</li>';
37:
      }).join('\n') +
38:
      '</ol>\n' +
39:
      '<h2>Data</h2>\n'+
40:
      '<pre>' + util.inspect(st, true, Infinity, false).replace(/</g, "<") + '</pre></body>\n</html>';
41:
 
42:
      fs.writeFile(
43:
        cov_dir + '/' +
44:
        f.replace(process.cwd() + '/', '').replace(/\//g, '+') + '.html',
45:
        out,
46:
        'utf8',
47:
        function(err) {
48:
          if (err) {
49:
            throw err;
50:
          }
51:
          index.push(f);
52:
          cb();
53:
        });
54:
    },
55:
    function(err) {
56:
      if (err) {
57:
        throw err;
58:
      }
59:
      var out = '<!doctype html>\n<html lang="en">\n<head>\n  ' +
60:
          '<meta charset="utf-8">\n  <title>Coverage Index</title>\n</head>\n' +
61:
          '<body>\n<h1>Code Coverage Information</h1>\n<ul>' +
62:
          index.map(function(fname) {
63:
            return '<li><a href="' +
64:
            fname.replace(process.cwd() + '/', '').replace(/\//g, '+') + '.html' +
65:
            '">' + fname + '</a></li>';
66:
          }).join('\n') + '</ul>\n</body>\n</html>';
67:
 
68:
      fs.writeFile(cov_dir + '/index.html', out, 'utf8', function(err) {
69:
        if (err) {
70:
          throw err;
71:
        }
72:
        cb();
73:
      });  
74:
    }
75:
  );
76:
};