Skip to content

Commit

Permalink
Merge pull request #15 from adamgruber/develop
Browse files Browse the repository at this point in the history
Fixed indentation and resolved #11
  • Loading branch information
adamgruber committed May 17, 2015
2 parents 6a5c61a + f722aff commit a393022
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 232 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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.1.0
- [Options](#options) support: change the location and/or filename for saved reports
##New in 1.2.0
- New [Option](#options): change the report title in the output

##Features
- At-a-glance stats including pass percentage
Expand All @@ -17,6 +17,7 @@ Mochawesome is a custom reporter for use with the Javascript testing framework,
- Stack trace for failed tests
- Responsive and mobile-friendly
- Saves JSON output for further processing
- Custom report [options](#options)
- Offline viewing

##Browser Support
Expand Down Expand Up @@ -82,7 +83,9 @@ The two main files to be aware of are:


##Options
Mochawesome supports options via environment variables or passed in to mocha via `--reporter-options`. You can change both the location where reports are saved and the filename of the report. *Setting a custom filename will change both the report html and json files.*
Mochawesome supports options via environment variables or passed in to mocha via `--reporter-options`.

With options you can specify the location where reports are saved, the filename of the report and the title of the report in the html output. *Setting a custom filename will change both the report html and json files.*

**Options passed in will take precedence over environment variables.**

Expand All @@ -91,19 +94,21 @@ Mochawesome supports options via environment variables or passed in to mocha via
```bash
$ export MOCHAWESOME_REPORTDIR=customReportDir
$ export MOCHAWESOME_REPORTNAME=customReportName
$ export MOCHAWESOME_REPORTTITLE=customReportTitle
```

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

```js
var mocha = new Mocha({
reporter: 'mochawesome',
reporterOptions: {
reportDir: 'customReportDir',
reportName: 'customReportName'
reportName: 'customReportName',
reportTitle: 'customReportTitle'
}
});
```
Expand Down Expand Up @@ -136,3 +141,6 @@ This will run jshint only, no building will occur.
####`gulp test` - Run Test
After building you can run this to test the reporter and see the output.
*Note: The default gulp task will run this task.*

####`gulp testOpts` - Run Test with Options
After building you can run this to test the reporter and see the output.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#Changelog

###1.2.0
- Enhancement: custom report title option. Closes [#11](https://github.com/adamgruber/mochawesome/issues/11)
- Fixed indentation in code block and stack traces

###1.1.2
- Fixes [#10](https://github.com/adamgruber/mochawesome/issues/10)

Expand Down
13 changes: 12 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ gulp.task('clientScripts', ['lint'], function () {
gulp.task('templates', function () {
var partials = gulp.src(path.join(config.srcHbsDir, '_*.mu'))
.pipe(handlebars({
handlebars: require('handlebars')
handlebars: require('handlebars'),
compilerOptions: {
preventIndent: true
}
}))
.pipe(wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, Handlebars.template(<%= contents %>));', {}, {
imports: {
Expand Down Expand Up @@ -162,6 +165,14 @@ gulp.task('test', function () {
.on('error', console.warn.bind(console));
});

gulp.task('testOpts', function () {
mochaOpts.reporterOptions = 'reportDir=customDir,reportName=customName,reportTitle=customTitle';
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
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function (options) {
// Base Directories
config.libDir = __dirname;
config.reportDir = _getOption('reportDir', options);
config.reportTitle = _getOption('reportTitle', options);
config.nodeModulesDir = path.join(__dirname, '..', 'node_modules');

// Build Directories
Expand Down
13 changes: 11 additions & 2 deletions lib/mochawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ var Base = mocha.reporters.Base,

var totalTestsRegistered = 0;

Highlight.configure({
useBR: true,
languages: ['javascript']
});

module.exports = Mochawesome;

/**
Expand Down Expand Up @@ -75,7 +80,7 @@ function Mochawesome (runner, options) {
traverseSuites(allSuites);

var obj = {
reportTitle: process.cwd().split(config.splitChar).pop(),
reportTitle: config.reportTitle || process.cwd().split(config.splitChar).pop(),
stats: self.stats,
suites: allSuites,
allTests: allTests.map(cleanTest),
Expand Down Expand Up @@ -236,7 +241,11 @@ function cleanTest (test) {
err = test.err ? _.pick( test.err, ['name', 'message', 'stack'] ) : test.err;
if(test.fn){
code = cleanCode(test.fn.toString());
code = Highlight.highlightAuto(code, ['javascript']).value;
code = Highlight.fixMarkup(Highlight.highlightAuto(code).value);
}

if(err && err.stack){
err.stack = Highlight.fixMarkup(Highlight.highlightAuto(err.stack).value);
}

var cleaned = {
Expand Down
Loading

0 comments on commit a393022

Please sign in to comment.