Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Boyd committed Jun 10, 2015
0 parents commit 52eb432
Show file tree
Hide file tree
Showing 341 changed files with 50,358 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.log
test/results
coverage
node_modules


17 changes: 17 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"maxerr" : 50, // {int} Maximum error before stopping
"indent" : 4, // {int} Number of spaces to use for indentation
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : true, // true: Prohibit use of empty blocks
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // Unused variables:
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
"node" : true // Node.js
}
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
node_js:
- "0.12"
- "0.11"
- "0.10"
os:
- linux
before_install: npm install grunt-cli grunt-env grunt-concurrent
before_script: chmod 0777 ./node_modules/.bin/mocha
after_script: grunt test:browser
after_script: istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
80 changes: 80 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

var _ = require('lodash');

var desireds = require('./test/browser/browserTestConfig');

var gruntConfig = {
env: {
// dynamically filled
},
concurrent: {
'test-browser': []
},
jshint: {
files: ['lib/*', 'test/*', '*.jsg'],
options: {
jshintrc: '.jshintrc'
}
},
/* jshint camelcase:false */
mocha_istanbul: {
coverage: {
src: ['test/*.js']
}
},
mochaTest: {
test: {
options: {
reporter: 'spec',
//quiet: false,
//clearRequireCache: true
},
src: ['test/*.js']
},
browser: {
options: {
timeout: 60000,
reporter: 'spec'
},
src: ['test/browser/*.js']
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
}
}

_.forIn(desireds, function (desired, key) {
gruntConfig.env[key] = {
DESIRED: JSON.stringify(desired)
};
gruntConfig.concurrent['test-browser'].push('test:browser:' + key);
});

module.exports = function (grunt) {

grunt.initConfig(gruntConfig);

grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-concurrent');

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-mocha-istanbul');

grunt.registerTask('cover', ['mocha_istanbul']);
grunt.registerTask('lint', ['jshint']);
grunt.registerTask('test', ['mochaTest:test']);
grunt.registerTask('test:browser', ['concurrent:test-browser']);

grunt.registerTask('default', ['jshint', 'cover']);

_.forIn(desireds, function (desired, key) {
grunt.registerTask('test:browser:' + key, ['env:' + key, 'mochaTest:browser']);
});
};


19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2015 Nathan Boyd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
REPORTER = spec

test-bdd:
@./node_modules/.bin/mocha \
--reporter $(REPORTER) \
--ui bdd \
test/*.js

test-all: test-bdd

.PHONY: test-all
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# report-generator

[![Build Status](https://travis-ci.org/nathan-boyd/report-generator.svg?branch=master)](https://travis-ci.org/nathan-boyd/report-generator) [![Coverage Status](https://coveralls.io/repos/nathan-boyd/report-generator/badge.svg?branch=master)](https://coveralls.io/r/nathan-boyd/report-generator?branch=master)

[![Sauce Test Status](https://saucelabs.com/browser-matrix/nathan-boyd.svg?auth=9459ca78bd664316a0cf84e43a98658a)](https://saucelabs.com/u/nathan-boyd)

report-generator encapsulates the task of creating simple html reports.

##quick example
```javascript

var reportGenerator = require('report-generator');

var generator new reportGenerator('report.html', ['col1', 'col2'], function (err) {
assert(err === null);
});

// write a simple row
generator.writeRow(['cell1', 'cell2'], function (err) {
assert(err === null);
});

// write a row using a cell object, with color support
var cells = [
{cellContent: '1', color: "red"},
{cellContent: '2', color: "red"}
];

var row = [cells];

generator.writeRows(row, function (err) {
assert(err === null);
done();
});

generator.closeReport(function(err){
assert(err === null);
});

```
113 changes: 113 additions & 0 deletions lib/report-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
'use strict';
var html = require("html");
var fs = require('fs');

(function () {

function ReportGenerator(reportFileName, columnNames, next) {

var self = this;

self.report = '';

next = (typeof next === 'function') ? next : function () {
};

if (!reportFileName) {
return next(new Error('_reportFileName parameter null'));
}

if (!columnNames) {
return next(new Error('columnNames parameter null'));
}

if (!Array.isArray(columnNames)) {
return next(new Error('columnNames parameter is not an array'));
}

self._reportFileName = reportFileName;
self._columnNames = columnNames;

var block = '<HTML>' +
'<BODY>' +
'<Table id="reportTable" align="center" border=.5 cellpadding=3 cellspacing=.5>';

self.report = self.report.concat(block);

//todo write a proper header row
self.writeRows(columnNames, next);
}

ReportGenerator.prototype.writeRows = function (rows, next) {

var self = this;

next = (typeof next === 'function') ? next : function () {
};

if (!rows) {
return next(new Error('rows is null'));
}

if (!Array.isArray(rows)) {
return next(new Error('rows parameter is not an array'));
}

var cells = '<TR>';
rows.forEach(function (row) {

if (typeof row === 'string' || row instanceof String) {
cells = cells.concat('<TD><pre>' + row + '</pre></TD>');
} else {
row.forEach(function (cell) {

var backgroundColor = '#FFFFFF';
if (cell.color) {
backgroundColor = cell.color;
}

var content = cell;
if (cell.cellContent) {
content = cell.cellContent;
}

cells = cells.concat('<TD bgcolor="' + backgroundColor + '"><pre>' + content + '</pre></TD>');
});
}
cells = cells.concat('</TR>');
});

self.report = self.report.concat(cells);
next(null);
};

ReportGenerator.prototype.closeReport = function (next) {

var self = this;

var block = '</Table>' +
'</BODY>' +
'</HTML>';

self.report = self.report.concat(block);

// get string size in bytes
var stringByteSize = Buffer.byteLength(self.report, 'utf8');

// pretty if string is less than half a MB
if (stringByteSize < 500000) {
/* jshint camelcase:false */
block = html.prettyPrint(self.report, {indent_size: 2});
}

try {
fs.writeFile(self._reportFileName, block, next);
}
catch (ex) {
return next(new Error(ex));
}

};

module.exports = ReportGenerator;
}());
15 changes: 15 additions & 0 deletions node_modules/.bin/_mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/_mocha.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node_modules/.bin/mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/mocha.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions node_modules/chai/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52eb432

Please sign in to comment.