Skip to content

Commit

Permalink
Merge pull request #28 from adamgruber/develop
Browse files Browse the repository at this point in the history
1.2.2
  • Loading branch information
adamgruber committed Jan 19, 2016
2 parents b9b86f6 + 7186625 commit 9c6a1fd
Show file tree
Hide file tree
Showing 17 changed files with 309 additions and 81 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ mochawesome

Mochawesome is a custom reporter for use with the Javascript testing framework, [mocha](http://visionmedia.github.io/mocha/). It generates a full fledged HTML/CSS report that helps visualize your test suites.

##New in 1.2.0
- New [Option](#options): change the report title in the output
##New in 1.2.2
- New [Options](#options):
- change the report title in the output
- generate report with assets inlined

##Features
- At-a-glance stats including pass percentage
Expand Down Expand Up @@ -95,11 +97,12 @@ With options you can specify the location where reports are saved, the filename
$ export MOCHAWESOME_REPORTDIR=customReportDir
$ export MOCHAWESOME_REPORTNAME=customReportName
$ export MOCHAWESOME_REPORTTITLE=customReportTitle
$ export MOCHAWESOME_INLINEASSETS=true
```

####Mocha options
```bash
$ mocha test.js --reporter mochawesome --reporter-options reportDir=customReportDir,reportName=customReportName,reportTitle=customReportTitle
$ mocha test.js --reporter mochawesome --reporter-options reportDir=customReportDir,reportName=customReportName,reportTitle=customReportTitle,inlineAssets=true
```

```js
Expand All @@ -108,7 +111,8 @@ var mocha = new Mocha({
reporterOptions: {
reportDir: 'customReportDir',
reportName: 'customReportName',
reportTitle: 'customReportTitle'
reportTitle: 'customReportTitle',
inlineAssets: true
}
});
```
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Changelog

###1.2.2
- Added option to generate report with all assets inlined. See [#26](https://github.com/adamgruber/mochawesome/issues/26)

###1.2.1
- Reset `totalTestsRegistered` when reporter is run. [PR #21](https://github.com/adamgruber/mochawesome/pull/21)

Expand Down
1 change: 1 addition & 0 deletions dist/css/mochawesome-64.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/css/mochawesome.css

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions dist/js/vendor.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,12 @@ gulp.task('test', function () {
});

gulp.task('testOpts', function () {
mochaOpts.reporterOptions = 'reportDir=customDir,reportName=customName,reportTitle=customTitle';
mochaOpts.reporterOptions = 'reportDir=customDir,reportName=customName,reportTitle=customTitle,inlineAssets=true';
return gulp.src(testPaths.basic)
.pipe(mocha(mochaOpts))
.on('error', console.warn.bind(console));
});


// Default/Combo Tasks
gulp.task('build', ['lint'], function () {
return gulp.start('assemble');
Expand Down
9 changes: 5 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = function (options) {
config.libDir = __dirname;
config.reportDir = _getOption('reportDir', options);
config.reportTitle = _getOption('reportTitle', options);
config.inlineAssets = _getOption('inlineAssets', options, true);
config.nodeModulesDir = path.join(__dirname, '..', 'node_modules');

// Build Directories
Expand Down Expand Up @@ -53,17 +54,17 @@ module.exports = function (options) {
return config;
};

function _getOption (optToGet, options) {
function _getOption (optToGet, options, isBool) {
var envVar = 'MOCHAWESOME_' + optToGet.toUpperCase();
// Order of precedence
// 1. Config option
// 2. Environment variable
// 3. Base config
if (options && typeof options[optToGet] !== 'undefined') {
return options[optToGet];
return isBool ? options[optToGet] === 'true' : options[optToGet];
}
if (typeof process.env[envVar] !== 'undefined') {
return process.env[envVar];
return isBool ? process.env[envVar] === 'true' : process.env[envVar];
}
return config[optToGet];
return isBool ? config[optToGet] === 'true' : config[optToGet];
}
3 changes: 2 additions & 1 deletion lib/mochawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Mochawesome (runner, options) {
// Create/Save necessary report dirs/files
var reporterOpts = options.reporterOptions || {},
config = conf(reporterOpts);

generateReport(config);

var self = this;
Expand Down Expand Up @@ -83,6 +83,7 @@ function Mochawesome (runner, options) {

var obj = {
reportTitle: config.reportTitle || process.cwd().split(config.splitChar).pop(),
inlineAssets: config.inlineAssets,
stats: self.stats,
suites: allSuites,
allTests: allTests.map(cleanTest),
Expand Down
12 changes: 9 additions & 3 deletions lib/reportGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ exports.saveToFile = saveToFile;

function generateReport (config) {
console.log('[' + chalk.gray('mochawesome') + '] Generating report files...\n');
if (config.inlineAssets) {
return createDirs(config, true, _.noop);
}
async.auto({
createDirs: function(callback) {
// console.log('createDirs');
// async code to create directories to store files
createDirs(config, callback);
createDirs(config, null, callback);
},
copyStyles: ['createDirs', function(callback) {
// after creating directories,
Expand All @@ -38,8 +41,11 @@ function generateReport (config) {
}


function createDirs (config, callback) {
var dirs = [config.reportDir, config.reportJsDir, config.reportFontsDir, config.reportCssDir];
function createDirs (config, inline, callback) {
var dirs = [config.reportDir];
if (!inline) {
dirs = dirs.concat([config.reportJsDir, config.reportFontsDir, config.reportCssDir]);
}
dirs.forEach(function(dir) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
Expand Down
Loading

0 comments on commit 9c6a1fd

Please sign in to comment.